Browse Source

分摊比例导出修改 模板

yurk 2 years ago
parent
commit
fbd0382d72

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectPercentageController.java

@@ -41,5 +41,10 @@ public class ProjectPercentageController {
                                   MultipartFile file, HttpServletRequest request,String ymonth) throws Exception {
         return projectPercentageService.importData(companyId,withCheckIn, file, request,ymonth);
     }
+
+    @RequestMapping("/getTemplate")
+    public HttpRespMsg getTemplate(String ymonth) throws Exception {
+        return projectPercentageService.getTemplate(ymonth);
+    }
 }
 

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectPercentageService.java

@@ -22,4 +22,6 @@ public interface ProjectPercentageService extends IService<ProjectPercentage> {
     HttpRespMsg getMonthSetting(String ymonth);
 
     HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile file, HttpServletRequest request,String ymonth) throws Exception;
+
+    HttpRespMsg getTemplate(String ymonth);
 }

+ 40 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectPercentageServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
+import com.management.platform.service.ExcelExportService;
 import com.management.platform.service.FinanceProjectsService;
 import com.management.platform.service.ProjectPercentageService;
 import com.management.platform.service.WxCorpInfoService;
@@ -14,15 +15,19 @@ import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
 import com.taobao.api.internal.util.StringUtils;
 import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddressList;
 import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.*;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -53,7 +58,11 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
     @Resource
     private WxCorpInfoMapper wxCorpInfoMapper;
     @Resource
+    private ExcelExportService excelExportService;
+    @Resource
     private ProjectPercentageService projectPercentageService;
+    @Value(value = "${upload.path}")
+    private String path;
     @Override
     public HttpRespMsg saveMonthSetting(String projectCols, String userSettings, String ymonth) {
         HttpRespMsg msg = new HttpRespMsg();
@@ -273,7 +282,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
                     }
                     //人员存在
                     User user = userOp.get();
-                    Integer s = 0;
+                    BigDecimal s = new BigDecimal(0);
                     JSONObject jsonObject=new JSONObject();
                     jsonObject.put("name",user.getName());
                     jsonObject.put("id",user.getId());
@@ -286,7 +295,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
                         if (StringUtils.isEmpty(stringCellValue)) {
                             stringCellValue = "0";
                         }
-                        s+=Integer.parseInt(stringCellValue);
+                        s=s.add(BigDecimal.valueOf(Double.parseDouble(stringCellValue)));
                         String pid = projectList.get(i-1);
                         jsonObject.put(pid,stringCellValue);
                         if (!filterFPList.stream().anyMatch(f->f.getProjectId().equals(pid))) {
@@ -310,7 +319,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
                     }else{
                         dataString+=dataStringOne+"]";
                     }
-                    if(s!=100){
+                    if(s.doubleValue()!=100){
                         //msg.setError("人员["+username+"]"+"分摊比例不满足100%,当前比例["+s+"%],请检查");
                         msg.setError(MessageUtils.message("staff.proportionError",username,s));
                         return msg;
@@ -378,4 +387,32 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
             System.out.println(file.delete());
         }
     }
+
+    @Override
+    public HttpRespMsg getTemplate(String ymonth) {
+        HttpRespMsg httpRespMsg=new HttpRespMsg();
+        HttpRespMsg monthSetting = getMonthSetting(ymonth);
+        Map<String,Object> data= (Map<String, Object>) monthSetting.data;
+        List<FinanceProjects> financeProjects = (List<FinanceProjects>) data.get("financeProjects");
+        List<List<String>> dataList=new ArrayList<>();
+        List<Map<String, Object>> userCostSetting = (List<Map<String, Object>>) data.get("userCostSetting");
+        List<String> titleList=new ArrayList<>();
+        titleList.add("姓名");
+        for (FinanceProjects financeProject : financeProjects) {
+            titleList.add(String.valueOf(financeProject.getProjectName()));
+        }
+        dataList.add(titleList);
+        for (Map<String, Object> map : userCostSetting) {
+            List<String> itemList=new ArrayList<>();
+            itemList.add(String.valueOf(map.get("name")));
+            for (FinanceProjects financeProject : financeProjects) {
+                itemList.add(String.valueOf(map.get(String.valueOf(financeProject.getProjectId()))));
+            }
+            dataList.add(itemList);
+        }
+        String fileName = "人员分摊比例导入模板"+"_"+System.currentTimeMillis();
+        ExcelUtil.exportGeneralExcelByTitleAndList(fileName, dataList, path);
+        httpRespMsg.data =  "/upload/" + fileName+".xls";
+        return httpRespMsg;
+    }
 }

+ 3 - 3
fhKeeper/formulahousekeeper/timesheet/src/views/project/finance.vue

@@ -649,7 +649,7 @@ import { error } from 'dingtalk-jsapi';
                 chosenProjectsChecked: false,
                 exportDataProcessing: false,
 
-                financialFlg: true
+                financialFlg: false
             };
         },
         methods: {
@@ -908,9 +908,9 @@ import { error } from 'dingtalk-jsapi';
                             this.allProjectList = res.data.allProjectList;
                             this.userCostSettingList = res.data.userCostSetting;
                             if(res.data.financeProjects.length <= 0 && res.data.userCostSetting <= 0) {
-                                this.financialFlg = false
-                            } else {
                                 this.financialFlg = true
+                            } else {
+                                this.financialFlg = false
                             }
                             console.log(this.financialFlg, '看看返回的数据是什么')
                             //上次如果没有配置过,需要初始化