瀏覽代碼

每日面料使用

home 2 年之前
父節點
當前提交
d4ba75f213

+ 128 - 0
hx-service-api/storage-api/src/main/java/com/fjhx/params/stock/StatisticsResult.java

@@ -0,0 +1,128 @@
+package com.fjhx.params.stock;
+
+import com.fjhx.utils.BigDecimalUtil;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class StatisticsResult {
+
+    /**
+     * 排班面积
+     */
+    private BigDecimal scheduleArea;
+
+    /**
+     * 修正面积
+     */
+    private BigDecimal correctArea;
+
+    /**
+     * 领料金额
+     */
+    private BigDecimal pickingMoney;
+
+    /**
+     * 领料卷数
+     */
+    private Integer pickingNum;
+
+    /**
+     * 领料米数
+     */
+    private BigDecimal pickingMeters;
+
+    /**
+     * 领料面积
+     */
+    private BigDecimal pickingArea;
+
+    /**
+     * 退料金额
+     */
+    private BigDecimal backMoney;
+
+    /**
+     * 退料卷数
+     */
+    private Integer backNum;
+
+    /**
+     * 退料米数
+     */
+    private BigDecimal backMeters;
+
+    /**
+     * 退料面积
+     */
+    private BigDecimal backArea;
+
+    /**
+     * 用户id
+     */
+    private String userId;
+
+    /**
+     * 工号
+     */
+    private String jobNo;
+
+    /**
+     * 用户id
+     */
+    private String userName;
+
+    /**
+     * 物料id
+     */
+    private String materialId;
+
+    /**
+     * 物料编码
+     */
+    private String materialCode;
+
+    /**
+     * 物料名称
+     */
+    private String materialName;
+
+    /**
+     * 实际使用
+     */
+    public BigDecimal getActualUse() {
+        return pickingArea.subtract(backArea).subtract(correctArea);
+    }
+
+    /**
+     * 使用率
+     */
+    public BigDecimal getUseRate() {
+        return BigDecimalUtil.init(scheduleArea).multiply(100).divide(getActualUse(), 2).getValue();
+    }
+
+    public BigDecimal getPickingMoney() {
+        return BigDecimalUtil.keepDecimals(pickingMoney);
+    }
+
+    public BigDecimal getPickingMeters() {
+        return BigDecimalUtil.keepDecimals(pickingMeters);
+    }
+
+    public BigDecimal getPickingArea() {
+        return BigDecimalUtil.keepDecimals(pickingArea);
+    }
+
+    public BigDecimal getBackMoney() {
+        return BigDecimalUtil.keepDecimals(backMoney);
+    }
+
+    public BigDecimal getBackMeters() {
+        return BigDecimalUtil.keepDecimals(backMeters);
+    }
+
+    public BigDecimal getBackArea() {
+        return BigDecimalUtil.keepDecimals(backArea);
+    }
+}

+ 19 - 0
hx-service/storage/src/main/java/com/fjhx/stock/controller/StockBackController.java

@@ -1,9 +1,11 @@
 package com.fjhx.stock.controller;
 
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.entity.stock.StockBackCorrect;
 import com.fjhx.entity.stock.StockBackDetails;
 import com.fjhx.params.stock.CheckDetailsVo;
+import com.fjhx.params.stock.StatisticsResult;
 import com.fjhx.params.stock.SubmitBackVo;
 import com.fjhx.stock.service.StockBackCorrectService;
 import com.fjhx.stock.service.StockBackService;
@@ -101,6 +103,23 @@ public class StockBackController {
         return R.success(result);
     }
 
+    /**
+     * 面料使用率用户统计
+     */
+    @PostMapping("/statisticsDetails")
+    public R statisticsDetails(@RequestBody Map<String, String> condition) {
+        StatisticsResult result = stockBackService.statisticsDetails(condition);
+        return R.success(result);
+    }
+
+    /**
+     * 面料使用率用户统计
+     */
+    @PostMapping("/statisticsPage")
+    public R statisticsPage(@RequestBody Map<String, String> condition) {
+        Page<StatisticsResult> result = stockBackService.statisticsPage(condition);
+        return R.success(result);
+    }
 
 }
 

