From a0d6e6897bff5bb513c285e3e612773e691baabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?= <14103883+leaf-phos@user.noreply.gitee.com> Date: Mon, 17 Feb 2025 18:03:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/MathUtils.java | 59 +++++++++++++++++++ .../com/ruoyi/yh/price/domain/PriceQuery.java | 6 ++ .../com/ruoyi/yh/price/mapper/PriceMapper.xml | 16 +++++ .../yh/prodOrder/domain/ProdOrderQuery.java | 3 + .../yh/prodOrder/mapper/ProdOrderMapper.xml | 6 ++ .../com/ruoyi/yh/report/domain/Report.java | 3 - .../service/impl/ReportConverterImpl.java | 18 ++++-- .../service/impl/ReportValidatorImpl.java | 6 +- .../yh/reportProd/domain/ReportProd.java | 14 ++--- .../yh/reportProd/mapper/ReportProdMapper.xml | 39 +++++++++++- .../service/impl/ReportProdConverterImpl.java | 15 ++++- 11 files changed, 163 insertions(+), 22 deletions(-) create mode 100644 common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/MathUtils.java diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/MathUtils.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/MathUtils.java new file mode 100644 index 0000000..82c3039 --- /dev/null +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/MathUtils.java @@ -0,0 +1,59 @@ +package com.ruoyi.common.utils; + +import java.math.BigDecimal; + +/** + * @author wjh + * 2025/1/17 + */ +public class MathUtils { + + + /** + * 判断a和b的值是否一致 + */ + public static boolean equals(BigDecimal a, BigDecimal b) { + return a != null && b != null && a.compareTo(b) == 0; + } + + /** + * 加法 + */ + public static BigDecimal addDecimal(BigDecimal... values) { + BigDecimal result = BigDecimal.ZERO; + for (BigDecimal value : values) { + if (value != null) { + result = result.add(value); + } + } + return result; + } + + /** + * 减法 + */ + public static BigDecimal subtractDecimal(BigDecimal a, BigDecimal ...values) { + BigDecimal result = a; + for (BigDecimal value : values) { + if (value != null) { + result = result.subtract(value); + } + } + return result; + } + + /** + * 乘法 + */ + public static BigDecimal multiply(BigDecimal a, BigDecimal b) { + if (a == null || b == null) { + return BigDecimal.ZERO; + } + return a.multiply(b); + } + + // 把Integer转为Long类型 + public static Long IntegerToLong(Integer num) { + return num == null ? null : Long.valueOf(num); + } +} diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/domain/PriceQuery.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/domain/PriceQuery.java index 97239ac..04582c1 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/domain/PriceQuery.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/domain/PriceQuery.java @@ -22,4 +22,10 @@ public class PriceQuery extends PriceVO { @ApiModelProperty("排除的单价ID列表") private List excludePriceIds; + + @ApiModelProperty("关键词") + private String keyword; + + @ApiModelProperty("关键词列表") + private List keywords; } diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/mapper/PriceMapper.xml b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/mapper/PriceMapper.xml index 8952cc1..5ee26ef 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/mapper/PriceMapper.xml +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/price/mapper/PriceMapper.xml @@ -67,6 +67,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and bp.deleted = false and bp.code like concat('%', #{query.code}, '%') and bp.surface like concat('%', #{query.surface}, '%') + + and ( + bp.name like concat('%', #{query.keyword}, '%') + or bp.code like concat('%', #{query.keyword}, '%') + ) + + + and ( + + ( + bp.name like concat('%', #{item}, '%') + or bp.code like concat('%', #{item}, '%') + ) + + ) + and bp.status in diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/domain/ProdOrderQuery.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/domain/ProdOrderQuery.java index 5a3597b..fd9934c 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/domain/ProdOrderQuery.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/domain/ProdOrderQuery.java @@ -33,4 +33,7 @@ public class ProdOrderQuery extends ProdOrderVO { @ApiModelProperty("用户部门ID") private Long userDeptId; + @ApiModelProperty("关键词") + private String keyword; + } diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/mapper/ProdOrderMapper.xml b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/mapper/ProdOrderMapper.xml index 8c9669b..340051c 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/mapper/ProdOrderMapper.xml +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/prodOrder/mapper/ProdOrderMapper.xml @@ -86,6 +86,12 @@ and bpo.material_graphics like concat('%',#{query.materialGraphics},'%') + + and ( + bpo.erp_bill_no like concat('%',#{query.keyword},'%') + or bpo.material_number like concat('%',#{query.keyword},'%') + ) + and bpo.erp_status in diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/domain/Report.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/domain/Report.java index 2a62b7e..cca23e6 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/domain/Report.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/domain/Report.java @@ -9,7 +9,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; -import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import java.math.BigDecimal; import java.time.LocalDate; @@ -67,8 +66,6 @@ public class Report extends BaseEntity implements LogBizParam @Excel(name = "总价(元)") @ApiModelProperty("总金额") - @NotNull(message = "总金额不能为空") - @Min(value = 0, message = "总金额必须大于0") private BigDecimal totalAmount; @Excel(name = "创建人") diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportConverterImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportConverterImpl.java index 138d438..8039820 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportConverterImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportConverterImpl.java @@ -1,10 +1,9 @@ package com.ruoyi.yh.report.service.impl; import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.MathUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysUserService; -import com.ruoyi.yh.price.service.PriceService; import com.ruoyi.yh.report.domain.ReportVO; import com.ruoyi.yh.report.domain.bo.ReportBO; import com.ruoyi.yh.report.domain.enums.ReportStatus; @@ -17,6 +16,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -54,7 +54,6 @@ public class ReportConverterImpl implements ReportConverter { } bo.setCreateId(user.getUserId()); bo.setReportDate(vo.getReportDate()); - bo.setTotalAmount(vo.getTotalAmount()); bo.setCreateBy(user.getNickName()); // 报表产量数据 @@ -69,6 +68,7 @@ public class ReportConverterImpl implements ReportConverter { // 组装数据 bo.setProductList(productList); bo.setDept(deptService.selectDeptById(bo.getDeptId(), true)); + bo.setTotalAmount(this.calculateTotalAmount(bo)); return bo; } @@ -85,7 +85,6 @@ public class ReportConverterImpl implements ReportConverter { bo.setReportId(vo.getReportId()); bo.setDeptId(vo.getDeptId()); bo.setReportDate(vo.getReportDate()); - bo.setTotalAmount(vo.getTotalAmount()); if (submit) { bo.setStatus(ReportStatus.WAIT_VERIFY.getStatus()); } @@ -105,6 +104,17 @@ public class ReportConverterImpl implements ReportConverter { bo.setProductList(productList); bo.setDept(deptService.selectDeptById(bo.getDeptId(), true)); bo.setOld(reportService.selectReportByReportId(vo.getReportId())); + bo.setTotalAmount(this.calculateTotalAmount(bo)); return bo; } + + private BigDecimal calculateTotalAmount(ReportBO bo) { + BigDecimal totalAmount = BigDecimal.ZERO; + if (CollectionUtils.isNotEmpty(bo.getProductList())) { + for (ReportProdBO item : bo.getProductList()) { + totalAmount = MathUtils.addDecimal(totalAmount, item.getTotalAmount()); + } + } + return totalAmount; + } } diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportValidatorImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportValidatorImpl.java index 7650392..f6ee888 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportValidatorImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/report/service/impl/ReportValidatorImpl.java @@ -77,7 +77,7 @@ public class ReportValidatorImpl implements ReportValidator { if (prod == null || prod.getPriceId() == null) { continue; } - ServiceUtil.assertion(!Objects.equals(prod.getPriceDeptId(), deptId), "工序%s不是部门%s的工序", prod.getPriceName(), vo.getDeptName()); + ServiceUtil.assertion(!Objects.equals(prod.getPriceDeptId(), deptId), "工序【%s】不是部门【%s】的工序", prod.getPriceName(), vo.getDeptName()); } // 订单校验 @@ -88,8 +88,8 @@ public class ReportValidatorImpl implements ReportValidator { if (orderProd == null || orderProd.getOrderId() == null) { continue; } - ServiceUtil.assertion(!Objects.equals(orderProd.getOrderDeptId(), deptId), "订单%s不是部门%s的订单", orderProd.getOrderErpBillNo(), vo.getDeptName()); - ServiceUtil.assertion(!ProdOrderErpStatus.canReport().contains(orderProd.getOrderErpStatus()), "订单%s当前状态不允许关联", orderProd.getOrderErpBillNo()); + ServiceUtil.assertion(!Objects.equals(orderProd.getOrderDeptId(), deptId), "订单【%s】不是部门【%s】的订单", orderProd.getOrderErpBillNo(), vo.getDeptName()); + ServiceUtil.assertion(!ProdOrderErpStatus.canReport().contains(orderProd.getOrderErpStatus()), "订单【%s】当前状态不允许关联", orderProd.getOrderErpBillNo()); } // 员工是否当天在该部门排班 diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/domain/ReportProd.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/domain/ReportProd.java index b74683d..c59a40e 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/domain/ReportProd.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/domain/ReportProd.java @@ -1,14 +1,11 @@ package com.ruoyi.yh.reportProd.domain; import com.ruoyi.common.annotation.Excel; -import com.ruoyi.common.constant.DictType; import com.ruoyi.common.core.domain.BaseEntity; -import com.ruoyi.system.valid.DictValid; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.math.BigDecimal; @@ -43,7 +40,6 @@ public class ReportProd extends BaseEntity @Excel(name = "不良品数") @ApiModelProperty("不良品数") - @NotNull(message = "不良品数不允许为空") @Min(value = 0, message = "不良品数不允许小于0") private BigDecimal defectNum; @@ -89,10 +85,7 @@ public class ReportProd extends BaseEntity @ApiModelProperty("工序生产数量倍数分母(个)") private BigDecimal priceQuantityDenominator; - @Excel(name = "工序类型", dictType = DictType.PRICE_TYPE) @ApiModelProperty("工序类型") - @NotBlank(message = "工序类型不允许为空") - @DictValid(type = DictType.PRICE_TYPE, message = "非法的工序类型") private String priceType; @Size(max = 200, message = "备注长度不允许超过200个字符") @@ -113,4 +106,11 @@ public class ReportProd extends BaseEntity @Excel(name = "颜色") @ApiModelProperty("颜色") private String color; + + @Excel(name = "是否成品", readConverterExp = "true=是,false=否") + @ApiModelProperty("是否成品") + private Boolean isEnd; + + @ApiModelProperty("排序") + private Integer sort; } diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/mapper/ReportProdMapper.xml b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/mapper/ReportProdMapper.xml index 79f8e59..a7148ad 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/mapper/ReportProdMapper.xml +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/mapper/ReportProdMapper.xml @@ -33,12 +33,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" brp.total_amount, brp.surface, brp.color, + brp.is_end, + brp.sort, bp.dept_id as price_dept_id, br.status as report_status, sd.dept_name as price_dept_name from bst_report_prod brp left join bst_report br on br.report_id = brp.report_id - left join bst_price bp on bp.price_id = brp.price_id left join sys_dept sd on sd.dept_id = bp.dept_id @@ -62,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and brp.price_code like concat('%', #{query.priceCode}, '%') and brp.surface = like concat('%', #{query.surface}, '%') and brp.color = like concat('%', #{query.color}, '%') + and brp.is_end = #{query.isEnd} and brp.report_id in @@ -111,10 +113,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" price_code, surface, color, + is_end, + sort, #{reportId}, - #{priceId}, #{num}, #{defectNum}, @@ -135,6 +138,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{priceCode}, #{surface}, #{color}, + #{isEnd}, + #{sort}, @@ -161,7 +166,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" total_amount, price_code, surface, - color + color, + is_end, + sort ) values @@ -209,6 +216,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" default, #{i.color}, default, + #{i.isEnd}, + default, + #{i.sort}, + default, @@ -244,6 +255,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" price_code = #{data.priceCode}, surface = #{data.surface}, color = #{data.color}, + is_end = #{data.isEnd}, + sort = #{data.sort}, @@ -460,6 +473,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + WHEN #{item.id} THEN #{item.isEnd} + + + WHEN #{item.id} THEN `is_end` + + + + + + + WHEN #{item.id} THEN #{item.sort} + + + WHEN #{item.id} THEN `sort` + + + where id in diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/service/impl/ReportProdConverterImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/service/impl/ReportProdConverterImpl.java index c12cbe4..7a582b8 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/service/impl/ReportProdConverterImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/yh/reportProd/service/impl/ReportProdConverterImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.yh.reportProd.service.impl; +import com.ruoyi.common.utils.MathUtils; import com.ruoyi.yh.reportOrderProd.domain.ReportOrderProdVO; import com.ruoyi.yh.reportOrderProd.domain.bo.ReportOrderProdBO; import com.ruoyi.yh.reportOrderProd.service.ReportOrderProdConverter; @@ -13,6 +14,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -55,7 +57,9 @@ public class ReportProdConverterImpl implements ReportProdConverter { bo.setPriceCode(vo.getPriceCode()); bo.setSurface(vo.getSurface()); bo.setColor(vo.getColor()); - bo.setTotalAmount(vo.getPricePrice().multiply(vo.getNum().add(vo.getDefectNum()))); + bo.setIsEnd(vo.getIsEnd()); + bo.setSort(vo.getSort()); + bo.setTotalAmount(this.calculateTotalAmount(bo)); // 用户产量明细 List userProdList = new ArrayList<>(); @@ -108,7 +112,9 @@ public class ReportProdConverterImpl implements ReportProdConverter { bo.setPriceCode(vo.getPriceCode()); bo.setSurface(vo.getSurface()); bo.setColor(vo.getColor()); - bo.setTotalAmount(vo.getPricePrice().multiply(vo.getNum().add(vo.getDefectNum()))); + bo.setIsEnd(vo.getIsEnd()); + bo.setSort(vo.getSort()); + bo.setTotalAmount(this.calculateTotalAmount(bo)); // 用户产量明细 List userProdList = new ArrayList<>(); @@ -133,4 +139,9 @@ public class ReportProdConverterImpl implements ReportProdConverter { return bo; } + + private BigDecimal calculateTotalAmount(ReportProdBO bo) { + BigDecimal count = MathUtils.addDecimal(bo.getNum(), bo.getDefectNum()); + return MathUtils.multiply(bo.getPricePrice(), count); + } }