Commit 387f832a3d4f9f6a6b80202c335d2491b776f711

Authored by 房远帅
1 parent fbec1694

采购:内贸客户资信-打印

1 1 package com.lframework.xingyun.sc.procurement.controller.credit;
2 2
  3 +import cn.hutool.core.io.resource.ClassPathResource;
3 4 import com.lframework.starter.common.exceptions.impl.DefaultClientException;
4 5 import com.lframework.starter.web.core.annotations.security.HasPermission;
5 6 import com.lframework.starter.web.core.components.redis.RedisHandler;
... ... @@ -8,23 +9,36 @@ import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
8 9 import com.lframework.starter.web.core.components.resp.PageResult;
9 10 import com.lframework.starter.web.core.controller.DefaultBaseController;
10 11 import com.lframework.starter.web.core.utils.JsonUtil;
  12 +import com.lframework.xingyun.sc.procurement.dto.DomesticReviewerDto;
11 13 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit;
12 14 import com.lframework.xingyun.sc.procurement.service.credit.ProcurementDomesticCustomerCreditService;
13 15 import com.lframework.xingyun.sc.procurement.vo.credit.CreateProcurementDomesticCustomerCreditVo;
14 16 import com.lframework.xingyun.sc.procurement.vo.credit.QueryProcurementDomesticCustomerCreditVo;
15 17 import com.lframework.xingyun.sc.procurement.vo.credit.UpdateProcurementDomesticCustomerCreditVo;
  18 +import com.lframework.xingyun.sc.utils.ExcelUtil;
  19 +import com.lframework.xingyun.sc.utils.ResponseUtil;
16 20 import io.swagger.annotations.Api;
17 21 import io.swagger.annotations.ApiImplicitParam;
18 22 import io.swagger.annotations.ApiOperation;
19 23 import javax.annotation.Resource;
  24 +import javax.servlet.http.HttpServletResponse;
20 25 import javax.validation.Valid;
21 26 import javax.validation.constraints.NotBlank;
  27 +import lombok.extern.slf4j.Slf4j;
  28 +import org.apache.poi.ss.usermodel.*;
  29 +import org.apache.poi.util.IOUtils;
  30 +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
22 31 import org.springframework.beans.factory.annotation.Autowired;
23 32 import org.springframework.validation.annotation.Validated;
24 33 import org.springframework.web.bind.annotation.*;
  34 +import java.io.*;
  35 +import java.time.format.DateTimeFormatter;
  36 +import java.util.HashMap;
  37 +import java.util.Map;
25 38
26 39 @Api(tags = "采购内贸资信调查表")
27 40 @Validated
  41 +@Slf4j
