Selaa lähdekoodia

修复按比例分配的工时错误问题

seyason 1 vuosi sitten
vanhempi
commit
0622334046

+ 37 - 7
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -2058,27 +2058,58 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                     for (Map<String, Object> map : mapList) {
                         curUserTotalTime += (Double)map.get("cost");
                     }
+                    //计算占比,并进行四舍五入造成的误差进行修正
+                    if (withPercent == 1) {
+                        for (Map<String, Object> map : mapList) {
+                            double cost = (Double)map.get("cost");
+                            if (curUserTotalTime > 0) {
+                                map.put("percent", new BigDecimal(cost/curUserTotalTime*100).setScale(2, BigDecimal.ROUND_HALF_UP));
+                            } else {
+                                map.put("percent", 0);
+                            }
+                        }
+                        if (curUserTotalTime > 0) {
+                            //修正误差
+                            BigDecimal totalPercent = new BigDecimal(0.0);
+                            for (Map<String, Object> map : mapList) {
+                                totalPercent = totalPercent.add((BigDecimal)map.get("percent"));
+                            }
+                            if (totalPercent.doubleValue() != 100) {
+                                //取最后一条数据,修正偏差
+                                int last = mapList.size() - 1;
+                                BigDecimal lastPercent = (BigDecimal)mapList.get(last).get("percent");
+                                mapList.get(last).put("percent", lastPercent.add(new BigDecimal(100).subtract(totalPercent)));
+                            }
+                        }
+                    }
+
                     for(Object i:projectIds){
                         List<Map<String, Object>> resultList = mapList.stream().filter(mp -> mp.get("projectId").equals(i)).collect(Collectors.toList());
                         if(resultList.size()>0){
+                            Map<String, Object> resultItem = resultList.get(0);
                             if ("hours".equals(exportContent) && functionTimeList.size()>0){
-                                membRowData.add(String.valueOf(resultList.get(0).get("cost")));
+                                membRowData.add(String.valueOf(resultItem.get("cost")));
                             }else if ("cost".equals(exportContent) && functionCostList.size()>0){
-                                membRowData.add(String.valueOf(resultList.get(0).get("costMoney")));
+                                membRowData.add(String.valueOf(resultItem.get("costMoney")));
                             }else {
                                 if(functionTimeList.size()>0){
-                                    membRowData.add(String.valueOf(resultList.get(0).get("cost")));
+                                    membRowData.add(String.valueOf(resultItem.get("cost")));
                                 }
                                 if (functionCostList.size()>0){
-                                    membRowData.add(String.valueOf(resultList.get(0).get("costMoney")));
+                                    membRowData.add(String.valueOf(resultItem.get("costMoney")));
                                 }
                             }
                             if (withPercent == 1) {
                                 //工时占比
-                                membRowData.add(String.valueOf(new BigDecimal((Double)resultList.get(0).get("cost")/curUserTotalTime*100).setScale(2, BigDecimal.ROUND_HALF_UP))+"%");
+                                if (resultItem.get("percent") != null) {
+                                    membRowData.add((BigDecimal)resultItem.get("percent")+"%");
+                                } else {
+                                    membRowData.add("0");
+                                }
+
                             }
                             costTime += (Double)resultList.get(0).get("cost");
-                            moneyCost = moneyCost.add((BigDecimal)resultList.get(0).get("costMoney"));
+                            moneyCost = moneyCost.add((BigDecimal)resultItem.get("costMoney"));
                         }else{
                             if ("hours".equals(exportContent) && functionTimeList.size()>0){
                                 membRowData.add("0");
@@ -2098,7 +2129,6 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                             }
                         }
                     }
-
                     if ("hours".equals(exportContent) && functionTimeList.size()>0){
                         membRowData.add(""+new BigDecimal(costTime).setScale(2, BigDecimal.ROUND_HALF_UP));
                     }else if ("cost".equals(exportContent) && functionCostList.size()>0){

+ 1 - 1
fhKeeper/formulahousekeeper/timesheet/src/views/workReport/daily.vue

@@ -4331,7 +4331,7 @@
                 if (this.reportTimeType.type == 3) {
                     //新增项目时,自动计算
                     console.log('===time====='+this.reportTimeType.allday * domain.progress/100);
-                    domain.workingTime = (this.reportTimeType.allday * domain.progress/100);
+                    domain.workingTime = (this.reportTimeType.allday * domain.progress/100).toFixed(1);
                 }
                 //加载昱众的工作职责
                 if (this.user.companyId == this.yuzhongCompId) {

+ 2 - 3
fhKeeper/formulahousekeeper/timesheet_deploy/copyFiles.sh

@@ -1,3 +1,2 @@
-\cp timesheet-3.4.0.jar /www/webapps/worktime/
-\cp -rf static_pc/dist/* /www/staticproject/timesheet/
-\cp -rf static_h5/dist/* /www/staticproject/timesheet_h5/
+\cp timesheet-3.4.0.jar /www/webapps/worktime/;\cp -rf static_pc/dist/* /www/staticproject/timesheet/;\cp -rf static_h5/dist/* /www/staticproject/timesheet_h5/;
+echo 'all files are copied successful, if there is db script, you should run sh import_sql.sh; then you can restart server with command: sh /www/webapps/worktime/restart.sh'