فهرست منبع

顽症-excel统计

zhuang 1 ماه پیش
والد
کامیت
cf9927d13e

+ 8 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxPersistentManageDao.java

@@ -90,4 +90,12 @@ public interface ZhcxPersistentManageDao extends BaseMapper<ZhcxPersistentManage
 
     @Select("SELECT * FROM ZHCX_CHECK_BEFORE_QUALIFIED WHERE DELETED ='0'")
     List<ZhcxCheckBeforeQualifiedDo> getCheckBeforeQualifiedDos();
+
+    @Select("SELECT a.ISSUETYPE,b.FULLNAME AS ORGNAME, COUNT(a.TENANTID) AS CNT\n" +
+            "FROM ZHCX_PERSISTENT_MANAGE a \n" +
+            "LEFT JOIN SYS_ORGANIZATION b on a.TENANTID = b.ID \n"+
+            "WHERE a.DELETED = '0' AND a.TENANTID = #{tenantid} AND a.FILL = #{fill} \n" +
+            "AND a.CHECKDATE BETWEEN TO_DATE(#{startDate}, 'YYYY-MM-DD') AND TO_DATE(#{endDate}, 'YYYY-MM-DD')\n" +
+            "GROUP BY a.ISSUETYPE, a.TENANTID,b.FULLNAME")
+    List<Map<String, Object>> listGroupData(Map<String, Object> map);
 }

+ 3 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxPersistentManageService.java

@@ -21,4 +21,7 @@ public interface ZhcxPersistentManageService extends IService<ZhcxPersistentMana
     void downloadReportData(Map<String, Object> map, HttpServletResponse response);
 
     void jyWordExport(Map<String, Object> map, HttpServletResponse response);
+
+    void issueExcelExport(Map<String, Object> map, HttpServletResponse response);
+
 }

+ 88 - 3
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPersistentManageServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.aspose.cells.BorderType;
+import com.aspose.cells.SaveFormat;
 import com.aspose.cells.Style;
 import com.aspose.cells.*;
 import com.aspose.words.Cell;
@@ -23,14 +24,15 @@ import com.rongwei.bsentity.dto.ZhcxPersistentReportDto;
 import com.rongwei.bsentity.vo.FormDataVO;
 import com.rongwei.bsentity.vo.OrganizationVo;
 import com.rongwei.bsentity.vo.PersistentVo;
-import com.rongwei.bsentity.vo.ZhcxPersistentWordVO;
 import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
 import com.rongwei.rwadmincommon.system.service.SysOrganizationService;
+import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import com.rongwei.rwcommoncomponent.excel.aspose.ExcelExportUtil;
 import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
+import com.rongwei.rwcommoncomponent.excel.utils.ExcelHelpUtils;
 import com.rongwei.rwcommoncomponent.excel.utils.WordHelpUtils;
 import com.rongwei.rwcommoncomponent.excel.vo.FormData;
 import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
@@ -44,7 +46,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
 import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedInputStream;
 import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
@@ -55,7 +56,6 @@ import java.time.ZoneId;
 import java.time.temporal.WeekFields;
 import java.util.List;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -537,6 +537,91 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
         }
     }
 
+    @Override
+    public void issueExcelExport(Map<String, Object> map, HttpServletResponse response) {
+        Object typeObj = map.get("type");
+        if( ObjectUtil.isEmpty(typeObj)){
+            throw  new CustomException("导出报错,请联系管理员");
+        }
+        String type = (String) typeObj;
+        int maxRow = 29;
+        SysFileItemDo fileItemDo = null;
+        if ("油漆".equals(type)) {
+            map.put("fill","油漆保护专项");
+            fileItemDo = sysFileItemService.getById("55edd353b7ae4035bcb0dfa148d6ecae");
+        }else if("焊接".equals(type)){
+            map.put("fill","焊接通病治理");
+            fileItemDo = sysFileItemService.getById("c34b09e16d1c48c6a40f92d19f7a2397");
+            maxRow = 26;
+        }
+        List<Map<String, Object>> result = zhcxPersistentManageDao.listGroupData(map);
+        Map<String, Map<String, Integer>> pivotData = new LinkedHashMap<>();
+
+        for (Map<String, Object> row : result) {
+            String issueType = (String) row.get("ISSUETYPE");
+            String orgName = (String) row.get("ORGNAME");
+            Integer count = ((Number) row.get("CNT")).intValue();
+
+            //orgNames.add(orgName); // 收集所有列名
+
+            pivotData.putIfAbsent(issueType, new HashMap<>());
+            pivotData.get(issueType).put(orgName, count);
+        }
+
+
+        try {
+            if (!excelUtils.GetLicense()) {
+                throw new CustomException("获取license异常");
+            }
+            Workbook wb = ExcelHelpUtils.getWorkbook(fileItemDo.getFullpath());
+            Worksheet sheet = wb.getWorksheets().get(0);
+            Cells cells = sheet.getCells();
+            // 读取公司列映射(第 2 行)
+            Map<String, Integer> companyColMap = new HashMap<>();
+            int maxCol = 9;
+            for (int col = 3; col <= maxCol; col++) {
+                String companyName = cells.get(1, col).getStringValue().trim();
+                if (!companyName.isEmpty()) {
+                    companyColMap.put(companyName, col);
+                }
+            }
+
+            // 读取类型行映射(第 0 列)
+            Map<String, Integer> typeRowMap = new HashMap<>();
+            for (int row = 2; row <= maxRow; row++) {
+                String issueType = cells.get(row, 0).getStringValue().trim();
+                if (!issueType.isEmpty()) {
+                    typeRowMap.put(issueType, row);
+                }
+            }
+            for (Map.Entry<String, Map<String, Integer>> issueTypeEntry : pivotData.entrySet()) {
+                String issueType = issueTypeEntry.getKey();
+                Integer row = typeRowMap.get(issueType);
+                if (row == null) {
+                    continue; // 模板中没有该类型,跳过
+                }
+
+                for (Map.Entry<String, Integer> companyEntry : issueTypeEntry.getValue().entrySet()) {
+                    String company = companyEntry.getKey();
+                    Integer col = companyColMap.get(company);
+                    if (col == null) {
+                        continue; // 模板中没有该公司,跳过
+                    }
+
+                    cells.get(row, col).putValue(companyEntry.getValue());
+                }
+            }
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=顽症.xlsx");
+            wb.save(response.getOutputStream(), SaveFormat.XLSX);
+            wb.dispose();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     private void buildHeader(Cells cells) {
         cells.merge(0, 0, 2, 1);
         cells.get(0, 0).setValue("月份");

+ 9 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxPersistentController.java

@@ -79,4 +79,13 @@ public class ZhcxPersistentController {
     public void saveDeptUserCount(){
         zhcxPersistentManageService.saveDeptUserCount();
     }
+
+    /**
+     * 问题类型导出
+     */
+    @PostMapping("/issueExcelExport")
+    public void issueExcelExport(@RequestBody Map<String,Object> map , HttpServletResponse response){
+        zhcxPersistentManageService.issueExcelExport(map,response);
+    }
+
 }