package com.qianwen.smartman.modules.cps.service.impl;
|
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONUtil;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayOutputStream;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.lang.invoke.SerializedLambda;
|
import java.lang.reflect.Field;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Optional;
|
import java.util.Set;
|
import java.util.function.Function;
|
import java.util.stream.Collectors;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import com.qianwen.smartman.common.constant.CommonConstant;
|
import com.qianwen.smartman.common.constant.CommonGroupConstant;
|
import com.qianwen.smartman.common.constant.ExcelConstant;
|
import com.qianwen.smartman.common.utils.ExcelUtils;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.smartman.common.utils.ValidatorUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.mp.support.Condition;
|
import com.qianwen.core.mp.support.Query;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.tool.constant.BladeConstant;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.core.tool.utils.StringUtil;
|
import com.qianwen.smartman.modules.coproduction.dto.CheckParamDTO;
|
import com.qianwen.smartman.modules.coproduction.dto.CheckResultDTO;
|
import com.qianwen.smartman.modules.cps.convert.ProductConvert;
|
import com.qianwen.smartman.modules.cps.dto.ProductCountDTO;
|
import com.qianwen.smartman.modules.cps.entity.Product;
|
import com.qianwen.smartman.modules.cps.entity.ProductType;
|
import com.qianwen.smartman.modules.cps.excel.ProductExcel;
|
import com.qianwen.smartman.modules.cps.excel.ProductExcelExport;
|
import com.qianwen.smartman.modules.cps.excel.ProductImport;
|
import com.qianwen.smartman.modules.cps.mapper.ProductMapper;
|
import com.qianwen.smartman.modules.cps.service.IProductService;
|
import com.qianwen.smartman.modules.cps.service.IProductTypeService;
|
import com.qianwen.smartman.modules.cps.vo.ProductAddVO;
|
import com.qianwen.smartman.modules.cps.vo.ProductChangeStatusVO;
|
import com.qianwen.smartman.modules.cps.vo.ProductEasyVO;
|
import com.qianwen.smartman.modules.cps.vo.ProductSearchVO;
|
import com.qianwen.smartman.modules.cps.vo.ProductSelectVO;
|
import com.qianwen.smartman.modules.cps.vo.ProductUpdateVO;
|
import com.qianwen.smartman.modules.cps.vo.ProductVO;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
import com.qianwen.smartman.modules.system.constant.FieldConstant;
|
import com.qianwen.smartman.modules.system.dto.CustomTemplateFieldRelationDTO;
|
import com.qianwen.smartman.modules.system.entity.CustomTemplate;
|
import com.qianwen.smartman.modules.system.enums.BusinessTypeEnums;
|
import com.qianwen.smartman.modules.system.enums.ConfigTypeEnum;
|
import com.qianwen.smartman.modules.system.handler.field.HandlerFieldSqlParse;
|
import com.qianwen.smartman.modules.system.mapper.CustomTemplateFieldRelationMapper;
|
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
|
import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldService;
|
import com.qianwen.smartman.modules.system.service.ICustomTemplateService;
|
import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldColumnVO;
|
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/ProductServiceImpl.class */
|
public class ProductServiceImpl extends BaseServiceImpl<ProductMapper, Product> implements IProductService {
|
private static final Logger log = LoggerFactory.getLogger(ProductServiceImpl.class);
|
private final IProductTypeService productTypeService;
|
private final OssBuilder ossBuilder;
|
private final ProductMapper productMapper;
|
private final ICodeGeneratorService codeGeneratorService;
|
private final HandlerFieldSqlParse handlerFieldSqlParse;
|
private final ICustomTemplateService customTemplateService;
|
private final ICustomTemplateFieldService customTemplateFieldService;
|
private final CustomTemplateFieldRelationMapper customTemplateFieldRelationMapper;
|
|
private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
|
String implMethodName = lambda.getImplMethodName();
|
boolean z = true;
|
switch (implMethodName.hashCode()) {
|
case -1041904421:
|
if (implMethodName.equals("getParentId")) {
|
z = true;
|
break;
|
}
|
break;
|
case -75622813:
|
if (implMethodName.equals("getCode")) {
|
z = true;
|
break;
|
}
|
break;
|
case -75308287:
|
if (implMethodName.equals("getName")) {
|
z = false;
|
break;
|
}
|
break;
|
case 98245393:
|
if (implMethodName.equals("getId")) {
|
z = true;
|
break;
|
}
|
break;
|
case 953775504:
|
if (implMethodName.equals("getBusinessType")) {
|
z = true;
|
break;
|
}
|
break;
|
}
|
switch (z) {
|
case false:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/ProductType") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getName();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getName();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getName();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/CustomTemplate") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getBusinessType();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/CustomTemplate") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
|
return (v0) -> {
|
return v0.getBusinessType();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getId();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
|
return (v0) -> {
|
return v0.getCode();
|
};
|
}
|
break;
|
case true:
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getParentId();
|
};
|
}
|
if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/Product") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
|
return (v0) -> {
|
return v0.getParentId();
|
};
|
}
|
break;
|
}
|
throw new IllegalArgumentException("Invalid lambda deserialization");
|
}
|
|
public ProductServiceImpl(final IProductTypeService productTypeService, final OssBuilder ossBuilder, final ProductMapper productMapper, final ICodeGeneratorService codeGeneratorService, final HandlerFieldSqlParse handlerFieldSqlParse, final ICustomTemplateService customTemplateService, final ICustomTemplateFieldService customTemplateFieldService, final CustomTemplateFieldRelationMapper customTemplateFieldRelationMapper) {
|
this.productTypeService = productTypeService;
|
this.ossBuilder = ossBuilder;
|
this.productMapper = productMapper;
|
this.codeGeneratorService = codeGeneratorService;
|
this.handlerFieldSqlParse = handlerFieldSqlParse;
|
this.customTemplateService = customTemplateService;
|
this.customTemplateFieldService = customTemplateFieldService;
|
this.customTemplateFieldRelationMapper = customTemplateFieldRelationMapper;
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public IPage<ProductVO> selectPage(IPage<ProductVO> page, ProductSelectVO productSelectVO) {
|
List<ProductVO> productVOS = selectProductVOList(page, productSelectVO, true);
|
long total = page.getTotal();
|
if (total == 0) {
|
return page;
|
}
|
page.setRecords(productVOS);
|
return page;
|
}
|
|
/* JADX WARN: Multi-variable type inference failed */
|
private List<ProductVO> selectProductVOList(IPage<ProductVO> page, ProductSelectVO productSelectVO, boolean isPage) {
|
String orderBy;
|
String typeId = productSelectVO.getTypeId();
|
if (Func.isNotEmpty(typeId)) {
|
long[] ids = StrUtil.splitToLong(typeId, ",");
|
List<Long> typeIds = Convert.toList(Long.class, ids);
|
productSelectVO.setTypeIds(typeIds);
|
}
|
Long parentId = productSelectVO.getParentId();
|
List<Long> all = new ArrayList<>();
|
List<Long> pids = new ArrayList<>();
|
pids.add(parentId);
|
selectChildrenId(all, pids, productSelectVO);
|
productSelectVO.setIds(all);
|
if (Func.equals(parentId, CommonGroupConstant.DEFAULT_ALL_GROUP_ID) || Func.equals(parentId, CommonGroupConstant.DEFAULT_GROUP_ID)) {
|
orderBy = "code";
|
} else {
|
orderBy = "create_time desc";
|
}
|
productSelectVO.setOrderBy(orderBy);
|
List<Long> ids2 = new ArrayList<>();
|
if (Func.isNotEmpty(productSelectVO.getIds())) {
|
List<Product> products = ((ProductMapper) this.baseMapper).selectIdById(productSelectVO);
|
ids2 = (List) products.stream().map((v0) -> {
|
return v0.getId();
|
}).distinct().collect(Collectors.toList());
|
}
|
List<Long> pageIds = new ArrayList<>();
|
if (Func.equals(parentId, CommonGroupConstant.DEFAULT_ALL_GROUP_ID) || Func.equals(parentId, CommonGroupConstant.DEFAULT_GROUP_ID)) {
|
ids2.remove(CommonGroupConstant.DEFAULT_GROUP_ID);
|
} else {
|
List<Long> tempIds = new ArrayList<>();
|
tempIds.add(parentId);
|
productSelectVO.setIds(tempIds);
|
List<Product> products2 = ((ProductMapper) this.baseMapper).selectIdById(productSelectVO);
|
if (Func.isNotEmpty(products2)) {
|
pageIds.add(parentId);
|
}
|
}
|
pageIds.addAll(ids2);
|
int total = pageIds.size();
|
if (isPage) {
|
page.setTotal(total);
|
if (total == 0) {
|
return new ArrayList();
|
}
|
long current = page.getCurrent();
|
long size = page.getSize();
|
long startIndex = (current - 1) * size;
|
long endIndex = startIndex + size;
|
pageIds = pageIds.subList(Func.toInt(Long.valueOf(startIndex > ((long) total) ? total : startIndex)), Func.toInt(Long.valueOf(endIndex > ((long) total) ? total : endIndex)));
|
}
|
List<ProductVO> productVOS = new ArrayList<>();
|
if (Func.isNotEmpty(pageIds)) {
|
productVOS = ((ProductMapper) this.baseMapper).selectListByIds(pageIds, orderBy);
|
}
|
if (Func.isNotEmpty(productVOS)) {
|
Optional<ProductVO> productOP = productVOS.stream().filter(item -> {
|
return Func.equals(item.getId(), parentId);
|
}).findFirst();
|
if (productOP.isPresent()) {
|
ProductVO productVO = productOP.get();
|
productVOS.remove(productVO);
|
List<ProductVO> arrayList = new ArrayList<>();
|
arrayList.add(productVO);
|
arrayList.addAll(productVOS);
|
productVOS = arrayList;
|
}
|
}
|
return productVOS;
|
}
|
|
public void selectChildrenId(List<Long> all, List<Long> parentIds, ProductSelectVO productSelectVO) {
|
productSelectVO.setPids(parentIds);
|
List<Product> products = ((ProductMapper) this.baseMapper).selectList((Wrapper) Wrappers.lambdaQuery().select(new SFunction[]{(v0) -> {
|
return v0.getId();
|
}}).in((v0) -> {
|
return v0.getParentId();
|
}, parentIds));
|
List<Long> ids = (List) products.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
if (Func.isNotEmpty(ids)) {
|
all.addAll(ids);
|
selectChildrenId(all, ids, productSelectVO);
|
}
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public Product insert(ProductAddVO productAddVO) {
|
this.handlerFieldSqlParse.handlerFieldSaveOrUpdateCheck(productAddVO.getExtendField(), BusinessTypeEnums.PRODUCT.getCode());
|
if (Func.isEmpty(productAddVO.getParentId())) {
|
productAddVO.setParentId(CommonGroupConstant.DEFAULT_GROUP_ID);
|
}
|
if (Func.isBlank(productAddVO.getCode())) {
|
String code = this.codeGeneratorService.getGeneratorCode(productAddVO, MetaTypeEnum.PRODUCT.getCode());
|
log.info("产品编码规则生成的code:{}", code + " ," + code.length());
|
productAddVO.setCode(code);
|
}
|
ProductType productType = (ProductType) this.productTypeService.getById(productAddVO.getTypeId());
|
if (Func.isEmpty(productType)) {
|
throw new ServiceException(MessageUtils.message("cps.product.type.not.exists", new Object[0]));
|
}
|
if (Func.isNotEmpty(productAddVO.getStatus()) && productAddVO.getStatus().equals(1)) {
|
Product product = (Product) getById(productAddVO.getParentId());
|
if (Func.isNotEmpty(product) && product.getStatus().equals(0)) {
|
throw new ServiceException(MessageUtils.message("cps.product.parent.is.stop", new Object[0]));
|
}
|
}
|
checkProductCodeAndName(null, productAddVO.getTypeId(), productAddVO.getCode(), productAddVO.getName());
|
Product product2 = ProductConvert.INSTANCE.convert(productAddVO);
|
save(product2);
|
return product2;
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public Product update(ProductUpdateVO productUpdateVO) {
|
this.handlerFieldSqlParse.handlerFieldSaveOrUpdateCheck(productUpdateVO.getExtendField(), BusinessTypeEnums.PRODUCT.getCode());
|
Long id = productUpdateVO.getId();
|
if (Func.equals(id, CommonGroupConstant.DEFAULT_ALL_GROUP_ID) || Func.equals(id, CommonGroupConstant.DEFAULT_GROUP_ID)) {
|
throw new ServiceException(MessageUtils.message("cps.product.be.all.group.or.default.group.cannot.update", new Object[0]));
|
}
|
if (Func.isEmpty(productUpdateVO.getParentId())) {
|
productUpdateVO.setParentId(CommonGroupConstant.DEFAULT_ALL_GROUP_ID);
|
}
|
ProductType productType = (ProductType) this.productTypeService.getById(productUpdateVO.getTypeId());
|
if (Func.isEmpty(productType)) {
|
throw new ServiceException(MessageUtils.message("cps.product.type.not.exists", new Object[0]));
|
}
|
if (Func.isNotEmpty(productUpdateVO.getStatus())) {
|
if (productUpdateVO.getStatus().equals(0)) {
|
Integer count = this.productMapper.getParentStatusCount(Arrays.asList(String.valueOf(productUpdateVO.getId())));
|
if (count.intValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.product.stop.children.first", new Object[0]));
|
}
|
} else {
|
Product product = (Product) getById(productUpdateVO.getParentId());
|
if (Func.isNotEmpty(product) && product.getStatus().equals(0)) {
|
throw new ServiceException(MessageUtils.message("cps.product.parent.is.stop", new Object[0]));
|
}
|
}
|
}
|
checkProductCodeAndName(productUpdateVO.getId(), productUpdateVO.getTypeId(), productUpdateVO.getCode(), productUpdateVO.getName());
|
productUpdateVO.setCode(null);
|
Product product2 = ProductConvert.INSTANCE.convert(productUpdateVO);
|
updateById(product2);
|
return product2;
|
}
|
|
private CustomTemplate getProductTemplate() {
|
List<CustomTemplate> list = this.customTemplateService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getBusinessType();
|
}, BusinessTypeEnums.PRODUCT.getCode()));
|
return list.stream().findFirst().orElse(null);
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
@Transactional(rollbackFor = {Exception.class})
|
public BladeFile importProduct(MultipartFile file) {
|
try {
|
ExcelUtils.ExcelDataDTO excelDataDTO = ExcelUtils.readExcel(file.getInputStream());
|
List<Map<String, String>> data = excelDataDTO.getData();
|
List<Map<String, String>> sysData = new ArrayList<>();
|
List<CheckResultDTO> checkResultDTOS = this.customTemplateService.checkImport(getCheckFunction(sysData), BusinessTypeEnums.PRODUCT.getCode(), data);
|
if (Func.isEmpty(checkResultDTOS)) {
|
throw new ServiceException("数据有误");
|
}
|
List<ProductImport> productImports = cover(sysData);
|
List<Product> products = checkImportData(checkResultDTOS, productImports);
|
saveBatch(products);
|
BladeFile bladeFile = putImportFail(excelDataDTO, checkResultDTOS);
|
if (Func.isNotEmpty(bladeFile)) {
|
return bladeFile;
|
}
|
return null;
|
} catch (Exception e) {
|
throw new ServiceException("表格数据有误");
|
}
|
}
|
|
List<ProductImport> cover(List<Map<String, String>> sysData) {
|
List<ProductImport> importVOS = new ArrayList<>();
|
sysData.forEach(item -> {
|
ProductImport prodectImport = new ProductImport();
|
importVOS.add(prodectImport);
|
item.forEach(k, v -> {
|
Field[] declaredFields = ProductImport.class.getDeclaredFields();
|
for (Field field : declaredFields) {
|
try {
|
if (Func.equals(field.getName(), k)) {
|
field.setAccessible(true);
|
field.set(prodectImport, v);
|
}
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
}
|
}
|
});
|
});
|
return importVOS;
|
}
|
|
private BladeFile putImportFail(ExcelUtils.ExcelDataDTO excelDataDTO, List<CheckResultDTO> checkResultDTOS) {
|
int pass = CommonConstant.ENABLE.intValue();
|
Iterator<CheckResultDTO> it = checkResultDTOS.iterator();
|
while (true) {
|
if (it.hasNext()) {
|
if (Func.equals(it.next().getCode(), CommonConstant.DEACTIVATE)) {
|
pass = CommonConstant.DEACTIVATE.intValue();
|
break;
|
}
|
} else {
|
break;
|
}
|
}
|
if (Func.equals(Integer.valueOf(pass), CommonConstant.ENABLE)) {
|
return null;
|
}
|
List<Map<String, String>> data = excelDataDTO.getData();
|
for (int i = 0; i < data.size(); i++) {
|
Map<String, String> map = data.get(i);
|
CheckResultDTO checkResultDTO = checkResultDTOS.get(i);
|
if (Func.equals(checkResultDTO.getCode(), CommonConstant.DEACTIVATE)) {
|
map.put(ExcelConstant.FAIL_REASON, checkResultDTO.getError());
|
}
|
}
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
Workbook workbook = ExcelUtils.generateFail(excelDataDTO);
|
try {
|
workbook.write(bos);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
InputStream is = new ByteArrayInputStream(bos.toByteArray());
|
return this.ossBuilder.systemTemplate().putFile("产品导入模板错误.xlsx", is);
|
}
|
|
private Function<List<Map<String, String>>, List<CheckParamDTO>> getCheckFunction(List<Map<String, String>> map) {
|
return dto -> {
|
map.addAll(dto);
|
List<CheckParamDTO> checkParamDTOS = new ArrayList<>();
|
List<CustomTemplate> templates = this.customTemplateService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getBusinessType();
|
}, BusinessTypeEnums.PRODUCT.getCode()));
|
Optional<CustomTemplate> customTemplateOptional = templates.stream().findFirst();
|
CustomTemplate customTemplate = null;
|
if (customTemplateOptional.isPresent()) {
|
customTemplate = customTemplateOptional.get();
|
}
|
List<CustomTemplateFieldRelationDTO> customTemplateFieldRelationDTOS = null;
|
if (Func.isNotEmpty(customTemplate)) {
|
List<Long> templateIds = Arrays.asList(customTemplate.getId());
|
customTemplateFieldRelationDTOS = this.customTemplateFieldRelationMapper.getImportFields(templateIds);
|
}
|
for (int i = 0; i < dto.size(); i++) {
|
CheckParamDTO checkParamDTO = new CheckParamDTO();
|
checkParamDTOS.add(checkParamDTO);
|
if (Func.isNotEmpty(customTemplate)) {
|
checkParamDTO.setCustomTemplate(customTemplate);
|
if (Func.isNotEmpty(customTemplateFieldRelationDTOS)) {
|
Map<String, CustomTemplateFieldRelationDTO> relationDTOMap = (Map) customTemplateFieldRelationDTOS.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getFieldCode();
|
}, item -> {
|
return item;
|
}));
|
checkParamDTO.setRelationMap(relationDTOMap);
|
}
|
}
|
}
|
return checkParamDTOS;
|
};
|
}
|
|
private List<Product> checkImportData(List<CheckResultDTO> results, List<ProductImport> planImportVOS) {
|
Set<String> typeNames = new HashSet<>();
|
Set<String> parentCodes = new HashSet<>();
|
Set<String> codes = new HashSet<>();
|
Set<String> names = new HashSet<>();
|
List<Product> pts = new ArrayList<>();
|
int passNum = 0;
|
for (int i = 0; i < planImportVOS.size(); i++) {
|
CheckResultDTO checkResultDTO = results.get(i);
|
ProductImport productImport = planImportVOS.get(i);
|
String parentCode = productImport.getParentId();
|
String typeName = productImport.getTypeName();
|
String code = productImport.getCode();
|
String name = productImport.getName();
|
if (Func.equals(checkResultDTO.getCode(), CommonConstant.DEACTIVATE)) {
|
passNum++;
|
} else {
|
if (StringUtil.isEmpty(code)) {
|
code = this.codeGeneratorService.getGeneratorCode(new ProductAddVO(), MetaTypeEnum.PRODUCT.getCode());
|
productImport.setCode(code);
|
} else if (StringUtil.isEmpty(name)) {
|
checkResultDTO.error(MessageUtils.message("cps.product.name.can.not.be.empty", new Object[0]));
|
} else if (StringUtil.isEmpty(typeName)) {
|
checkResultDTO.error(MessageUtils.message("cps.product.type.name.can.not.be.empty", new Object[0]));
|
} else if (codes.contains(code)) {
|
checkResultDTO.error(MessageUtils.message("cps.product.code.already.exists", new Object[0]));
|
} else if (names.contains(name)) {
|
checkResultDTO.error(MessageUtils.message("cps.product.name.already.exists", new Object[0]));
|
} else if (ValidatorUtils.stringFilter(code)) {
|
checkResultDTO.error(MessageUtils.message("cps.product.code.contains.illegal.characters", new Object[0]));
|
}
|
typeNames.add(typeName);
|
parentCodes.add(parentCode);
|
codes.add(code);
|
names.add(name);
|
}
|
}
|
if (passNum == planImportVOS.size()) {
|
return pts;
|
}
|
List<ProductType> productTypes = this.productTypeService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getName();
|
}, typeNames));
|
Map<String, ProductType> productTypeMap = (Map) productTypes.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getName();
|
}, item -> {
|
return item;
|
}));
|
List<Product> products = list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getCode();
|
}, parentCodes));
|
Map<String, Product> productMap = (Map) products.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getCode();
|
}, item2 -> {
|
return item2;
|
}));
|
List<Product> codeList = list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getCode();
|
}, codes));
|
Set<String> codeSet = (Set) codeList.stream().map((v0) -> {
|
return v0.getCode();
|
}).collect(Collectors.toSet());
|
List<Product> nameList = list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getName();
|
}, names));
|
Set<String> nameSet = (Set) nameList.stream().map((v0) -> {
|
return v0.getName();
|
}).collect(Collectors.toSet());
|
for (int i2 = 0; i2 < planImportVOS.size(); i2++) {
|
CheckResultDTO checkResultDTO2 = results.get(i2);
|
if (!Func.equals(checkResultDTO2.getCode(), CommonConstant.DEACTIVATE)) {
|
Product product = new Product();
|
ProductImport productImport2 = planImportVOS.get(i2);
|
String parentCode2 = productImport2.getParentId();
|
String typeName2 = productImport2.getTypeName();
|
String code2 = productImport2.getCode();
|
String name2 = productImport2.getName();
|
if (StringUtil.isNotBlank(code2) && code2.length() > 32) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.code.too.long", new Object[0]));
|
} else if (StringUtil.isNotBlank(name2) && name2.length() > 24) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.name.too.long", new Object[0]));
|
} else if (!productTypeMap.containsKey(typeName2)) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.type.not.exists", new Object[0]));
|
} else {
|
ProductType productType = productTypeMap.get(typeName2);
|
Integer status = productType.getStatus();
|
if (!Convert.toBool(status).booleanValue()) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.type.disable.cannot.add.data", new Object[0]));
|
}
|
Long id = productType.getId();
|
product.setTypeId(id);
|
if (Func.isNotEmpty(parentCode2)) {
|
if (!productMap.containsKey(parentCode2)) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.parent.code.not.exist", new Object[0]));
|
} else {
|
Product p = productMap.get(parentCode2);
|
Integer status2 = p.getStatus();
|
if (!Convert.toBool(status2).booleanValue()) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.parent.disable.cannot.add.data", new Object[0]));
|
}
|
Long parentId = p.getId();
|
product.setParentId(parentId);
|
}
|
}
|
if (codeSet.contains(code2)) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.code.already.exists", new Object[0]));
|
} else if (nameSet.contains(name2)) {
|
checkResultDTO2.error(MessageUtils.message("cps.product.name.already.exists", new Object[0]));
|
} else {
|
if (Func.isEmpty(parentCode2)) {
|
product.setParentId(BladeConstant.TOP_PARENT_ID);
|
}
|
pts.add(product);
|
product.setCode(productImport2.getCode());
|
product.setName(productImport2.getName());
|
product.setUnit(productImport2.getUnit());
|
product.setStandardModel(productImport2.getStandardModel());
|
product.setDescription(productImport2.getDescription());
|
product.setDocuments(productImport2.getDocuments());
|
product.setExtendField(checkResultDTO2.getJson());
|
String status3 = productImport2.getStatus();
|
product.setStatus(Func.equals(status3, "停用") ? CommonConstant.DISABLE : CommonConstant.ENABLE);
|
}
|
}
|
}
|
}
|
return pts;
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public BladeFile exportProduct(String id, ProductSearchVO vo) {
|
Wrapper<ProductSearchVO> wrapper = (QueryWrapper) Wrappers.query().eq(Func.isNotEmpty(id), "bp1.id", id).nested(Func.isNotEmpty(vo), n -> {
|
n.eq(Func.isNotEmpty(vo.getTypeId()), "bp1.type_id", vo.getTypeId()).eq(Func.isNotEmpty(vo.getStandardModel()), "bp1.standard_model", vo.getStandardModel()).eq(Func.isNotEmpty(vo.getStatus()), "bp1.status", vo.getStatus()).and(Func.isNotEmpty(vo.getKeyWord()), i -> {
|
QueryWrapper queryWrapper = (QueryWrapper) ((QueryWrapper) ((QueryWrapper) i.likeRight("bp1.name", vo.getKeyWord())).or()).likeRight("bp1.code", vo.getKeyWord());
|
});
|
});
|
String filedSql = this.handlerFieldSqlParse.getExtraFiledSql(vo.getFilter(), "bp1", BusinessTypeEnums.PRODUCT.getCode());
|
List<ProductExcel> productExcels = ((ProductMapper) this.baseMapper).exportProduct(wrapper, filedSql);
|
for (ProductExcel r : productExcels) {
|
String fieldResult = this.handlerFieldSqlParse.handlerFieldQueryResult(FieldConstant.DEFAULT_PRODUCT_ID, r.getExtendField());
|
r.setExtendField(fieldResult);
|
}
|
CustomTemplate productTemplate = getProductTemplate();
|
List<CustomTemplateFieldColumnVO> columns = this.customTemplateFieldService.getColumns(productTemplate.getId(), ConfigTypeEnum.VIEW_PAGE.getCode());
|
Map<String, CustomTemplateFieldColumnVO> fieldCodeMap = (Map) columns.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getFieldCode();
|
}, item -> {
|
return item;
|
}));
|
ExcelUtils.ExcelExportDTO excelExportDTO = ExcelUtils.buildExcelExportDTO();
|
columns.forEach(item2 -> {
|
if (Func.equals(item2.getSystemField(), CommonConstant.ENABLE)) {
|
if (Func.equals(item2.getSupportExport(), CommonConstant.ENABLE)) {
|
excelExportDTO.addTableHead(item2.getFieldName(), Func.equals(item2.getMustField(), CommonConstant.ENABLE));
|
return;
|
}
|
return;
|
}
|
excelExportDTO.addTableHead(item2.getFieldName(), Func.equals(item2.getMustField(), CommonConstant.ENABLE));
|
});
|
List<ProductExcelExport> excelExports = (List) productExcels.stream().map(item3 -> {
|
ProductExcelExport productExcelExport = new ProductExcelExport();
|
productExcelExport.setParentId(item3.getParentCode());
|
productExcelExport.setCode(item3.getCode());
|
productExcelExport.setName(item3.getName());
|
productExcelExport.setTypeName(item3.getTypeName());
|
productExcelExport.setUnit(item3.getUnit());
|
productExcelExport.setStandardModel(item3.getStandardModel());
|
productExcelExport.setDescription(item3.getDescription());
|
productExcelExport.setStatus(Func.equals(CommonConstant.ENABLE, item3.getStatus()) ? "启用" : "停用");
|
productExcelExport.setExtendField(item3.getExtendField());
|
return productExcelExport;
|
}).collect(Collectors.toList());
|
Field[] fields = ProductExcelExport.class.getDeclaredFields();
|
for (ProductExcelExport export : excelExports) {
|
Map<String, String> item4 = MapUtil.newHashMap();
|
excelExportDTO.addData(item4);
|
for (Field field : fields) {
|
field.setAccessible(true);
|
try {
|
if (fieldCodeMap.containsKey(field.getName())) {
|
CustomTemplateFieldColumnVO customTemplateFieldColumnVO = fieldCodeMap.get(field.getName());
|
if (!Func.equals(customTemplateFieldColumnVO.getSystemField(), CommonConstant.ENABLE) || !Func.equals(customTemplateFieldColumnVO.getSupportExport(), CommonConstant.ENABLE)) {
|
break;
|
}
|
Object o = field.get(export);
|
if (Func.isNotEmpty(o)) {
|
item4.put(customTemplateFieldColumnVO.getFieldName(), String.valueOf(o));
|
} else {
|
item4.put(customTemplateFieldColumnVO.getFieldName(), "");
|
}
|
}
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
}
|
}
|
String extendField = export.getExtendField();
|
JSONObject jsonObject = JSONUtil.parseObj(extendField);
|
jsonObject.forEach(key, value -> {
|
if (!fieldCodeMap.containsKey(key)) {
|
return;
|
}
|
CustomTemplateFieldColumnVO customTemplateFieldColumnVO2 = (CustomTemplateFieldColumnVO) fieldCodeMap.get(key);
|
String fieldName = customTemplateFieldColumnVO2.getFieldName();
|
String v = value.toString();
|
if (JSONUtil.isJsonArray(value.toString())) {
|
List<String> vs = JSONUtil.toList(JSONUtil.parseArray(value.toString()), String.class);
|
v = StringUtil.join(vs, ",");
|
}
|
item4.put(fieldName, v);
|
});
|
}
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
Workbook workbook = ExcelUtils.generateExport(excelExportDTO);
|
try {
|
workbook.write(bos);
|
} catch (IOException e2) {
|
e2.printStackTrace();
|
}
|
InputStream is = new ByteArrayInputStream(bos.toByteArray());
|
return this.ossBuilder.systemTemplate().putFile("产品数据.xlsx", is);
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public BladeFile exportTemplateProduct() {
|
CustomTemplate customTemplate = getProductTemplate();
|
if (Func.isEmpty(customTemplate)) {
|
return new BladeFile();
|
}
|
return this.customTemplateService.getTemplate(BusinessTypeEnums.PRODUCT.getCode());
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public boolean delete(List<Long> ids) {
|
List<Product> list = list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getParentId();
|
}, ids));
|
if (Func.isNotEmpty(list)) {
|
throw new ServiceException(MessageUtils.message("cps.product.cannot.delete", new Object[0]));
|
}
|
((ProductMapper) this.baseMapper).removeBindCraft(ids);
|
return removeByIds(ids);
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public ProductVO detail(Long id) {
|
Product product = (Product) getById(id);
|
ProductVO convert = ProductConvert.INSTANCE.convert(product);
|
Long typeId = product.getTypeId();
|
ProductType productType = (ProductType) this.productTypeService.getById(typeId);
|
if (Func.isNotEmpty(productType)) {
|
convert.setTypeName(productType.getName());
|
}
|
Long parentId = product.getParentId();
|
if (Func.isNotEmpty(parentId) && parentId.longValue() != 0) {
|
Product parent = (Product) getById(parentId);
|
if (Func.isNotEmpty(parent)) {
|
convert.setParentName(parent.getName());
|
convert.setParentCode(parent.getCode());
|
convert.setParentStatus(parent.getStatus());
|
}
|
}
|
String detailResult = this.handlerFieldSqlParse.handlerFieldDetailResult(FieldConstant.DEFAULT_PRODUCT_ID, product.getExtendField());
|
convert.setExtendField(detailResult);
|
return convert;
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public void changeStatusCheck(ProductChangeStatusVO changeStatusVO) {
|
changeStatusVO.setStatus(0);
|
Integer count = this.productMapper.getParentStatusCount(changeStatusVO.getIds());
|
if (count.intValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.product.stop.children.first", new Object[0]));
|
}
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public List<ProductVO> selectList(ProductSelectVO productSelectVO) {
|
String typeId = productSelectVO.getTypeId();
|
if (Func.isNotEmpty(typeId)) {
|
long[] ids = StrUtil.splitToLong(typeId, ",");
|
List<Long> typeIds = Convert.toList(Long.class, ids);
|
productSelectVO.setTypeIds(typeIds);
|
}
|
return ((ProductMapper) this.baseMapper).selectListByParam(productSelectVO);
|
}
|
|
/* JADX WARN: Multi-variable type inference failed */
|
@Override // org.springblade.modules.cps.service.IProductService
|
public IPage<ProductEasyVO> lazyTree(Query query, String id, ProductSearchVO vo) {
|
Wrapper<Product> wrapper = (QueryWrapper) Wrappers.query().eq(Func.isNotEmpty(id), "bp1.parent_id", Long.valueOf(Func.toLong(id))).in(Func.isNotEmpty(vo.getTypeId()), "bp1.type_id", vo.getTypeId()).likeRight(Func.isNotEmpty(vo.getStandardModel()), "bp1.standard_model", vo.getStandardModel()).eq(Func.isNotEmpty(vo.getStatus()), "bp1.status", vo.getStatus()).and(Func.isNotEmpty(vo.getKeyWord()), i -> {
|
QueryWrapper queryWrapper = (QueryWrapper) ((QueryWrapper) ((QueryWrapper) i.likeRight("bp1.name", vo.getKeyWord())).or()).likeRight("bp1.code", vo.getKeyWord());
|
});
|
String filedSql = this.handlerFieldSqlParse.getExtraFiledSql(vo.getFilter(), "bp1", BusinessTypeEnums.PRODUCT.getCode());
|
IPage<ProductEasyVO> page = ((ProductMapper) this.baseMapper).lazyTree(Condition.getPage(query), wrapper, filedSql);
|
List<ProductEasyVO> records = page.getRecords();
|
Map<Long, Boolean> hasChildMap = new HashMap<>(16);
|
if (Func.isNotEmpty(records)) {
|
List<Long> ids = (List) records.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
List<ProductCountDTO> childCounts = ((ProductMapper) this.baseMapper).hasChild(ids, vo.getStatus());
|
hasChildMap = (Map) childCounts.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getProductId();
|
}, p -> {
|
return Boolean.valueOf(p.getCount().intValue() > 0);
|
}));
|
}
|
for (ProductEasyVO r : records) {
|
Boolean hasChild = hasChildMap.get(r.getId());
|
r.setHasChild(Func.isEmpty(hasChild) ? Boolean.FALSE : hasChild);
|
String fieldResult = this.handlerFieldSqlParse.handlerFieldQueryResult(FieldConstant.DEFAULT_PRODUCT_ID, r.getExtendField());
|
r.setExtendField(fieldResult);
|
}
|
page.setTotal(((ProductMapper) this.baseMapper).lazyTreeCount(wrapper, filedSql).intValue());
|
return page;
|
}
|
|
private List<ProductEasyVO> list(Query query, String id, ProductSearchVO vo) {
|
List<ProductEasyVO> easyVOS = new ArrayList<>();
|
query.setSize(-1);
|
tree(easyVOS, query, id, vo);
|
return easyVOS;
|
}
|
|
private void tree(List<ProductEasyVO> easyVOS, Query query, String id, ProductSearchVO vo) {
|
IPage<ProductEasyVO> productEasyVOIPage = lazyTree(query, id, vo);
|
List<ProductEasyVO> records = productEasyVOIPage.getRecords();
|
if (Func.isNotEmpty(records)) {
|
easyVOS.addAll(records);
|
tree(easyVOS, query, id, vo);
|
}
|
}
|
|
@Override // org.springblade.modules.cps.service.IProductService
|
public List<Product> notBandProduct(Long craftId) {
|
return ((ProductMapper) this.baseMapper).notBandProduct(craftId);
|
}
|
|
private void checkProductCodeAndName(Long id, Long typeId, String code, String name) {
|
Long count = Long.valueOf(count((Wrapper) Wrappers.lambdaQuery().ne(Func.isNotEmpty(id), (v0) -> {
|
return v0.getId();
|
}, id).eq((v0) -> {
|
return v0.getCode();
|
}, code)));
|
if (count.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.product.code.already.exists", new Object[0]));
|
}
|
Long countName = Long.valueOf(count((Wrapper) Wrappers.lambdaQuery().ne(Func.isNotEmpty(id), (v0) -> {
|
return v0.getId();
|
}, id).eq((v0) -> {
|
return v0.getName();
|
}, name)));
|
if (countName.longValue() > 0) {
|
throw new ServiceException(MessageUtils.message("cps.product.name.already.exists", new Object[0]));
|
}
|
}
|
}
|