设置超级物料
This commit is contained in:
parent
0439b0dbe5
commit
2dec35f109
|
|
@ -1,19 +1,24 @@
|
|||
package com.nflg.product.bomnew.api.user;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.product.base.core.api.BaseApi;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.MBomConstantEnum;
|
||||
import com.nflg.product.bomnew.pojo.query.BomNewMbomParentQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewMbomParentVO;
|
||||
import com.nflg.product.bomnew.service.BomNewMbomDetailService;
|
||||
import com.nflg.product.bomnew.service.BomNewMbomParentService;
|
||||
import com.nflg.product.bomnew.util.EnumUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* t_bom_new_mbom_parent 表控制层
|
||||
|
|
@ -33,6 +38,10 @@ public class MBomApi extends BaseApi {
|
|||
@Resource
|
||||
private BomNewMbomParentService bomNewMbomParentService;
|
||||
|
||||
@Resource
|
||||
private BomNewMbomDetailService bomNewMbomDetailService ;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询所有数据
|
||||
*
|
||||
|
|
@ -44,7 +53,25 @@ public class MBomApi extends BaseApi {
|
|||
public ResultVO<IPage<BomNewMbomParentVO>> selectBomNewMbomParentEntityPageByCondition(@RequestBody BomNewMbomParentQuery query) {
|
||||
return ResultVO.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("superSaterialStatus")
|
||||
@ApiOperation("设置超级物料")
|
||||
public ResultVO<Boolean> superSaterialStatus(@ApiParam("超级物料 0-否 1-是") @RequestParam(value = "status") Integer status, @RequestParam(value = "rowId") Long rowId ) {
|
||||
if(Objects.isNull(rowId)){
|
||||
throw new NflgBusinessException(STATE.ParamErr,"选择行后操作");
|
||||
}
|
||||
|
||||
if(Objects.isNull(status)){
|
||||
throw new NflgBusinessException(STATE.ParamErr,"status 不能为空");
|
||||
}
|
||||
if(StrUtil.isEmpty(EnumUtils.getEnumDescription(MBomConstantEnum.MBomSuperMaterialStatusEnum.class,status))){
|
||||
throw new NflgBusinessException(STATE.ParamErr,"status 不在范围内");
|
||||
}
|
||||
|
||||
return ResultVO.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.nflg.product.bomnew.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
public class MBomConstantEnum {
|
||||
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MBomStatusEnum implements ValueEnum<Integer> {
|
||||
//1、待发布(sap)、3=已发布
|
||||
UNPUB_SAP(1, "未发布"),
|
||||
|
||||
PUB_SAP(3, "已发布");
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MBomSuperMaterialStatusEnum implements ValueEnum<Integer> {
|
||||
//超级物料 0-否 1-是
|
||||
UN_SUPER(0, "否"),
|
||||
|
||||
SUPER(1, "是");
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +1,27 @@
|
|||
package com.nflg.product.bomnew.service;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.MBomConstantEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewMbomDetailMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewMbomDetailEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewMbomParentEntity;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* t_bom_new_mbom_detail 表服务实现类
|
||||
*
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-01-01 10:53:17
|
||||
|
|
@ -17,4 +29,87 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class BomNewMbomDetailService extends ServiceImpl<BomNewMbomDetailMapper, BomNewMbomDetailEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 超级物料标签
|
||||
* <p>
|
||||
* 1. 此MBOM没有导入到SAP中,且此物料是超级物料的情况;
|
||||
* 2. 此物料存在上级节点。
|
||||
* 3. 此节点下,多个物料必须有一个物料可以被打“超级物料”的标签。
|
||||
*
|
||||
* @param rowId
|
||||
*/
|
||||
public void superSaterialStatusTag(Long rowId, Integer status) {
|
||||
|
||||
BomNewMbomDetailEntity entity = getById(rowId);
|
||||
if (entity == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "设置超级物料数据不存在");
|
||||
}
|
||||
|
||||
BomNewMbomParentEntity parentEntity = SpringUtil.getBean(BomNewMbomParentService.class).getById(entity.getBomRowId());
|
||||
if (parentEntity == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "根数据不存在");
|
||||
}
|
||||
|
||||
if (Objects.equals(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue(), parentEntity.getStatus())) {
|
||||
throw new NflgBusinessException(STATE.Error, "已发布数据不能操作");
|
||||
}
|
||||
|
||||
//取消超级物料标签
|
||||
if (Objects.equals(status, MBomConstantEnum.MBomSuperMaterialStatusEnum.UN_SUPER.getValue())) {
|
||||
BomNewMbomDetailEntity uppdateBomNewMbomDetailEntity = new BomNewMbomDetailEntity();
|
||||
uppdateBomNewMbomDetailEntity.setSuperMaterialStatus(MBomConstantEnum.MBomSuperMaterialStatusEnum.UN_SUPER.getValue());
|
||||
uppdateBomNewMbomDetailEntity.setModifyTime(LocalDateTime.now());
|
||||
uppdateBomNewMbomDetailEntity.setRowId(rowId);
|
||||
updateById(uppdateBomNewMbomDetailEntity);
|
||||
return;
|
||||
}
|
||||
|
||||
//当前数据已是超级物料
|
||||
if (Objects.equals(MBomConstantEnum.MBomSuperMaterialStatusEnum.SUPER.getValue(), entity.getSuperMaterialStatus())) {
|
||||
throw new NflgBusinessException(STATE.Error, StrUtil.format("物料{}已为超级物料", entity.getMaterialNo()));
|
||||
}
|
||||
|
||||
//parentRowId 空情况
|
||||
if (entity.getParentRowId() == null) {
|
||||
QueryWrapper<BomNewMbomDetailEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().isNull(BomNewMbomDetailEntity::getParentRowId)
|
||||
.eq(BomNewMbomDetailEntity::getSuperMaterialStatus, MBomConstantEnum.MBomSuperMaterialStatusEnum.SUPER.getValue());
|
||||
List<BomNewMbomDetailEntity> list = this.list(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
throw new NflgBusinessException(STATE.Error, "同级已有物料设置为超级物料");
|
||||
}
|
||||
} else {
|
||||
//check 父级为超级物料 子级才能为超级物料
|
||||
QueryWrapper<BomNewMbomDetailEntity> queryParentWrapper = new QueryWrapper<>();
|
||||
queryParentWrapper.lambda().eq(BomNewMbomDetailEntity::getRowId, entity.getParentRowId());
|
||||
BomNewMbomDetailEntity parentDetail = this.getOne(queryParentWrapper);
|
||||
if (parentDetail == null) {
|
||||
throw new NflgBusinessException(STATE.Error, "数据异常联系管理员");
|
||||
}
|
||||
if (!Objects.equals(MBomConstantEnum.MBomSuperMaterialStatusEnum.SUPER.getValue(), parentDetail.getSuperMaterialStatus())) {
|
||||
throw new NflgBusinessException(STATE.Error, "父级不为超级物料,不能设置子级为超级物料");
|
||||
}
|
||||
//check 同级不能多个超级物料
|
||||
QueryWrapper<BomNewMbomDetailEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(BomNewMbomDetailEntity::getParentRowId, entity.getParentRowId())
|
||||
.eq(BomNewMbomDetailEntity::getSuperMaterialStatus, MBomConstantEnum.MBomSuperMaterialStatusEnum.SUPER.getValue());
|
||||
List<BomNewMbomDetailEntity> list = this.list(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
throw new NflgBusinessException(STATE.Error, "同级已有物料设置为超级物料");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
BomNewMbomDetailEntity uppdateBomNewMbomDetailEntity = new BomNewMbomDetailEntity();
|
||||
uppdateBomNewMbomDetailEntity.setSuperMaterialStatus(MBomConstantEnum.MBomSuperMaterialStatusEnum.SUPER.getValue());
|
||||
uppdateBomNewMbomDetailEntity.setModifyTime(LocalDateTime.now());
|
||||
uppdateBomNewMbomDetailEntity.setRowId(rowId);
|
||||
updateById(uppdateBomNewMbomDetailEntity);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue