|
|
@@ -163,6 +163,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
List<ProductUsers> productUsers = new ArrayList<ProductUsers>();
|
|
|
List<String> alters = new ArrayList<String>();
|
|
|
List<String> existedProducts = new ArrayList<>();
|
|
|
+ List<Product> products = new ArrayList<>();
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
Long useruu = SystemSession.getUser().getUserUU();
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
@@ -175,7 +176,6 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
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);
|
|
|
@@ -247,16 +247,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
}
|
|
|
}
|
|
|
// 判断物料编号是否存在
|
|
|
- if(product.getCode() != null ) {
|
|
|
- List<Product> prods = productDao.findByEnUUAndCode(enuu, product.getCode());
|
|
|
- if(prods.size() > 0) {
|
|
|
- // 生成随机物料编码
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("mmsssss");
|
|
|
- String code = SystemSession.getUser().getEnterprise().getUu() + sdf.format(new Date());
|
|
|
- product.setCode(code);
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
+ if (product.getCode() == null) {
|
|
|
// 生成随机物料编码
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("mmsssss");
|
|
|
String code = SystemSession.getUser().getEnterprise().getUu() + sdf.format(new Date());
|
|
|
@@ -292,11 +283,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Long proId = ProductUtils.updateOne(product);
|
|
|
- prod.setDate(new Date());
|
|
|
- prod.setEnuu(enuu);
|
|
|
- prod.setPrid(proId);
|
|
|
- prod.setUseruu(useruu);
|
|
|
+ products.add(product);
|
|
|
} else {
|
|
|
// 已存在,直接更新
|
|
|
Product oldProd = prods.get(0);
|
|
|
@@ -304,16 +291,23 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
oldProd.setCmpCode(product.getCmpCode());
|
|
|
oldProd.setBrand(product.getBrand());
|
|
|
oldProd.setTitle(product.getTitle());
|
|
|
+ oldProd.setSpec(product.getSpec());
|
|
|
oldProd.setUnit(product.getUnit());
|
|
|
oldProd.setMinOrder(product.getMinOrder());
|
|
|
oldProd.setMinPack(product.getMinPack());
|
|
|
oldProd.setLeadtime(product.getLeadtime());
|
|
|
oldProd.setLtinstock(product.getLtinstock());
|
|
|
- ProductUtils.updateOne(oldProd);
|
|
|
- prod.setDate(new Date());
|
|
|
- prod.setEnuu(enuu);
|
|
|
- prod.setPrid(oldProd.getId());
|
|
|
- prod.setUseruu(useruu);
|
|
|
+ List<Role> roles = roleService.findByEnUUAndUserUU(enuu, useruu);
|
|
|
+ if(!CollectionUtils.isEmpty(roles)) {
|
|
|
+ for(Role role : roles) {
|
|
|
+ if(role.getDesc().equals("业务员") || role.getDesc().equals("销售经理")) {
|
|
|
+ oldProd.setIsSale(Constant.YES);
|
|
|
+ } else if(role.getDesc().equals("采购员")) {
|
|
|
+ oldProd.setIsPurchase(Constant.YES);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ products.add(oldProd);
|
|
|
// 如果已存在,且被禁用,修改为可用
|
|
|
List<ProductStatus> productStatuses = productStatusDao.findByPrIdAndB2bDisabled(oldProd.getId(), Constant.YES);
|
|
|
if (!CollectionUtils.isEmpty(productStatuses)) {
|
|
|
@@ -321,20 +315,35 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
status.setB2bDisabled(Constant.NO);
|
|
|
productStatusDao.save(status);
|
|
|
}
|
|
|
- existedProducts.add(prods.get(0).getCode());
|
|
|
+ existedProducts.add(product.getCode());
|
|
|
}
|
|
|
- productUsers.add(prod);
|
|
|
+// productUsers.add(prod);
|
|
|
} else {
|
|
|
alters.add(existProds.get(0).getProduct().getTitle());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
modelMap.put("total", total);
|
|
|
- if (!CollectionUtils.isEmpty(productUsers)) {
|
|
|
+ if (!CollectionUtils.isEmpty(products)) {
|
|
|
try {
|
|
|
- ProductUtils.updateProductUsersByBatch(productUsers);
|
|
|
-// productUsers = productUsersDao.save(productUsers);
|
|
|
- modelMap.put("success", productUsers.size());
|
|
|
+ List<Long> idList = ProductUtils.update(products);
|
|
|
+ if (!CollectionUtils.isEmpty(idList)) {
|
|
|
+ for (Long id: idList) {
|
|
|
+ ProductUsers prodUser = productUsersDao.findByEnuuAndUseruuAndPrid(enuu, useruu, id);
|
|
|
+ if (null == prodUser) {
|
|
|
+ ProductUsers prod = new ProductUsers();
|
|
|
+ prod.setDate(new Date());
|
|
|
+ prod.setEnuu(enuu);
|
|
|
+ prod.setPrid(id);
|
|
|
+ prod.setUseruu(useruu);
|
|
|
+ productUsers.add(prod);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(productUsers)) {
|
|
|
+ ProductUtils.updateProductUsersByBatch(productUsers);
|
|
|
+ modelMap.put("success", productUsers.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
if(alters.size() > 0)
|
|
|
modelMap.put("alters", alters);
|
|
|
if (existedProducts.size() > 0) {
|
|
|
@@ -404,7 +413,11 @@ public class ProductUsersServiceImpl implements ProductUsersService {
|
|
|
|
|
|
@Override
|
|
|
public void deleteByBatch(List<Long> idList) throws Exception {
|
|
|
- ProductUtils.deleteProductUserByBatch(idList);
|
|
|
+ try {
|
|
|
+ ProductUtils.deleteProductUserByBatch(idList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("访问接口方法异常");
|
|
|
+ }
|
|
|
// List<ProductUsers> prods = productUsersDao.findAll(idList);
|
|
|
// productUsersDao.delete(prods);
|
|
|
}
|