|
|
|
@ -16,10 +16,17 @@ import cn.iocoder.yudao.module.common.dal.dataobject.moldrepair.MoldRepairDO;
|
|
|
|
import cn.iocoder.yudao.module.common.dal.dataobject.moldrepair.MoldRepairLineDO;
|
|
|
|
import cn.iocoder.yudao.module.common.dal.dataobject.moldrepair.MoldRepairLineDO;
|
|
|
|
import cn.iocoder.yudao.module.common.dal.dataobject.moldticketresults.MoldTicketResultsDO;
|
|
|
|
import cn.iocoder.yudao.module.common.dal.dataobject.moldticketresults.MoldTicketResultsDO;
|
|
|
|
import cn.iocoder.yudao.module.common.enums.CodeTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.common.enums.CodeTypeEnum;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.common.enums.MoldBrandStatusEnum;
|
|
|
|
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
|
|
|
|
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.MoldBrandPageRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.MoldBrandRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.MoldBrandStatusStatisticsRespVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.MoldBrandTreeRespVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.MoldBrandTreeRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldOperateSimpleDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldOperateQueryMapper;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
|
|
|
|
import cn.iocoder.yudao.module.common.dal.mysql.mold.MoldBrandMapper;
|
|
|
|
import cn.iocoder.yudao.module.common.dal.mysql.mold.MoldBrandMapper;
|
|
|
|
@ -78,37 +85,66 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
private ErpProductService productService;
|
|
|
|
private ErpProductService productService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private QrcodeRecordService qrcodeService;
|
|
|
|
private QrcodeRecordService qrcodeService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private MoldOperateQueryMapper moldOperateQueryMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private AutoCodeUtil autoCodeUtil;
|
|
|
|
private AutoCodeUtil autoCodeUtil;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Long createMoldBrand(MoldBrandSaveReqVO createReqVO) {
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
// 插入
|
|
|
|
public Long createMoldBrand(MoldBrandSaveReqVO createReqVO) throws UnsupportedEncodingException {
|
|
|
|
// MoldBrandDO moldBrand = BeanUtils.toBean(createReqVO, MoldBrandDO.class);
|
|
|
|
|
|
|
|
String Code = createReqVO.getCode();
|
|
|
|
String code = createReqVO.getCode();
|
|
|
|
if (StrUtil.isBlank(Code)) {
|
|
|
|
boolean autoGeneratedCode = StringUtils.isBlank(code);
|
|
|
|
throw new ServiceException(ErrorCodeConstants.MOLD_BRAND_CODE_EMPTY);
|
|
|
|
|
|
|
|
|
|
|
|
if (autoGeneratedCode) {
|
|
|
|
|
|
|
|
code = autoCodeUtil.genSerialCode("MOLD_SET_CODE", null);
|
|
|
|
|
|
|
|
createReqVO.setCode(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean exists = moldBrandMapper.exists(
|
|
|
|
boolean exists = moldBrandMapper.exists(
|
|
|
|
new LambdaQueryWrapperX<MoldBrandDO>().eq(MoldBrandDO::getCode, Code)
|
|
|
|
new LambdaQueryWrapperX<MoldBrandDO>().eq(MoldBrandDO::getCode, code)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (exists) {
|
|
|
|
if (exists) {
|
|
|
|
throw new ServiceException(ErrorCodeConstants.MOLD_BRAND_CODE_DUPLICATE);
|
|
|
|
throw new ServiceException(ErrorCodeConstants.MOLD_BRAND_CODE_DUPLICATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MoldBrandDO moldBrand = BeanUtils.toBean(createReqVO, MoldBrandDO.class);
|
|
|
|
MoldBrandDO moldBrand = BeanUtils.toBean(createReqVO, MoldBrandDO.class);
|
|
|
|
|
|
|
|
fillProductName(moldBrand);
|
|
|
|
moldBrandMapper.insert(moldBrand);
|
|
|
|
moldBrandMapper.insert(moldBrand);
|
|
|
|
|
|
|
|
createMoldBrandProducts(moldBrand.getId(), createReqVO.getProductIds(), createReqVO.getProductId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//二维码
|
|
|
|
|
|
|
|
CodeTypeEnum codeType = autoCodeUtil.queryCodeType("MOLD_SET_CODE");
|
|
|
|
|
|
|
|
if (codeType==null){
|
|
|
|
|
|
|
|
log.warn("[创建模具组]未配置码类型,ruleCode={}","MOLD_SET_CODE");
|
|
|
|
|
|
|
|
return moldBrand.getId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qrcodeService.generateOrRefresh(
|
|
|
|
|
|
|
|
QrcodeBizTypeEnum.MOLD,
|
|
|
|
|
|
|
|
moldBrand.getId(),
|
|
|
|
|
|
|
|
moldBrand.getCode(),
|
|
|
|
|
|
|
|
"DETAIL",
|
|
|
|
|
|
|
|
codeType
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 返回
|
|
|
|
// 返回
|
|
|
|
return moldBrand.getId();
|
|
|
|
return moldBrand.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void updateMoldBrand(MoldBrandSaveReqVO updateReqVO) {
|
|
|
|
public void updateMoldBrand(MoldBrandSaveReqVO updateReqVO) {
|
|
|
|
// 校验存在
|
|
|
|
// 校验存在
|
|
|
|
validateMoldBrandExists(updateReqVO.getId());
|
|
|
|
validateMoldBrandExists(updateReqVO.getId());
|
|
|
|
// 更新
|
|
|
|
// 更新
|
|
|
|
MoldBrandDO updateObj = BeanUtils.toBean(updateReqVO, MoldBrandDO.class);
|
|
|
|
MoldBrandDO updateObj = BeanUtils.toBean(updateReqVO, MoldBrandDO.class);
|
|
|
|
|
|
|
|
fillProductName(updateObj);
|
|
|
|
moldBrandMapper.updateById(updateObj);
|
|
|
|
moldBrandMapper.updateById(updateObj);
|
|
|
|
|
|
|
|
syncMoldBrandProducts(updateReqVO.getId(), updateReqVO.getProductIds(), updateReqVO.getProductId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -121,6 +157,7 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
|
|
|
|
|
|
|
|
// 删除子表
|
|
|
|
// 删除子表
|
|
|
|
deleteMoldByBrandId(id);
|
|
|
|
deleteMoldByBrandId(id);
|
|
|
|
|
|
|
|
deleteMoldBrandProductByBrandId(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validateMoldBrandExists(Long id) {
|
|
|
|
private void validateMoldBrandExists(Long id) {
|
|
|
|
@ -133,6 +170,38 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
public MoldBrandDO getMoldBrand(Long id) {
|
|
|
|
public MoldBrandDO getMoldBrand(Long id) {
|
|
|
|
return moldBrandMapper.selectById(id);
|
|
|
|
return moldBrandMapper.selectById(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public MoldBrandRespVO getMoldBrandDetail(Long id) {
|
|
|
|
|
|
|
|
MoldBrandDO moldBrand = getMoldBrand(id);
|
|
|
|
|
|
|
|
if (moldBrand == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MoldBrandRespVO moldBrandRespVO = buildMoldBrandVOList(Collections.singletonList(moldBrand)).stream().findFirst().orElse(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String qrcodeUrl = qrcodeService.selectQrcodeUrlByIdAndCode(QrcodeBizTypeEnum.MOLD.getCode(),id,moldBrand.getCode());
|
|
|
|
|
|
|
|
moldBrandRespVO.setQrCodeUrl(qrcodeUrl);
|
|
|
|
|
|
|
|
return moldBrandRespVO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void fillLatestOperateDeviceName(MoldBrandRespVO respVO) {
|
|
|
|
|
|
|
|
if (respVO == null || respVO.getId() == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fillLatestOperateDeviceName(Collections.singletonList(respVO));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void fillLatestOperateDeviceName(List<MoldBrandRespVO> respVOList) {
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(respVOList)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<Long, MoldOperateSimpleDO> latestOperateMap = getLatestOperateMapByBrandIds(
|
|
|
|
|
|
|
|
convertSet(respVOList, MoldBrandRespVO::getId));
|
|
|
|
|
|
|
|
respVOList.forEach(item -> fillCurrentDeviceNameByLatestOperate(item, latestOperateMap.get(item.getId())));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<MoldBrandDO> selectBy(MoldBrandPageReqVO reqVO){
|
|
|
|
public List<MoldBrandDO> selectBy(MoldBrandPageReqVO reqVO){
|
|
|
|
return moldBrandMapper.selectBy(reqVO);
|
|
|
|
return moldBrandMapper.selectBy(reqVO);
|
|
|
|
@ -140,21 +209,202 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PageResult<MoldBrandRespVO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
|
|
|
|
public PageResult<MoldBrandRespVO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(pageReqVO.getDeviceName())) {
|
|
|
|
|
|
|
|
List<MoldBrandDO> filteredList = selectByDeviceName(pageReqVO);
|
|
|
|
|
|
|
|
List<MoldBrandDO> pageList = paginateList(filteredList, pageReqVO);
|
|
|
|
|
|
|
|
return new PageResult<>(buildMoldBrandVOList(pageList), (long) filteredList.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
PageResult<MoldBrandDO> pageResult = moldBrandMapper.selectPage(pageReqVO);
|
|
|
|
PageResult<MoldBrandDO> pageResult = moldBrandMapper.selectPage(pageReqVO);
|
|
|
|
return new PageResult<>(buildMoldBrandVOList(pageResult.getList()), pageResult.getTotal());
|
|
|
|
return new PageResult<>(buildMoldBrandVOList(pageResult.getList()), pageResult.getTotal());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public MoldBrandPageRespVO getMoldBrandPageWithStatistics(MoldBrandPageReqVO pageReqVO) {
|
|
|
|
|
|
|
|
MoldBrandPageRespVO respVO = new MoldBrandPageRespVO();
|
|
|
|
|
|
|
|
respVO.setPageResult(getMoldBrandPage(pageReqVO));
|
|
|
|
|
|
|
|
MoldBrandStatusStatisticsRespVO statistics = getMoldBrandStatusStatistics(pageReqVO);
|
|
|
|
|
|
|
|
respVO.setAllCount(statistics.getAllCount());
|
|
|
|
|
|
|
|
respVO.setOnMachineCount(statistics.getOnMachineCount());
|
|
|
|
|
|
|
|
respVO.setStandbyCount(statistics.getStandbyCount());
|
|
|
|
|
|
|
|
respVO.setRepairingCount(statistics.getRepairingCount());
|
|
|
|
|
|
|
|
respVO.setScrappedCount(statistics.getScrappedCount());
|
|
|
|
|
|
|
|
return respVO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public MoldBrandStatusStatisticsRespVO getMoldBrandStatusStatistics(MoldBrandPageReqVO pageReqVO) {
|
|
|
|
|
|
|
|
MoldBrandPageReqVO statisticsReqVO = BeanUtils.toBean(pageReqVO, MoldBrandPageReqVO.class);
|
|
|
|
|
|
|
|
statisticsReqVO.setStatus(null);
|
|
|
|
|
|
|
|
List<MoldBrandDO> list = StrUtil.isNotBlank(statisticsReqVO.getDeviceName())
|
|
|
|
|
|
|
|
? selectByDeviceName(statisticsReqVO)
|
|
|
|
|
|
|
|
: moldBrandMapper.selectBy(statisticsReqVO);
|
|
|
|
|
|
|
|
MoldBrandStatusStatisticsRespVO respVO = new MoldBrandStatusStatisticsRespVO();
|
|
|
|
|
|
|
|
respVO.setAllCount((long) list.size());
|
|
|
|
|
|
|
|
respVO.setOnMachineCount(countByStatus(list, MoldBrandStatusEnum.ON_MACHINE.getStatus()));
|
|
|
|
|
|
|
|
respVO.setStandbyCount(countByStatus(list, MoldBrandStatusEnum.STANDBY.getStatus()));
|
|
|
|
|
|
|
|
respVO.setRepairingCount(countByStatus(list, MoldBrandStatusEnum.REPAIRING.getStatus()));
|
|
|
|
|
|
|
|
respVO.setScrappedCount(countByStatus(list, MoldBrandStatusEnum.SCRAPPED.getStatus()));
|
|
|
|
|
|
|
|
return respVO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<MoldBrandRespVO> buildMoldBrandVOList(List<MoldBrandDO> list) {
|
|
|
|
private List<MoldBrandRespVO> buildMoldBrandVOList(List<MoldBrandDO> list) {
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(
|
|
|
|
|
|
|
|
convertSet(list, MoldBrandDO::getProductId));
|
|
|
|
List<MoldBrandProductDO> relations = moldBrandProductMapper.selectListByBrandIds(convertSet(list, MoldBrandDO::getId));
|
|
|
|
|
|
|
|
Map<Long, List<MoldBrandProductDO>> relationMap = relations.stream()
|
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(MoldBrandProductDO::getBrandId));
|
|
|
|
|
|
|
|
Set<Long> productIds = new LinkedHashSet<>(convertSet(list, MoldBrandDO::getProductId));
|
|
|
|
|
|
|
|
productIds.addAll(convertSet(relations, MoldBrandProductDO::getProductId));
|
|
|
|
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(productIds);
|
|
|
|
return BeanUtils.toBean(list, MoldBrandRespVO.class, item -> {
|
|
|
|
return BeanUtils.toBean(list, MoldBrandRespVO.class, item -> {
|
|
|
|
|
|
|
|
if (item.getStatus() == null) {
|
|
|
|
|
|
|
|
item.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String qrcodeUrl = qrcodeService.selectQrcodeUrlByIdAndCode(QrcodeBizTypeEnum.MOLD.getCode(),item.getId(),item.getCode());
|
|
|
|
|
|
|
|
item.setQrCodeUrl(qrcodeUrl);
|
|
|
|
|
|
|
|
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
product -> item.setProductName(product.getName()));
|
|
|
|
product -> item.setProductName(product.getName()));
|
|
|
|
|
|
|
|
List<MoldBrandProductDO> brandProducts = relationMap.getOrDefault(item.getId(), Collections.emptyList());
|
|
|
|
|
|
|
|
List<Long> relationProductIds = brandProducts.stream()
|
|
|
|
|
|
|
|
.map(MoldBrandProductDO::getProductId)
|
|
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.distinct()
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(relationProductIds) && item.getProductId() != null) {
|
|
|
|
|
|
|
|
relationProductIds = Collections.singletonList(item.getProductId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
item.setProductIds(relationProductIds);
|
|
|
|
|
|
|
|
item.setProducts(relationProductIds.stream()
|
|
|
|
|
|
|
|
.map(productId -> {
|
|
|
|
|
|
|
|
ErpProductDO product = map.get(productId);
|
|
|
|
|
|
|
|
if (product != null) {
|
|
|
|
|
|
|
|
return product;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String snapshotName = brandProducts.stream()
|
|
|
|
|
|
|
|
.filter(rel -> Objects.equals(rel.getProductId(), productId))
|
|
|
|
|
|
|
|
.map(MoldBrandProductDO::getProductName)
|
|
|
|
|
|
|
|
.filter(StrUtil::isNotBlank)
|
|
|
|
|
|
|
|
.findFirst()
|
|
|
|
|
|
|
|
.orElse(null);
|
|
|
|
|
|
|
|
return ErpProductDO.builder().id(productId).name(snapshotName).build();
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
|
|
if (StrUtil.isBlank(item.getProductName()) && item.getProductId() != null) {
|
|
|
|
|
|
|
|
brandProducts.stream()
|
|
|
|
|
|
|
|
.filter(rel -> Objects.equals(rel.getProductId(), item.getProductId()))
|
|
|
|
|
|
|
|
.map(MoldBrandProductDO::getProductName)
|
|
|
|
|
|
|
|
.filter(StrUtil::isNotBlank)
|
|
|
|
|
|
|
|
.findFirst()
|
|
|
|
|
|
|
|
.ifPresent(item::setProductName);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Long, MoldOperateSimpleDO> getLatestOperateMapByBrandIds(Collection<Long> brandIds) {
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(brandIds)) {
|
|
|
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<MoldDO> moldList = moldMapper.selectList(new LambdaQueryWrapperX<MoldDO>()
|
|
|
|
|
|
|
|
.in(MoldDO::getBrandId, brandIds)
|
|
|
|
|
|
|
|
.select(MoldDO::getId, MoldDO::getBrandId));
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(moldList)) {
|
|
|
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<Long, Long> moldBrandMap = moldList.stream().collect(Collectors.toMap(MoldDO::getId, MoldDO::getBrandId));
|
|
|
|
|
|
|
|
List<MoldOperateSimpleDO> operateList = moldOperateQueryMapper.selectByMoldIds(moldBrandMap.keySet());
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(operateList)) {
|
|
|
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<Long, MoldOperateSimpleDO> latestOperateMap = new HashMap<>();
|
|
|
|
|
|
|
|
for (MoldOperateSimpleDO operate : operateList) {
|
|
|
|
|
|
|
|
for (Long moldId : parseMoldIds(operate.getMoldId())) {
|
|
|
|
|
|
|
|
Long brandId = moldBrandMap.get(moldId);
|
|
|
|
|
|
|
|
if (brandId != null) {
|
|
|
|
|
|
|
|
latestOperateMap.putIfAbsent(brandId, operate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (latestOperateMap.size() >= brandIds.size()) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return latestOperateMap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void fillCurrentDeviceNameByLatestOperate(MoldBrandRespVO item, MoldOperateSimpleDO latestOperate) {
|
|
|
|
|
|
|
|
if (latestOperate == null) {
|
|
|
|
|
|
|
|
item.setDeviceName(null);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Objects.equals(latestOperate.getOperateType(), "1")) {
|
|
|
|
|
|
|
|
item.setDeviceName(latestOperate.getDeviceName());
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
item.setDeviceName(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Long> parseMoldIds(String moldIds) {
|
|
|
|
|
|
|
|
if (StrUtil.isBlank(moldIds)) {
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Arrays.stream(moldIds.split(","))
|
|
|
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
|
|
|
.filter(StrUtil::isNotBlank)
|
|
|
|
|
|
|
|
.map(Long::valueOf)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<MoldBrandDO> selectByDeviceName(MoldBrandPageReqVO reqVO) {
|
|
|
|
|
|
|
|
MoldBrandPageReqVO queryReqVO = BeanUtils.toBean(reqVO, MoldBrandPageReqVO.class);
|
|
|
|
|
|
|
|
queryReqVO.setDeviceName(null);
|
|
|
|
|
|
|
|
List<MoldBrandDO> moldBrandList = moldBrandMapper.selectBy(queryReqVO);
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(moldBrandList)) {
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<Long, MoldOperateSimpleDO> latestOperateMap = getLatestOperateMapByBrandIds(convertSet(moldBrandList, MoldBrandDO::getId));
|
|
|
|
|
|
|
|
return moldBrandList.stream()
|
|
|
|
|
|
|
|
.filter(item -> matchDeviceName(latestOperateMap.get(item.getId()), reqVO.getDeviceName()))
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean matchDeviceName(MoldOperateSimpleDO latestOperate, String deviceName) {
|
|
|
|
|
|
|
|
return latestOperate != null
|
|
|
|
|
|
|
|
&& Objects.equals(latestOperate.getOperateType(), "1")
|
|
|
|
|
|
|
|
&& StrUtil.contains(latestOperate.getDeviceName(), deviceName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<MoldBrandDO> paginateList(List<MoldBrandDO> list, PageParam pageReqVO) {
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(list) || Objects.equals(pageReqVO.getPageSize(), PageParam.PAGE_SIZE_NONE)) {
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int fromIndex = (pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize();
|
|
|
|
|
|
|
|
if (fromIndex >= list.size()) {
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int toIndex = Math.min(fromIndex + pageReqVO.getPageSize(), list.size());
|
|
|
|
|
|
|
|
return list.subList(fromIndex, toIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void fillProductName(MoldBrandDO moldBrand) {
|
|
|
|
|
|
|
|
if (moldBrand == null || moldBrand.getProductId() == null) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moldBrand.getStatus() == null) {
|
|
|
|
|
|
|
|
moldBrand.setStatus(MoldBrandStatusEnum.STANDBY.getStatus());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ErpProductRespVO product = productService.getProduct(moldBrand.getProductId());
|
|
|
|
|
|
|
|
if (product != null) {
|
|
|
|
|
|
|
|
moldBrand.setProductName(product.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Long countByStatus(List<MoldBrandDO> list, Integer status) {
|
|
|
|
|
|
|
|
return list.stream()
|
|
|
|
|
|
|
|
.filter(item -> Objects.equals(item.getStatus(), status))
|
|
|
|
|
|
|
|
.count();
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<MoldBrandDO> getList(Collection<Long> ids) {
|
|
|
|
public List<MoldBrandDO> getList(Collection<Long> ids) {
|
|
|
|
return moldBrandMapper.selectBatchIds(ids);
|
|
|
|
return moldBrandMapper.selectBatchIds(ids);
|
|
|
|
@ -216,30 +466,31 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
|
|
|
|
|
|
|
|
moldMapper.insert(mold);
|
|
|
|
moldMapper.insert(mold);
|
|
|
|
|
|
|
|
|
|
|
|
CodeTypeEnum codeType = autoCodeUtil.queryCodeType("MOLD_CODE_GENERATE");
|
|
|
|
// CodeTypeEnum codeType = autoCodeUtil.queryCodeType("MOLD_CODE_GENERATE");
|
|
|
|
if (codeType==null){
|
|
|
|
// if (codeType==null){
|
|
|
|
log.warn("[创建模具]未配置码类型,跳过生产,ruleCode={}","MOLD_CODE_GENERATE");
|
|
|
|
// log.warn("[创建模具]未配置码类型,跳过生产,ruleCode={}","MOLD_CODE_GENERATE");
|
|
|
|
return mold.getId();
|
|
|
|
// return mold.getId();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
qrcodeService.generateOrRefresh(
|
|
|
|
// qrcodeService.generateOrRefresh(
|
|
|
|
QrcodeBizTypeEnum.MOLD,
|
|
|
|
// QrcodeBizTypeEnum.MOLD,
|
|
|
|
mold.getId(),
|
|
|
|
// mold.getId(),
|
|
|
|
mold.getCode(),
|
|
|
|
// mold.getCode(),
|
|
|
|
"DETAIL",
|
|
|
|
// "DETAIL",
|
|
|
|
codeType
|
|
|
|
// codeType
|
|
|
|
);
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mold.getId();
|
|
|
|
return mold.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateMold(MoldDO mold) {
|
|
|
|
public void updateMold(MoldSaveReqVO updateReqVO) {
|
|
|
|
// 校验存在
|
|
|
|
// 校验存在
|
|
|
|
validateMoldExists(mold.getId());
|
|
|
|
validateMoldExists(updateReqVO.getId());
|
|
|
|
// 更新
|
|
|
|
// 更新
|
|
|
|
moldMapper.updateById(mold);
|
|
|
|
MoldDO updateObj = BeanUtils.toBean(updateReqVO, MoldDO.class);
|
|
|
|
|
|
|
|
moldMapper.updateById(updateObj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -361,6 +612,7 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(
|
|
|
|
Map<Long, ErpProductDO> map = productService.getProductMap(
|
|
|
|
convertSet(list, MoldBrandProductDO::getProductId));
|
|
|
|
convertSet(list, MoldBrandProductDO::getProductId));
|
|
|
|
return BeanUtils.toBean(list, MoldProductRespVO.class, item -> {
|
|
|
|
return BeanUtils.toBean(list, MoldProductRespVO.class, item -> {
|
|
|
|
|
|
|
|
item.setProductNameSnapshot(item.getProductName());
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
MapUtils.findAndThen(map, item.getProductId(),
|
|
|
|
product -> item.setProductName(product.getName()));
|
|
|
|
product -> item.setProductName(product.getName()));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -373,6 +625,11 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
if(list!=null && list.size()>0){
|
|
|
|
if(list!=null && list.size()>0){
|
|
|
|
throw exception(MOLD_BRAND_PRODUCT_EXISTS);
|
|
|
|
throw exception(MOLD_BRAND_PRODUCT_EXISTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErpProductDO product = productService.validProductList(Collections.singletonList(moldBrandProduct.getProductId()))
|
|
|
|
|
|
|
|
.stream().findFirst().orElse(null);
|
|
|
|
|
|
|
|
if (product != null) {
|
|
|
|
|
|
|
|
moldBrandProduct.setProductName(product.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
moldBrandProductMapper.insert(moldBrandProduct);
|
|
|
|
moldBrandProductMapper.insert(moldBrandProduct);
|
|
|
|
return moldBrandProduct.getId();
|
|
|
|
return moldBrandProduct.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -381,6 +638,11 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
public void updateMoldBrandProduct(MoldBrandProductDO moldBrandProduct) {
|
|
|
|
public void updateMoldBrandProduct(MoldBrandProductDO moldBrandProduct) {
|
|
|
|
// 校验存在
|
|
|
|
// 校验存在
|
|
|
|
validateMoldBrandProductExists(moldBrandProduct.getId());
|
|
|
|
validateMoldBrandProductExists(moldBrandProduct.getId());
|
|
|
|
|
|
|
|
ErpProductDO product = productService.validProductList(Collections.singletonList(moldBrandProduct.getProductId()))
|
|
|
|
|
|
|
|
.stream().findFirst().orElse(null);
|
|
|
|
|
|
|
|
if (product != null) {
|
|
|
|
|
|
|
|
moldBrandProduct.setProductName(product.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
// 更新
|
|
|
|
// 更新
|
|
|
|
moldBrandProductMapper.updateById(moldBrandProduct);
|
|
|
|
moldBrandProductMapper.updateById(moldBrandProduct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -418,6 +680,36 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
moldBrandProductMapper.deleteByBrandId(brandId);
|
|
|
|
moldBrandProductMapper.deleteByBrandId(brandId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void createMoldBrandProducts(Long brandId, List<Long> productIds, Long fallbackProductId) {
|
|
|
|
|
|
|
|
List<Long> finalProductIds = normalizeProductIds(productIds, fallbackProductId);
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(finalProductIds)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
productService.validProductList(finalProductIds);
|
|
|
|
|
|
|
|
Map<Long, ErpProductDO> productMap = productService.getProductMap(finalProductIds);
|
|
|
|
|
|
|
|
finalProductIds.forEach(productId -> moldBrandProductMapper.insert(MoldBrandProductDO.builder()
|
|
|
|
|
|
|
|
.brandId(brandId)
|
|
|
|
|
|
|
|
.productId(productId)
|
|
|
|
|
|
|
|
.productName(productMap.containsKey(productId) ? productMap.get(productId).getName() : null)
|
|
|
|
|
|
|
|
.build()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void syncMoldBrandProducts(Long brandId, List<Long> productIds, Long fallbackProductId) {
|
|
|
|
|
|
|
|
deleteMoldBrandProductByBrandId(brandId);
|
|
|
|
|
|
|
|
createMoldBrandProducts(brandId, productIds, fallbackProductId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Long> normalizeProductIds(List<Long> productIds, Long fallbackProductId) {
|
|
|
|
|
|
|
|
LinkedHashSet<Long> finalIds = new LinkedHashSet<>();
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(productIds)) {
|
|
|
|
|
|
|
|
finalIds.addAll(productIds.stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fallbackProductId != null) {
|
|
|
|
|
|
|
|
finalIds.add(fallbackProductId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ArrayList<>(finalIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<MoldBrandTreeRespVO> getMoldBrandTree() {
|
|
|
|
public List<MoldBrandTreeRespVO> getMoldBrandTree() {
|
|
|
|
// 1. 查询所有模具类型
|
|
|
|
// 1. 查询所有模具类型
|
|
|
|
@ -429,14 +721,14 @@ public class MoldBrandServiceImpl implements MoldBrandService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void regenerateCode(Long id, String code) throws UnsupportedEncodingException {
|
|
|
|
public void regenerateCode(Long id, String code) throws UnsupportedEncodingException {
|
|
|
|
if(moldMapper.selectById(id)==null){
|
|
|
|
if(moldBrandMapper.selectById(id)==null){
|
|
|
|
throw exception(MOLD_BRAND_PRODUCT_NOT_EXISTS);
|
|
|
|
throw exception(MOLD_SET_NOT_EXISTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(StringUtils.isBlank(code)){
|
|
|
|
if(StringUtils.isBlank(code)){
|
|
|
|
throw exception(MOLD_CODE_EMPTY);
|
|
|
|
throw exception(MOLD_CODE_EMPTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodeTypeEnum codeGenerate = autoCodeUtil.queryCodeType("MOLD_CODE_GENERATE");
|
|
|
|
CodeTypeEnum codeGenerate = autoCodeUtil.queryCodeType("MOLD_SET_CODE");
|
|
|
|
//
|
|
|
|
//
|
|
|
|
qrcodeService.regenerateByCodeType(
|
|
|
|
qrcodeService.regenerateByCodeType(
|
|
|
|
QrcodeBizTypeEnum.MOLD,
|
|
|
|
QrcodeBizTypeEnum.MOLD,
|
|
|
|
|