Parcourir la source

修改导出分时耗用进度表研发工艺

yusm il y a 8 mois
Parent
commit
6545809010

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -27,6 +27,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.UnsupportedEncodingException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -1496,7 +1497,7 @@ public class ProjectController {
 
     //依斯倍定制 分组耗用人员分组耗用
     @RequestMapping("/exportGroupExpendProcessListForUser")
-    public HttpRespMsg exportGroupExpendProcessListForUser(String startDate,String endDate,String projectIds,String groupNames,String titleStr,String deptIdStr){
+    public HttpRespMsg exportGroupExpendProcessListForUser(String startDate,String endDate,String projectIds,String groupNames,String titleStr,String deptIdStr) throws UnsupportedEncodingException {
         return projectService.exportGroupExpendProcessListForUser(startDate,endDate,projectIds,groupNames,titleStr,deptIdStr);
     }
 

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectService.java

@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
 import java.time.LocalDate;
 
 /**
@@ -307,6 +308,6 @@ public interface ProjectService extends IService<Project> {
 
     HttpRespMsg groupExpendProcessListForProject(String startDate, String endDate, String projectIds, String groupNames, String deptIdStr,Integer pageIndex,Integer pageSize);
 
-    HttpRespMsg exportGroupExpendProcessListForUser(String startDate, String endDate, String projectIds, String groupNames,String titleStr, String deptIdStr);
+    HttpRespMsg exportGroupExpendProcessListForUser(String startDate, String endDate, String projectIds, String groupNames,String titleStr, String deptIdStr) throws UnsupportedEncodingException;
 
 }

+ 46 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -52,6 +52,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.net.URLDecoder;
 import java.sql.Timestamp;
 import java.text.*;
 import java.time.*;
@@ -14899,8 +14900,15 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return msg;
     }
 
+    // 从map中获取Double值,如果键不存在则返回0.0
+    private static double getDoubleValue(Map<String, Object> map, String key) {
+        return Optional.ofNullable(map.get(key))
+                .filter(Double.class::isInstance)
+                .map(Double.class::cast)
+                .orElse(0.0);
+    }
     @Override
-    public HttpRespMsg exportGroupExpendProcessListForUser(String startDate, String endDate, String projectIds, String groupNames,String titleStr, String deptIdStr) {
+    public HttpRespMsg exportGroupExpendProcessListForUser(String startDate, String endDate, String projectIds, String groupNames,String titleStr, String deptIdStr) throws UnsupportedEncodingException {
         User user = userMapper.selectById(request.getHeader("token"));
         WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
         List<List<String>> dataList=new ArrayList<>();
@@ -14908,8 +14916,12 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         titleList.add("所属部门");
         titleList.add("工号");
         titleList.add("员工");
+        List<String> strings=new ArrayList<>();
         if(!StringUtils.isEmpty(titleStr)){
-            List<String> strings = Arrays.asList(titleStr.split(","));
+            // 解码
+            String decodedString = URLDecoder.decode(titleStr, "UTF-8");
+            System.out.println("Decoded String: " + decodedString);
+            strings = Arrays.asList(decodedString.split(","));
             titleList.addAll(strings);
         }
         dataList.add(titleList);
@@ -14917,6 +14929,13 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         Map<String, Object> data = (Map<String, Object>)  msg.data;
         List<Map<String, Object>> mapList = (List<Map<String, Object>>) data.get("record");
         for (Map<String, Object> map : mapList) {
+            // 提取值并提供默认值
+            double design = getDoubleValue(map, "方案设计");
+            double research = getDoubleValue(map, "研发部");
+            double researchDesign = getDoubleValue(map, "研发部工艺设计");
+            double researchDesignShou = getDoubleValue(map, "研发部工艺调试验收");
+            double researchTiao = getDoubleValue(map, "研发部工艺调试");
+            Double sum=design+research+researchDesign+researchDesignShou+researchTiao;
             List<String> item=new ArrayList<>();
             if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                 item.add("$departmentName="+String.valueOf(map.get("departmentName"))+"$");
@@ -14929,7 +14948,24 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
             }else {
                 item.add(String.valueOf(map.get("userName")));
             }
-            for (String s : titleList) {
+            // 格式化为两位小数
+            DecimalFormat df = new DecimalFormat("#.00");
+            for (String s : strings) {
+                if (s.equals("报价占比")){
+                    extracted(sum, design, df, item);
+                    continue;
+                } else if (s.equals("行政占比")) {
+                    // 计算百分比
+                    extracted(sum, research, df, item);
+                    continue;
+                } else if (s.equals("项目设计占比")) {
+                    // 计算百分比
+                    extracted(sum, researchDesign, df, item);
+                    continue;
+                }else if (s.equals("总计")) {
+                    item.add(String.valueOf(sum));
+                    continue;
+                }
                 item.add(String.valueOf(map.get(s)));
             }
             dataList.add(item);
@@ -14941,4 +14977,11 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         }
         return msg;
     }
+
+    private static void extracted(Double sum, double design, DecimalFormat df, List<String> item) {
+        // 计算百分比
+        double percentage = (sum == 0) ? 0 : (design / sum) * 100;
+        String formattedPercentage =percentage==0 ? "0.00%": df.format(percentage)+"%";
+        item.add(formattedPercentage);
+    }
 }