| | |
| | | import com.ruoyi.approve.mapper.ApprovalTemplateMapper; |
| | | import com.ruoyi.basic.mapper.CustomerMapper; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.mapper.SupplierManageMapper; |
| | | import com.ruoyi.common.enums.TypeEnums; |
| | | import com.ruoyi.mock.dto.DataCheckRequest; |
| | | import com.ruoyi.mock.service.DataCheckService; |
| | | import com.ruoyi.mock.vo.DataCheckResult; |
| | | import com.ruoyi.mock.vo.DataCheckResult.CheckItem; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.quality.mapper.QualityTestStandardBindingMapper; |
| | | import com.ruoyi.quality.mapper.QualityTestStandardMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyBomMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyBomStructureMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyOperationMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyRoutingOperationMapper; |
| | | import com.ruoyi.technology.pojo.TechnologyBom; |
| | | import com.ruoyi.technology.pojo.TechnologyBomStructure; |
| | | import com.ruoyi.technology.pojo.TechnologyRouting; |
| | | import com.ruoyi.technology.pojo.TechnologyRoutingOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | public class DataCheckServiceImpl implements DataCheckService { |
| | | |
| | | private final ProductMapper productMapper; |
| | | private final ProductModelMapper productModelMapper; |
| | | private final CustomerMapper customerMapper; |
| | | private final SupplierManageMapper supplierManageMapper; |
| | | private final ApprovalTemplateMapper approvalTemplateMapper; |
| | | private final QualityTestStandardMapper qualityTestStandardMapper; |
| | | private final QualityTestStandardBindingMapper qualityTestStandardBindingMapper; |
| | | private final TechnologyRoutingMapper technologyRoutingMapper; |
| | | private final TechnologyRoutingOperationMapper technologyRoutingOperationMapper; |
| | | private final TechnologyOperationMapper technologyOperationMapper; |
| | | private final TechnologyBomMapper technologyBomMapper; |
| | | private final TechnologyBomStructureMapper technologyBomStructureMapper; |
| | | private final SysUserMapper sysUserMapper; |
| | | |
| | | @Override |
| | | public DataCheckResult check(DataCheckRequest request) { |
| | |
| | | |
| | | if (!modules.isEmpty()) { |
| | | addProductCheck(itemMap); |
| | | addUserChecks(itemMap); |
| | | } |
| | | |
| | | for (String module : modules) { |
| | |
| | | case "sales" -> addSalesChecks(itemMap); |
| | | case "purchase" -> addPurchaseChecks(itemMap); |
| | | case "quality" -> addQualityChecks(itemMap); |
| | | case "production" -> addProductionChecks(itemMap); |
| | | } |
| | | } |
| | | |
| | |
| | | long count = productMapper.selectCount(null); |
| | | itemMap.put(key, buildItem("common", "产品数据", 1, (int) count, |
| | | "缺少产品数据,请先在【基础数据-产品管理】中添加至少1条产品")); |
| | | } |
| | | |
| | | private void addUserChecks(Map<String, CheckItem> itemMap) { |
| | | // 1. 系统用户 |
| | | String userKey = "common:系统用户"; |
| | | if (!itemMap.containsKey(userKey)) { |
| | | List<SysUser> users = sysUserMapper.selectUserListWithDetail(); |
| | | itemMap.put(userKey, buildItem("common", "系统用户", 1, (int) users.size(), |
| | | "缺少系统用户,请先在【系统管理-用户管理】中添加用户")); |
| | | } |
| | | |
| | | // 2. 有角色的用户 |
| | | String userWithRoleKey = "common:用户角色配置"; |
| | | if (!itemMap.containsKey(userWithRoleKey)) { |
| | | List<SysUser> users = sysUserMapper.selectUserListWithDetail(); |
| | | long withRole = users.stream().filter(u -> u.getRoleNames() != null && !u.getRoleNames().isBlank()).count(); |
| | | itemMap.put(userWithRoleKey, buildItem("common", "用户角色配置", 1, (int) withRole, |
| | | "没有用户分配角色,请先在【系统管理-用户管理】中为用户分配角色")); |
| | | } |
| | | |
| | | // 3. 有部门的用户 |
| | | String userWithDeptKey = "common:用户部门配置"; |
| | | if (!itemMap.containsKey(userWithDeptKey)) { |
| | | List<SysUser> users = sysUserMapper.selectUserListWithDetail(); |
| | | long withDept = users.stream().filter(u -> u.getDeptNames() != null && !u.getDeptNames().isBlank()).count(); |
| | | itemMap.put(userWithDeptKey, buildItem("common", "用户部门配置", 1, (int) withDept, |
| | | "没有用户分配部门,请先在【系统管理-用户管理】中为用户分配部门")); |
| | | } |
| | | } |
| | | |
| | | private void addSalesChecks(Map<String, CheckItem> itemMap) { |
| | |
| | | } |
| | | } |
| | | |
| | | private void addProductionChecks(Map<String, CheckItem> itemMap) { |
| | | // 1. 产品规格 |
| | | String modelKey = "production:产品规格"; |
| | | if (!itemMap.containsKey(modelKey)) { |
| | | long count = productModelMapper.selectCount(null); |
| | | itemMap.put(modelKey, buildItem("production", "产品规格", 1, (int) count, |
| | | "缺少产品规格,请先在【基础数据-产品管理】中为产品添加规格型号")); |
| | | } |
| | | |
| | | // 2. 工序 |
| | | String operationKey = "production:工序"; |
| | | if (!itemMap.containsKey(operationKey)) { |
| | | long count = technologyOperationMapper.selectCount(null); |
| | | itemMap.put(operationKey, buildItem("production", "工序", 1, (int) count, |
| | | "缺少工序,请先在【工艺设计-工序管理】中创建工序")); |
| | | } |
| | | |
| | | // 3. BOM |
| | | String bomKey = "production:BOM"; |
| | | if (!itemMap.containsKey(bomKey)) { |
| | | long count = technologyBomMapper.selectCount(null); |
| | | itemMap.put(bomKey, buildItem("production", "BOM", 1, (int) count, |
| | | "缺少BOM,请先在【工艺设计-BOM管理】中创建BOM")); |
| | | } |
| | | |
| | | // 4. BOM产品结构 |
| | | String bomStructureKey = "production:BOM产品结构"; |
| | | if (!itemMap.containsKey(bomStructureKey)) { |
| | | long count = technologyBomStructureMapper.selectCount(null); |
| | | itemMap.put(bomStructureKey, buildItem("production", "BOM产品结构", 1, (int) count, |
| | | "缺少BOM产品结构,请先在【工艺设计-BOM管理】中为BOM添加产品结构节点")); |
| | | } |
| | | |
| | | // 5. 工艺路线 |
| | | String routingKey = "production:工艺路线"; |
| | | if (!itemMap.containsKey(routingKey)) { |
| | | long count = technologyRoutingMapper.selectCount(null); |
| | | itemMap.put(routingKey, buildItem("production", "工艺路线", 1, (int) count, |
| | | "缺少工艺路线,请先在【工艺设计-工艺路线】中创建工艺路线")); |
| | | } |
| | | |
| | | // 6. 工艺路线工序 |
| | | String routingOpKey = "production:工艺路线工序"; |
| | | if (!itemMap.containsKey(routingOpKey)) { |
| | | long count = technologyRoutingOperationMapper.selectCount(null); |
| | | itemMap.put(routingOpKey, buildItem("production", "工艺路线工序", 1, (int) count, |
| | | "缺少工艺路线工序,请先在【工艺设计-工艺路线】中为工艺路线添加工序")); |
| | | } |
| | | |
| | | // 7. 关联性检测:有产品规格但无工艺路线的 |
| | | String linkageKey = "production:产品-工艺路线关联"; |
| | | if (!itemMap.containsKey(linkageKey)) { |
| | | long modelCount = productModelMapper.selectCount(null); |
| | | long routedCount = technologyRoutingMapper.selectCount( |
| | | new LambdaQueryWrapper<TechnologyRouting>() |
| | | .isNotNull(TechnologyRouting::getProductModelId) |
| | | .gt(TechnologyRouting::getProductModelId, 0)); |
| | | itemMap.put(linkageKey, buildItem("production", "产品-工艺路线关联", |
| | | (int) Math.min(modelCount, 1), (int) routedCount, |
| | | "部分产品规格未关联工艺路线,请先在【工艺设计-工艺路线】中为产品规格创建工艺路线")); |
| | | } |
| | | |
| | | // 8. 关联性检测:有工艺路线但无工序的 |
| | | String routingOpLinkKey = "production:工艺路线-工序关联"; |
| | | if (!itemMap.containsKey(routingOpLinkKey)) { |
| | | long routingCount = technologyRoutingMapper.selectCount(null); |
| | | long routedOpCount = technologyRoutingOperationMapper.selectCount( |
| | | new LambdaQueryWrapper<TechnologyRoutingOperation>() |
| | | .gt(TechnologyRoutingOperation::getTechnologyRoutingId, 0)); |
| | | itemMap.put(routingOpLinkKey, buildItem("production", "工艺路线-工序关联", |
| | | (int) Math.min(routingCount, 1), (int) routedOpCount, |
| | | "部分工艺路线未添加工序,请先在【工艺设计-工艺路线】中为工艺路线添加工序")); |
| | | } |
| | | |
| | | // 9. 关联性检测:有BOM但无产品结构的 |
| | | String bomStructureLinkKey = "production:BOM-产品结构关联"; |
| | | if (!itemMap.containsKey(bomStructureLinkKey)) { |
| | | long bomCount = technologyBomMapper.selectCount(null); |
| | | long structureCount = technologyBomStructureMapper.selectCount( |
| | | new LambdaQueryWrapper<TechnologyBomStructure>() |
| | | .gt(TechnologyBomStructure::getBomId, 0)); |
| | | itemMap.put(bomStructureLinkKey, buildItem("production", "BOM-产品结构关联", |
| | | (int) Math.min(bomCount, 1), (int) structureCount, |
| | | "部分BOM未添加产品结构,请先在【工艺设计-BOM管理】中为BOM添加产品结构节点")); |
| | | } |
| | | } |
| | | |
| | | private CheckItem buildItem(String module, String itemName, int minRequired, int currentCount, String failMessage) { |
| | | CheckItem item = new CheckItem(); |
| | | item.setModule(module); |