28 42 @RestController
29 43 @RequestMapping("/procurement/domesticCustomerCredit")
30 44 public class ProcurementDomesticCustomerCreditController extends DefaultBaseController {
... ... @@ -112,4 +126,183 @@ public class ProcurementDomesticCustomerCreditController extends DefaultBaseCont
112 126 return InvokeResultBuilder.success(data);
113 127 }
114 128 }
  129 +
  130 + @ApiOperation("打印")
  131 + @GetMapping("/print")
  132 + public void printPurchaseOrder(@NotBlank(message = "id不能为空") String id, HttpServletResponse response) throws IOException {
  133 + ProcurementDomesticCustomerCredit data = procurementDomesticCustomerCreditService.findById(id);
  134 +
  135 + try {
  136 + // 加载模板文件
  137 + ClassPathResource templateResource = new ClassPathResource("templates/procurementDomesticCustomerCreditTemplate.xlsx");
  138 +
  139 + try (InputStream inputStream = templateResource.getStream();
  140 + Workbook workbook = new XSSFWorkbook(inputStream)) {
  141 + try {
  142 + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  143 +
  144 + Map<String, Object> dataMap = new HashMap<>();
  145 + dataMap.put("reviewDate", dateFormatter.format(data.getCreateTime()));
  146 + dataMap.put("unitName", data.getUnitName() == null ? "" : data.getUnitName());
  147 + String companyNature = "①、进口贸易□ ②、国内贸易□\n" +
  148 + "③、终端产废□ ④、其他□";
  149 + if ("IMPORT_TRADE".equals(data.getCompanyNature())) {
  150 + companyNature = "①、进口贸易☑ ②、国内贸易□\n" +
  151 + "③、终端产废□ ④、其他□";
  152 + } else if ("DOMESTIC_TRADE".equals(data.getCompanyNature())) {
  153 + companyNature = "①、进口贸易□ ②、国内贸易☑\n" +
  154 + "③、终端产废□ ④、其他□";
  155 + } else if ("TERMINAL_WASTE".equals(data.getCompanyNature())) {
  156 + companyNature = "①、进口贸易□ ②、国内贸易□\n" +
  157 + "③、终端产废☑ ④、其他□";
  158 + } else if ("OTHER".equals(data.getCompanyNature())) {
  159 + companyNature = "①、进口贸易□ ②、国内贸易□\n" +
  160 + "③、终端产废□ ④、其他☑";
  161 + }
  162 + dataMap.put("companyNature", companyNature);
  163 + dataMap.put("bankName", data.getBankName() == null ? "" : data.getBankName());
  164 + dataMap.put("bankAccount", data.getBankAccount() == null ? "" : data.getBankAccount());
  165 + dataMap.put("registeredCapital", data.getRegisteredCapital() == null ? "" : data.getRegisteredCapital());
  166 + dataMap.put("legalRepresentative", data.getLegalRepresentative() == null ? "" : data.getLegalRepresentative());
  167 + dataMap.put("companyEstablishedTime", data.getCompanyEstablishedTime() == null ? "" : data.getCompanyEstablishedTime().format(dateFormatter));
  168 + dataMap.put("address", data.getAddress() == null ? "" : data.getAddress());
  169 + dataMap.put("businessPrincipal", data.getBusinessPrincipal() == null ? "" : data.getBusinessPrincipal());
  170 + dataMap.put("businessPrincipalPosition", data.getBusinessPrincipalPosition() == null ? "" : data.getBusinessPrincipalPosition());
  171 + dataMap.put("businessPrincipalPhone", data.getBusinessPrincipalPhone() == null ? "" : data.getBusinessPrincipalPhone());
  172 + dataMap.put("legalBusinessRelation", data.getLegalBusinessRelation() == null ? "" : data.getLegalBusinessRelation());
  173 + dataMap.put("factoryOfficeProperty", data.getFactoryOfficeProperty() == null ? "" : data.getFactoryOfficeProperty());
  174 + dataMap.put("factoryOfficeArea", data.getFactoryOfficeArea() == null ? "" : data.getFactoryOfficeArea());
  175 + dataMap.put("warehouseYardProperty", data.getWarehouseYardProperty() == null ? "" : data.getWarehouseYardProperty());
  176 + dataMap.put("warehouseYardArea", data.getWarehouseYardArea() == null ? "" : data.getWarehouseYardArea());
  177 + dataMap.put("mainEquipment", data.getMainEquipment() == null ? "" : data.getMainEquipment());
  178 + dataMap.put("normalInventory", data.getNormalInventory() == null ? "" : data.getNormalInventory());
  179 + dataMap.put("mainVarieties", data.getMainVarieties() == null ? "" : data.getMainVarieties());
  180 + dataMap.put("monthlyPurchaseVolume", data.getMonthlyPurchaseVolume() == null ? "" : data.getMonthlyPurchaseVolume());
  181 + String purchaseSource = " 国外进口□/本企业报废□/零散收购□/其它□";
  182 + if ("FOREIGN_IMPORTS".equals(data.getPurchaseSource())) {
  183 + purchaseSource = " 国外进口☑/本企业报废□/零散收购□/其它□";
  184 + } else if ("SCRAPPED_COMPANY".equals(data.getPurchaseSource())) {
  185 + purchaseSource = " 国外进口□/本企业报废☑/零散收购□/其它□";
  186 + } else if ("SCATTERED_TAKEOVER".equals(data.getPurchaseSource())) {
  187 + purchaseSource = " 国外进口□/本企业报废□/零散收购☑/其它□";
  188 + } else if ("OTHER".equals(data.getPurchaseSource())) {
  189 + purchaseSource = " 国外进口□/本企业报废□/零散收购□/其它☑";
  190 + }
  191 + dataMap.put("purchaseSource", purchaseSource);
  192 + dataMap.put("stockInProductName", data.getStockInProductName() == null ? "" : data.getStockInProductName());
  193 + dataMap.put("productName", data.getProductName() == null ? "" : data.getProductName());
  194 + dataMap.put("capacity", data.getCapacity() == null ? "" : data.getCapacity());
  195 + dataMap.put("salesChannel", data.getSalesChannel() == null ? "" : data.getSalesChannel());
  196 + String hasPreferentialPolicy;
  197 + if (data.getHasPreferentialPolicy()) {
  198 + hasPreferentialPolicy = "是☑/否□";
  199 + } else {
  200 + hasPreferentialPolicy = "是□/否☑";
  201 + }
  202 + dataMap.put("hasPreferentialPolicy", hasPreferentialPolicy);
  203 + String investInFutures;
  204 + if (data.getInvestInFutures()) {
  205 + investInFutures = "是☑/否□";
  206 + } else {
  207 + investInFutures = "是□/否☑";
  208 + }
  209 + dataMap.put("investInFutures", investInFutures);
  210 + String hasPenaltyRecord;
  211 + if (data.getHasPenaltyRecord()) {
  212 + hasPenaltyRecord = "是☑/否□";
  213 + } else {
  214 + hasPenaltyRecord = "是□/否☑";
  215 + }
  216 + dataMap.put("hasPenaltyRecord", hasPenaltyRecord);
  217 + String businessScopeMatch;
  218 + if (data.getBusinessScopeMatch()) {
  219 + businessScopeMatch = "是☑/否□";
  220 + } else {
  221 + businessScopeMatch = "是□/否☑";
  222 + }
  223 + dataMap.put("businessScopeMatch", businessScopeMatch);
  224 + dataMap.put("firstCooperationYear", data.getFirstCooperationYear() == null ? "" : data.getFirstCooperationYear());
  225 + String operationMode = "买断自提□\n" + "送货到厂□";
  226 + if ("BUYOUT_SELF-PICKUP".equals(data.getOperationMode())) {
  227 + operationMode = "买断自提☑\n" + "送货到厂□";
  228 + } else if ("DELIVERY_FACTORY".equals(data.getOperationMode())){
  229 + operationMode = "买断自提□\n" + "送货到厂☑";
  230 + }
  231 + dataMap.put("operationMode", operationMode);
  232 + String hasFailedPlanRecord;
  233 + if (data.getHasFailedPlanRecord()) {
  234 + hasFailedPlanRecord = "是☑/否□";
  235 + } else {
  236 + hasFailedPlanRecord = "是□/否☑";
  237 + }
  238 + dataMap.put("hasFailedPlanRecord", hasFailedPlanRecord);
  239 + String hasPlanPerformanceIssue;
  240 + if (data.getHasPlanPerformanceIssue()) {
  241 + hasPlanPerformanceIssue = "是☑/否□";
  242 + } else {
  243 + hasPlanPerformanceIssue = "是□/否☑";
  244 + }
  245 + dataMap.put("hasPlanPerformanceIssue", hasPlanPerformanceIssue);
  246 + String isNewDevelopment = "新客户□/再接轨□/老客户□";
  247 + if ("REGULAR_CUSTOMER".equals(data.getIsNewDevelopment())) {
  248 + isNewDevelopment = "新客户□/再接轨□/老客户☑";
  249 + } else if ("NEW_CUSTOMER".equals(data.getIsNewDevelopment())){
  250 + isNewDevelopment = "新客户☑/再接轨□/老客户□";
  251 + } else if ("REALIGN_WITH".equals(data.getIsNewDevelopment())){
  252 + isNewDevelopment = "新客户□/再接轨☑/老客户□";
  253 + }
  254 + dataMap.put("isNewDevelopment", isNewDevelopment);
  255 + dataMap.put("accountingProcess", data.getAccountingProcess() == null ? "" : data.getAccountingProcess());
  256 + String invoiceNameMatch;
  257 + if (data.getInvoiceNameMatch()) {
  258 + invoiceNameMatch = "是☑/否□";
  259 + } else {
  260 + invoiceNameMatch = "是□/否☑";
  261 + }
  262 + dataMap.put("invoiceNameMatch", invoiceNameMatch);
  263 + String outboundProcessStandard;
  264 + if (data.getOutboundProcessStandard()) {
  265 + outboundProcessStandard = "是☑/否□";
  266 + } else {
  267 + outboundProcessStandard = "是□/否☑";
  268 + }
  269 + dataMap.put("outboundProcessStandard", outboundProcessStandard);
  270 + dataMap.put("transportMode", data.getTransportMode() == null ? "" : data.getTransportMode());
  271 + dataMap.put("commonMaterialIssue", data.getCommonMaterialIssue() == null ? "" : data.getCommonMaterialIssue());
  272 + dataMap.put("otherIssue", data.getOtherIssue() == null ? "" : data.getOtherIssue());
  273 +
  274 + DomesticReviewerDto reviewer = procurementDomesticCustomerCreditService.getReviewerById(id);
  275 + if (reviewer == null) {
  276 + reviewer = new DomesticReviewerDto();
  277 + }
  278 + //供应部
  279 + dataMap.put("supplyDepartment", reviewer.getSupplyDepartment() == null ? "" : reviewer.getSupplyDepartment());
  280 + //供应管理科
  281 + dataMap.put("supplyManagementSection", reviewer.getSupplyManagementSection() == null ? "" : reviewer.getSupplyManagementSection());
  282 + //采购处
  283 + dataMap.put("procurementOffice", reviewer.getProcurementOffice() == null ? "" : reviewer.getProcurementOffice());
  284 + //制单人
  285 + dataMap.put("createBy", data.getCreateBy());
  286 +
  287 + ExcelUtil.processTemplate(workbook, dataMap);
  288 +
  289 + ResponseUtil.setExcelResponseHead(response, data.getUnitName() + "-内贸客户资信调查表打印.xlsx");
  290 + // 写入响应流
  291 + workbook.write(response.getOutputStream());
  292 + response.getOutputStream().flush();
  293 +
  294 + } finally {
  295 + IOUtils.closeQuietly(workbook);
  296 + }
  297 +
  298 + } catch (FileNotFoundException e) {
  299 + throw new RuntimeException("模板文件不存在: templates/procurementDomesticCustomerCreditTemplate.xlsx", e);
  300 + } catch (IOException e) {
  301 + throw new RuntimeException("无法读取模板文件: templates/procurementDomesticCustomerCreditTemplate.xlsx", e);
  302 + }
  303 + } catch (Exception e) {
  304 + log.error("内贸客户资信调查表导出失败: {}", e.getMessage(), e);
  305 + throw new RuntimeException("内贸客户资信调查表导出失败:", e);
  306 + }
  307 + }