+ 44 - 0
hx-service/storage/src/main/java/com/fjhx/stock/mapper/StockBackMapper.java

@@ -1,11 +1,15 @@
 package com.fjhx.stock.mapper;
 
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.entity.stock.StockBack;
+import com.fjhx.params.stock.StatisticsResult;
 import org.apache.ibatis.annotations.Param;
 import org.springblade.core.tenant.annotation.TenantIgnore;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -25,7 +29,47 @@ public interface StockBackMapper extends BaseMapper<StockBack> {
     @TenantIgnore
     List<Map<String, Object>> checkList();
 
+    @InterceptorIgnore(tenantLine = "1")
     @TenantIgnore
     List<Map<String, Object>> userStatistics(@Param("ew") QueryWrapper<Object> wrapper);
 
+    @InterceptorIgnore(tenantLine = "1")
+    @TenantIgnore
+    Double selectSchedule(@Param("materialCode") String materialCode,
+                          @Param("technologyType") String technologyType,
+                          @Param("jobNo") String jobNo,
+                          @Param("beginTime") Date beginTime,
+                          @Param("endTime") Date endTime);
+
+    @InterceptorIgnore(tenantLine = "1")
+    @TenantIgnore
+    StatisticsResult selectPicking(@Param("technologyType") String technologyType,
+                                   @Param("userId") String userId,
+                                   @Param("beginTime") Date beginTime,
+                                   @Param("endTime") Date endTime);
+
+    @InterceptorIgnore(tenantLine = "1")
+    @TenantIgnore
+    StatisticsResult selectBack(@Param("materialCode") String materialCode,
+                                @Param("technologyType") String technologyType,
+                                @Param("userId") String userId,
+                                @Param("beginTime") Date beginTime,
+                                @Param("endTime") Date endTime);
+
+    @InterceptorIgnore(tenantLine = "1")
+    @TenantIgnore
+    Double selectCorrect(@Param("materialId") String materialId,
+                         @Param("technologyType") String technologyType,
+                         @Param("userId") String userId,
+                         @Param("beginTime") Date beginTime,
+                         @Param("endTime") Date endTime);
+
+    @InterceptorIgnore(tenantLine = "1")
+    @TenantIgnore
+    Page<StatisticsResult> selectPickingPage(@Param("page") Page<StockBack> page,
+                                             @Param("technologyType") String technologyType,
+                                             @Param("userId") String userId,
+                                             @Param("beginTime") Date beginTime,
+                                             @Param("endTime") Date endTime);
+
 }

+ 199 - 17
hx-service/storage/src/main/java/com/fjhx/stock/mapper/StockBackMapper.xml

@@ -23,24 +23,206 @@
     </select>
 
     <select id="userStatistics" resultType="java.util.Map">
-        select distinct t.jobNo,
-                        m.TechnologyType technologyType,
+        select distinct m.TechnologyType technologyType,
+                        uu.ID            userId,
+                        uu.JobNo         jobNo,
                         uu.RealName      realName
