package com.zzg.web.controller.state;
|
|
import com.alibaba.excel.EasyExcelFactory;
|
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.github.pagehelper.PageInfo;
|
import com.zzg.common.constant.state.UrlConstants;
|
import com.zzg.common.core.domain.AjaxResult;
|
import com.zzg.common.core.domain.entity.state.StateSettlement;
|
import com.zzg.common.core.domain.entity.system.SysDept;
|
import com.zzg.common.enums.SettledProcessEnum;
|
import com.zzg.common.enums.SubmitStatusEnum;
|
import com.zzg.common.exception.GlobalException;
|
import com.zzg.common.utils.file.FileUtils;
|
import com.zzg.system.convert.StateProjectConvert;
|
import com.zzg.system.convert.easyExcel.MultiDropdownWriteHandler;
|
import com.zzg.system.domain.bo.ImportSettlementBO;
|
import com.zzg.system.domain.bo.SettlementBO;
|
import com.zzg.system.domain.bo.SettlementDetailBO;
|
import com.zzg.system.domain.bo.StateExecutionBO;
|
import com.zzg.system.domain.bo.WorkFlowSubmitBO;
|
import com.zzg.system.domain.vo.HouseholdVO;
|
import com.zzg.system.domain.vo.NotResettlementHouseholdExportVO;
|
import com.zzg.system.domain.vo.ProjectExecutionSumVO;
|
import com.zzg.system.domain.vo.ResettlementHouseholdExportVO;
|
import com.zzg.system.domain.vo.SettlementDetailPageVO;
|
import com.zzg.system.domain.vo.SettlementSumVO;
|
import com.zzg.system.domain.vo.StateExecutionDetailExportVO;
|
import com.zzg.system.domain.vo.StateExecutionDetailVO;
|
import com.zzg.system.service.state.StateSettlementService;
|
import com.zzg.system.service.system.ISysDeptService;
|
import com.zzg.web.core.enums.TemplateFileTypeEnum;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.http.MediaType;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.lang.reflect.Method;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
import static com.zzg.system.service.state.impl.StateSettlementImpl.extractNumber;
|
|
@RequiredArgsConstructor
|
@RestController
|
@Slf4j
|
public class StateSettlementController {
|
|
private final StateSettlementService settlementService;
|
private final ISysDeptService deptService;
|
|
@ApiOperation(value = "安置情况保存", notes = "安置情况保存")
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_SAVE)
|
public AjaxResult<List<StateSettlement>> saveSettlement(@RequestBody List<StateSettlement> stateSettlement) {
|
settlementService.saveOrUpdateSettlement(stateSettlement);
|
return AjaxResult.success(stateSettlement);
|
}
|
|
@ApiOperation(value = "安置情况删除", notes = "安置情况删除")
|
@GetMapping(UrlConstants.STATE_SETTLEMENT_DEL)
|
public AjaxResult<Boolean> delSettlement(@RequestParam String settlementId) {
|
settlementService.deleteSettlement(settlementId);
|
return AjaxResult.success(true);
|
}
|
|
@ApiOperation(value = "安置详情", notes = "安置详情")
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_DETAIL_LIST)
|
public AjaxResult<SettlementDetailPageVO> listSettlementDetail(@RequestBody SettlementDetailBO settlementBO) {
|
return AjaxResult.success(settlementService.listDetailData(settlementBO));
|
}
|
|
@ApiOperation(value = "安置详情-回显", notes = "安置详情-回显")
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_DETAIL_UPDATE_LIST)
|
public AjaxResult<SettlementDetailPageVO> listSettlementDetailUpdate(@RequestBody SettlementDetailBO settlementBO) {
|
return AjaxResult.success(settlementService.listDetailUpdateData(settlementBO));
|
}
|
|
@ApiOperation(value = "外层项目实施数据", notes = "外层项目实施数据")
|
@GetMapping(UrlConstants.STATE_SETTLEMENT_SUM)
|
public AjaxResult<SettlementSumVO> sumSettled(@RequestParam String projectId) {
|
return AjaxResult.success(settlementService.sumSettleData(projectId));
|
}
|
// 安置情况页面 数据
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_LIST)
|
public AjaxResult<PageInfo<HouseholdVO>> listSettlement(@RequestBody SettlementBO settlementBO) {
|
return AjaxResult.success(settlementService.listSettleData(settlementBO));
|
}
|
// 安置情况页面 导出
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_EXPORT)
|
public AjaxResult<Void> exportSettlement(@RequestBody SettlementBO settlementBO, HttpServletResponse response) {
|
try {
|
List<HouseholdVO> result = settlementService.exportSettleData(settlementBO, response);
|
if (Objects.equals(settlementBO.getIsSettled(), SettledProcessEnum.NOT_SETTLE.getValue())) {
|
List<NotResettlementHouseholdExportVO> exportVOList = StateProjectConvert.INSTANCE.toNotResettlementHouseholdExportVO(result);
|
List<String> deptIdList = exportVOList.stream()
|
.map(NotResettlementHouseholdExportVO::getDeptId)
|
.collect(Collectors.toList());
|
Map<String, SysDept> stringSysDeptMap = deptService.selectMapDeptById(deptIdList);
|
Collections.reverse(exportVOList);
|
for (int i = 0; i < exportVOList.size(); i++) {
|
NotResettlementHouseholdExportVO exportVO = exportVOList.get(i);
|
if (StringUtils.isNoneBlank(exportVO.getAgreeMoveStr())) {
|
if (exportVO.getAgreeMoveStr().contains("同意")) {
|
exportVO.setAgreeMoveStr("是");
|
} else if (exportVO.getAgreeMoveStr().contains("拒绝")) {
|
exportVO.setAgreeMoveStr("否");
|
}
|
} else {
|
exportVO.setAgreeMoveStr("否");
|
}
|
exportVO.setIndex(String.valueOf(i + 1));
|
SysDept sysDept = stringSysDeptMap.get(exportVO.getDeptId());
|
if (Objects.nonNull(sysDept)) {
|
exportVO.setBelongingStreetTown(sysDept.getDeptName());
|
}
|
}
|
|
FileUtils.setExcelResponseHeader(response, "未安置情况导出.xlsx");
|
EasyExcelFactory.write(response.getOutputStream(), NotResettlementHouseholdExportVO.class)
|
.sheet("sheet")
|
.doWrite(exportVOList);
|
} else if (Objects.equals(settlementBO.getIsSettled(), SettledProcessEnum.SETTLE.getValue())) {
|
List<ResettlementHouseholdExportVO> exportVOList = StateProjectConvert.INSTANCE.toResettlementHouseholdExportVO(result);
|
List<String> deptIdList = exportVOList.stream()
|
.map(ResettlementHouseholdExportVO::getDeptId)
|
.collect(Collectors.toList());
|
Map<String, SysDept> stringSysDeptMap = deptService.selectMapDeptById(deptIdList);
|
exportVOList.sort((o1, o2) -> {
|
int num1 = extractNumber(o1.getSettleName());
|
int num2 = extractNumber(o2.getSettleName());
|
return Integer.compare(num1, num2);
|
});
|
// Collections.reverse(exportVOList);
|
for (int i = 0; i < exportVOList.size(); i++) {
|
ResettlementHouseholdExportVO exportVO = exportVOList.get(i);
|
if (StringUtils.isNoneBlank(exportVO.getAgreeMoveStr())) {
|
if (exportVO.getAgreeMoveStr().contains("同意")) {
|
exportVO.setAgreeMoveStr("是");
|
} else if (exportVO.getAgreeMoveStr().contains("拒绝")) {
|
exportVO.setAgreeMoveStr("否");
|
}
|
} else {
|
exportVO.setAgreeMoveStr("否");
|
}
|
exportVO.setIndex(String.valueOf(i + 1));
|
exportVO.setSettleStatusStr(SubmitStatusEnum.getTextByValue(exportVO.getSettleStatus()));
|
SysDept sysDept = stringSysDeptMap.get(exportVO.getDeptId());
|
if (Objects.nonNull(sysDept)) {
|
exportVO.setBelongingStreetTown(sysDept.getDeptName());
|
}
|
}
|
|
FileUtils.setExcelResponseHeader(response, "已安置情况导出.xlsx");
|
EasyExcelFactory.write(response.getOutputStream(), ResettlementHouseholdExportVO.class)
|
.sheet("sheet")
|
.doWrite(exportVOList);
|
}
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
return AjaxResult.success();
|
} catch (IOException e) {
|
return AjaxResult.error();
|
}
|
}
|
|
@GetMapping(UrlConstants.STATE_SETTLEMENT_IMPORT_TEMPLATE)
|
public void importStateHouseholdTemplate(@RequestParam Integer compensationType, HttpServletResponse response) {
|
|
try {
|
TemplateFileTypeEnum pathByFileType;
|
if (1 == compensationType) {
|
pathByFileType = TemplateFileTypeEnum.getEnumByFileType(4);
|
} else if (2 == compensationType) {
|
pathByFileType = TemplateFileTypeEnum.getEnumByFileType(7);
|
} else {
|
throw new GlobalException("补偿类型错误");
|
}
|
Method generateExampleDataMethod = pathByFileType.getClazz().getMethod("generateExampleData");
|
Method generateHeaderDataMethod = pathByFileType.getClazz().getMethod("generateHeaderData");
|
Object exampleData = generateExampleDataMethod.invoke(null);
|
Object headerData = generateHeaderDataMethod.invoke(null);
|
|
FileUtils.setExcelResponseHeader(response, pathByFileType.getFileName());
|
ExcelWriterBuilder write = EasyExcelFactory.write(response.getOutputStream(), pathByFileType.getClazz());
|
if (Objects.nonNull(headerData)) {
|
write.registerWriteHandler((MultiDropdownWriteHandler) headerData);
|
}
|
write.sheet("sheet")
|
.doWrite(Collections.singletonList(exampleData));
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
} catch (Exception e) {
|
log.error("下载文件失败", e);
|
}
|
}
|
|
// 新增安置详情页面 导入
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_IMPORT)
|
public AjaxResult<Void> importSettlement(ImportSettlementBO importSettlementBO) throws IOException {
|
settlementService.stateSettlementImport(importSettlementBO);
|
return AjaxResult.success();
|
|
}
|
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_LIST_EXPORT)
|
public AjaxResult<Void> exportSettlementDetail(@RequestBody(required = false) StateExecutionBO executionBO, HttpServletResponse response) {
|
try {
|
List<StateExecutionDetailVO> exportVOList = settlementService.exportExecution(executionBO);
|
List<StateExecutionDetailExportVO> detailExportVOList = StateProjectConvert.INSTANCE.toExportVO(exportVOList);
|
|
FileUtils.setExcelResponseHeader(response, "实施明细.xlsx");
|
|
EasyExcelFactory.write(response.getOutputStream(), StateExecutionDetailExportVO.class)
|
.sheet("sheet")
|
.doWrite(detailExportVOList);
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
return AjaxResult.success();
|
} catch (IOException e) {
|
return AjaxResult.error();
|
}
|
}
|
|
//项目实施明细
|
@PostMapping(UrlConstants.STATE_EXECUTION_DETAIL)
|
public AjaxResult<PageInfo<StateExecutionDetailVO>> listExecution(@RequestBody(required = false) StateExecutionBO executionBO) {
|
return AjaxResult.success(settlementService.listExecution(executionBO));
|
}
|
|
//给项目展示使用
|
@PostMapping(UrlConstants.STATE_EXECUTION_SUM)
|
public AjaxResult<Map<String, Map<Integer, ProjectExecutionSumVO>>> listProjectExecution(@RequestBody List<String> projectIdList) {
|
return AjaxResult.success(settlementService.listProjectExecutionByProjectId(projectIdList, null));
|
}
|
|
@PostMapping(UrlConstants.STATE_SETTLEMENT_EXECUTION_WORKFLOW_SUBMIT)
|
public AjaxResult<Boolean> submitSettle(@RequestBody WorkFlowSubmitBO workFlowSubmitBO) {
|
if (Objects.isNull(workFlowSubmitBO.getSettlementIdList()) || workFlowSubmitBO.getSettlementIdList().isEmpty()) {
|
return AjaxResult.success(false);
|
}
|
List<StateSettlement> agreementList = settlementService.listByIds(workFlowSubmitBO.getSettlementIdList());
|
if (CollectionUtils.isEmpty(agreementList)) {
|
return AjaxResult.success(false);
|
}
|
agreementList.forEach(stateAgreement -> {
|
//需要显示文件名,直接存json
|
stateAgreement.setSettleName(workFlowSubmitBO.getBatchName());
|
stateAgreement.setFileUrl(workFlowSubmitBO.getFileBO());
|
stateAgreement.setAuditStatus(SubmitStatusEnum.PENDING_REVIEW.getValue());
|
});
|
settlementService.workflowSubmit(workFlowSubmitBO.getSettlementIdList());
|
return AjaxResult.success(settlementService.saveOrUpdateBatch(agreementList));
|
}
|
|
/**
|
* @param projectId
|
* @param componsationType
|
* @return
|
*/
|
@GetMapping(UrlConstants.STATE_SETTLEMENT_GENERATE_SETTLE_BATCH)
|
public AjaxResult<String> generateSettleBatch(@RequestParam String projectId, @RequestParam(required = false) String componsationType) {
|
return AjaxResult.success(settlementService.generateBatchName(projectId, componsationType));
|
}
|
|
@GetMapping(UrlConstants.STATE_SETTLEMENT_BATCH_NAME_LIST)
|
public AjaxResult<List<String>> listBatchName(@RequestParam String projectId) {
|
return AjaxResult.success(settlementService.listBatchName(projectId));
|
}
|
|
}
|