package com.mgm.mcrm.allotment.controllers; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.mgm.mcrm.allotment.dtos.request.OtherAllotmentDashboardGetDataRequest; import com.mgm.mcrm.allotment.services.OtherAllotmentService; import com.mgm.mcrm.basesetting.daylight.dtos.response.CfgOtherSegmentResponse; import com.mgm.mcrm.basesetting.room.services.OtherSegmentService; import com.mgm.mcrm.common.dtos.QueryFilter; import com.mgm.mcrm.common.dtos.excelmodel.ExportDefine; import com.mgm.mcrm.common.dtos.excelmodel.GroupItem; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Strings; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson.JSONObject; import com.mgm.mcrm.common.annotation.security.CheckPermission; import com.mgm.mcrm.common.dtos.AjaxResult; import com.mgm.mcrm.appsetting.dtos.OtherDashboardExportRow; import com.mgm.mcrm.common.utils.ExcelUtils; @Tag(name = "Allotment", description = "APIs for Room Allotment functions") @RestController @RequestMapping("/crm_api") public class OtherAllotmentDashboardController { @Resource private OtherAllotmentService allotmentService; @Resource private OtherSegmentService segmentService; @CheckPermission(routerId="00404",permissionCode="VIEW") @RequestMapping(value = "/app/other_allotment_dashboard/get_dashboard_column", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") public AjaxResult getAllotmentDashboardSegment(@RequestBody(required=false)OtherAllotmentDashboardGetDataRequest otherAllotmentDashboardGetDataRequest) { boolean isSuccess = false; String processMessage=""; String errorCode=""; AjaxResult processResult = new AjaxResult(); //-- List allotmentDashboard = allotmentService.getDashboardColumns(otherAllotmentDashboardGetDataRequest); if(allotmentDashboard!=null) { isSuccess = true; processMessage = "Query Successed"; processResult.setData(allotmentDashboard); }else { isSuccess = false; processMessage = "Query Failed with Error."; errorCode = "ERR_DATA_NOT_FOUND"; } //-- processResult.setSuccess(isSuccess); processResult.setErrorCode(errorCode); processResult.setMessage(processMessage); return processResult; } @CheckPermission(routerId="00404",permissionCode="VIEW") @RequestMapping(value = "/app/other_allotment_dashboard/get_dashboard_data", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") public AjaxResult getOtherAllotmentViewById(@RequestBody(required=false) OtherAllotmentDashboardGetDataRequest OtherAllotmentDashboardGetDataRequest) { boolean isSuccess = false; String processMessage=""; String errorCode=""; AjaxResult processResult = new AjaxResult(); //-- List allotment = allotmentService.getDashboardData(OtherAllotmentDashboardGetDataRequest); if(allotment!=null) { isSuccess = true; processMessage = "Query Successed"; processResult.setData(allotment); }else { isSuccess = false; processMessage = "Query Failed with Error."; errorCode = "ERR_DATA_NOT_FOUND"; } //-- processResult.setSuccess(isSuccess); processResult.setErrorCode(errorCode); processResult.setMessage(processMessage); return processResult; } @CheckPermission(routerId="00404",permissionCode="EXPORT") @RequestMapping(value = "/app/other_allotment_dashboard/export_excel") public void exportExcel(HttpServletRequest request, HttpServletResponse response,@RequestBody(required=false) OtherAllotmentDashboardGetDataRequest otherAllotmentDashboardGetDataRequest) throws Exception { ExportDefine reportDef = ExcelUtils.getExportDefineByName("EXPORT_OTHER_DASHBOARD"); if(reportDef!=null) { //-- List searchBookDate = otherAllotmentDashboardGetDataRequest.getSearchBookDate(); if(searchBookDate!=null && !searchBookDate.isEmpty()) { List dateList = new ArrayList(searchBookDate); otherAllotmentDashboardGetDataRequest.setSearchBookDate(dateList); }else { otherAllotmentDashboardGetDataRequest.setSearchBookDate(null); } String searchSegmentId = otherAllotmentDashboardGetDataRequest.getSegmentId(); List segments= segmentService.listOtherSegment(new QueryFilter()); String segmentLable = "Segment:"; List segmentData = new ArrayList(); if(segments!=null) { for(int i=0;i0?",":"")+segments.get(i).getSegmentName(); }else if(Strings.CS.equals(searchSegmentId, String.valueOf(segments.get(i).getId()))) { segmentLable+= segments.get(i).getSegmentName(); break; } } } segmentData.add(segmentLable); List listDashboardExportData = allotmentService.getDashboardExportData(otherAllotmentDashboardGetDataRequest); String reportFileName = "OtherPropertyDashboard.xlsx"; Map exportData = new HashMap<>(); exportData.put("segmentFilter",segmentData); exportData.put("masterData", listDashboardExportData); List dashboardCols = allotmentService.getDashboardColumns(otherAllotmentDashboardGetDataRequest); List roomItems = new ArrayList(); for(JSONObject col:dashboardCols) { GroupItem groupItem = new GroupItem(); groupItem.setItemText(col.getString("channelName")); groupItem.setItemKey(col.getString("channelKey")); groupItem.setHeaderIndex(0); roomItems.add(groupItem); } Map> groupInfos = new HashMap>(); groupInfos.put("CHANNEL_GROUP", roomItems); try { ExcelUtils.exportToResponse(reportDef, reportFileName, exportData,groupInfos, response,request,null); }catch(Exception err) { ExcelUtils.errorResponse(err.getMessage(),request, response); } }else { ExcelUtils.errorResponse("EXPORT_OTHER_DASHBOARD not found",request, response); } } }