-        from ((select ss.printer       jobNo,
-                      ss.material_code materialCode
-               from stock_scheduling ss
-                   ${ew.customSqlSegment}
-              )
-              union all
-              (
-                  select ss.paper_man  jobNo,
-                         ss.paper_code materialCode
-                  from stock_scheduling ss
-                      ${ew.customSqlSegment}
-              )) t
-                 left join material m on m.code = t.materialCode
-                 left join u_user uu on t.jobNo = uu.JobNo
-        where m.TechnologyType in (0, 1, 2)
+        from stock_waterdetial swd
+                 left join material m on m.code = swd.materialCode
+                 left join u_user uu on swd.OperUserId = uu.ID
+            ${ew.customSqlSegment}
+    </select>
+    <select id="selectSchedule" resultType="java.lang.Double">
+        select sum(m.Width * t.materialQuantity / 100) area
+        from
+        (
+        (
+        select
+        ss.printer jobNo,
+        ss.material_code materialCode,
+        ss.material_quantity materialQuantity
+        from stock_scheduling ss
+        where ss.create_time between #{beginTime} and #{endTime}
+        <if test="jobNo neq null and jobNo neq ''">
+            and ss.printer = #{jobNo}
+        </if>
+        <if test="materialCode neq null and materialCode neq ''">
+            and ss.material_code = #{materialCode}
+        </if>
+        )
+        union all
+        (
+        select
+        ss.paper_man jobNo,
+        ss.paper_code materialCode,
+        ss.paper_quantity materialQuantity
+        from stock_scheduling ss
+        where ss.create_time between #{beginTime} and #{endTime}
+        <if test="jobNo neq null and jobNo neq ''">
+            and ss.paper_man = #{jobNo}
+        </if>
+        <if test="materialCode neq null and materialCode neq ''">
+            and ss.paper_code = #{materialCode}
+        </if>
+        )
+        )
+        t
+        left join material m on t.materialCode = m.code
+        where
+        <choose>
+            <when test="technologyType neq null and technologyType neq ''">
+                m.TechnologyType = #{technologyType}
+            </when>
+            <otherwise>
+                m.TechnologyType in (0, 1, 2)
+            </otherwise>
+        </choose>
+    </select>
+    <select id="selectPicking" resultType="com.fjhx.params.stock.StatisticsResult">
+        select
+        count(0) pickingNum,
+        sum(swd.ChangeNum) pickingMeters,
+        sum(m.Width * swd.ChangeNum / 100) pickingArea,
+        sum(swd.ChangeNum * m.Price) pickingMoney
+        from stock_waterdetial swd
+        left join material m on swd.MaterialCode = m.Code
+        where
+        swd.StockChangeType in (20,23)
+        and swd.CreatedTime between #{beginTime} and #{endTime}
+        <if test="userId neq null and userId neq ''">
+            and swd.OperUserId = #{userId}
+        </if>
+        and
+        <choose>
+            <when test="technologyType neq null and technologyType neq ''">
+                m.TechnologyType = #{technologyType}
+            </when>
+            <otherwise>
+                m.TechnologyType in (0, 1, 2)
+            </otherwise>
+        </choose>
+    </select>
+
+    <select id="selectBack" resultType="com.fjhx.params.stock.StatisticsResult">
+        select
+        count(0) backNum,
+        sum(swd.ChangeNum) backMeters,
+        sum(m.Width * swd.ChangeNum / 100) backArea,
+        sum(swd.ChangeNum * m.Price) backMoney
+        from stock_waterdetial swd
+        left join material m on swd.MaterialCode = m.Code
+        where
+        swd.StockChangeType = 16
+        and swd.CreatedTime between #{beginTime} and #{endTime}
+        <if test="userId neq null and userId neq ''">
+            and swd.OperUserId = #{userId}
+        </if>
+        <if test="materialCode neq null and materialCode neq ''">
+            and m.code = #{materialCode}
+        </if>
+        and
+        <choose>
+            <when test="technologyType neq null and technologyType neq ''">
+                m.TechnologyType = #{technologyType}
+            </when>
+            <otherwise>
+                m.TechnologyType in (0, 1, 2)
+            </otherwise>
+        </choose>
+    </select>
+
+    <select id="selectCorrect" resultType="java.lang.Double">
+        select sum(correct_area) correctArea
+        from stock_back_correct sbc
+        left join material m on sbc.material_id = m.ID
+        where
+        sbc.correct_time between #{beginTime} and #{endTime}
+        <if test="userId neq null and userId neq ''">
+            and sbc.user_id = #{userId}
+        </if>
+        <if test="materialId neq null and materialId neq ''">
+            and m.ID = #{materialId}
+        </if>
+        and
+        <choose>
+            <when test="technologyType neq null and technologyType neq ''">
+                m.TechnologyType = #{technologyType}
+            </when>
+            <otherwise>
+                m.TechnologyType in (0, 1, 2)
+            </otherwise>
+        </choose>
+    </select>
+
+    <select id="selectPickingPage" resultType="com.fjhx.params.stock.StatisticsResult">
+        select
+        uu.ID userId,
+        uu.JobNo jobNo,
+        uu.RealName userName,
+        m.id materialId,
+        m.Code materialCode,
+        m.Name materialName,
+        sum(m.Width * swd.ChangeNum / 100) pickingArea
+        from stock_waterdetial swd
+        left join material m on swd.MaterialCode = m.Code
+        left join u_user uu on uu.ID = swd.OperUserId
+        where
+        swd.StockChangeType in (20,23)
+        and swd.CreatedTime between #{beginTime} and #{endTime}
+        <if test="userId neq null and userId neq ''">
+            and swd.OperUserId = #{userId}
+        </if>
+        and
+        <choose>
+            <when test="technologyType neq null and technologyType neq ''">
+                m.TechnologyType = #{technologyType}
+            </when>
+            <otherwise>
+                m.TechnologyType in (0, 1, 2)
+            </otherwise>
+        </choose>
+        group by swd.OperUserId, swd.MaterialCode
+    </select>
+
+    <select id="selectScheduleArea" resultType="java.lang.Double">
+        select sum(m.Width * t.materialQuantity / 100) area
+        from
+        (
+        (
+        select
+        ss.printer jobNo,
+        ss.material_code materialCode,
+        ss.material_quantity materialQuantity
+        from stock_scheduling ss
+        where ss.create_time between #{beginTime} and #{endTime}
+        <if test="jobNo neq null and jobNo neq ''">
+            and ss.printer = #{jobNo}
+        </if>
+        )
+        union all
+        (
+        select
+        ss.paper_man jobNo,
+        ss.paper_code materialCode,
+        ss.paper_quantity materialQuantity
+        from stock_scheduling ss
+        where ss.create_time between #{beginTime} and #{endTime}
+        <if test="jobNo neq null and jobNo neq ''">
+            and ss.paper_man = #{jobNo}
+        </if>
+        )
+        )
+        t
+        left join material m on t.materialCode = m.code
+        where
+        <choose>
+            <when test="technologyType neq null and technologyType neq ''">
+                m.TechnologyType = #{technologyType}
+            </when>
+            <otherwise>
+                m.TechnologyType in (0, 1, 2)
+            </otherwise>
+        </choose>
     </select>
 
 

