diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/advice/LoggingRequestBodyAdvice.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/advice/LoggingRequestBodyAdvice.java new file mode 100644 index 00000000..a414ef07 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/advice/LoggingRequestBodyAdvice.java @@ -0,0 +1,63 @@ +package com.nflg.product.bomnew.advice; + +import cn.hutool.core.util.StrUtil; +import com.nflg.product.bomnew.util.JsonUtil; +import lombok.extern.slf4j.Slf4j; +import nflg.product.common.constant.STATE; +import nflg.product.common.util.JwtUtil; +import nflg.product.common.vo.ResultVO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.core.MethodParameter; +import org.springframework.http.HttpInputMessage; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice; + +import java.lang.reflect.Type; + +/** + * @author 曹鹏飞 + * @date 2024/6/18 09:41:31 + */ +@Slf4j +@ControllerAdvice +@RefreshScope +public class LoggingRequestBodyAdvice implements RequestBodyAdvice { + + @Value("${logging.http.detailed:false}") + private Boolean enableHttpDetailed; + + @Override + public boolean supports(MethodParameter methodParameter, Type type, Class> aClass) { + return enableHttpDetailed; + } + + @Override + public HttpInputMessage beforeBodyRead(HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class> aClass) { + return httpInputMessage; + } + + @Override + public Object afterBodyRead(Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class> aClass) { + try { + log.info("请求参数: {}", JsonUtil.toJson(o)); + log.info("请求头: {}", JsonUtil.toJson(httpInputMessage.getHeaders())); + String token = httpInputMessage.getHeaders().getFirst("Authorization"); + if (StrUtil.isNotBlank(token)) { + ResultVO result = JwtUtil.parse(token); + if (result.getState().equals(STATE.Success.getState())) { + log.info("请求用户: {}", JsonUtil.toJson(result.getData())); + } + } + } catch (Exception ex) { + log.error("读取请求体出错", ex); + } + return o; + } + + @Override + public Object handleEmptyBody(Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class> aClass) { + return o; + } +} \ No newline at end of file diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/advice/LoggingResponseBodyAdvice.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/advice/LoggingResponseBodyAdvice.java new file mode 100644 index 00000000..1fc4e76f --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/advice/LoggingResponseBodyAdvice.java @@ -0,0 +1,41 @@ +package com.nflg.product.bomnew.advice; + +import com.nflg.product.bomnew.util.JsonUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.core.MethodParameter; +import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.server.ServerHttpRequest; +import org.springframework.http.server.ServerHttpResponse; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; + +/** + * @author 曹鹏飞 + * @date 2024/6/18 09:42:06 + */ +@Slf4j +@ControllerAdvice +@RefreshScope +public class LoggingResponseBodyAdvice implements ResponseBodyAdvice { + + @Value("${logging.http.detailed:false}") + private Boolean enableHttpDetailed; + + @Override + public boolean supports(MethodParameter methodParameter, Class> aClass) { + return enableHttpDetailed; + } + + @Override + public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) { + try { + log.info("响应数据: {}", JsonUtil.toJson(o)); + } catch (Exception ex) { + log.error("读取响应数据出错", ex); + } + return o; + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java index 7ed66be7..0785aff4 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java @@ -910,7 +910,7 @@ public class BomNewEbomParentService extends ServiceImpl delParentBom = delEBomParents.stream().filter(u -> u.getBomRowId() > 0).map(BomNewEbomParentVO::getBomRowId).collect(Collectors.toList()); if(CollUtil.isNotEmpty(delParentBom)){ this.getBaseMapper().delBatch(delParentBom); - ebomChildService.getBaseMapper().delBomChild(delParentBom); +// ebomChildService.getBaseMapper().delBomChild(delParentBom); } } //需修改正式版BOM的版本 @@ -933,11 +933,11 @@ public class BomNewEbomParentService extends ServiceImpl bomRowIds = bomTree.stream().filter(u -> u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList()); + List bomRowIds = bomTree.stream().filter(u ->!EBomStatusEnum.PUBLISHED.equalsValue(u.getStatus()) && u.getBomRowId() > 0).map(u -> u.getBomRowId()).collect(Collectors.toList()); if (CollUtil.isNotEmpty(bomRowIds)) { this.getBaseMapper().updateStateBatchByRowIds(EBomStatusEnum.PUBLISHED.getValue(), bomRowIds); //将历史已发布版-转移到正式历史表 - eBomToFormal(bomRowIds, bomTree.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList()) ); + eBomToFormal(bomRowIds, bomTree.stream().filter(u ->!EBomStatusEnum.PUBLISHED.equalsValue(u.getStatus()) && u.getBomRowId() > 0).collect(Collectors.toList()) ); } //子级记录-bom版本 List bomChildren = new ArrayList<>(); @@ -1932,10 +1932,10 @@ public class BomNewEbomParentService extends ServiceImpl materialBaseInfo = SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT); - - checkException(materialBaseInfo); + SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT); + checkException(); } public void initException(List unCheckException) { //初始化物料信息 - List materialBaseInfo = SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT); + SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT); this.unCheckExcept=unCheckException; - checkException(materialBaseInfo); + checkException(); } public void initException(String... ignorePropertyList) { - List materialBaseInfo = SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, ignorePropertyList); - checkException(materialBaseInfo); + SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, ignorePropertyList); + checkException(); } - public void checkException(List materialBaseInfo) { + public void checkException() { for (BomNewEbomParentVO vo : allBomDetail) { - // if(Objects.isNull(vo.getExceptionStatus())) { //忽略不检查的如14 if (CollectionUtil.isNotEmpty(unCheckExcept) && vo.getExceptionStatus() != null && unCheckExcept.contains(vo.getExceptionStatus())) { continue; } - // BaseMaterialVO mainVO = materialBaseInfo.stream() - // .filter(u -> StrUtil.equals(u.getMaterialNo(), vo.getMaterialNo())) - // .findFirst() - // .orElse(null); vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); - // } if (StrUtil.equals(BomConstant.PROJECT_TYPE_TEMPORARY, vo.getProjectType(), true)) { if (StrUtil.isBlank(vo.getMaterialDesc())) { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_4.getValue()); @@ -137,7 +130,6 @@ public class CheckEBomException { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_8.getValue()); } else if ((!StrUtil.equals("KG", StringUtil.toUpperCase(vo.getMaterialUnit())) && !StrUtil.equals(StringUtil.toUpperCase(vo.getMaterialUnit()), "PC")) - //|| (!Objects.isNull(mainVO) && !StrUtil.equals(vo.getMaterialUnit(), mainVO.getMaterialUnit()))) { && (StrUtil.isBlank(vo.getExceptionTag()) || (!vo.getExceptionTag().contains("16")) && !vo.getExceptionTag().contains("12")) && Objects.equals(vo.getSource(), EBomSourceEnum.FROM_BOM.getValue())) { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_12.getValue()); diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java index 83dd8ae8..636413cc 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomEdit.java @@ -14,6 +14,7 @@ import com.nflg.product.bomnew.constant.*; import com.nflg.product.bomnew.pojo.dto.BomNewEBomParentEditDTO; import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity; +import com.nflg.product.bomnew.pojo.entity.MaterialMainEntity; import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO; import com.nflg.product.bomnew.service.BomNewEbomChildService; @@ -21,6 +22,7 @@ import com.nflg.product.bomnew.service.BomNewEbomParentService; import com.nflg.product.bomnew.service.MaterialMainService; import com.nflg.product.bomnew.service.UserRoleService; import com.nflg.product.bomnew.util.ListCommonUtil; +import com.nflg.product.bomnew.util.MaterialshouldBomExistUtil; import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VersionUtil; import lombok.Getter; @@ -75,6 +77,11 @@ public class EBomEdit { parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); parent.setNum(new BigDecimal(1)); parent.setBomExist(1); + MaterialMainEntity materialMainEntity = SpringUtil.getBean(MaterialMainService.class).lambdaQuery() + .eq(MaterialMainEntity::getMaterialNo, parent.getMaterialNo()) + .one(); + parent.setShouldBomExist(MaterialshouldBomExistUtil.checkShouldBomExist(materialMainEntity.getMaterialCategoryCode() + , materialMainEntity.getMaterialGetType()) ? 1 : 0); parent.setLastVersionIs(1); parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); @@ -132,6 +139,7 @@ public class EBomEdit { parentEntity.setRootIs(parentEntity.getMaterialNo().startsWith("31") ? 1 : 0); parentEntity.setUserRootIs(1); parentEntity.setDeptRowId(SessionUtil.getDepartRowId()); + parentEntity.setBomExist(CollUtil.isEmpty(createDTO.getDatas()) ? 0 : 1); createDTO.getDatas().forEach(k -> { k.setParentRowId(parentEntity.getRowId()); @@ -274,9 +282,9 @@ public class EBomEdit { throw new NflgBusinessException(STATE.Error, "parent 数据不能为空"); } - if (CollUtil.isEmpty(dto.getDatas())) { - throw new NflgBusinessException(STATE.Error, "datas 数据不能为空"); - } + // if (CollUtil.isEmpty(dto.getDatas())) { + // throw new NflgBusinessException(STATE.Error, "datas 数据不能为空"); + // } List materialNos = dto.getDatas().stream().map(u -> u.getMaterialNo()).collect(Collectors.toList()); if(materialNos.contains(dto.getParent().getMaterialNo())){ @@ -356,6 +364,7 @@ public class EBomEdit { parentEntity.setModifyTime(LocalDateTime.now()); } parentEntity.setEditStatus(dto.getOpType()); + parentEntity.setBomExist(CollUtil.isEmpty(dto.getDatas()) ? 0 : 1); //提交 if (Objects.equals(dto.getOpType(), EbomEditStatusEnum.HANDLER_FINISHED.getValue())) { //工艺人员 diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml index 18b0d035..6bab6f5a 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml @@ -511,27 +511,40 @@ - INSERT INTO `t_bom_new_ebom_parent_formal` (`row_id`, `batch_no`, `drawing_no`, `material_no`, `order_number`, `material_name`, `material_desc`, `material_texture`, `material_unit`, `material_original_unit`, `unit_weight`, `total_weight`, `current_version`, `num`, `source`, `root_is`, `should_bom_exist`, `super_material_status`, `bom_exist`, `last_version_is`, `edit_status`, `status`, `user_root_is`, `virtrual_package_enum`, `exception_status`, `virtual_package_is`, `source_row_id`, `devise_user_code`, `devise_name`, `created_by`, `created_time`, `created_job`, `audit_time`, `audit_user_name`, `release_time`, `release_user_name`, `revert_time`, `revert_user_name`, `expire_end_time`, `convert_to_ebom_time`, `remark`, `dept_name`, `level_num`, `change_desc`, `notice_nums`, `modify_time`, `sap_state`, `sap_time`) - select `row_id`, `batch_no`, `drawing_no`, `material_no`, `order_number`, `material_name`, `material_desc`, `material_texture`, `material_unit`, `material_original_unit`, `unit_weight`, `total_weight`, `current_version`, `num`, `source`, `root_is`, `should_bom_exist`, `super_material_status`, `bom_exist`, `last_version_is`, `edit_status`, `status`, `user_root_is`, `virtrual_package_enum`, `exception_status`, `virtual_package_is`, `source_row_id`, `devise_user_code`, `devise_name`, `created_by`, `created_time`, `created_job`, `audit_time`, `audit_user_name`, `release_time`, `release_user_name`, `revert_time`, `revert_user_name`, `expire_end_time`, `convert_to_ebom_time`, `remark`, `dept_name`, `level_num`, `change_desc`, `notice_nums`, `modify_time`, `sap_state`, `sap_time` from t_bom_new_ebom_parent - where row_id in - - #{item} - and row_id not in ( - select row_id from t_bom_new_ebom_parent_formal where row_id in + INSERT INTO `t_bom_new_ebom_parent_formal` (`row_id`, `batch_no`, `drawing_no`, `material_no`, `order_number`, + `material_name`, `material_desc`, `material_texture`, `material_unit`, `material_original_unit`, `unit_weight`, + `total_weight`, `current_version`, `num`, `source`, `root_is`, `should_bom_exist`, `super_material_status`, + `bom_exist`, `last_version_is`, `edit_status`, `status`, `user_root_is`, `virtrual_package_enum`, + `exception_status`, `virtual_package_is`, `source_row_id`, `devise_user_code`, `devise_name`, `created_by`, + `created_time`, `created_job`, `audit_time`, `audit_user_name`, `release_time`, `release_user_name`, + `revert_time`, `revert_user_name`, `expire_end_time`, `convert_to_ebom_time`, `remark`, + `dept_name`,`dept_row_id`, `level_num`, `change_desc`, `notice_nums`, `modify_time`, `sap_state`, `sap_time`) + select a.`row_id`, a.`batch_no`, a.`drawing_no`, a.`material_no`, a.`order_number`, a.`material_name`, + a.`material_desc`, a.`material_texture`, a.`material_unit`, a.`material_original_unit`, a.`unit_weight`, + a.`total_weight`, a.`current_version`, a.`num`, a.`source`, a.`root_is`, a.`should_bom_exist`, + a.`super_material_status`, a.`bom_exist`, a.`last_version_is`, a.`edit_status`, a.`status`, a.`user_root_is`, + a.`virtrual_package_enum`, a.`exception_status`, a.`virtual_package_is`, a.`source_row_id`, + a.`devise_user_code`, a.`devise_name`, a.`created_by`, a.`created_time`, a.`created_job`, a.`audit_time`, + a.`audit_user_name`, a.`release_time`, a.`release_user_name`, a.`revert_time`, a.`revert_user_name`, + a.`expire_end_time`, a.`convert_to_ebom_time`, a.`remark`, a.`dept_name`,`dept_row_id`, a.`level_num`, + a.`change_desc`, a.`notice_nums`, a.`modify_time`, a.`sap_state`, a.`sap_time` + from t_bom_new_ebom_parent a + left join t_bom_new_ebom_parent_formal b on a.row_id = b.row_id + where a.row_id in #{item} - ) + and b.row_id is null INSERT INTO `t_bom_new_ebom_child_formal` (`row_id`, `parent_row_id`, `identity_no`, `order_number`, `drawing_no`, `material_no`, `material_name`, `material_desc`, `material_texture`, `material_unit`, `material_category_code`, `unit_weight`, `num`, `total_weight`, `project_type`, `project_type_input_type`, `created_by`, `virtual_part_is`, `created_time`, `modify_time`, `edit_status`, `exception_status`, `source`, `source_row_id`, `remark`, `virtual_part_type`, `virtual_part_root_material_no`, `bom_version_row_id`) select `row_id`, `parent_row_id`, `identity_no`, `order_number`, `drawing_no`, `material_no`, `material_name`, `material_desc`, `material_texture`, `material_unit`, `material_category_code`, `unit_weight`, `num`, `total_weight`, `project_type`, `project_type_input_type`, `created_by`, `virtual_part_is`, `created_time`, `modify_time`, `edit_status`, `exception_status`, `source`, `source_row_id`, `remark`, `virtual_part_type`, `virtual_part_root_material_no`, `bom_version_row_id` - from t_bom_new_ebom_child + from t_bom_new_ebom_child a where parent_row_id in #{parentRowId} - and row_id not in ( + and parent_row_id not in( select row_id from t_bom_new_ebom_parent_formal where row_id in #{item} diff --git a/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java b/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java index 6e43b547..838f590e 100644 --- a/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java +++ b/nflg_project_dev/nflg-boot-base/nflg-boot-core/src/main/java/com/nflg/product/base/core/exception/BaseGlobalExceptionHandle.java @@ -1,5 +1,6 @@ package com.nflg.product.base.core.exception; +import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import nflg.product.common.constant.STATE; import nflg.product.common.vo.ResultVO; @@ -51,7 +52,7 @@ public class BaseGlobalExceptionHandle { public ResultVO handleDuplicateKeyException(DuplicateKeyException e) { log.error(e.getMessage(), e); //return ResultVO.error("已存在该记录,请勿重复操作"); - return ResultVO.error("已存在该记录,请勿重复操作"); + return ResultVO.error("数据库存在重复数据"); } @@ -59,8 +60,11 @@ public class BaseGlobalExceptionHandle { @ResponseBody public ResultVO handleException(Exception e) { log.error(e.getMessage(), e); - //return ResultVO.error("操作失败,请联系系统管理员"); - return ResultVO.error("操作失败,请联系系统管理员"); + if (StrUtil.isNotBlank(e.getMessage()) && e.getMessage().contains("Deadlock")) { + return ResultVO.error("操作失败,请重试"); + } else { + return ResultVO.error("操作失败,请联系系统管理员"); + } } /**