Min před 1 rokem
rodič
revize
73fad87d19

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

@@ -2445,5 +2445,10 @@ public class ReportController {
     public HttpRespMsg exportUserWorkTimeByCategory(@RequestParam(required = true) Integer categoryId,Integer deptId,String userId,String startDate,String endDate){
         return reportService.exportUserWorkTimeByCategory(categoryId,deptId,userId,startDate,endDate);
     }
+
+    @RequestMapping("getCustomDataWithDate")
+    public HttpRespMsg getCustomDataWithDate(String startDate,String endDate,HttpServletRequest request){
+        return reportService.getCustomDataWithDate(startDate,endDate,request);
+    }
 }
 

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ReportMapper.java

@@ -201,4 +201,5 @@ public interface ReportMapper extends BaseMapper<Report> {
 
     List<Map<String, Object>> getUserWorkTimeByCategory(Integer categoryId, String userId,Integer companyId,@Param("list")List<Integer> deptIds, Integer deptId, String startDate, String endDate);
 
+    List<Map<String, Object>> getCustomDataWithDate(String startDate, String endDate, Integer companyId);
 }

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

@@ -147,4 +147,6 @@ public interface ReportService extends IService<Report> {
     HttpRespMsg cannelAllReport();
 
     HttpRespMsg getHasPushForSap(String startDate, String endDate, String employeeID);
+
+    HttpRespMsg getCustomDataWithDate(String startDate, String endDate, HttpServletRequest request);
 }

+ 80 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -8580,4 +8580,84 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
         msg.setData(actualEmployeeTimes);
         return msg;
     }
+
+    @Override
+    public HttpRespMsg getCustomDataWithDate(String startDate, String endDate, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg=new HttpRespMsg();
+        Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
+        DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        List<LocalDate> dateList = getDays(LocalDate.parse(startDate,df), LocalDate.parse(endDate,df));
+        //检查是否有查看全公司数值的权限
+        User curUser = userMapper.selectById(request.getHeader("TOKEN"));
+        List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(curUser.getRoleId(), "查看全公司数值");
+        List<Map<String,Object>> mapList=reportMapper.getCustomDataWithDate(startDate,endDate,companyId);
+        if(functionList==null){
+           mapList=new ArrayList<>();
+        }
+        Map<String, List<Map<String, Object>>> tempMap = new HashMap<>();
+        List<Map<String,Object>> createDateList = new ArrayList<>();
+        Double totalCost = 0.0;
+        //结果集中默认加上不存在的日期数据
+        for (LocalDate date : dateList) {
+            String dateString = df.format(date);
+            Optional<Map<String, Object>> first = mapList.stream().filter(m -> String.valueOf(m.get("createDate")).equals(dateString)).findFirst();
+            if(!first.isPresent()){
+                Map<String,Object> map=new HashMap<>();
+                map.put("createDate",dateString);
+                map.put("project","");
+                map.put("cost",Double.valueOf(0));
+                mapList.add(map);
+            }
+        }
+        mapList = mapList.stream().sorted(Comparator.comparing(m->LocalDate.parse(String.valueOf(m.get("createDate")),df))).collect(Collectors.toList());
+        for (Map<String, Object> map : mapList) {
+            if (tempMap.containsKey(map.get("createDate"))) {
+                //这个名字已经装进数组中了
+                List<Map<String, Object>> tempList = tempMap.get(map.get("createDate"));
+                Map<String, Object> dataMap = new HashMap<>();
+                dataMap.put("project", map.get("project"));
+                Double cost = (Double) map.getOrDefault("cost", 0);
+                totalCost = totalCost + cost;
+                dataMap.put("cost", cost);
+                tempList.add(dataMap);
+            } else {
+                Map<String,Object> createMap=new HashMap<>();
+                createMap.put("createDate",(String)map.get("createDate"));
+                createDateList.add(createMap);
+                //这个名字尚未装进数组中
+                List<Map<String, Object>> tempList = new ArrayList<>();
+                if (map.containsKey("project")) {
+                    Map<String, Object> dataMap = new HashMap<>();
+                    dataMap.put("project", map.get("project"));
+                    Double cost = (Double) map.getOrDefault("cost", 0);
+                    totalCost = totalCost + cost;
+                    dataMap.put("cost", cost);
+                    tempList.add(dataMap);
+                }
+                tempMap.put((String) map.get("createDate"), tempList);
+            }
+        }
+        Map<String, Object> finalMap = new HashMap<>();
+        List<Map<String, Object>> finalList = new ArrayList<>();
+        for (String key : tempMap.keySet()) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", key);
+            List<Map<String, Object>> userProjectTime = tempMap.get(key);
+            map.put("project", userProjectTime);
+            //计算总时间
+            double userTotalTime = 0;
+            for (Map<String, Object> timeItem: userProjectTime) {
+                double t = (double)timeItem.get("cost");
+                userTotalTime += t;
+            }
+            map.put("cost", userTotalTime);
+            finalList.add(map);
+        }
+        finalList=finalList.stream().sorted(Comparator.comparing(m->LocalDate.parse(String.valueOf(m.get("name")),df))).collect(Collectors.toList());
+        finalMap.put("totalCost", totalCost);
+        finalMap.put("list", finalList);
+        finalMap.put("createDateList",createDateList);
+        httpRespMsg.data = finalMap;
+        return httpRespMsg;
+    }
 }

