|
|
@@ -2,6 +2,9 @@ package com.jeeplus.assess.workContract.controller;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@@ -13,17 +16,28 @@ import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
|
import com.jeeplus.assess.program.configuration.projectList.domain.ProgramProjectListInfo;
|
|
|
import com.jeeplus.assess.workContract.domain.WorkContractInfo;
|
|
|
import com.jeeplus.assess.workContract.service.WorkContractService;
|
|
|
+import com.jeeplus.assess.workContract.service.dto.WorkContractExportDTO;
|
|
|
import com.jeeplus.assess.workContract.service.dto.WorkContractInfoDto;
|
|
|
+import com.jeeplus.assess.projectRecords.Utils.EasyPoiUtil;
|
|
|
+import com.jeeplus.common.excel.ExcelOptions;
|
|
|
+import com.jeeplus.common.excel.ExportMode;
|
|
|
+import com.jeeplus.sys.feign.IDictApi;
|
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Api(tags ="合同登记")
|
|
|
@@ -58,6 +72,106 @@ public class WorkContractController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 导出合同登记列表
|
|
|
+ * 复用列表查询条件,支持 全部(all)/当前页(current)/选中(selected) 三种导出模式
|
|
|
+ */
|
|
|
+ @ApiLog(value = "导出合同数据")
|
|
|
+ @ApiOperation(value = "导出合同数据")
|
|
|
+ @GetMapping(value = "export")
|
|
|
+ public void export(WorkContractInfo workClientInfo, Page<WorkContractInfo> page, ExcelOptions options, HttpServletResponse response) throws Exception {
|
|
|
+ String fileName = options.getFilename();
|
|
|
+ String sheetName = options.getSheetName();
|
|
|
+ // 构建与列表查询相同的过滤条件
|
|
|
+ String clientName = workClientInfo.getClientName();
|
|
|
+ String[] contractDates = workClientInfo.getContractDates();
|
|
|
+ String[] contractAmounts = workClientInfo.getContractAmounts();
|
|
|
+ String statusList = workClientInfo.getStatusList();
|
|
|
+ String status = workClientInfo.getStatus();
|
|
|
+ String contractType = workClientInfo.getContractType();
|
|
|
+ QueryWrapper<WorkContractInfo> queryWrapper = QueryWrapperGenerator.buildQueryCondition(workClientInfo, WorkContractInfo.class);
|
|
|
+ if (ObjectUtil.isNotEmpty(workClientInfo) && StringUtils.isNotBlank(workClientInfo.getCreateById())) {
|
|
|
+ queryWrapper.eq("a.create_by_id", workClientInfo.getCreateById()).or().like("c.name", workClientInfo.getCreateById());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(workClientInfo.getCancelStatus())) {
|
|
|
+ queryWrapper.eq("wcc.status", workClientInfo.getCancelStatus());
|
|
|
+ }
|
|
|
+ // 全部导出时取消分页
|
|
|
+ if (ExportMode.all.equals(options.getMode())) {
|
|
|
+ page.setSize(-1);
|
|
|
+ page.setCurrent(0);
|
|
|
+ }
|
|
|
+ List<WorkContractInfo> records = workContractService.list(page, queryWrapper, clientName, contractDates, contractAmounts, statusList, status, contractType, workClientInfo.getReportNo()).getRecords();
|
|
|
+ // 选中导出时按选中id过滤
|
|
|
+ if (ExportMode.selected.equals(options.getMode())) {
|
|
|
+ records = records.stream().filter(item -> options.getSelectIds().contains(item.getId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ // 加载状态字典,用于把状态码翻译为中文(含审批中/驳回/撤回等进行中状态)
|
|
|
+ Map<String, String> statusDict = loadDictMap("approval_type");
|
|
|
+ Map<String, String> filedDict = loadDictMap("filed_type");
|
|
|
+ Map<String, String> cancelDict = loadDictMap("contract_cancel");
|
|
|
+ // 转换为导出DTO
|
|
|
+ List<WorkContractExportDTO> result = new ArrayList<>();
|
|
|
+ for (WorkContractInfo info : records) {
|
|
|
+ WorkContractExportDTO dto = new WorkContractExportDTO();
|
|
|
+ BeanUtils.copyProperties(info, dto);
|
|
|
+ // 状态翻译:未发起的归档/作废给出默认文案,进行中/已完成按字典翻译
|
|
|
+ dto.setStatus(translateDict(statusDict, info.getStatus(), null));
|
|
|
+ dto.setFiledType(translateDict(filedDict, info.getFiledType(), "未归档"));
|
|
|
+ dto.setCancelStatus(translateDict(cancelDict, info.getCancelStatus(), "未作废"));
|
|
|
+ // 合同金额格式归一化:去掉千分位逗号,统一保留两位小数
|
|
|
+ dto.setContractAmount(formatAmount(info.getContractAmount()));
|
|
|
+ result.add(dto);
|
|
|
+ }
|
|
|
+ EasyPoiUtil.exportExcel(result, sheetName, sheetName, WorkContractExportDTO.class, fileName, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载字典 value->label 映射
|
|
|
+ * 使用 getDictListMapByDict(服务端直接返回 value->label 的Map JSON),
|
|
|
+ * 与报销模块导出的字典加载方式一致;getDictMap 返回的是带循环引用的对象列表JSON,解析不可靠
|
|
|
+ */
|
|
|
+ private Map<String, String> loadDictMap(String dict) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ String datas = SpringUtil.getBean(IDictApi.class).getDictListMapByDict(dict);
|
|
|
+ Map<String, Object> dictMap = JSON.parseObject(datas, new TypeReference<Map<String, Object>>() {});
|
|
|
+ if (dictMap != null) {
|
|
|
+ for (Map.Entry<String, Object> entry : dictMap.entrySet()) {
|
|
|
+ map.put(entry.getKey(), entry.getValue() == null ? null : String.valueOf(entry.getValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 状态码翻译为中文label;code为空时返回默认文案
|
|
|
+ */
|
|
|
+ private String translateDict(Map<String, String> dict, String code, String defaultLabel) {
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ return defaultLabel == null ? "" : defaultLabel;
|
|
|
+ }
|
|
|
+ String label = dict.get(code);
|
|
|
+ return StringUtils.isNotBlank(label) ? label : code;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 金额格式归一化:去掉千分位逗号,统一保留两位小数;空值返回空串
|
|
|
+ */
|
|
|
+ private String formatAmount(String amount) {
|
|
|
+ if (StringUtils.isBlank(amount)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 去掉千分位逗号
|
|
|
+ String clean = amount.replace(",", "");
|
|
|
+ java.math.BigDecimal bd = new java.math.BigDecimal(clean);
|
|
|
+ return bd.setScale(2, java.math.RoundingMode.HALF_UP).toPlainString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 解析失败返回原值
|
|
|
+ return amount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 合同登记新增/修改
|
|
|
*/
|
|
|
@ApiOperation(value = "合同登记新增/修改")
|
|
|
@@ -142,4 +256,16 @@ public class WorkContractController {
|
|
|
workContractService.getThreeMonthsUnarchivedContracts();
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ /**
|
|
|
+ * 根据报告号查询项目ID
|
|
|
+ * @param reportNo 报告号
|
|
|
+ * @return 项目ID
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "根据报告号查询项目ID")
|
|
|
+ @GetMapping("/getProjectIdByReportNo")
|
|
|
+ public ResponseEntity<String> getProjectIdByReportNo(@RequestParam("reportNo") String reportNo) {
|
|
|
+ String projectId = workContractService.getProjectIdByReportNo(reportNo);
|
|
|
+ return ResponseEntity.ok(projectId);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|