+ 5 - 0
hx-service/storage/src/main/java/com/fjhx/stock/service/StockBackService.java

@@ -5,6 +5,7 @@ import com.fjhx.base.BaseService;
 import com.fjhx.entity.stock.StockBack;
 import com.fjhx.entity.stock.StockBackDetails;
 import com.fjhx.params.stock.CheckDetailsVo;
+import com.fjhx.params.stock.StatisticsResult;
 import com.fjhx.params.stock.StockBackVo;
 import com.fjhx.params.stock.SubmitBackVo;
 
@@ -41,4 +42,8 @@ public interface StockBackService extends BaseService<StockBack> {
 
     Map<Integer, List<Map<String, Object>>> userStatistics(Map<String, String> condition);
 
+    StatisticsResult statisticsDetails(Map<String, String> condition);
+
+    Page<StatisticsResult> statisticsPage(Map<String, String> condition);
+
 }

+ 145 - 9
hx-service/storage/src/main/java/com/fjhx/stock/service/impl/StockBackServiceImpl.java

@@ -17,6 +17,7 @@ import com.fjhx.stock.mapper.StockBackMapper;
 import com.fjhx.stock.service.StockBackDetailsService;
 import com.fjhx.stock.service.StockBackService;
 import com.fjhx.utils.Assert;
