瀏覽代碼

统计接口

lipenghui 1 天之前
父節點
當前提交
4c4eb3f8cf

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintain/vo/IotMaintainPageReqVO.java

@@ -91,4 +91,5 @@ public class IotMaintainPageReqVO extends PageParam {
      */
     private String outFile;
     private Set<Long> deptIds;
+    private String timeType;
 }

+ 63 - 16
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotRepairController.java

@@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainW
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.ReportCost;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorder.IotMainWorkOrderDO;
-import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.IotMaintainDO;
 import cn.iocoder.yudao.module.pms.dal.mysql.maintain.IotMaintainMapper;
 import cn.iocoder.yudao.module.pms.service.iotmainworkorder.IotMainWorkOrderService;
 import cn.iocoder.yudao.module.pms.service.maintain.IotMaintainService;
@@ -24,9 +23,9 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
 import java.math.BigDecimal;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@@ -45,7 +44,9 @@ public class IotRepairController {
     private final IotMainWorkOrderService iotMainWorkOrderService;
 
     @GetMapping("/fee")
-    public CommonResult<ImmutableMap<String, BigDecimal>> getRepairFee(@Valid IotMaintainPageReqVO pageReqVO) {
+    public CommonResult<ImmutableMap<String, Object>> getRepairFee(@Valid IotMaintainPageReqVO pageReqVO) {
+        LocalDateTime startTime = pageReqVO.getCreateTime()[0];
+        LocalDateTime endTime = pageReqVO.getCreateTime()[1];
         Set<Long> ids;
         if (Objects.isNull(pageReqVO.getDeptId())){
             Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
@@ -56,26 +57,72 @@ public class IotRepairController {
             ids.add(pageReqVO.getDeptId());
         }
         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
-        PageResult<IotMaintainDO> iotMaintainDOPageResult = iotMaintainMapper.selectPage(pageReqVO, ids);
+        pageReqVO.setDeptIds(ids);
+        BigDecimal totalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
+        pageReqVO.setType("out");
+        BigDecimal outFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+        //获取环比
+        LocalDateTime lastYearStart = pageReqVO.getCreateTime()[0].minusYears(1);
+        LocalDateTime lastYearEnd = pageReqVO.getCreateTime()[1].minusYears(1);
+        LocalDateTime[] createTime = pageReqVO.getCreateTime();
+        createTime[0] = lastYearStart;
+        createTime[1] = lastYearEnd;
+        pageReqVO.setCreateTime(createTime);
+        pageReqVO.setType(pageReqVO.getType());
+        BigDecimal hbTotalFee;
+        BigDecimal hbOutFee;
+        hbTotalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
+        pageReqVO.setType("out");
+        hbOutFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+
+        BigDecimal tbTotalFee = new BigDecimal("0");
+        BigDecimal tbOutFee = new BigDecimal("0");
+        //获取同比
+        if ("year".equals(pageReqVO.getTimeType())){
+            tbTotalFee = hbTotalFee==null?BigDecimal.ZERO:hbTotalFee;
+            tbOutFee = hbOutFee==null?BigDecimal.ZERO:hbOutFee;
+        } else if ("month".equals(pageReqVO.getTimeType())){
+            LocalDateTime lastMonthStart = startTime.minusMonths(1);
+            LocalDateTime lastMonthEnd = endTime.minusMonths(1);
+            LocalDateTime[] monthTime = pageReqVO.getCreateTime();
+            monthTime[0] = lastMonthStart;
+            monthTime[1] = lastMonthEnd;
+            pageReqVO.setCreateTime(monthTime);
+            pageReqVO.setType(pageReqVO.getType());
+            tbTotalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
+            pageReqVO.setType("out");
+            tbOutFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+        } else if ("day".equals(pageReqVO.getTimeType())){
+            LocalDateTime lastDayStart = startTime.minusDays(1);
+            LocalDateTime lastDayEnd = endTime.minusDays(1);
+            LocalDateTime[] dayTime = pageReqVO.getCreateTime();
+            dayTime[0] = lastDayStart;
+            dayTime[1] = lastDayEnd;
+            pageReqVO.setCreateTime(dayTime);
+            pageReqVO.setType(pageReqVO.getType());
+            tbTotalFee = iotMaintainMapper.getMaintainFeeIn(pageReqVO);
+            pageReqVO.setType("out");
+            tbOutFee = iotMaintainMapper.getMaintainFee(pageReqVO);
+        }
         // 查询保养费用
         IotMainWorkOrderPageReqVO workOrderReqVO = new IotMainWorkOrderPageReqVO();
         workOrderReqVO.setDeptIds(ids);
         workOrderReqVO.setCreateTime(pageReqVO.getCreateTime());
         List<IotMainWorkOrderDO> workOrders = iotMainWorkOrderService.workOrders(workOrderReqVO);
-
-        BigDecimal totalFee = iotMaintainDOPageResult.getList().stream()
-                .map(IotMaintainDO::getMaintainFee)
-                .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
-                .reduce(BigDecimal.ZERO, BigDecimal::add);
-        BigDecimal outFee = iotMaintainDOPageResult.getList().stream().filter(e -> "out".equals(e.getType()))
-                .map(IotMaintainDO::getMaintainFee)
-                .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
-                .reduce(BigDecimal.ZERO, BigDecimal::add);
         BigDecimal byFee = workOrders.stream()
                 .map(IotMainWorkOrderDO::getCost)
                 .map(fee -> Objects.isNull(fee) ? BigDecimal.ZERO : fee)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
-        return CommonResult.success(ImmutableMap.of("repair", totalFee, "out", outFee, "byFee", byFee));
+        Map<String, Object> totalMap = new HashMap<>();
+        totalMap.put("total", totalFee);
+        totalMap.put("hb", hbTotalFee==null|| hbTotalFee.equals(BigDecimal.ZERO) ? hbTotalFee :((totalFee.subtract(hbTotalFee)).divide(hbTotalFee,2, RoundingMode.HALF_UP)));
+        totalMap.put("tb", tbTotalFee==null||tbTotalFee.equals(BigDecimal.ZERO)?tbTotalFee:((totalFee.subtract(tbTotalFee)).divide(tbTotalFee,2, RoundingMode.HALF_UP)));
+        Map<String, Object> outMap = new HashMap<>();
+        outMap.put("total", outFee);
+        outMap.put("hb", hbOutFee==null||hbOutFee.equals(BigDecimal.ZERO)?hbOutFee:((outFee.subtract(hbOutFee)).divide(hbOutFee,2, RoundingMode.HALF_UP)));
+        outMap.put("tb", tbOutFee==null||tbOutFee.equals(BigDecimal.ZERO)?tbOutFee:((outFee.subtract(tbOutFee)).divide(tbOutFee,2, RoundingMode.HALF_UP)));
+        return CommonResult.success(ImmutableMap.of("repair", totalMap,
+                "out", outMap, "byFee", byFee));
     }
 
 

+ 6 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotReportDeviceController.java

@@ -32,7 +32,6 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.annotation.security.PermitAll;
 import javax.validation.Valid;
-import java.sql.Array;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
@@ -288,4 +287,10 @@ public class IotReportDeviceController {
         return success(new PageResult<>(iotDeviceRespVOS, pageResult.getTotal()));
     }
 
+
+    @GetMapping("/dept/{deptId}")
+    public CommonResult<String> getCompanyCode(@PathVariable("deptId") Long deptId) {
+        String companyCode = deptUtil.getCompanyCode(deptId);
+        return CommonResult.success(companyCode);
+    }
 }

+ 6 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/maintain/IotMaintainMapper.java

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pms.dal.mysql.maintain;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.pms.controller.admin.inspect.item.vo.IotInspectItemPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
@@ -21,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -96,5 +98,9 @@ public interface IotMaintainMapper extends BaseMapperX<IotMaintainDO> {
     }
 
     List<AllOrderResp> selectStatusNumber(@Param("reqVO") IotMaintainPageReqVO reqVO);
+    @TenantIgnore
     IPage<AllOrderResp> getAllOrder(IPage<IotMaintainPageReqVO> page, @Param("reqVO") IotMaintainPageReqVO reqVO);
+
+    BigDecimal getMaintainFee(@Param("reqVO") IotMaintainPageReqVO reqVO);
+    BigDecimal getMaintainFeeIn(@Param("reqVO") IotMaintainPageReqVO reqVO);
 }

+ 112 - 45
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotMaintainMapper.xml

@@ -55,8 +55,25 @@
 
     <select id="getCost" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
             resultType="cn.iocoder.yudao.module.pms.controller.admin.stat.vo.ReportCost">
-        select CAST(create_time AS CHAR) as date, '维修'as type, device_code as deviceCode, device_name as deviceName, maintain_fee as cost from rq_iot_maintain a
+        select * from (select CAST(create_time AS CHAR) as date, '内部维修'as type, device_code as deviceCode, device_name as deviceName, maintain_fee as cost from rq_iot_maintain a
         <where>
+            a.deleted=0 and a.type!='out'
+            <if test="reqVO.createTime[0] != null">
+                AND a.create_time &gt;= #{reqVO.createTime[0]}
+            </if>
+            <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
+                AND a.create_time &lt;= #{reqVO.createTime[1]}
+            </if>
+            <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+                AND a.dept_id IN
+                <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                    #{key}
+                </foreach>
+            </if>
+        </where>
+        select CAST(create_time AS CHAR) as date, '委外维修'as type, device_code as deviceCode, device_name as deviceName, maintain_fee as cost from rq_iot_maintain a
+        <where>
+            a.deleted=0 and a.type='out'
             <if test="reqVO.createTime[0] != null">
                 AND a.create_time &gt;= #{reqVO.createTime[0]}
             </if>
@@ -96,7 +113,12 @@
                 #{key}
             </foreach>
         </if>
-        GROUP BY wo.id, wob.device_id
+        GROUP BY wo.id, wob.device_id) fin
+        <where>
+            <if test="reqVO.type != null">
+                AND fin.type = #{reqVO.type}
+            </if>
+        </where>
     </select>
 
     <select id="selectStatusNumber" parameterType="cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO"
@@ -223,14 +245,21 @@ select * from (
 
         UNION ALL
 
-        select b.id,'保养工单' as type,
-                '' as taskId,
-               b.create_time as createTime,
+        SELECT
+        c.id,
+        '' AS taskId,
+        '运行记录' AS type,
+        c.create_time AS createTime,
+        -- 核心优化:status 数值转中文描述
         CASE
-        WHEN b.result = 1 THEN '未完成'
-        WHEN b.result = 2 THEN '已完成'
+        WHEN c.order_status = 0 THEN '未完成'
+        WHEN c.order_status = 1 THEN '已完成'
+        WHEN c.order_status = 2 THEN '填写中'
         ELSE '' -- 兼容其他未知状态值
-        END AS status, '' as device,b.dept_id as deptId,
+        END AS status,
+        '' AS device,
+        c.dept_id AS deptId,
+        -- 按type规则填充company字段
         CASE
         WHEN d.type = 1 THEN COALESCE(d.`name`, '')
         WHEN d.type = 2 THEN COALESCE(p1.`name`, '')
@@ -248,37 +277,36 @@ select * from (
         WHEN d.type = 3 THEN COALESCE(d.`name`, '')
         ELSE ''
         END AS deptName
-        from rq_iot_main_work_order b
+        FROM rq_iot_opeation_fill_order c
         -- 左关联当前部门(避免主表数据丢失)
-        LEFT JOIN system_dept d ON b.dept_id = d.id
+        LEFT JOIN system_dept d ON c.dept_id = d.id
         -- 左关联父级部门(type=2/3时用)
         LEFT JOIN system_dept p1 ON d.parent_id = p1.id
         -- 左关联祖父级部门(type=3时用)
         LEFT JOIN system_dept p2 ON p1.parent_id = p2.id
         <where>
-            b.deleted = 0
+            c.deleted=0
             <if test="reqVO.createTime[0] != null">
-                AND b.create_time &gt;= #{reqVO.createTime[0]}
+                AND c.create_time &gt;= #{reqVO.createTime[0]}
             </if>
             <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
-                AND b.create_time &lt;= #{reqVO.createTime[1]}
+                AND c.create_time &lt;= #{reqVO.createTime[1]}
             </if>
             <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
-                AND b.dept_id IN
+                AND c.dept_id IN
                 <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
                     #{key}
                 </foreach>
             </if>
         </where>
+        union all
 
-        UNION ALL
-
-        select b.id,'瑞恒日报' as type,
-            b.task_id as taskId,
-            b.create_time as createTime,
+        select b.id,'保养工单' as type,
+                '' as taskId,
+               b.create_time as createTime,
         CASE
-        WHEN b.status = 0 THEN '未完成'
-        WHEN b.status = 1 THEN '已完成'
+        WHEN b.result = 1 THEN '未完成'
+        WHEN b.result = 2 THEN '已完成'
         ELSE '' -- 兼容其他未知状态值
         END AS status, '' as device,b.dept_id as deptId,
         CASE
@@ -298,7 +326,7 @@ select * from (
         WHEN d.type = 3 THEN COALESCE(d.`name`, '')
         ELSE ''
         END AS deptName
-        from rq_iot_rh_daily_report b
+        from rq_iot_main_work_order b
         -- 左关联当前部门(避免主表数据丢失)
         LEFT JOIN system_dept d ON b.dept_id = d.id
         -- 左关联父级部门(type=2/3时用)
@@ -323,8 +351,8 @@ select * from (
 
         UNION ALL
 
-        select b.id,'瑞日报' as type,
-            b.task_id taskId,
+        select b.id,'瑞日报' as type,
+            b.task_id as taskId,
             b.create_time as createTime,
         CASE
         WHEN b.status = 0 THEN '未完成'
@@ -348,7 +376,7 @@ select * from (
         WHEN d.type = 3 THEN COALESCE(d.`name`, '')
         ELSE ''
         END AS deptName
-        from rq_iot_ry_daily_report b
+        from rq_iot_rh_daily_report b
         -- 左关联当前部门(避免主表数据丢失)
         LEFT JOIN system_dept d ON b.dept_id = d.id
         -- 左关联父级部门(type=2/3时用)
@@ -373,8 +401,8 @@ select * from (
 
         UNION ALL
 
-        select b.id,'瑞日报' as type,
-            b.task_id as taskId,
+        select b.id,'瑞日报' as type,
+            b.task_id taskId,
             b.create_time as createTime,
         CASE
         WHEN b.status = 0 THEN '未完成'
@@ -398,7 +426,7 @@ select * from (
         WHEN d.type = 3 THEN COALESCE(d.`name`, '')
         ELSE ''
         END AS deptName
-        from rq_iot_rd_daily_report b
+        from rq_iot_ry_daily_report b
         -- 左关联当前部门(避免主表数据丢失)
         LEFT JOIN system_dept d ON b.dept_id = d.id
         -- 左关联父级部门(type=2/3时用)
@@ -423,21 +451,14 @@ select * from (
 
         UNION ALL
 
-        SELECT
-            c.id,
-            '' AS taskId,
-        '运行记录' AS type,
-        c.create_time AS createTime,
-        -- 核心优化:status 数值转中文描述
+        select b.id,'瑞都日报' as type,
+            b.task_id as taskId,
+            b.create_time as createTime,
         CASE
-        WHEN c.order_status = 0 THEN '未完成'
-        WHEN c.order_status = 1 THEN '已完成'
-        WHEN c.order_status = 2 THEN '填写中'
+        WHEN b.status = 0 THEN '未完成'
+        WHEN b.status = 1 THEN '已完成'
         ELSE '' -- 兼容其他未知状态值
-        END AS status,
-        '' AS device,
-        c.dept_id AS deptId,
-        -- 按type规则填充company字段
+        END AS status, '' as device,b.dept_id as deptId,
         CASE
         WHEN d.type = 1 THEN COALESCE(d.`name`, '')
         WHEN d.type = 2 THEN COALESCE(p1.`name`, '')
@@ -455,13 +476,38 @@ select * from (
         WHEN d.type = 3 THEN COALESCE(d.`name`, '')
         ELSE ''
         END AS deptName
-        FROM rq_iot_opeation_fill_order c
+        from rq_iot_rd_daily_report b
         -- 左关联当前部门(避免主表数据丢失)
-        LEFT JOIN system_dept d ON c.dept_id = d.id
+        LEFT JOIN system_dept d ON b.dept_id = d.id
         -- 左关联父级部门(type=2/3时用)
         LEFT JOIN system_dept p1 ON d.parent_id = p1.id
         -- 左关联祖父级部门(type=3时用)
         LEFT JOIN system_dept p2 ON p1.parent_id = p2.id
+        <where>
+            b.deleted = 0
+            <if test="reqVO.createTime[0] != null">
+                AND b.create_time &gt;= #{reqVO.createTime[0]}
+            </if>
+            <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
+                AND b.create_time &lt;= #{reqVO.createTime[1]}
+            </if>
+            <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+                AND b.dept_id IN
+                <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                    #{key}
+                </foreach>
+            </if>
+        </where>
+
+        ) fin
+        <where>
+            <if test="reqVO.type != null">
+                AND fin.type LIKE concat("%",#{reqVO.type},"%")
+            </if>
+        </where>
+    </select>
+    <select id="getMaintainFee" resultType="java.math.BigDecimal" >
+        select sum(maintain_fee) from rq_iot_maintain c
         <where>
             c.deleted=0
             <if test="reqVO.createTime[0] != null">
@@ -476,11 +522,32 @@ select * from (
                     #{key}
                 </foreach>
             </if>
-        </where>) fin
+            <if test="reqVO.type != null">
+                AND c.type = #{reqVO.type}
+            </if>
+        </where>
+
+    </select>
+    <select id="getMaintainFeeIn" resultType="java.math.BigDecimal" >
+        select sum(maintain_fee) from rq_iot_maintain c
         <where>
+            c.deleted=0 and c.type !='out'
+            <if test="reqVO.createTime[0] != null">
+                AND c.create_time &gt;= #{reqVO.createTime[0]}
+            </if>
+            <if test="reqVO.createTime.length > 1 and reqVO.createTime[1] != null">
+                AND c.create_time &lt;= #{reqVO.createTime[1]}
+            </if>
+            <if test="reqVO.deptIds != null and reqVO.deptIds.size &gt; 0">
+                AND c.dept_id IN
+                <foreach collection="reqVO.deptIds" index="index" item="key" open="(" separator="," close=")">
+                    #{key}
+                </foreach>
+            </if>
             <if test="reqVO.type != null">
-                AND fin.type= #{reqVO.type}
+                AND c.type = #{reqVO.type}
             </if>
         </where>
+
     </select>
 </mapper>