|
|
@@ -7,14 +7,11 @@ import com.uas.ps.core.util.CollectionUtils;
|
|
|
import com.uas.ps.entity.Product;
|
|
|
import com.uas.ps.entity.ProductUsers;
|
|
|
import com.uas.ps.product.entity.Constant;
|
|
|
+import com.uas.ps.product.entity.ProductSaler;
|
|
|
import com.uas.ps.product.repository.ProductDao;
|
|
|
import com.uas.ps.product.repository.ProductUsersDao;
|
|
|
import com.uas.ps.product.service.ProductUsersService;
|
|
|
import com.uas.ps.product.util.ThreadUtils;
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -48,7 +45,15 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void save(List<ProductUsers> productUsers) {
|
|
|
- productUsersDao.save(productUsers);
|
|
|
+ List<ProductUsers> saveList = new ArrayList<>();
|
|
|
+ for (ProductUsers prodUsers : productUsers) {
|
|
|
+ ProductUsers existedProductUser = productUsersDao.findByEnuuAndUseruuAndErpid(prodUsers.getEnuu(), prodUsers.getUseruu(), prodUsers.getPrid());
|
|
|
+ if (null == existedProductUser) {
|
|
|
+ prodUsers.setDate(new Date());
|
|
|
+ saveList.add(prodUsers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ productUsersDao.save(saveList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -122,169 +127,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ModelMap releaseByWorkbook(Workbook workbook, Long enUU, Long userUU) {
|
|
|
- ModelMap modelMap = new ModelMap();
|
|
|
- List<ProductUsers> productUsers = new ArrayList<>();
|
|
|
- List<String> alters = new ArrayList<>();
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- int rowNum = sheet.getLastRowNum();
|
|
|
- Row headerRow = sheet.getRow(0);
|
|
|
- int total = 0;
|
|
|
- if (headerRow != null) {
|
|
|
- for (int r = 3; r <= rowNum; r++) {
|
|
|
- Row row = sheet.getRow(r);
|
|
|
- if (row != null && row.getCell(0) != null && row.getCell(0).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
- total++;
|
|
|
- Product product = new Product();
|
|
|
- ProductUsers prod = new ProductUsers();
|
|
|
- // 物料编号
|
|
|
- if (row.getCell(0) != null) {
|
|
|
- row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setCode(row.getCell(0).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 物料名称
|
|
|
- if (row.getCell(1) != null) {
|
|
|
- row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setTitle(row.getCell(1).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 原厂型号
|
|
|
- if (row.getCell(2) != null) {
|
|
|
- row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setCmpCode(row.getCell(2).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 品牌
|
|
|
- if (row.getCell(3) != null) {
|
|
|
- row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setBrand(row.getCell(3).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 单位
|
|
|
- if (row.getCell(4) != null) {
|
|
|
- row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- product.setUnit(row.getCell(4).getStringCellValue().trim());
|
|
|
- }
|
|
|
-
|
|
|
- // 最小包装量
|
|
|
- if (row.getCell(5) != null) {
|
|
|
- row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(5).getStringCellValue()
|
|
|
- && !row.getCell(5).getStringCellValue().trim().equals("")) {
|
|
|
- product.setMinPack(Double.valueOf(row.getCell(5).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 最小订购量
|
|
|
- if (row.getCell(6) != null) {
|
|
|
- row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(6).getStringCellValue().trim()
|
|
|
- && !row.getCell(6).getStringCellValue().trim().equals("")) {
|
|
|
- product.setMinOrder(Double.valueOf(row.getCell(6).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 交货周期
|
|
|
- if (row.getCell(7) != null) {
|
|
|
- row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(7).getStringCellValue().trim()
|
|
|
- && !row.getCell(7).getStringCellValue().trim().equals("")) {
|
|
|
- product.setLeadTime(Double.valueOf(row.getCell(7).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 交货提前期
|
|
|
- if (row.getCell(8) != null) {
|
|
|
- row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
|
|
|
- if (null != row.getCell(8).getStringCellValue().trim()
|
|
|
- && !row.getCell(8).getStringCellValue().trim().equals("")) {
|
|
|
- product.setLtinstock(Double.valueOf(row.getCell(8).getStringCellValue()));
|
|
|
- }
|
|
|
- }
|
|
|
- // 判断物料编号是否存在
|
|
|
- if(product.getCode() != null ) {
|
|
|
- List<Product> prods = productDao.findByEnUUAndCode(enUU, product.getCode());
|
|
|
- if(prods.size() > 0) {
|
|
|
- // 生成随机物料编码
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("mmsssss");
|
|
|
- String code = enUU + sdf.format(new Date());
|
|
|
- product.setCode(code);
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- // 生成随机物料编码
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("mmsssss");
|
|
|
- String code = enUU + sdf.format(new Date());
|
|
|
- product.setCode(code);
|
|
|
- }
|
|
|
- List<ProductUsers> existProds = productUsersDao.findByEnuuAndUseruuAndTitleAndCmpCodeAndBrand
|
|
|
- (enUU, userUU, product.getTitle(), product.getCmpCode(), product.getBrand());
|
|
|
- if(CollectionUtils.isEmpty(existProds)) {
|
|
|
- List<Product> prods = productDao.findByTitleAndCmpCodeAndBrandAndEnUU(
|
|
|
- product.getTitle(), product.getCmpCode(), product.getBrand(), enUU);
|
|
|
- if(CollectionUtils.isEmpty(prods)) {// 如果非标不存在再查询标准
|
|
|
- prods = productDao.findByTitleAndPCmpCodeAndPBrandAndEnUU(product.getTitle(), product.getCmpCode(), product.getBrand(), enUU);
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(prods)) {
|
|
|
- // 如果物料不存在,先生成物料信息
|
|
|
- product.setEnUU(enUU);
|
|
|
- product.setUserUU(userUU);
|
|
|
- product.setSourceApp("B2B");
|
|
|
- product.setIsPubsale(Constant.NO);
|
|
|
- product.setIsShow(Constant.NO);
|
|
|
- product.setStandard(Constant.NO);
|
|
|
- product.setErpDate(new Date());
|
|
|
-// List<Role> roles = roleService.findByEnUUAndUserUU(enuu, useruu);
|
|
|
-// if(!CollectionUtils.isEmpty(roles)) {
|
|
|
-// for(Role role : roles) {
|
|
|
-// if(role.getDesc().equals("业务员") || role.getDesc().equals("销售经理")) {
|
|
|
-// product.setIsSale(Constant.YES);
|
|
|
-// } else if(role.getDesc().equals("采购员")) {
|
|
|
-// product.setIsPurchase(Constant.YES);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- product = productDao.save(product);
|
|
|
- prod.setDate(new Date());
|
|
|
- prod.setEnuu(enUU);
|
|
|
- prod.setPrid(product.getId());
|
|
|
- prod.setUseruu(userUU);
|
|
|
- } else {
|
|
|
- Product oldProd = prods.get(0);
|
|
|
- prod.setDate(new Date());
|
|
|
- prod.setEnuu(enUU);
|
|
|
- prod.setPrid(oldProd.getId());
|
|
|
- prod.setUseruu(userUU);
|
|
|
- }
|
|
|
- productUsers.add(prod);
|
|
|
- } else {
|
|
|
- alters.add(existProds.get(0).getProduct().getTitle());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- modelMap.put("total", total);
|
|
|
- if (!CollectionUtils.isEmpty(productUsers)) {
|
|
|
- try {
|
|
|
- productUsers = productUsersDao.save(productUsers);
|
|
|
- modelMap.put("success", productUsers.size());
|
|
|
- if(alters.size() > 0)
|
|
|
- modelMap.put("alters", alters);
|
|
|
- } catch (Exception e) {
|
|
|
- modelMap.put("error", "物料添加失败");
|
|
|
- }
|
|
|
- } else {
|
|
|
- modelMap.put("success", 0);
|
|
|
- if(alters.size() > 0)
|
|
|
- modelMap.put("alters", alters);
|
|
|
- }
|
|
|
- }
|
|
|
- return modelMap;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ModelMap coverToUserProdByIds(String ids, Long userUU, Long enUU) {
|
|
|
- ids = ids.replace("["," ");
|
|
|
- ids = ids.replace("]"," ");
|
|
|
-// Integer count = productUsersDao.coverToUserProdByIds(ids, userUU, enUU);
|
|
|
- // 存储过程改为代码实现
|
|
|
+ public Integer coverToUserProdByIds(String ids, Long userUU, Long enUU) {
|
|
|
List<Long> prIds = JSON.parseArray(ids, Long.class);
|
|
|
// 保存的个人产品
|
|
|
List<ProductUsers> productUsersList = new ArrayList<>();
|
|
|
@@ -298,7 +141,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
}
|
|
|
productUsersList = productUsersDao.save(productUsersList);
|
|
|
// logger.log("我的产品库", "新增了我产品信息", "size:" + count);
|
|
|
- return new ModelMap("count", productUsersList.size());
|
|
|
+ return productUsersList.size();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -376,4 +219,24 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ERP productSaler 实体转换成 productUsers 实体
|
|
|
+ *
|
|
|
+ * @param productSalers productUsers List
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ProductUsers> convertProductUsers(List<ProductSaler> productSalers) {
|
|
|
+ List<ProductUsers> productUsersList = new ArrayList<>();
|
|
|
+ for (ProductSaler productSaler : productSalers) {
|
|
|
+ List<Product> products = productDao.findByEnUUAndCode(productSaler.getEn_uu(), productSaler.getPs_code());
|
|
|
+ if (!CollectionUtils.isEmpty(products)) {
|
|
|
+ ProductUsers productUsers = productSaler.convert();
|
|
|
+ productUsers.setPrid(products.get(0).getId());
|
|
|
+ productUsersList.add(productUsers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return productUsersList;
|
|
|
+ }
|
|
|
}
|