Browse Source

生产端报表

yzc 1 năm trước cách đây
mục cha
commit
455a987905

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

@@ -0,0 +1,41 @@
+package com.fjhx.form.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.form.entity.ProductionReportBo;
+import com.fjhx.form.entity.ProductionReportSelectDto;
+import com.fjhx.form.entity.SaleReportBo;
+import com.fjhx.form.service.ReportService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/report")
+public class ReportController {
+
+    private final ReportService reportService;
+
+    @Autowired
+    public ReportController(ReportService reportService) {
+        this.reportService = reportService;
+    }
+
+    /**
+     * 生产端报表
+     */
+    @PostMapping("/productionReport")
+    Page<ProductionReportBo> productionReport(@RequestBody ProductionReportSelectDto dto) {
+        return reportService.productionReport(dto);
+    }
+
+    /**
+     * 业务端报表
+     */
+    @PostMapping("/saleReport")
+    Page<SaleReportBo> saleReport(@RequestBody ProductionReportSelectDto dto) {
+        return reportService.saleReport(dto);
+    }
+
+}

+ 111 - 0
hx-form/src/main/java/com/fjhx/form/entity/ProductionReportBo.java

@@ -0,0 +1,111 @@
+package com.fjhx.form.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Getter
+@Setter
+public class ProductionReportBo {
+    private Long id;
+    /**
+     * 工厂id
+     */
+    private Long factoryId;
+    /**
+     * 工厂名称
+     */
+    private String factoryName;
+    /**
+     * 订单号
+     */
+    private String orderCode;
+    /**
+     * 产品id
+     */
+    private Long productId;
+    /**
+     * 产品编号
+     */
+    private String productCode;
+    /**
+     * 产品名称
+     */
+    private String productName;
+    /**
+     * 产品长
+     */
+    private BigDecimal productLength;
+    /**
+     * 产品宽
+     */
+    private BigDecimal productWidth;
+    /**
+     * 产品高
+     */
+    private BigDecimal productHeight;
+    /**
+     * 产品颜色
+     */
+    private String productColor;
+    /**
+     * 生产数量
+     */
+    private BigDecimal quantity;
+    /**
+     * 交期
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
+    private Date deliveryPeriod;
+    /**
+     * 完工时间
+     */
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
+    private Date finishTime;
+    /**
+     * 是否逾期
+     */
+    private Integer isOverdue;
+    /**
+     * 逾期天数
+     */
+    private Integer overdueDay;
+    /**
+     * 及时率
+     */
+    private Integer timelyRate;
+
+    /**
+     * 原材料损耗数量
+     */
+    private BigDecimal rawLossCount;
+    /**
+     * 原材料损耗价格
+     */
+    private BigDecimal rawLossAmount;
+
+    /**
+     * 物料损耗数量
+     */
+    private BigDecimal bomLossCount;
+    /**
+     * 物料损耗价格
+     */
+    private BigDecimal bomLossAmount;
+
+    /**
+     * 返工数量
+     */
+    private Integer reworkCount;
+    /**
+     * 返工价格
+     */
+    private BigDecimal reworkAmount;
+    /**
+     * 错误率
+     */
+    private BigDecimal errRate;
+}

+ 7 - 0
hx-form/src/main/java/com/fjhx/form/entity/ProductionReportSelectDto.java

@@ -0,0 +1,7 @@
+package com.fjhx.form.entity;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+
+public class ProductionReportSelectDto extends BaseSelectDto {
+
+}

+ 78 - 0
hx-form/src/main/java/com/fjhx/form/entity/SaleReportBo.java

@@ -0,0 +1,78 @@
+package com.fjhx.form.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Getter
+@Setter
+public class SaleReportBo {
+
+    /**
+     * 等等类型
+     */
+    private Integer contractType;
+
+    /**
+     * 订单号
+     */
+    private String code;
+
+    /**
+     * 业务公司
+     */
+    private Long ofCompanyId;
+    private String ofCompanyName;
+    /**
+     * 业务部门
+     */
+    private String ofDeptName;
+
+    /**
+     * 生产公司
+     */
+    private Long companyId;
+    private String companyName;
+
+    /**
+     * 订单归属
+     */
+    private Integer belongType;
+
+    /**
+     * 订单金额
+     */
+    private BigDecimal amount;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 交期
+     */
+    private Date deliveryTime;
+
+    /**
+     * 完工入库时间
+     */
+    private Date finishTime;
+
+    /**
+     * 出货时间
+     */
+    private Date outboundTime;
+
+    /**
+     * 出货间隔天数
+     */
+    private BigDecimal outInterval;
+
+    /**
+     * 出货不及时率
+     */
+    private BigDecimal untimelyRate;
+
+}

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

@@ -0,0 +1,17 @@
+package com.fjhx.form.mapper;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.form.entity.ProductionReportBo;
+import com.fjhx.form.entity.SaleReportBo;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface ReportMapper {
+
+    Page<ProductionReportBo> productionReport(@Param("page") Page<Object> page, @Param("ew") IWrapper<Object> wrapper);
+
+    Page<SaleReportBo> saleReport(@Param("page") Page<Object> page, @Param("ew") IWrapper<Object> wrapper);
+
+}

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