+import com.fjhx.utils.BigDecimalUtil;
 import com.fjhx.utils.WrapperUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -215,24 +216,159 @@ public class StockBackServiceImpl extends ServiceImpl<StockBackMapper, StockBack
     @Override
     public Map<Integer, List<Map<String, Object>>> userStatistics(Map<String, String> condition) {
 
-        QueryWrapper<Object> wrapper = createWrapper(condition);
+        String beginTimeStr = condition.get("beginTime");
+        Assert.notEmpty(beginTimeStr, "开始时间不能为空");
+        Date beginTime = DateUtil.beginOfDay(DateUtil.parse(beginTimeStr));
+
+        String endTimeStr = condition.get("endTime");
+        Assert.notEmpty(endTimeStr, "结束时间不能为空");
+        Date endTime = DateUtil.endOfDay(DateUtil.parse(endTimeStr));
+
+        QueryWrapper<Object> wrapper = Wrappers.query()
+                .between("swd.CreatedTime", beginTime, endTime)
+                .in("m.TechnologyType", 0, 1, 2);
 
         List<Map<String, Object>> result = baseMapper.userStatistics(wrapper);
 
+        for (Map<String, Object> map : result) {
+
+            String jobNo = map.get("jobNo").toString();
+            String userId = map.get("userId").toString();
+            String technologyType = map.get("technologyType").toString();
+
+            // 排班
+            BigDecimal scheduleArea = BigDecimalUtil.keepDecimals(
+                    baseMapper.selectSchedule(null, technologyType, jobNo, beginTime, endTime));
+
+            // 领料
+            BigDecimal pickingArea = baseMapper.selectPicking(technologyType, userId, beginTime, endTime).getPickingArea();
+
+            // 退仓
+            BigDecimal backArea = baseMapper.selectBack(null, technologyType, userId, beginTime, endTime).getBackArea();
+
+            // 修正
+            BigDecimal correctArea = BigDecimalUtil.keepDecimals(
+                    baseMapper.selectCorrect(null, technologyType, userId, beginTime, endTime));
+
+
+            // 赋值使用率
+            BigDecimal value = BigDecimalUtil.init(scheduleArea).multiply(100).
+                    divideTry(pickingArea.subtract(backArea).subtract(correctArea), 2).getValue();
+            map.put("useRate", value);
+        }
+
         return result.stream().collect(Collectors.groupingBy(item -> (Integer) item.get("technologyType")));
     }
 
