diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/price/domain/enums/PriceStatus.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/price/domain/enums/PriceStatus.java index 5e425ce..05c5e73 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/price/domain/enums/PriceStatus.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/price/domain/enums/PriceStatus.java @@ -69,4 +69,11 @@ public enum PriceStatus { public static List canEnable() { return asList(PASS); } + + /** + * 允许被报表使用的状态 + */ + public static List canCheckToReport() { + return asList(PASS); + } } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/ReportValidator.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/ReportValidator.java index 8215721..f276b0f 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/ReportValidator.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/ReportValidator.java @@ -1,5 +1,6 @@ package com.ruoyi.web.yh.report.service; +import com.ruoyi.web.yh.report.domain.ReportVO; import com.ruoyi.web.yh.report.domain.bo.ReportBO; /** @@ -13,5 +14,10 @@ public interface ReportValidator { */ void checkPreEdit(ReportBO bo); + /** + * 后校验 + */ + void afterCheck(ReportVO vo); + } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/impl/ReportValidatorImpl.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/impl/ReportValidatorImpl.java index 00ce602..d1d9e51 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/impl/ReportValidatorImpl.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/service/impl/ReportValidatorImpl.java @@ -1,14 +1,30 @@ package com.ruoyi.web.yh.report.service.impl; +import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.utils.ServiceUtil; +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.system.domain.dto.SysUserQuery; +import com.ruoyi.system.domain.vo.SysUserVO; +import com.ruoyi.system.service.ISysDeptService; +import com.ruoyi.system.service.ISysUserService; +import com.ruoyi.web.yh.price.domain.PriceQuery; +import com.ruoyi.web.yh.price.domain.PriceVO; +import com.ruoyi.web.yh.price.domain.enums.PriceStatus; +import com.ruoyi.web.yh.price.service.PriceService; import com.ruoyi.web.yh.report.domain.ReportVO; import com.ruoyi.web.yh.report.domain.bo.ReportBO; import com.ruoyi.web.yh.report.domain.enums.ReportStatus; import com.ruoyi.web.yh.report.service.ReportService; import com.ruoyi.web.yh.report.service.ReportValidator; +import com.ruoyi.web.yh.reportProd.domain.bo.ReportProdBO; +import com.ruoyi.web.yh.reportUserProd.domain.bo.ReportUserProdBO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + /** * @author wjh * 2024/11/8 @@ -19,6 +35,15 @@ public class ReportValidatorImpl implements ReportValidator { @Autowired private ReportService reportService; + @Autowired + private ISysDeptService deptService; + + @Autowired + private PriceService priceService; + + @Autowired + private ISysUserService userService; + @Override public void checkPreEdit(ReportBO bo) { ServiceUtil.assertion(bo == null || bo.getReportId() == null, "参数错误"); @@ -27,16 +52,76 @@ public class ReportValidatorImpl implements ReportValidator { ServiceUtil.assertion(old == null || old.getReportId() == null, "待更新的报表不存在"); ServiceUtil.assertion(!ReportStatus.canEdit().contains(old.getStatus()), "报表当前状态不允许更新,请刷新后重试"); - // TODO 业务表校验 - // TODO 部门是否当前用户可选 + // 校验部门 + this.checkDept(bo.getDeptId()); - // TODO 工序是否当前用户可选 + // 校验产量 + this.checkProduct(bo.getProductList()); + + + } + + @Override + public void afterCheck(ReportVO vo) { // TODO 工序是否当前部门的工序 - // TODO 员工是否当前用户可选 - // TODO 员工是否当前部门的员工 + // TODO 订单是否当前部门订单 + } + + private void checkProduct(List productList) { + if (CollectionUtils.isEmptyElement(productList)) { + return; + } + + PriceQuery query = new PriceQuery(); + query.setPriceIds(CollectionUtils.map(productList, ReportProdBO::getPriceId)); + query.setNeedScope(true); + List priceList = priceService.selectPriceList(query); + + for (ReportProdBO prod : productList) { + if (prod == null || prod.getPriceId() == null) { + continue; + } + // 校验工序 + PriceVO price = priceList.stream().filter(item -> Objects.equals(item.getPriceId(), prod.getPriceId())).findFirst().orElse(null); + ServiceUtil.assertion(price == null, "工序%s不存在", prod.getPriceName()); + ServiceUtil.assertion(!PriceStatus.canCheckToReport().contains(price.getStatus()), "工序%s当前状态不允许被使用", price.getName()); + ServiceUtil.assertion(price.getDisabled() == null || price.getDisabled(), "工序%s已被禁用,无法使用", price.getName()); + + // 校验产量和工序的数值是否一致 + + } + + // 员工是否当前用户可选 + List userProdList = productList.stream().map(ReportProdBO::getUserProdList).flatMap(List::stream).collect(Collectors.toList()); + SysUserQuery userQuery = new SysUserQuery(); + userQuery.setUserIds(CollectionUtils.map(userProdList, ReportUserProdBO::getUserId)); + userQuery.setNeedScope(true); + List userList = userService.selectUserList(userQuery); + for (ReportUserProdBO userProd : userProdList) { + if (userProd == null || userProd.getUserId() == null) { + continue; + } + // 校验员工 + SysUserVO user = userList.stream().filter(item -> Objects.equals(item.getUserId(), userProd.getUserId())).findFirst().orElse(null); + ServiceUtil.assertion(user == null, "员工不存在"); + } + + // TODO 订单是否当前用户可选 + + + } + + private void checkDept(Long deptId) { + if (deptId == null) { + return; + } + + // 部门是否当前用户可选 + SysDept dept = deptService.selectDeptById(deptId, true); + ServiceUtil.assertion(dept == null, "部门不存在"); } }