@@ -0,0 +1,16 @@
+package com.fjhx.form.service;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.form.entity.ProductionReportBo;
+import com.fjhx.form.entity.ProductionReportSelectDto;
+import com.fjhx.form.entity.SaleReportBo;
+
+public interface ReportService {
+
+    /**
+     * 生产报表
+     */
+    Page<ProductionReportBo> productionReport(ProductionReportSelectDto dto);
+
+    Page<SaleReportBo> saleReport(ProductionReportSelectDto dto);
+}

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

@@ -0,0 +1,105 @@
+package com.fjhx.form.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.form.entity.ProductionReportBo;
+import com.fjhx.form.entity.ProductionReportSelectDto;
+import com.fjhx.form.entity.SaleReportBo;
+import com.fjhx.form.mapper.ReportMapper;
+import com.fjhx.form.service.ReportService;
+import com.fjhx.item.service.product.ProductInfoService;
+import com.fjhx.mes.entity.report.po.ReportLossesDetails;
+import com.fjhx.mes.service.report.ReportLossesDetailsService;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.system.service.ISysDeptService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+public class ReportServiceImpl implements ReportService {
+
+    private final ReportMapper reportMapper;
+    private final ReportLossesDetailsService reportLossesDetailsService;
+    private final ProductInfoService productInfoService;
+    private final ISysDeptService deptService;
+
+    @Autowired
+    public ReportServiceImpl(ReportMapper reportMapper, ReportLossesDetailsService reportLossesDetailsService, ProductInfoService productInfoService, ISysDeptService sysDeptService) {
+        this.reportMapper = reportMapper;
+        this.reportLossesDetailsService = reportLossesDetailsService;
+        this.productInfoService = productInfoService;
+        this.deptService = sysDeptService;
+    }
+
+    @Override
+    public Page<ProductionReportBo> productionReport(ProductionReportSelectDto dto) {
+        IWrapper<Object> wrapper = IWrapper.getWrapper();
+
+        Page<ProductionReportBo> page = reportMapper.productionReport(dto.getPage(), wrapper);
+        List<ProductionReportBo> productionReportBos = page.getRecords();
+        List<Long> ptIds = productionReportBos.stream().map(ProductionReportBo::getId).collect(Collectors.toList());
+
+        //赋值产品信息
+        productInfoService.attributeAssign(productionReportBos, ProductionReportBo::getProductId, (item, productInfo) -> {
+            item.setProductName(productInfo.getName());
+            item.setProductCode(productInfo.getCustomCode());
+            item.setProductLength(productInfo.getLength());
+            item.setProductWidth(productInfo.getWidth());
+            item.setProductHeight(productInfo.getHeight());
+            item.setProductColor(productInfo.getColor());
+        });
+
+        //获取部门列表
+        List<SysDept> companyList = deptService.list();
+        Map<Long, String> companyMap = companyList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
+
+        //获取报损信息
+        List<ReportLossesDetails> reportLossesDetails = reportLossesDetailsService.list(q -> q.in(ReportLossesDetails::getProdTaskId, ptIds));
+        Map<Long, List<ReportLossesDetails>> reportLossesMap = reportLossesDetails.stream().collect(Collectors.groupingBy(ReportLossesDetails::getProdTaskId));
+
+        for (ProductionReportBo vo : productionReportBos) {
+            vo.setFactoryName(companyMap.get(vo.getFactoryId()));
+
+            List<ReportLossesDetails> reportLossesList = reportLossesMap.getOrDefault(vo.getId(), new ArrayList<>());
+            //原材料损耗 数量,成本
+            List<ReportLossesDetails> rawReportLosses = reportLossesList.stream()
+                    .filter(item -> ObjectUtil.equals(item.getMaterialType(), 1)).collect(Collectors.toList());
+            BigDecimal rawLossCount = rawReportLosses.stream().map(ReportLossesDetails::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal rawLossAmount = rawReportLosses.stream().map(ReportLossesDetails::getMaterialPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            vo.setRawLossCount(rawLossCount);
+            vo.setRawLossAmount(rawLossAmount);
+            //普通物料 损耗 数量,成本
+            List<ReportLossesDetails> bomReportLosses = reportLossesList.stream()
+                    .filter(item -> ObjectUtil.notEqual(item.getMaterialType(), 1)).collect(Collectors.toList());
+            BigDecimal bomLossCount = bomReportLosses.stream().map(ReportLossesDetails::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal bomLossAmount = bomReportLosses.stream().map(ReportLossesDetails::getMaterialPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            vo.setBomLossCount(bomLossCount);
+            vo.setBomLossAmount(bomLossAmount);
+            //返工 道数,成本
+            Integer reworkCount = bomReportLosses.stream().map(ReportLossesDetails::getReCount).reduce(Integer::sum).orElse(0);
+            BigDecimal reworkAmount = bomReportLosses.stream().map(ReportLossesDetails::getRePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            vo.setReworkCount(reworkCount);
+            vo.setReworkAmount(reworkAmount);
+            //出错率
+            BigDecimal multiply = vo.getRawLossCount().divide(vo.getQuantity(), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+            vo.setErrRate(multiply);
+        }
+
+        return page;
+    }
+
+    @Override
+    public Page<SaleReportBo> saleReport(ProductionReportSelectDto dto) {
+        IWrapper<Object> wrapper = IWrapper.getWrapper();
+        Page<SaleReportBo> saleReportBoPage = reportMapper.saleReport(dto.getPage(), wrapper);
+        return saleReportBoPage;
+    }
+}

+ 37 - 0
hx-form/src/main/resources/mapper/ReportMapper.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.form.mapper.ReportMapper">
+
+    <select id="productionReport" resultType="com.fjhx.form.entity.ProductionReportBo">
+        SELECT pod.id,
+               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,
+               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) /
+               DATEDIFF(IFNULL(po.finish_time, NOW()), po.produce_time) * 100     as timelyRate
+        FROM production_order_detail pod
+                 LEFT JOIN production_order po ON pod.produce_order_id = po.id
+    </select>
+    <select id="saleReport" resultType="com.fjhx.form.entity.SaleReportBo">
+        SELECT c.contract_type,
+               c.`code`,
+               c.of_company_id,
+               c.company_id,
+               c.belong_type,
+               c.amount,
+               c.create_time,
+               c.delivery_time,
+               po.finish_time,
+               c.outbound_time,
+               DATEDIFF(IFNULL(c.outbound_time, now()), IFNULL(po.finish_time, now())) as outInterval
+        FROM contract c
+                 LEFT JOIN production_order po ON po.contract_id = c.id
+    </select>
+</mapper>

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java

@@ -486,4 +486,9 @@ public class Contract extends BasePo {
      */
     private Long ofCompanyId;
 
+    /**
+     * 出货时间
+     */
+    private Date outboundTime;
+
 }

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/entity/quotation/vo/QuotationEstimateVo.java

@@ -16,7 +16,7 @@ public class QuotationEstimateVo extends QuotationEstimate {
 
     private String code;
     private String name;
-
     private String materialColor;
+    private String moldName;
 
 }

+ 3 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/quotation/QuotationEstimateMapper.java

@@ -3,6 +3,7 @@ package com.fjhx.sale.mapper.quotation;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fjhx.item.entity.product.ProcessesBo;
 import com.fjhx.sale.entity.quotation.po.QuotationEstimate;
+import com.fjhx.sale.entity.quotation.vo.QuotationEstimateVo;
 
 import java.util.List;
 
@@ -19,4 +20,6 @@ public interface QuotationEstimateMapper extends BaseMapper<QuotationEstimate> {
 
     List<ProcessesBo> getProductionProcessesList();
 
+    List<QuotationEstimateVo> getMoldInfoList(List<Long> moldIds);
+
 }

+ 1 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -2965,6 +2965,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         this.update(q -> q
                 .eq(Contract::getId, id)
                 .set(Contract::getOutboundStatus, 1)
+                .set(Contract::getOutboundTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
                 .set(BasePo::getUpdateTime, new Date())
         );

+ 8 - 0
hx-sale/src/main/java/com/fjhx/sale/service/quotation/impl/QuotationEstimateServiceImpl.java

@@ -127,6 +127,14 @@ public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateM
     }
 
     private void setEstimateInfo(List<QuotationEstimateVo> quotationEstimateVos) {
+        //赋值模具信息
+        List<Long> moldIds = quotationEstimateVos.stream().map(QuotationEstimate::getMoldId).collect(Collectors.toList());
+        List<QuotationEstimateVo> moldInfoList = baseMapper.getMoldInfoList(moldIds);
+        Map<Long, String> moldMap = moldInfoList.stream().collect(Collectors.toMap(QuotationEstimateVo::getId, QuotationEstimateVo::getMoldName));
+        for (QuotationEstimateVo quotationEstimateVo : quotationEstimateVos) {
+            quotationEstimateVo.setMoldName(moldMap.get(quotationEstimateVo.getMoldId()));
+        }
+
         //赋值物料信息
         productInfoService.attributeAssign(quotationEstimateVos, QuotationEstimateVo::getMaterialId, (detail, product) -> {
             detail.setMaterialLength(product.getLength());

+ 11 - 0
hx-sale/src/main/resources/mapper/quotation/QuotationEstimateMapper.xml

@@ -5,4 +5,15 @@
         SELECT *
         FROM production_processes
     </select>
+    <select id="getMoldInfoList" resultType="com.fjhx.sale.entity.quotation.vo.QuotationEstimateVo">
+        SELECT
+        mi.*
+        FROM
+        mold_info mi
+        <where>
+            <foreach collection="moldIds" item="moldId" open="AND mi.id IN (" separator="," close=")">
+                #{moldId}
+            </foreach>
+        </where>
+    </select>
 </mapper>