|
|
@@ -1,6 +1,7 @@
|
|
|
package com.uas.ps.product.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.util.StringUtil;
|
|
|
import com.uas.ps.brand.entity.BrandInfo;
|
|
|
import com.uas.ps.component.entity.ComponentInfo;
|
|
|
@@ -42,6 +43,7 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
|
|
import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
@@ -1049,39 +1051,35 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ModelMap map = new ModelMap();
|
|
|
if (CollectionUtils.isEmpty(productIds) || userUU == null) {
|
|
|
return map;
|
|
|
- } else {
|
|
|
- boolean isExist = false;
|
|
|
- ProductUsers productUsers1 = null;
|
|
|
- List<Product> products = productDao.findByIdList(productIds);
|
|
|
- List<ProductUsers> list = new ArrayList<>();
|
|
|
- List<ProductUsers> productUsers = productUsersDao.findByUseruuAndPrids(userUU, productIds);
|
|
|
- for (final Long productId : productIds) {
|
|
|
- isExist = false;
|
|
|
- for (ProductUsers productUser : productUsers) {
|
|
|
- if ((productId != null && productUser.getPrid() != null) && (productUser.getPrid().longValue() == productId.longValue())) {
|
|
|
- isExist = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isExist) {
|
|
|
- productUsers1 = new ProductUsers();
|
|
|
- productUsers1.setUseruu(userUU);
|
|
|
- for (Product product : products) {
|
|
|
- if (product.getId().equals(productId)) {
|
|
|
- productUsers1.setProduct(product);
|
|
|
- productUsers1.setEnuu(product.getEnUU());
|
|
|
- productUsers1.setPrid(productId);
|
|
|
- }
|
|
|
- }
|
|
|
- productUsers1.setDate(new Date(System.currentTimeMillis()));
|
|
|
- list.add(productUsers1);
|
|
|
- }
|
|
|
+ }
|
|
|
+ Long enuu = null;
|
|
|
+ for (Long id : productIds) {
|
|
|
+ Product product = productDao.getOne(id);
|
|
|
+ if (product != null) {
|
|
|
+ enuu = product.getEnUU();
|
|
|
+ break;
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- productUsersDao.save(list);
|
|
|
+
|
|
|
+ }
|
|
|
+ //筛选已经存在个人物料库的信息
|
|
|
+ if (!CollectionUtils.isEmpty(productIds)) {
|
|
|
+ List<Long> productIdInProductPerson = productUsersDao.findProductIdInProductUsers(productIds, userUU);
|
|
|
+ for (Long productid : productIdInProductPerson) {
|
|
|
+ productIds.remove(productid);
|
|
|
}
|
|
|
- return map;
|
|
|
}
|
|
|
+
|
|
|
+ //转成需要保存的信息
|
|
|
+ List<ProductUsers> list = new ArrayList<>();
|
|
|
+ ProductUsers productUsers = null;
|
|
|
+ for (Long prId : productIds) {
|
|
|
+ productUsers = new ProductUsers(enuu, userUU, prId);
|
|
|
+ list.add(productUsers);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ batchInsert(list);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1365,4 +1363,55 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
return infoList;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量插入个人物料信息
|
|
|
+ * @param list 需要插入的数据
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED)
|
|
|
+ @Override
|
|
|
+ public void batchInsert(final List<ProductUsers> list) {
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ String sql = "insert into product$users(pu_date, pu_enuu, pu_prid, pu_useruu) values (?, ?, ?, ?)";
|
|
|
+ try {
|
|
|
+ jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
|
|
+ @Override
|
|
|
+ public void setValues(PreparedStatement ps, int i) throws SQLException {
|
|
|
+ ps.setDate(1, new java.sql.Date(System.currentTimeMillis()));
|
|
|
+ ps.setLong(2, list.get(i).getEnuu());
|
|
|
+ ps.setLong(3, list.get(i).getPrid());
|
|
|
+ ps.setLong(4, list.get(i).getUseruu());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getBatchSize() {
|
|
|
+ return list.size();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 如果报了已经存在了这颗料,则做移除动作
|
|
|
+ String message = e.getMessage();
|
|
|
+ if (!StringUtils.isEmpty(message) && message.contains("UNIQUE_ENUU_USERUU_PRID")) {
|
|
|
+ //截取物料id
|
|
|
+ int lastH = message.lastIndexOf("-");
|
|
|
+ message = message.substring(0, lastH);
|
|
|
+ lastH = message.lastIndexOf("-");
|
|
|
+ String prid = message.substring(lastH + 1);
|
|
|
+
|
|
|
+ //移除对应物料
|
|
|
+ for (ProductUsers productPerson : list) {
|
|
|
+ if (productPerson.getPrid().longValue() == Long.valueOf(prid).longValue()) {
|
|
|
+ list.remove(productPerson);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ batchInsert(list);
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|