From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 01 八月 2025 13:27:59 +0800
Subject: [PATCH] yys 密码已重置

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/FinishProductSpotCheckServiceImpl.java |  681 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 681 insertions(+), 0 deletions(-)

diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/FinishProductSpotCheckServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/FinishProductSpotCheckServiceImpl.java
new file mode 100644
index 0000000..357d1c7
--- /dev/null
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/FinishProductSpotCheckServiceImpl.java
@@ -0,0 +1,681 @@
+package com.ruoyi.inspect.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.config.ConfigureBuilder;
+import com.deepoove.poi.data.Pictures;
+import com.ruoyi.common.core.domain.Result;
+import com.ruoyi.common.utils.DateImageUtil;
+import com.ruoyi.common.utils.api.IfsApiUtils;
+import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.framework.exception.ErrorException;
+import com.ruoyi.inspect.dto.IfsStockQueryDTO;
+import com.ruoyi.inspect.dto.SpotCheckQuarterDto;
+import com.ruoyi.inspect.dto.SpotCheckYearDto;
+import com.ruoyi.inspect.mapper.SpotCheckQuarterMapper;
+import com.ruoyi.inspect.mapper.SpotCheckYearMapper;
+import com.ruoyi.inspect.pojo.SpotCheckQuarter;
+import com.ruoyi.inspect.pojo.SpotCheckQuarterItem;
+import com.ruoyi.inspect.pojo.SpotCheckYear;
+import com.ruoyi.inspect.pojo.SpotCheckYearItem;
+import com.ruoyi.inspect.service.FinishProductSpotCheckService;
+import com.ruoyi.inspect.service.SpotCheckQuarterItemService;
+import com.ruoyi.inspect.service.SpotCheckYearItemService;
+import com.ruoyi.system.mapper.UserMapper;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 鎴愬搧鎶芥牱
+ *
+ * @Author zhuo
+ * @Date 2024/9/29
+ */
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class FinishProductSpotCheckServiceImpl implements FinishProductSpotCheckService {
+
+    @Resource
+    private IfsApiUtils ifsApiUtils;
+    @Resource
+    private SpotCheckQuarterMapper spotCheckQuarterMapper;
+    @Resource
+    private SpotCheckQuarterItemService spotCheckQuarterItemService;
+    @Resource
+    private SpotCheckYearMapper spotCheckYearMapper;
+    @Resource
+    private SpotCheckYearItemService spotCheckYearItemService;
+    @Value("${wordUrl}")
+    private String wordUrl;
+    @Value("${file.path}")
+    private String imgUrl;
+    @Resource
+    private UserMapper userMapper;
+
+
+    public Result getIfsStockReport(IfsStockQueryDTO ifsStockQueryDTO) {
+        JSONObject jresult = new JSONObject();
+        jresult.put("total", 0);
+        jresult.put("count", 0);
+        jresult.put("data", new JSONArray());
+        JSONObject jsonObject = new JSONObject();
+        generateIfsStockQueryParams(jsonObject, ifsStockQueryDTO, ifsStockQueryDTO.getPage(), ifsStockQueryDTO.getLimit());
+        Result result = ifsApiUtils.getIfsStock(jsonObject.toJSONString());
+        if (result.getCode() == 200) {
+            JSONObject data = (JSONObject) JSON.toJSON(result.getData());
+            JSONArray array = new JSONArray();
+            for (int i = 0; i < data.getJSONArray("LIST_INFO").size(); i++) {
+                JSONObject listInfo = data.getJSONArray("LIST_INFO").getJSONObject(i);
+                array.add(listInfo);
+            }
+            //鑾峰彇鎬绘暟閲�
+            int count = data.getIntValue("TOTAL_RECORD");
+            //鑾峰彇椤垫暟
+            int total = (int) Math.ceil((double) count / (double) ifsStockQueryDTO.getLimit());
+            jresult.put("total", total);
+            jresult.put("count", count);
+            jresult.put("data", array);
+        }
+        return Result.success(jresult);
+    }
+
+    public void generateIfsStockQueryParams(JSONObject result, IfsStockQueryDTO ifsStockQueryDTO, Long pageNo, Long pageSize) {
+        result.put("PAGE", pageNo);
+        result.put("LIMIT", pageSize);
+        result.put("WAREHOUSE", "鎴愬搧浠撳簱");
+        result.put("QUANTITY_FLAG", ">0");
+        //琛ㄩ噷闈㈢殑OTC琛屽彿
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getCotcOrderNo())) {
+            result.put("C_OTC_ORDER_NO", ifsStockQueryDTO.getCotcOrderNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getCotcLineNo())) {
+            result.put("C_OTC_LINE_NO", ifsStockQueryDTO.getCotcLineNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getPartNo())) {
+            result.put("PART_NO", ifsStockQueryDTO.getPartNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getPartDescription())) {
+            result.put("PART_DESC", "%" + ifsStockQueryDTO.getPartDescription() + "%");
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLocNo())) {
+            result.put("LOCATION_NO", ifsStockQueryDTO.getLocNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLocDesc())) {
+            result.put("LOCATION_DESC", ifsStockQueryDTO.getLocDesc());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLotBatchNo())) {
+            result.put("LOT_BATCH_NO", ifsStockQueryDTO.getLotBatchNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getWdrNo())) {
+            result.put("WDR_NO", ifsStockQueryDTO.getWdrNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getWarehouse())) {
+            result.put("WAREHOUSE", ifsStockQueryDTO.getWarehouse());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLocationGroup())) {
+            result.put("LOCATION_GROUP", ifsStockQueryDTO.getLocationGroup());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLocationGroupDesc())) {
+            result.put("LOCATION_GROUP_DESC", ifsStockQueryDTO.getLocationGroupDesc());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getReelNumber())) {
+            result.put("ATTR1", ifsStockQueryDTO.getReelNumber());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getStartMeter())) {
+            result.put("ATTR2", ifsStockQueryDTO.getStartMeter());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getEndMeter())) {
+            result.put("ATTR3", ifsStockQueryDTO.getEndMeter());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getOuterColor())) {
+            result.put("ATTR4", ifsStockQueryDTO.getOuterColor());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getInsulationColor())) {
+            result.put("ATTR5", ifsStockQueryDTO.getInsulationColor());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getOtcOrderNo())) {
+            result.put("ATTR6", ifsStockQueryDTO.getOtcOrderNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getMpsNo())) {
+            result.put("ATTR7", ifsStockQueryDTO.getMpsNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLetteringInfo())) {
+            result.put("ATTR8", ifsStockQueryDTO.getLetteringInfo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getSStockQuantity())) {
+            result.put("ATTR9", ifsStockQueryDTO.getSStockQuantity());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getSAvailableStockQuantity())) {
+            result.put("ATTR10", ifsStockQueryDTO.getSAvailableStockQuantity());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getSunit())) {
+            result.put("ATTR11", ifsStockQueryDTO.getSunit());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getStockSource())) {
+            result.put("ATTR12", ifsStockQueryDTO.getStockSource());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getInspInstorageTime())) {
+            result.put("ATTR13", ifsStockQueryDTO.getInspInstorageTime());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getTestRemark())) {
+            result.put("ATTR14", ifsStockQueryDTO.getTestRemark());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getGrossWeight())) {
+            result.put("ATTR15", ifsStockQueryDTO.getGrossWeight());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getNetWeight())) {
+            result.put("ATTR16", ifsStockQueryDTO.getNetWeight());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getPackingManner())) {
+            result.put("ATTR17", ifsStockQueryDTO.getPackingManner());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getCylinderNumber())) {
+            result.put("ATTR18", ifsStockQueryDTO.getCylinderNumber());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getRemark())) {
+            result.put("ATTR19", ifsStockQueryDTO.getRemark());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getLengthRequirement())) {
+            result.put("ATTR20", ifsStockQueryDTO.getLengthRequirement());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getCustomerName())) {
+            result.put("ATTR21", ifsStockQueryDTO.getCustomerName());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getSystemNo())) {
+            result.put("ATTR22", ifsStockQueryDTO.getSystemNo());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getInSource())) {
+            result.put("ATTR23", ifsStockQueryDTO.getInSource());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getSplitQuality())) {
+            result.put("ATTR24", ifsStockQueryDTO.getSplitQuality());
+        }
+        if (StrUtil.isNotBlank(ifsStockQueryDTO.getReserveQuantity())) {
+            result.put("QTY_RESERVED", ifsStockQueryDTO.getReserveQuantity());
+        }
+    }
+
+    /************************************************* 瀛e害鎶芥牱 ***********************************************************/
+
+    /**
+     * 鏂板瀛e害鎶芥
+     * @param spotCheckQuarterDto
+     * @return
+     */
+    @Override
+    public boolean addQuarter(SpotCheckQuarterDto spotCheckQuarterDto) {
+        // 鏍规嵁缂栧彿鏌ヨ涔嬪墠鐨�
+        SpotCheckQuarter spotCheckQuarter = spotCheckQuarterMapper.selectOne(Wrappers.<SpotCheckQuarter>lambdaQuery()
+                .eq(SpotCheckQuarter::getQuarterNo, spotCheckQuarterDto.getQuarterNo())
+                .orderByDesc(SpotCheckQuarter::getCreateTime)
+                .last("limit 1"));
+        if (spotCheckQuarter == null) {
+            spotCheckQuarterMapper.insert(spotCheckQuarterDto);
+            // 娣诲姞璇︽儏
+            for (SpotCheckQuarterItem quarterItem : spotCheckQuarterDto.getQuarterItems()) {
+                quarterItem.setQuarterId(spotCheckQuarterDto.getQuarterId());
+            }
+            spotCheckQuarterItemService.saveBatch(spotCheckQuarterDto.getQuarterItems());
+        } else {
+            // 绱姞璇︽儏
+            for (SpotCheckQuarterItem quarterItem : spotCheckQuarterDto.getQuarterItems()) {
+                quarterItem.setQuarterId(spotCheckQuarter.getQuarterId());
+            }
+            spotCheckQuarterItemService.saveBatch(spotCheckQuarterDto.getQuarterItems());
+        }
+
+        return true;
+    }
+
+    /**
+     * 鏌ヨ瀛e害鎶芥牱璇︽儏
+     * @param quarterId
+     * @return
+     */
+    @Override
+    public SpotCheckQuarterDto getQuarter(Integer quarterId) {
+        SpotCheckQuarter spotCheckQuarter = spotCheckQuarterMapper.selectById(quarterId);
+
+        // 鏌ヨ璇︽儏
+        List<SpotCheckQuarterItem> list = spotCheckQuarterItemService.list(Wrappers.<SpotCheckQuarterItem>lambdaQuery()
+                .eq(SpotCheckQuarterItem::getQuarterId, spotCheckQuarter.getQuarterId()));
+        SpotCheckQuarterDto spotCheckQuarterDto = new SpotCheckQuarterDto();
+        BeanUtil.copyProperties(spotCheckQuarter, spotCheckQuarterDto);
+        spotCheckQuarterDto.setQuarterItems(list);
+
+        return spotCheckQuarterDto;
+    }
+
+    /**
+     * 瀛e害鎶芥牱鍒嗛〉鏌ヨ
+     * @param page
+     * @param spotCheckQuarter
+     * @return
+     */
+    @Override
+    public IPage<SpotCheckQuarterDto> getQuarterPage(Page page, SpotCheckQuarterDto spotCheckQuarter) {
+        return spotCheckQuarterMapper.getQuarterPage(page, QueryWrappers.queryWrappers(spotCheckQuarter));
+    }
+
+    /**
+     * 鍒犻櫎瀛e害鎶芥牱
+     * @param quarterId
+     * @return
+     */
+    @Override
+    public boolean deleteQuarter(Integer quarterId) {
+        spotCheckQuarterMapper.deleteById(quarterId);
+        spotCheckQuarterItemService.remove(Wrappers.<SpotCheckQuarterItem>lambdaQuery()
+                .eq(SpotCheckQuarterItem::getQuarterId, quarterId));
+        return true;
+    }
+
+    /**
+     * 鎴愬搧涓嬪崟鐣岄潰鏌ヨ瀛e害淇℃伅
+     * @return
+     */
+    @Override
+    public List<Map<String, Object>> getQuarterOnOrder() {
+        List<Map<String, Object>> quarterOnOrder = spotCheckQuarterMapper.getQuarterOnOrder();
+        for (Map<String, Object> stringMap : quarterOnOrder) {
+            List<SpotCheckQuarterItem> list = spotCheckQuarterItemService.list(Wrappers.<SpotCheckQuarterItem>lambdaQuery()
+                    .eq(SpotCheckQuarterItem::getQuarterId, (Integer) stringMap.get("value")));
+            List<Map<String, Object>> itemMaps = list.stream().map(spotCheckQuarterItem -> {
+                Map<String, Object> map = new HashMap<>();
+                map.put("value", spotCheckQuarterItem.getQuarterItemId());
+                map.put("label", spotCheckQuarterItem.getProductModel() + " "
+                        + spotCheckQuarterItem.getProductType() + " "
+                        + spotCheckQuarterItem.getSpotCheckNumber());
+                return map;
+            }).collect(Collectors.toList());
+            stringMap.put("children", itemMaps);
+
+        }
+
+        return quarterOnOrder;
+    }
+
+    /**
+     * 淇敼瀛e害妫�楠�
+     * @param spotCheckQuarterDto
+     * @return
+     */
+    @Override
+    public boolean updateQuarterOnOrder(SpotCheckQuarterDto spotCheckQuarterDto) {
+        if (CollectionUtils.isNotEmpty(spotCheckQuarterDto.getQuarterItems())) {
+            // 娓呴櫎涔嬪墠璇︽儏
+            spotCheckQuarterItemService.remove(Wrappers.<SpotCheckQuarterItem>lambdaQuery()
+                    .eq(SpotCheckQuarterItem::getQuarterId, spotCheckQuarterDto.getQuarterId()));
+            // 娣诲姞璇︽儏
+            for (SpotCheckQuarterItem quarterItem : spotCheckQuarterDto.getQuarterItems()) {
+                quarterItem.setQuarterId(spotCheckQuarterDto.getQuarterId());
+            }
+            spotCheckQuarterItemService.saveBatch(spotCheckQuarterDto.getQuarterItems());
+        }
+
+        spotCheckQuarterMapper.updateById(spotCheckQuarterDto);
+        return true;
+    }
+
+    /**
+     * 鐢熸垚鏈�缁堟姤鍛�
+     * @param quarterId
+     * @return
+     */
+    @Override
+    public boolean finalReportQuarter(Integer quarterId, HttpServletResponse response) {
+        // 娣诲姞鎶ュ憡淇℃伅
+        SpotCheckQuarter spotCheckQuarter = spotCheckQuarterMapper.selectById(quarterId);
+
+        // 鏌ヨ璇︽儏
+        List<SpotCheckQuarterItem> itemList = spotCheckQuarterItemService.list(Wrappers.<SpotCheckQuarterItem>lambdaQuery()
+                .eq(SpotCheckQuarterItem::getQuarterId, spotCheckQuarter.getQuarterId()));
+
+        for (SpotCheckQuarterItem spotCheckQuarterItem : itemList) {
+            // 鎷兼帴鍨嬪彿鍜屾暟閲�
+            spotCheckQuarterItem.setSpotCheckNumber((StringUtils.isBlank(spotCheckQuarterItem.getProductModel()) ? "" : spotCheckQuarterItem.getProductModel()) +
+                    (StringUtils.isBlank(spotCheckQuarterItem.getSpotCheckNumber()) ? "" : spotCheckQuarterItem.getSpotCheckNumber()));
+        }
+
+        //缂栧埗浜�
+        String writeUrl = null;
+        if (spotCheckQuarter.getWriteUser() != null) {
+            try {
+                writeUrl = userMapper.selectById(spotCheckQuarter.getWriteUser()).getSignatureUrl();
+            } catch (Exception e) {
+                throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+            }
+            if (StrUtil.isBlank(writeUrl)) {
+                throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+            }
+        }
+
+        // 鍒濆鍖栨墍鏈夌殑 countersignUrl 鍙橀噺
+        String[] countersignUrls = new String[7];
+
+        // 濡傛灉 spotCheckQuarter.getCountersignUser() 涓嶆槸绌烘垨绌虹櫧瀛楃涓�
+        if (StrUtil.isNotBlank(spotCheckQuarter.getCountersignUser())) {
+            String[] split = spotCheckQuarter.getCountersignUser().split(",");
+
+            // 閬嶅巻 split 鏁扮粍锛屽苟灏嗗厓绱犱緷娆¤祴鍊肩粰 countersignUrls 鏁扮粍
+            for (int i = 0; i < Math.min(split.length, countersignUrls.length); i++) {
+
+                String countersignUrl = null;
+                try {
+                    countersignUrl = userMapper.selectById(Integer.parseInt(split[i])).getSignatureUrl();
+                } catch (Exception e) {
+                    throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+                }
+                if (StrUtil.isBlank(countersignUrl)) {
+                    throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+                }
+
+                countersignUrls[i] = countersignUrl;
+            }
+        }
+
+        // 灏� countersignUrls 鏁扮粍涓殑鍊间緷娆¤祴鍊肩粰 countersignUrl1 鍒� countersignUrl7
+        String countersignUrl1 = countersignUrls[0];
+        String countersignUrl2 = countersignUrls[1];
+        String countersignUrl3 = countersignUrls[2];
+        String countersignUrl4 = countersignUrls[3];
+        String countersignUrl5 = countersignUrls[4];
+        String countersignUrl6 = countersignUrls[5];
+        String countersignUrl7 = countersignUrls[6];
+
+        //瀹℃牳浜�
+        String examineUrl = null;
+        if (spotCheckQuarter.getExamineUser() != null) {
+            try {
+                examineUrl = userMapper.selectById(spotCheckQuarter.getExamineUser()).getSignatureUrl();
+            } catch (Exception e) {
+                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+            }
+            if (StrUtil.isBlank(examineUrl)) {
+                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+            }
+        }
+
+        //鎵瑰噯浜�
+        String ratifyUrl = null;
+        if (spotCheckQuarter.getRatifyUser() != null) {
+            try {
+                ratifyUrl = userMapper.selectById(spotCheckQuarter.getRatifyUser()).getSignatureUrl();
+            } catch (Exception e) {
+                throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�");
+            }
+            if (StrUtil.isBlank(ratifyUrl)) {
+                throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�");
+            }
+        }
+
+        String finalWriteUrl = writeUrl;
+        String finalExamineUrl = examineUrl;
+        String finalRatifyUrl = ratifyUrl;
+
+        // 鑾峰彇璺緞
+        InputStream inputStream = this.getClass().getResourceAsStream("/static/spot_check_quarter.docx");
+        ConfigureBuilder builder = Configure.builder();
+        builder.useSpringEL(true);
+
+        XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
+                new HashMap<String, Object>() {{
+                    put("quarter", spotCheckQuarter);
+                    put("quarterItems", itemList);
+                    put("writeUrl", StrUtil.isBlank(finalWriteUrl) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + finalWriteUrl).create());
+                    put("countersignUrl1", StrUtil.isBlank(countersignUrl1) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl1).create());
+                    put("countersignUrl2", StrUtil.isBlank(countersignUrl2) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl2).create());
+                    put("countersignUrl3", StrUtil.isBlank(countersignUrl3) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl3).create());
+                    put("countersignUrl4", StrUtil.isBlank(countersignUrl4) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl4).create());
+                    put("countersignUrl5", StrUtil.isBlank(countersignUrl5) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl5).create());
+                    put("countersignUrl6", StrUtil.isBlank(countersignUrl6) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl6).create());
+                    put("countersignUrl7", StrUtil.isBlank(countersignUrl7) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl7).create());
+                    put("examineUrl", StrUtil.isBlank(finalExamineUrl) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + finalExamineUrl).create());
+                    put("ratifyUrl", StrUtil.isBlank(finalRatifyUrl) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + finalRatifyUrl).create());
+                    put("createDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(spotCheckQuarter.getCreateTime())).create());
+                }});
+        try {
+            response.setContentType("application/msword");
+            String fileName = URLEncoder.encode(
+                    spotCheckQuarter.getQuarterNo() + "鎶芥牱璁″垝", "UTF-8");
+            response.setHeader("Content-disposition",
+                    "attachment;filename=" + fileName + ".docx");
+            OutputStream os = response.getOutputStream();
+            template.write(os);
+            os.flush();
+            os.close();
+            inputStream.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("瀵煎嚭澶辫触");
+        }
+        return true;
+    }
+
+
+    /******************************************************* 骞村害鎶芥牱  *************************************************************/
+
+    @Override
+    public boolean addSpotCheckYear(SpotCheckYearDto spotCheckYearDto) {
+        spotCheckYearMapper.insert(spotCheckYearDto);
+        // 璇︽儏
+        for (SpotCheckYearItem yearItem : spotCheckYearDto.getYearItems()) {
+            yearItem.setYearId(spotCheckYearDto.getYearId());
+        }
+        spotCheckYearItemService.saveBatch(spotCheckYearDto.getYearItems());
+        return true;
+    }
+
+    @Override
+    public SpotCheckYearDto getSpotCheckYear(Integer yearId) {
+        SpotCheckYear spotCheckYear = spotCheckYearMapper.selectById(yearId);
+
+        // 鏌ヨ璇︽儏
+        List<SpotCheckYearItem> list = spotCheckYearItemService.list(Wrappers.<SpotCheckYearItem>lambdaQuery()
+                .eq(SpotCheckYearItem::getYearId, spotCheckYear.getYearId()));
+        SpotCheckYearDto spotCheckYearDto = new SpotCheckYearDto();
+        BeanUtil.copyProperties(spotCheckYear, spotCheckYearDto);
+        spotCheckYearDto.setYearItems(list);
+
+        return spotCheckYearDto;
+    }
+
+    @Override
+    public IPage<SpotCheckYearDto> getSpotCheckYearPage(Page page, SpotCheckYearDto spotCheckYear) {
+        return spotCheckYearMapper.getSpotCheckYearPage(page, QueryWrappers.queryWrappers(spotCheckYear));
+    }
+
+    @Override
+    public boolean deleteSpotCheckYear(Integer yearId) {
+        spotCheckYearMapper.deleteById(yearId);
+        spotCheckYearItemService.remove(Wrappers.<SpotCheckYearItem>lambdaQuery()
+                .eq(SpotCheckYearItem::getYearId, yearId));
+        return true;
+    }
+
+    /**
+     * 淇敼骞村害妫�楠�
+     * @param spotCheckYearDto
+     * @return
+     */
+    @Override
+    public boolean updateSpotCheckYear(SpotCheckYearDto spotCheckYearDto) {
+        spotCheckYearMapper.updateById(spotCheckYearDto);
+
+        // 鍒犻櫎璇︽儏
+        spotCheckYearItemService.remove(Wrappers.<SpotCheckYearItem>lambdaQuery()
+                .eq(SpotCheckYearItem::getYearId, spotCheckYearDto.getYearId()));
+
+        // 閲嶆柊鏂板
+        for (SpotCheckYearItem yearItem : spotCheckYearDto.getYearItems()) {
+            yearItem.setYearId(spotCheckYearDto.getYearId());
+        }
+        spotCheckYearItemService.saveBatch(spotCheckYearDto.getYearItems());
+        return false;
+    }
+
+    @Override
+    public boolean finalReportSpotCheckYear(Integer yearId, HttpServletResponse response) {
+        SpotCheckYear spotCheckYear = spotCheckYearMapper.selectById(yearId);
+
+        // 鏌ヨ璇︽儏
+        List<SpotCheckYearItem> itemList = spotCheckYearItemService.list(Wrappers.<SpotCheckYearItem>lambdaQuery()
+                .eq(SpotCheckYearItem::getYearId, spotCheckYear.getYearId()));
+
+        //缂栧埗浜�
+        String writeUrl = null;
+        if (spotCheckYear.getWriteUser() != null) {
+            try {
+                writeUrl = userMapper.selectById(spotCheckYear.getWriteUser()).getSignatureUrl();
+            } catch (Exception e) {
+                throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+            }
+            if (StrUtil.isBlank(writeUrl)) {
+                throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+            }
+        }
+
+        // 鍒濆鍖栨墍鏈夌殑 countersignUrl 鍙橀噺
+        String[] countersignUrls = new String[7];
+
+        // 濡傛灉涓嶆槸绌烘垨绌虹櫧瀛楃涓�
+        if (StrUtil.isNotBlank(spotCheckYear.getCountersignUser())) {
+            String[] split = spotCheckYear.getCountersignUser().split(",");
+
+            // 閬嶅巻 split 鏁扮粍锛屽苟灏嗗厓绱犱緷娆¤祴鍊肩粰 countersignUrls 鏁扮粍
+            for (int i = 0; i < Math.min(split.length, countersignUrls.length); i++) {
+
+                String countersignUrl = null;
+                try {
+                    countersignUrl = userMapper.selectById(Integer.parseInt(split[i])).getSignatureUrl();
+                } catch (Exception e) {
+                    throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+                }
+                if (StrUtil.isBlank(countersignUrl)) {
+                    throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
+                }
+
+                countersignUrls[i] = countersignUrl;
+            }
+        }
+
+        // 灏� countersignUrls 鏁扮粍涓殑鍊间緷娆¤祴鍊肩粰 countersignUrl1 鍒� countersignUrl7
+        String countersignUrl1 = countersignUrls[0];
+        String countersignUrl2 = countersignUrls[1];
+        String countersignUrl3 = countersignUrls[2];
+        String countersignUrl4 = countersignUrls[3];
+        String countersignUrl5 = countersignUrls[4];
+        String countersignUrl6 = countersignUrls[5];
+        String countersignUrl7 = countersignUrls[6];
+
+        //瀹℃牳浜�
+        String examineUrl = null;
+        if (spotCheckYear.getExamineUser() != null) {
+            try {
+                examineUrl = userMapper.selectById(spotCheckYear.getExamineUser()).getSignatureUrl();
+            } catch (Exception e) {
+                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+            }
+            if (StrUtil.isBlank(examineUrl)) {
+                throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
+            }
+        }
+
+        //鎵瑰噯浜�
+        String ratifyUrl = null;
+        if (spotCheckYear.getRatifyUser() != null) {
+            try {
+                ratifyUrl = userMapper.selectById(spotCheckYear.getRatifyUser()).getSignatureUrl();
+            } catch (Exception e) {
+                throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�");
+            }
+            if (StrUtil.isBlank(ratifyUrl)) {
+                throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�");
+            }
+        }
+
+        String finalWriteUrl = writeUrl;
+        String finalExamineUrl = examineUrl;
+        String finalRatifyUrl = ratifyUrl;
+
+        // 鑾峰彇璺緞
+        InputStream inputStream = this.getClass().getResourceAsStream("/static/spot_check_year.docx");
+        ConfigureBuilder builder = Configure.builder();
+        builder.useSpringEL(true);
+        XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
+                new HashMap<String, Object>() {{
+                    put("year", spotCheckYear);
+                    put("yearItems", itemList);
+                    put("writeUrl", StrUtil.isBlank(finalWriteUrl) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + finalWriteUrl).create());
+                    put("countersignUrl1", StrUtil.isBlank(countersignUrl1) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl1).create());
+                    put("countersignUrl2", StrUtil.isBlank(countersignUrl2) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl2).create());
+                    put("countersignUrl3", StrUtil.isBlank(countersignUrl3) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl3).create());
+                    put("countersignUrl4", StrUtil.isBlank(countersignUrl4) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl4).create());
+                    put("countersignUrl5", StrUtil.isBlank(countersignUrl5) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl5).create());
+                    put("countersignUrl6", StrUtil.isBlank(countersignUrl6) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl6).create());
+                    put("countersignUrl7", StrUtil.isBlank(countersignUrl7) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + countersignUrl7).create());
+                    put("examineUrl", StrUtil.isBlank(finalExamineUrl) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + finalExamineUrl).create());
+                    put("ratifyUrl", StrUtil.isBlank(finalRatifyUrl) ? null :
+                            Pictures.ofLocal(imgUrl + "/" + finalRatifyUrl).create());
+                    put("createDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(spotCheckYear.getCreateTime())).create());
+                }});
+        try {
+            response.setContentType("application/msword");
+            String fileName = URLEncoder.encode(
+                    spotCheckYear.getYearHead(), "UTF-8");
+            response.setHeader("Content-disposition",
+                    "attachment;filename=" + fileName + ".docx");
+            OutputStream os = response.getOutputStream();
+            template.write(os);
+            os.flush();
+            os.close();
+            inputStream.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return true;
+    }
+
+
+}

--
Gitblit v1.9.3