115 308 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.dto;
  2 +
  3 +import com.lframework.starter.web.core.dto.BaseDto;
  4 +import lombok.Data;
  5 +
  6 +import java.io.Serializable;
  7 +
  8 +@Data
  9 +public class DomesticReviewerDto implements BaseDto, Serializable {
  10 +
  11 + private static final long serialVersionUID = 1L;
  12 +
  13 + /**
  14 + * ID
  15 + */
  16 + private String id;
  17 +
  18 + /**
  19 + * 采购处
  20 + */
  21 + private String procurementOffice;
  22 +
  23 + /**
  24 + * 供应管理科
  25 + */
  26 + private String supplyManagementSection;
  27 +
  28 + /**
  29 + * 供应部
  30 + */
  31 + private String supplyDepartment;
  32 +}
... ...
... ... @@ -21,7 +21,7 @@ import com.lframework.starter.web.core.utils.*;
21 21 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
22 22 import com.lframework.starter.web.inner.entity.SysUser;
23 23 import com.lframework.starter.web.inner.service.system.SysUserService;
24   -import com.lframework.xingyun.sc.entity.CustomerCredit;
  24 +import com.lframework.xingyun.sc.procurement.dto.DomesticReviewerDto;
25 25 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit;
26 26 import com.lframework.xingyun.sc.procurement.mappers.credit.ProcurementDomesticCustomerCreditMapper;
27 27 import com.lframework.xingyun.sc.procurement.service.credit.ProcurementDomesticCustomerCreditService;
... ... @@ -317,4 +317,13 @@ public class ProcurementDomesticCustomerCreditServiceImpl
317 317 getBaseMapper().updateById(customerCredit);
318 318 OpLogUtil.setExtra(data);
319 319 }
  320 +
  321 + @Override
  322 + public DomesticReviewerDto getReviewerById(String id) {
  323 + if (StringUtils.isBlank(id)) {
  324 + return new DomesticReviewerDto();
  325 + }
  326 + DomesticReviewerDto reviewer = getBaseMapper().getReviewerById(id);
  327 + return reviewer == null ? new DomesticReviewerDto() : reviewer;
  328 + }
