Browse Source

员工绩效pc

yzc 10 months ago
parent
commit
60cf449a74

+ 8 - 0
hx-form/src/main/java/com/fjhx/form/controller/ReportController.java

@@ -99,4 +99,12 @@ public class ReportController {
         return reportService.getReceivableAccounts(dto);
     }
 
+    /**
+     * 员工绩效
+     */
+    @PostMapping("/userPerformanceReport")
+    List<UserPerformanceBo> userPerformanceReport(@RequestBody UserPerformanceSelectDto dto) {
+        return reportService.userPerformanceReport(dto);
+    }
+
 }

+ 20 - 0
hx-form/src/main/java/com/fjhx/form/entity/UserPerformanceBo.java

@@ -0,0 +1,20 @@
+package com.fjhx.form.entity;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class UserPerformanceBo {
+    private Long userId;
+    private String userName;
+    private BigDecimal amount;
+    private JSONObject dayData;
+    private Integer month;
+    @JsonIgnore
+    private String dayJson;
+}

+ 14 - 0
hx-form/src/main/java/com/fjhx/form/entity/UserPerformanceSelectDto.java

@@ -0,0 +1,14 @@
+package com.fjhx.form.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Getter
+@Setter
+public class UserPerformanceSelectDto {
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
+    private Date dataDate;
+}

+ 6 - 0
hx-form/src/main/java/com/fjhx/form/mapper/ReportMapper.java

@@ -6,6 +6,7 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 @Mapper
@@ -29,4 +30,9 @@ public interface ReportMapper {
      * 获取客户某年每月 装车金额,到账金额
      */
     List<CustomerMonthlyAccounts> getCustomerMonthlyAccounts(@Param("year") Integer year);
+
+    /**
+     * 员工绩效
+     */
+    List<UserPerformanceBo> userPerformanceReport(@Param("dataDate") Date dataDate);
 }

+ 5 - 0
hx-form/src/main/java/com/fjhx/form/service/ReportService.java

@@ -47,4 +47,9 @@ public interface ReportService {
      * 应收账款-批单
      */
     List<JSONObject> getReceivableAccounts(ReceivableAccountsSelectDto dto);
+
+    /**
+     * 员工绩效
+     */
+    List<UserPerformanceBo> userPerformanceReport(UserPerformanceSelectDto dto);
 }

+ 41 - 0
hx-form/src/main/java/com/fjhx/form/service/impl/ReportServiceImpl.java

@@ -468,4 +468,45 @@ public class ReportServiceImpl implements ReportService {
         SecurityUtils.clearTenantId();
         DynamicDataSourceContextHolder.clear();
     }
+
+    @Override
+    public List<UserPerformanceBo> userPerformanceReport(UserPerformanceSelectDto dto) {
+        Assert.notEmpty(dto.getDataDate(), "日期过滤不能为空");
+        List<UserPerformanceBo> userPerformanceBos = reportMapper.userPerformanceReport(dto.getDataDate());
+        //获取月份天数
+        int month = DateUtil.month(dto.getDataDate()) + 1;
+        int dayCount = DateUtil.lengthOfMonth(month, DateUtil.isLeapYear(DateUtil.year(dto.getDataDate())));
+
+        //合计
+        UserPerformanceBo totalBo = new UserPerformanceBo();
+        totalBo.setUserName("合计");
+        totalBo.setMonth(month);
+        totalBo.setAmount(BigDecimal.ZERO);
+        totalBo.setDayData(new JSONObject());
+
+        for (UserPerformanceBo userPerformanceBo : userPerformanceBos) {
+            userPerformanceBo.setMonth(month);
+
+            JSONObject parse = JSONObject.parse(userPerformanceBo.getDayJson());
+
+            JSONObject dayData = new JSONObject();
+            for (int i = 1; i <= dayCount; i++) {
+                dayData.put("" + i, parse.getOrDefault(i, 0));
+
+                //计算合计
+                JSONObject totalDayData = totalBo.getDayData();
+                totalDayData.put("" + i, ObjectUtil.defaultIfNull(totalDayData.getBigDecimal("" + i), BigDecimal.ZERO).add(dayData.getBigDecimal("" + i)));
+                totalBo.setDayData(totalDayData);
+            }
+
+            userPerformanceBo.setDayData(dayData);
+
+            //计算合计
+            totalBo.setAmount(totalBo.getAmount().add(ObjectUtil.defaultIfNull(userPerformanceBo.getAmount(), BigDecimal.ZERO)));
+        }
+
+        userPerformanceBos.add(totalBo);
+
+        return userPerformanceBos;
+    }
 }

+ 18 - 3
hx-form/src/main/resources/mapper/ReportMapper.xml

@@ -4,14 +4,14 @@
 
     <select id="productionReport" resultType="com.fjhx.form.entity.ProductionReportBo">
         SELECT pod.id,
-               pod.company_id                                                     AS factoryId,
-               po.`code`                                                          AS orderCode,
+               pod.company_id AS factoryId,
+               po.`code`      AS orderCode,
                pod.product_id,
                pod.quantity,
                po.delivery_period,
                pod.finish_time,
                IF(DATE_FORMAT(IFNULL(po.finish_time, NOW()), '%Y-%m-%d') > DATE_FORMAT(po.delivery_period, '%Y-%m-%d'),
-                  1, 0)                                                           as isOverdue,
+                  1, 0)       as isOverdue,
                IF(DATE_FORMAT(IFNULL(po.finish_time, NOW()), '%Y-%m-%d') > DATE_FORMAT(po.delivery_period, '%Y-%m-%d'),
                   DATEDIFF(IFNULL(po.finish_time, NOW()), po.delivery_period), 0) as overdueDay,
                DATEDIFF(po.delivery_period, po.produce_time) /
@@ -218,4 +218,19 @@
         GROUP BY t1.buy_corporation_id,
                  t1.data_month
     </select>
+    <select id="userPerformanceReport" resultType="com.fjhx.form.entity.UserPerformanceBo">
+        SELECT t1.user_id,
+               su.nick_name                                                                AS user_name,
+               sum(t1.amount)                                                              AS amount,
+               CONCAT('{', GROUP_CONCAT(CONCAT('"', t1.`data_day`, '":', t1.amount)), '}') AS dayJson
+        FROM (SELECT prd.user_id,
+                     IFNULL(sum(prd.amount), 0)         AS amount,
+                     DATE_FORMAT(prd.create_time, '%d') AS data_day
+              FROM production_reporting_detail prd
+              WHERE DATE_FORMAT(prd.create_time, '%Y-%m') = DATE_FORMAT(#{dataDate}, '%Y-%m')
+              GROUP BY prd.user_id,
+                       data_day) t1
+                 LEFT JOIN sys_user su ON t1.user_id = su.user_id
+        GROUP BY t1.user_id
+    </select>
 </mapper>