+ 13 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -1146,4 +1146,17 @@
         </if>
         group by p.id,r.create_date,u.id
     </select>
+
+    <select id="getCustomDataWithDate" resultType="java.util.Map">
+        SELECT  DATE_FORMAT(b.`create_date`,'%Y-%m-%d') AS createDate,c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
+        FROM  report AS b
+        LEFT JOIN project AS c ON b.project_id = c.id
+        WHERE b.state = 1
+        AND b.company_id =#{companyId}
+        <if test="startDate!=null and endDate!=null">
+        AND b.create_date BETWEEN #{startDate} AND #{endDate}
+        </if>
+        GROUP BY b.project_id,b.`create_date`
+        HAVING IFNULL(SUM(b.custom_data),0) > 0
+    </select>
 </mapper>

+ 5 - 4
fhKeeper/formulahousekeeper/timesheet/src/views/project/custom_data.vue

@@ -21,6 +21,7 @@
                 <!-- <el-radio-button :label="部门"></el-radio-button> -->
                 <el-radio-button :label="$t('ren-yuan')"></el-radio-button>
                 <el-radio-button :label="$t('lable.department')"></el-radio-button>
+                <el-radio-button :label="'日期'"></el-radio-button>
                 <!-- <el-radio-button :label="namess" v-if="jichu.customDegreeActive == 1"></el-radio-button> -->
             </el-radio-group>
         </el-col>
@@ -225,7 +226,7 @@
             //获取人员成本统计列表
             getUserCostList() {
                 this.listLoading = true;
-                let url = this.radio == this.$t('ren-yuan') ? '/department/getUserCustomDataStatistic' : '/department/getDeptCustomDataStatistic'
+                let url = this.radio == this.$t('ren-yuan') ? '/department/getUserCustomDataStatistic' :this.radio == '日期'?'/report/getCustomDataWithDate': '/department/getDeptCustomDataStatistic'
                 this.http.post(url, {
                     startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange, 
                     endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
@@ -472,7 +473,7 @@
                     url = '/project/getCustomDataSum';
                 // } else if (this.radio=='部门') {
                 //     url = '/department/getDeptCustomDataStatistic';
-                } else if (this.radio==this.$t('ren-yuan') || this.radio == this.$t('lable.department')) {
+                } else if (this.radio==this.$t('ren-yuan') || this.radio == this.$t('lable.department')||this.radio == '日期') {
                     this.getUserCostList();
                     return;
                 } else if (this.radio == this.namess) {
@@ -519,7 +520,7 @@
                                     totalHours += parseFloat(list[i].costTime);
                                 }
                             }
-                        } else {
+                        } else if(this.radio == this.$t('ren-yuan') || this.radio=='日期') {
                             list = res.data
                             var totalMoneyCost = 0;
                             for(var i in list) {
@@ -547,7 +548,7 @@
                         if(totalMoneyCost) {
                             this.zhishin = totalMoneyCost.toFixed(2)
                         } 
-                        if(this.radio == this.$t('other.project') || this.radio == this.$t('ren-yuan') || this.radio==this.$t('lable.department')) {
+                        if(this.radio == this.$t('other.project') || this.radio == this.$t('ren-yuan') || this.radio==this.$t('lable.department')|| this.radio=='日期') {
                             var option = {
                                 title: {
                                     text: _this.user.timeType.customDataName+_this.$t('zong-ji')+':' + totalHours,