320 329 }
... ...
1 1 package com.lframework.xingyun.sc.procurement.mappers.credit;
2 2
3 3 import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.dto.DomesticReviewerDto;
4 5 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit;
5 6 import com.lframework.xingyun.sc.procurement.vo.credit.QueryProcurementDomesticCustomerCreditVo;
6 7 import java.util.List;
... ... @@ -11,4 +12,9 @@ public interface ProcurementDomesticCustomerCreditMapper extends BaseMapper<Proc
11 12 List<ProcurementDomesticCustomerCredit> query(@Param("vo") QueryProcurementDomesticCustomerCreditVo vo);
12 13
13 14 ProcurementDomesticCustomerCredit findById(@Param("id") String id);
  15 +
  16 + /**
  17 + * 获取审核人
  18 + */
  19 + DomesticReviewerDto getReviewerById(@Param("id") String id);
14 20 }
... ...
... ... @@ -2,10 +2,12 @@ package com.lframework.xingyun.sc.procurement.service.credit;
2 2
3 3 import com.lframework.starter.web.core.components.resp.PageResult;
4 4 import com.lframework.starter.web.core.service.BaseMpService;
  5 +import com.lframework.xingyun.sc.procurement.dto.DomesticReviewerDto;
5 6 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit;
6 7 import com.lframework.xingyun.sc.procurement.vo.credit.CreateProcurementDomesticCustomerCreditVo;
7 8 import com.lframework.xingyun.sc.procurement.vo.credit.QueryProcurementDomesticCustomerCreditVo;
8 9 import com.lframework.xingyun.sc.procurement.vo.credit.UpdateProcurementDomesticCustomerCreditVo;
  10 +import org.apache.ibatis.annotations.Param;
