157 lines
6.3 KiB
Java
157 lines
6.3 KiB
Java
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<JSONObject> 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<JSONObject> 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<String> searchBookDate = otherAllotmentDashboardGetDataRequest.getSearchBookDate();
|
|
if(searchBookDate!=null && !searchBookDate.isEmpty()) {
|
|
List<String> dateList = new ArrayList<String>(searchBookDate);
|
|
otherAllotmentDashboardGetDataRequest.setSearchBookDate(dateList);
|
|
}else {
|
|
otherAllotmentDashboardGetDataRequest.setSearchBookDate(null);
|
|
}
|
|
String searchSegmentId = otherAllotmentDashboardGetDataRequest.getSegmentId();
|
|
List<CfgOtherSegmentResponse> segments= segmentService.listOtherSegment(new QueryFilter());
|
|
String segmentLable = "Segment:";
|
|
List<String> segmentData = new ArrayList<String>();
|
|
if(segments!=null) {
|
|
for(int i=0;i<segments.size();i++) {
|
|
if(StringUtils.isBlank(searchSegmentId)) {
|
|
segmentLable+=(i>0?",":"")+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<OtherDashboardExportRow> listDashboardExportData = allotmentService.getDashboardExportData(otherAllotmentDashboardGetDataRequest);
|
|
String reportFileName = "OtherPropertyDashboard.xlsx";
|
|
Map<String,List> exportData = new HashMap<>();
|
|
exportData.put("segmentFilter",segmentData);
|
|
exportData.put("masterData", listDashboardExportData);
|
|
List<JSONObject> dashboardCols = allotmentService.getDashboardColumns(otherAllotmentDashboardGetDataRequest);
|
|
List<GroupItem> roomItems = new ArrayList<GroupItem>();
|
|
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<String, List<GroupItem>> groupInfos = new HashMap<String,List<GroupItem>>();
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|