|
|
@@ -12,11 +12,9 @@ import com.uas.ps.core.page.criteria.SimpleExpression;
|
|
|
import com.uas.ps.core.util.StringUtils;
|
|
|
import com.uas.ps.entity.*;
|
|
|
import com.uas.ps.product.ProductConstant;
|
|
|
+import com.uas.ps.product.dao.ProductPrivateViewDao;
|
|
|
import com.uas.ps.product.data.MyJdbcTemplate;
|
|
|
-import com.uas.ps.product.entity.Constant;
|
|
|
-import com.uas.ps.product.entity.Prod;
|
|
|
-import com.uas.ps.product.entity.ProductReplace;
|
|
|
-import com.uas.ps.product.entity.ProductSaler;
|
|
|
+import com.uas.ps.product.entity.*;
|
|
|
import com.uas.ps.product.repository.*;
|
|
|
import com.uas.ps.product.service.ProductService;
|
|
|
import com.uas.ps.product.sync.WaitSyncHelper;
|
|
|
@@ -26,6 +24,7 @@ import com.uas.ps.support.ResultMap;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.log4j.Logger;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -73,9 +72,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private MyJdbcTemplate jdbcTemplate;
|
|
|
|
|
|
- @Autowired
|
|
|
- private WaitSyncHelper waitSyncHelper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ProductPrivateDao productPrivateDao;
|
|
|
|
|
|
@@ -85,6 +81,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private SyncMessageDao syncMessageDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductPrivateViewDao privateViewDao;
|
|
|
+
|
|
|
/**
|
|
|
* B2C物料可用属性
|
|
|
*/
|
|
|
@@ -740,7 +739,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @param data 物料资料
|
|
|
* @return 保存之后的idList
|
|
|
*/
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = SQLException.class)
|
|
|
@Override
|
|
|
public List<Long> update(List<Product> data) {
|
|
|
List<Product> newList = new ArrayList<>();
|
|
|
@@ -780,7 +779,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public void updateExisted(List<Product> updateList) {
|
|
|
jdbcTemplate.batchUpdate("update products set pr_enuu=?,pr_useruu=?,pr_code=?,pr_title=?,pr_spec=?,pr_cmpcode=?,pr_brand=?," +
|
|
|
- "pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=?,pr_pcmpcode=?,pr_pbranden=? " +
|
|
|
+ "pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=?,pr_pcmpcode=?,pr_pbranden=?,pr_kind=? " +
|
|
|
"where pr_id=?",
|
|
|
updateList, updateList.size(), new ParameterizedPreparedStatementSetter<Product>() {
|
|
|
@Override
|
|
|
@@ -802,7 +801,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ps.setObject(15, product.getSourceApp());
|
|
|
ps.setObject(16, product.getCmpCode());
|
|
|
ps.setObject(17, product.getBrand());
|
|
|
- ps.setLong(18, product.getId());
|
|
|
+ ps.setObject(18, product.getKind());
|
|
|
+ ps.setLong(19, product.getId());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -815,9 +815,10 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public List<Long> insertAndReturnKey(final List<Product> newList) {
|
|
|
return jdbcTemplate.batchInsert("insert into products(pr_enuu,pr_useruu,pr_code,pr_title,pr_spec,pr_cmpcode,pr_brand," +
|
|
|
- "pr_unit,pr_minorder,pr_minpack,pr_leadtime,pr_ltinstock,pr_issale,pr_ispurchase,pr_sourceapp,pr_pcmpcode,pr_pbranden) " +
|
|
|
- "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) on duplicate key update pr_useruu=?,pr_title=?,pr_spec=?,pr_cmpcode=?,pr_brand=?," +
|
|
|
- "pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=?,pr_pcmpcode=?,pr_pbranden=?", new BatchPreparedStatementSetter() {
|
|
|
+ "pr_unit,pr_minorder,pr_minpack,pr_leadtime,pr_ltinstock,pr_issale,pr_ispurchase,pr_sourceapp,pr_pcmpcode,pr_pbranden,pr_kind) " +
|
|
|
+ "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) on duplicate key update pr_useruu=?,pr_title=?,pr_spec=?,pr_cmpcode=?,pr_brand=?," +
|
|
|
+ "pr_unit=?,pr_minorder=?,pr_minpack=?,pr_leadtime=?,pr_ltinstock=?,pr_issale=?,pr_ispurchase=?,pr_sourceapp=?,pr_pcmpcode=?," +
|
|
|
+ "pr_pbranden=?,pr_kind=?", new BatchPreparedStatementSetter() {
|
|
|
@Override
|
|
|
public void setValues(PreparedStatement ps, int i) throws SQLException {
|
|
|
Product product = newList.get(i);
|
|
|
@@ -838,22 +839,26 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ps.setObject(15, product.getSourceApp());
|
|
|
ps.setObject(16, product.getCmpCode());
|
|
|
ps.setObject(17, product.getBrand());
|
|
|
+ // 这里将导入的title信息赋值给kind
|
|
|
+ ps.setObject(18, product.getTitle());
|
|
|
+
|
|
|
+ ps.setLong(19, product.getUserUU());
|
|
|
+ ps.setObject(20, product.getTitle());
|
|
|
+ ps.setObject(21, product.getSpec());
|
|
|
+ ps.setObject(22, product.getCmpCode());
|
|
|
+ ps.setObject(23, product.getBrand());
|
|
|
+ ps.setObject(24, product.getUnit());
|
|
|
+ ps.setObject(25, product.getMinOrder());
|
|
|
+ ps.setObject(26, product.getMinPack());
|
|
|
+ ps.setObject(27, product.getLeadTime());
|
|
|
+ ps.setObject(28, product.getLtinstock());
|
|
|
+ ps.setObject(29, product.getIsSale());
|
|
|
+ ps.setObject(30, product.getIsPurchase());
|
|
|
+ ps.setObject(31, product.getSourceApp());
|
|
|
+ ps.setObject(32, product.getCmpCode());
|
|
|
+ ps.setObject(33, product.getBrand());
|
|
|
+ ps.setObject(34, product.getTitle());
|
|
|
|
|
|
- ps.setLong(18, product.getUserUU());
|
|
|
- ps.setObject(19, product.getTitle());
|
|
|
- ps.setObject(20, product.getSpec());
|
|
|
- ps.setObject(21, product.getCmpCode());
|
|
|
- ps.setObject(22, product.getBrand());
|
|
|
- ps.setObject(23, product.getUnit());
|
|
|
- ps.setObject(24, product.getMinOrder());
|
|
|
- ps.setObject(25, product.getMinPack());
|
|
|
- ps.setObject(26, product.getLeadTime());
|
|
|
- ps.setObject(27, product.getLtinstock());
|
|
|
- ps.setObject(28, product.getIsSale());
|
|
|
- ps.setObject(29, product.getIsPurchase());
|
|
|
- ps.setObject(30, product.getSourceApp());
|
|
|
- ps.setObject(31, product.getCmpCode());
|
|
|
- ps.setObject(32, product.getBrand());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -867,7 +872,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* 更新个人产品库
|
|
|
* @param products 物料信息
|
|
|
*/
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = SQLException.class)
|
|
|
@Override
|
|
|
public int updateProductUser(List<Product> products) {
|
|
|
final Date now = new Date();
|
|
|
@@ -1077,8 +1082,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
info.setPrid(product.getId());
|
|
|
info.setUseruu(productSaler.getEm_uu());
|
|
|
info.setErpid(productSaler.getPs_id());
|
|
|
- info = productUsersDao.save(info);
|
|
|
-// erpLogger.log("ERP个人物料信息同步", "关联物料id:" + info.getPrid(), 1);
|
|
|
+ productUsersDao.save(info);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1098,7 +1102,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
List<ProductUsers> prods = productUsersDao.findByEnuuAndUseruuAndErpid(productSaler.getEn_uu(), productSaler.getEm_uu(), productSaler.getPs_id());
|
|
|
if (!CollectionUtils.isEmpty(prods)) {
|
|
|
deleteList.addAll(prods);
|
|
|
-// erpLogger.log("ERP删除个人物料信息同步", "关联物料id: " + prod.getPrid(), 1);
|
|
|
}
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(deleteList)) {
|
|
|
@@ -1142,7 +1145,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @return 物料page
|
|
|
*/
|
|
|
@Override
|
|
|
- public Page<Product> findByPageInfo(final PageInfo pageInfo, String keyword) {
|
|
|
+ public Page<ProductPrivateView> findByPageInfo(final PageInfo pageInfo, String keyword) {
|
|
|
if (null == pageInfo) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -1150,18 +1153,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
|
|
pageInfo.setSort(sort);
|
|
|
}
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- SimpleExpression pBrandEn = new SimpleExpression("pBrandEn", keyword, CriterionExpression.Operator.LIKE);
|
|
|
- SimpleExpression title = new SimpleExpression("title", keyword, CriterionExpression.Operator.LIKE);
|
|
|
- SimpleExpression pCmpCode = new SimpleExpression("pCmpCode", keyword, CriterionExpression.Operator.LIKE);
|
|
|
- SimpleExpression spec = new SimpleExpression("spec", keyword, CriterionExpression.Operator.LIKE);
|
|
|
- SimpleExpression[] simpleExpressions = new SimpleExpression[]{pBrandEn, title, pCmpCode, spec};
|
|
|
- LogicalExpression logicalExpression = PredicateUtils.or(simpleExpressions);
|
|
|
- pageInfo.expression(logicalExpression);
|
|
|
- }
|
|
|
- return productDao.findAll(new Specification<Product>() {
|
|
|
+ return privateViewDao.findAll(new Specification<ProductPrivateView>() {
|
|
|
@Override
|
|
|
- public Predicate toPredicate(Root<Product> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ public Predicate toPredicate(Root<ProductPrivateView> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
query.where(pageInfo.getPredicates(root, query, cb));
|
|
|
return null;
|
|
|
}
|
|
|
@@ -1216,8 +1210,85 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
public int ordinalIndexOf(String str, String substr, int start, int n) {
|
|
|
int pos = str.indexOf(substr, start);
|
|
|
- while (--n > 0 && pos != -1)
|
|
|
+ while (--n > 0 && pos != -1) {
|
|
|
pos = str.indexOf(substr, pos + 1);
|
|
|
+ }
|
|
|
return pos;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量校验导入物料信息
|
|
|
+ *
|
|
|
+ * @param products 物料
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> checkImportProductList(List<ProductInfo> products) {
|
|
|
+ int success = 0;
|
|
|
+ for (ProductInfo productInfo : products) {
|
|
|
+ if (null != productInfo.getCode()) {
|
|
|
+ List<Long> idList = productDao.findIdByEnUUAndCode(productInfo.getEnUU(), productInfo.getCode());
|
|
|
+ if (!CollectionUtils.isEmpty(idList)) {
|
|
|
+ productInfo.setId(idList.get(0));
|
|
|
+ success++;
|
|
|
+ } else {
|
|
|
+ List<Product> productList = new ArrayList<>();
|
|
|
+ Product product = new Product();
|
|
|
+ BeanUtils.copyProperties(productInfo, product, Product.class);
|
|
|
+ productList.add(product);
|
|
|
+ productList = updateB2bProdInfo(productList);
|
|
|
+ productInfo.setId(productList.get(0).getId());
|
|
|
+ success++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ PageInfo pageInfo = new PageInfo(1, 1);
|
|
|
+ List<Object[]> objects = productDao.findIdAndCodeByEnUUAndTitle(productInfo.getEnUU(), productInfo.getTitle(), pageInfo);
|
|
|
+ if (!CollectionUtils.isEmpty(objects)) {
|
|
|
+ Object[] object = objects.get(0);
|
|
|
+ productInfo.setId(Long.valueOf(object[0].toString()));
|
|
|
+ productInfo.setCode(object[1].toString());
|
|
|
+ success++;
|
|
|
+ } else {
|
|
|
+ //生成随机编码
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yymmddhhmm_sss");
|
|
|
+ productInfo.setCode("prod" + sdf.format(new Date()));
|
|
|
+ List<Product> productList = new ArrayList<>();
|
|
|
+ Product product = new Product();
|
|
|
+ BeanUtils.copyProperties(productInfo, product, Product.class);
|
|
|
+ productList.add(product);
|
|
|
+ productList = updateB2bProdInfo(productList);
|
|
|
+ productInfo.setCode(productList.get(0).getCode());
|
|
|
+ productInfo.setId(productList.get(0).getId());
|
|
|
+ success++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashedMap();
|
|
|
+ map.put("products", products);
|
|
|
+ map.put("success", success);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据传入的企业UU信息获取物料数量和最近一次上传时间
|
|
|
+ *
|
|
|
+ * @param enUUList 企业UU信息
|
|
|
+ * @return InviteProdInfo List
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<InviteProdInfo> getCountAndTime(List<Long> enUUList) {
|
|
|
+ List<InviteProdInfo> infoList = new ArrayList<>();
|
|
|
+ for (Long enUU : enUUList) {
|
|
|
+ InviteProdInfo info = new InviteProdInfo();
|
|
|
+ info.setEnUU(enUU);
|
|
|
+ Long count = countByEnUU(enUU);
|
|
|
+ info.setCount(count);
|
|
|
+ if (count > 0) {
|
|
|
+ Date date = jdbcTemplate.queryForObject("select max(pr_erpdate) from products where pr_enuu = " + enUU, Date.class);
|
|
|
+ info.setLastDate(date);
|
|
|
+ }
|
|
|
+ infoList.add(info);
|
|
|
+ }
|
|
|
+ return infoList;
|
|
|
+ }
|
|
|
}
|