9 11 import java.util.List;
10 12
11 13 public interface ProcurementDomesticCustomerCreditService extends BaseMpService<ProcurementDomesticCustomerCredit> {
... ... @@ -65,4 +67,9 @@ public interface ProcurementDomesticCustomerCreditService extends BaseMpService<
65 67 * 修改(不走审核)
66 68 */
67 69 void updateNoFlowInstance(ProcurementDomesticCustomerCredit customerCredit);
  70 +
  71 + /**
  72 + * 获取审核人
  73 + */
  74 + DomesticReviewerDto getReviewerById(@Param("id") String id);
68 75 }
... ...
... ... @@ -173,4 +173,14 @@
173 173 <include refid="ProcurementDomesticCustomerCreditSql"/>
174 174 WHERE tb.id = #{id}
175 175 </select>
  176 +
  177 + <select id="getReviewerById" resultType="com.lframework.xingyun.sc.procurement.dto.DomesticReviewerDto">
  178 + SELECT business_id,
  179 + JSON_UNQUOTE(JSON_EXTRACT(def_json, '$.nodeList[2].extMap.handleInfos[0].createBy')) AS procurementOffice,
  180 + JSON_UNQUOTE(JSON_EXTRACT(def_json, '$.nodeList[3].extMap.handleInfos[0].createBy')) AS supplyManagementSection,
  181 + JSON_UNQUOTE(JSON_EXTRACT(def_json, '$.nodeList[4].extMap.handleInfos[0].createBy')) AS supplyDepartment
  182 + FROM flow_instance
  183 + WHERE business_id = #{id}
  184 + ORDER BY create_time DESC LIMIT 1
  185 + </select>
176 186 </mapper>
... ...