+    @Override
+    public StatisticsResult statisticsDetails(Map<String, String> condition) {
+
+        StatisticsResult statisticsResult = new StatisticsResult();
 
-    private QueryWrapper<Object> createWrapper(Map<String, String> condition) {
-        String beginTime = condition.get("beginTime");
-        Assert.notEmpty(beginTime, "开始时间不能为空");
+        String technologyType = condition.get("technologyType");
+        String jobNo = condition.get("jobNo");
+        String userId = condition.get("userId");
+
+        String beginTimeStr = condition.get("beginTime");
+        Assert.notEmpty(beginTimeStr, "开始时间不能为空");
+        Date beginTime = DateUtil.beginOfDay(DateUtil.parse(beginTimeStr));
 
-        String endTime = condition.get("endTime");
-        Assert.notEmpty(endTime, "结束时间不能为空");
+        String endTimeStr = condition.get("endTime");
+        Assert.notEmpty(endTimeStr, "结束时间不能为空");
+        Date endTime = DateUtil.endOfDay(DateUtil.parse(endTimeStr));
 
-        return Wrappers.query().between("ss.create_time",
-                DateUtil.beginOfDay(DateUtil.parse(beginTime)),
-                DateUtil.endOfDay(DateUtil.parse(endTime)));
+        // 查询排班
+        Thread selectScheduleThread = new Thread(() -> {
+            Double scheduleArea = baseMapper.selectSchedule(null, technologyType, jobNo, beginTime, endTime);
+            statisticsResult.setScheduleArea(BigDecimalUtil.keepDecimals(scheduleArea));
+        });
+        selectScheduleThread.start();
+
+        // 查询领料
+        Thread selectPickingThread = new Thread(() -> {
+            StatisticsResult itemStatisticsResult = baseMapper.selectPicking(technologyType, userId, beginTime, endTime);
+            statisticsResult.setPickingArea(itemStatisticsResult.getPickingArea());
+            statisticsResult.setPickingMeters(itemStatisticsResult.getPickingMeters());
+            statisticsResult.setPickingMoney(itemStatisticsResult.getPickingMoney());
+            statisticsResult.setPickingNum(itemStatisticsResult.getPickingNum());
+        });
+        selectPickingThread.start();
+
+        // 查询退料
+        Thread selectBackThread = new Thread(() -> {
+            StatisticsResult itemStatisticsResult = baseMapper.selectBack(null, technologyType, userId, beginTime, endTime);
+            statisticsResult.setBackArea(itemStatisticsResult.getBackArea());
+            statisticsResult.setBackMeters(itemStatisticsResult.getBackMeters());
+            statisticsResult.setBackMoney(itemStatisticsResult.getBackMoney());
+            statisticsResult.setBackNum(itemStatisticsResult.getBackNum());
+        });
+        selectBackThread.start();
+
+        // 修正
+        Thread selectCorrectThread = new Thread(() -> {
+            Double correctArea = baseMapper.selectCorrect(null, technologyType, userId, beginTime, endTime);
+            statisticsResult.setCorrectArea(BigDecimalUtil.keepDecimals(correctArea));
+        });
+        selectCorrectThread.start();
+
+        try {
+            selectScheduleThread.join();
+            selectPickingThread.join();
+            selectBackThread.join();
+            selectCorrectThread.join();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+        return statisticsResult;
     }
 
+    @Override
+    public Page<StatisticsResult> statisticsPage(Map<String, String> condition) {
+
+        String technologyType = condition.get("technologyType");
+        String jobNo = condition.get("jobNo");
+        String userId = condition.get("userId");
+
+        String beginTimeStr = condition.get("beginTime");
+        Assert.notEmpty(beginTimeStr, "开始时间不能为空");
+        Date beginTime = DateUtil.beginOfDay(DateUtil.parse(beginTimeStr));
+
+        String endTimeStr = condition.get("endTime");
+        Assert.notEmpty(endTimeStr, "结束时间不能为空");
+        Date endTime = DateUtil.endOfDay(DateUtil.parse(endTimeStr));
+
+        Page<StatisticsResult> result = baseMapper.selectPickingPage(createPage(condition), technologyType, userId, beginTime, endTime);
+
+        List<StatisticsResult> records = result.getRecords();
+
+        if (records.size() == 0) {
+            return result;
+        }
+
+        for (StatisticsResult record : records) {
+
+            String materialId = record.getMaterialId();
+            String materialCode = record.getMaterialCode();
+            String itemJobNo = record.getJobNo();
+            String itemUserId = record.getUserId();
+
+            // 排班面积
+            Double scheduleArea = baseMapper.selectSchedule(materialCode, technologyType, itemJobNo, beginTime, endTime);
+            record.setScheduleArea(BigDecimalUtil.keepDecimals(scheduleArea));
+
+            // 退仓
+            StatisticsResult itemStatisticsResult = baseMapper.selectBack(materialCode, technologyType, itemUserId, beginTime, endTime);
+            record.setBackArea(itemStatisticsResult.getBackArea());
+
+            // 修正
+            Double correctArea = baseMapper.selectCorrect(materialId, technologyType, itemUserId, beginTime, endTime);
+            record.setCorrectArea(BigDecimalUtil.keepDecimals(correctArea));
+
+        }
+
+        return result;
+    }
+
+
 }