|
@@ -22,6 +22,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
@@ -32,6 +33,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -71,7 +73,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
private ExcelExportService excelExportService;
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getProductPage(Integer cateId, Integer pageIndex, Integer pageSize, String name, String code, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg getProductPage(Integer cateId, Integer pageIndex, Integer pageSize, String name, String code,Integer status, HttpServletRequest request) {
|
|
|
QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
|
|
|
if (cateId != null) {
|
|
|
queryWrapper.eq("category_id",cateId);
|
|
@@ -82,6 +84,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if (!StringUtils.isEmpty(code)) {
|
|
|
queryWrapper.like("code",code);
|
|
|
}
|
|
|
+ queryWrapper.eq("status",status);
|
|
|
User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
queryWrapper.eq("company_id",user.getCompanyId()).orderByDesc("id");
|
|
|
|
|
@@ -310,17 +313,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if(StringUtils.isEmpty(nameCell.getStringCellValue())){
|
|
|
continue;
|
|
|
}
|
|
|
- Integer count = productMapper.selectCount(new LambdaQueryWrapper<Product>()
|
|
|
+ Product selectOne = productMapper.selectOne(new LambdaQueryWrapper<Product>()
|
|
|
.eq(companyId != null, Product::getCompanyId, companyId)
|
|
|
- .eq(!StringUtils.isEmpty( nameCell.getStringCellValue()), Product::getName, nameCell.getStringCellValue())
|
|
|
+ .eq(!StringUtils.isEmpty(nameCell.getStringCellValue()), Product::getName, nameCell.getStringCellValue())
|
|
|
);
|
|
|
- if(count==0){
|
|
|
+ if(selectOne!=null){
|
|
|
product.setName(nameCell.getStringCellValue());
|
|
|
-
|
|
|
- }else{
|
|
|
- msg.setError("产品名和已存在的产品重复");
|
|
|
- return msg;
|
|
|
+ product.setId(selectOne.getId());
|
|
|
}
|
|
|
+// else{
|
|
|
+// msg.setError("产品名和已存在的产品重复");
|
|
|
+// return msg;
|
|
|
+// }
|
|
|
|
|
|
}else{
|
|
|
msg.setError("产品名称不能为空");
|
|
@@ -472,16 +476,22 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
|
|
|
//插入数据
|
|
|
- if(saveBatch(productList)) {
|
|
|
-
|
|
|
+ if(saveOrUpdateBatch(productList)) {
|
|
|
+ List<Integer> productIds = productList.stream().map(Product::getId).distinct().collect(Collectors.toList());
|
|
|
+ List<ProdProcedure> prodProcedures = prodProcedureMapper.selectList(new LambdaQueryWrapper<ProdProcedure>().in(ProdProcedure::getProductId, productIds));
|
|
|
for (Product product : productList) {
|
|
|
- prodProcedureList.stream()
|
|
|
- .filter(prodProcedure -> prodProcedure.getProductName().equals(product.getName()))
|
|
|
- .forEach(prodProcedure ->{
|
|
|
- prodProcedure.setProductId(product.getId());
|
|
|
- prodProcedure.setCompanyId(companyId);
|
|
|
-
|
|
|
- } );
|
|
|
+ List<ProdProcedure> procedureList = prodProcedures.stream().filter(p -> p.getProductId().equals(product.getId())).collect(Collectors.toList());
|
|
|
+ //找到当前产品下的工序版本号集合
|
|
|
+ List<String> versionNumberList = procedureList.stream().map(ProdProcedure::getVersionNumber).distinct().collect(Collectors.toList());
|
|
|
+ List<ProdProcedure> procedures = prodProcedureList.stream()
|
|
|
+ .filter(prodProcedure -> prodProcedure.getProductName().equals(product.getName())).collect(Collectors.toList());
|
|
|
+ for (ProdProcedure prodProcedure : procedures) {
|
|
|
+ if(versionNumberList.contains(prodProcedure.getVersionNumber())){
|
|
|
+ throw new Exception("产品["+product.getName()+"]下工序["+prodProcedure.getName()+"]版本号["+prodProcedure.getVersionNumber()+"]已存在");
|
|
|
+ }
|
|
|
+ prodProcedure.setProductId(product.getId());
|
|
|
+ prodProcedure.setCompanyId(companyId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
prodProcedureService.saveBatch(prodProcedureList);
|