|
|
@@ -7,6 +7,7 @@ import com.uas.platform.b2c.advertise.ad.service.RecommendProductService;
|
|
|
import com.uas.platform.b2c.common.account.dao.UserDao;
|
|
|
import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
import com.uas.platform.b2c.common.account.service.EnterpriseService;
|
|
|
+import com.uas.platform.b2c.common.base.dao.CommonDao;
|
|
|
import com.uas.platform.b2c.common.search.rpc.service.SearchService;
|
|
|
import com.uas.platform.b2c.common.search.util.SPage;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
@@ -23,6 +24,7 @@ import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.*;
|
|
|
+import com.uas.platform.b2c.prod.commodity.type.InOutBoundType;
|
|
|
import com.uas.platform.b2c.prod.commodity.type.ProductConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
@@ -227,6 +229,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductPrivateService productPrivateService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InOutboundDetailService inOutboundDetailService;
|
|
|
+
|
|
|
private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
|
|
|
@Override
|
|
|
@@ -235,88 +243,46 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (StringUtils.isEmpty(type)) {
|
|
|
type = "nStandard";
|
|
|
}
|
|
|
-// page.expression(PredicateUtils.eq("enUU", enuu, true));
|
|
|
-// page.expression(PredicateUtils.isNotNull("pcmpcode"));
|
|
|
-// page.expression(PredicateUtils.isNotNull("pbranden"));
|
|
|
-// if (type.contains("standard")) {
|
|
|
-// SPage<Long> ids = searchService.get
|
|
|
-// } else if (type.contains("nonStandard")) {
|
|
|
-// page.filter("standard", (short)0);
|
|
|
-// page.filter("b2cEnabled", (short) 1);
|
|
|
-// } else if (type.contains("all")) {
|
|
|
-// SimpleExpression[] arr = new SimpleExpression[2];
|
|
|
-// arr[0] = PredicateUtils.eq("b2cEnabled", (short) 1, false);
|
|
|
-// arr[1] = PredicateUtils.eq("standard", (short) 1, false);
|
|
|
-// LogicalExpression logicalExpression = PredicateUtils.and(arr);
|
|
|
-// SimpleExpression standard = PredicateUtils.eq("standard", (short) 0, false);
|
|
|
-// page.orExpression(standard);
|
|
|
-// page.orExpression(logicalExpression);
|
|
|
-// page.sorting("standard", Sort.Direction.DESC);
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (StringUtils.hasText(keyword)) {
|
|
|
-// SimpleExpression code = PredicateUtils.like("prodNum", keyword, true);
|
|
|
-// SimpleExpression kind = PredicateUtils.like("kind", keyword, true);
|
|
|
-// SimpleExpression brandEn = PredicateUtils.like("pbranden", keyword, true);
|
|
|
-// SimpleExpression cmpCode = PredicateUtils.like("pcmpcode", keyword, true);
|
|
|
-// SimpleExpression[] expressions4 = new SimpleExpression[]{code, kind, brandEn, cmpCode};
|
|
|
-// LogicalExpression logicalExpression4 = PredicateUtils.or(expressions4);
|
|
|
-// page.expression(logicalExpression4);
|
|
|
-// }
|
|
|
-
|
|
|
- // TODO 搜索用户个人物料搜索暂时未实现,之后完善
|
|
|
-// if (!StringUtils.isEmpty(userUU)) {
|
|
|
-// // 先查询userUU在当前企业 有哪些物料
|
|
|
-// List<Long> ids = productPersonDao.findIdByEnuuAndUserUU(enuu, userUU);
|
|
|
-//
|
|
|
-// if (CollectionUtils.isEmpty(ids)) {
|
|
|
-// return null;
|
|
|
-// } else {
|
|
|
-// page.expression(PredicateUtils.in("id", ids, true));
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
SPage<Long> ids = searchService.getProducts(enUU, keyword, page.getPageNumber(), page.getPageSize(), type);
|
|
|
- if (null == ids) {
|
|
|
- return null;
|
|
|
+ if (ids == null || CollectionUtils.isEmpty(ids.getContent())) {
|
|
|
+ return new PageImpl<V_ProductPrivate>(new ArrayList<>(), page, 0);
|
|
|
}
|
|
|
-// Page<V_ProductPrivate> productPage = v_productPrivateDao.findAll(new Specification<V_ProductPrivate>() {
|
|
|
-// @Override
|
|
|
-// public Predicate toPredicate(Root<V_ProductPrivate> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
-// query.where(page.getPredicates(root, query, cb));
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// }, page);
|
|
|
List<Long> idList = ids.getContent();
|
|
|
List<V_ProductPrivate> productList = v_productPrivateDao.findAll(idList);
|
|
|
+ List<ProductDetail> productDetails = productDetailDao.findByProductIds(idList);
|
|
|
+ userUU = SystemSession.getUser().getUserUU();
|
|
|
+ List<ProductAttachSubmit> productAttachSubmits = productAttachService.findByProductidsAndStatus(idList, Status.UNAUDIT.value());
|
|
|
+ List<Long> productIds = productPersonDao.findIdByEnuuAndUserUU(enUU, userUU);
|
|
|
+ List<Goods> goodsList = goodsService.findByProductids(idList);
|
|
|
for (V_ProductPrivate product : productList) {
|
|
|
- product.setAddProductPerson(false);
|
|
|
- if ("ERP".equals(product.getSourceApp())) {
|
|
|
- ProductDetail productDetail = productDetailDao.findByProductId(product.getId());
|
|
|
- if (productDetail != null) {
|
|
|
+ // 设置ERP信息
|
|
|
+ for (ProductDetail productDetail : productDetails) {
|
|
|
+ if ((productDetail.getProductId() != null) && (productDetail.getProductId().longValue() == product.getId().longValue())) {
|
|
|
product.setProductDetail(productDetail);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- // 拿私有物料信息
|
|
|
- ProductPrivate productPrivate = productPrivateService.findByPrId(product.getId());
|
|
|
- if (null != productPrivate) {
|
|
|
- product.setB2cEnabled(productPrivate.getB2cEnabled());
|
|
|
- product.setBatchCount(productPrivate.getBatchCount());
|
|
|
- }
|
|
|
- }
|
|
|
- userUU = SystemSession.getUser().getUserUU();
|
|
|
- List<ProductAttachSubmit> productAttachSubmits = productAttachService.findByProductidsAndStatus(idList, Status.UNAUDIT.value());
|
|
|
- List<Long> productIds = productPersonDao.findIdByEnuuAndUserUU(enUU, userUU);
|
|
|
- for (V_ProductPrivate v_productPrivate : productList) {
|
|
|
+
|
|
|
+ // 设置是否关联到了个人
|
|
|
+ product.setAddProductPerson(false);
|
|
|
for (Long productId : productIds) {
|
|
|
- if (v_productPrivate.getId().equals(productId)) {
|
|
|
- v_productPrivate.setAddProductPerson(true);
|
|
|
+ if (product.getId().equals(productId)) {
|
|
|
+ product.setAddProductPerson(true);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 设置规格书提交的信息
|
|
|
for (ProductAttachSubmit attachSubmit : productAttachSubmits) {
|
|
|
- if ((attachSubmit.getProductId() != null) && attachSubmit.getProductId().longValue() == v_productPrivate.getId().longValue()) {
|
|
|
- v_productPrivate.setProductAttachSubmit(attachSubmit);
|
|
|
+ if (product.getId().equals(attachSubmit.getProductId())) {
|
|
|
+ product.setProductAttachSubmit(attachSubmit);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ if (product.getId().equals(goods.getProductid())) {
|
|
|
+ product.setGoods(goods);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -1930,45 +1896,38 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (id == null) {
|
|
|
return new ResultMap(CodeType.NOT_COMPLETE_INFO, "物料主键信息丢失");
|
|
|
}
|
|
|
- Product persistProduct = productDao.findOne(id);
|
|
|
- if (persistProduct == null) {
|
|
|
+ V_ProductPrivate productPrivate = v_productPrivateDao.findOne(id);
|
|
|
+ if (productPrivate == null) {
|
|
|
return new ResultMap(CodeType.NOT_EXiST, "数据库找不到对应的信息,请重新操作");
|
|
|
}
|
|
|
- List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(id);
|
|
|
- if ((CollectionUtils.isNotEmpty(productPrivates)) && productPrivates.get(0).getB2cEnabled() != IntegerConstant.YES_SHORT) {
|
|
|
+ Product persistProduct = productDao.findOne(id);
|
|
|
+ if (productPrivate.getB2cEnabled() != IntegerConstant.YES_SHORT) {
|
|
|
return new ResultMap(CodeType.NOT_PERMIT, "该物料商城未启用,不能操作");
|
|
|
}
|
|
|
- if (!StringUtilB2C.equals(persistProduct.getSpec() , product.getSpec())) {
|
|
|
- String spec = product.getSpec();
|
|
|
- ResultMap resultMap = StringUtilB2C.validateSpec(spec);
|
|
|
- if (resultMap.getCode() != CodeType.OK.code()) {
|
|
|
- return resultMap;
|
|
|
- } else {
|
|
|
- spec = (String) resultMap.getData();
|
|
|
- persistProduct.setSpec(spec);
|
|
|
- }
|
|
|
+ persistProduct.setMinPackQty(product.getMinPackQty());
|
|
|
+ persistProduct.setPackaging(product.getPackaging());
|
|
|
+ ResultMap specResultMap = StringUtilB2C.validateSpec(product.getSpec());
|
|
|
+ if (specResultMap.getCode() != CodeType.OK.code()) {
|
|
|
+ return specResultMap;
|
|
|
+ } else {
|
|
|
+ persistProduct.setSpec((String) specResultMap.getData());
|
|
|
}
|
|
|
- if (persistProduct.getStandard() == IntegerConstant.NO_SHORT) {
|
|
|
- Component component = findBybrNameAndcmpCode(persistProduct.getPbranden(), persistProduct.getPcmpcode());
|
|
|
+ if (productPrivate.getStandard() == IntegerConstant.NO_SHORT) {
|
|
|
+ Component component = findBybrNameAndcmpCode(productPrivate.getPbranden(), productPrivate.getPcmpcode());
|
|
|
if (component != null) {
|
|
|
//更新物料信息
|
|
|
updateProductByComponent(persistProduct, component);
|
|
|
- if ((!StringUtils.isEmpty(component.getAttach())) && (!StringUtils.isEmpty(attachUrl))) {
|
|
|
- return new ResultMap(CodeType.NOT_PERMIT, "该物料已匹配为标准,规格书已存在,规格书不能修改");
|
|
|
- } else {
|
|
|
- if (!StringUtils.isEmpty(attachUrl)) {
|
|
|
- productAttachService.submit(persistProduct.getId(), attachUrl);
|
|
|
- }
|
|
|
- return new ResultMap(CodeType.OK.code(), "成功");
|
|
|
+ if (!StringUtils.isEmpty(attachUrl) && StringUtils.isEmpty(component.getAttach())) {
|
|
|
+ productAttachService.submit(productPrivate.getId(), attachUrl);
|
|
|
}
|
|
|
-
|
|
|
+ return new ResultMap(CodeType.OK.code(), "成功");
|
|
|
} else {
|
|
|
//非标且找不到标准信息
|
|
|
String brand = "", code = "", kind = "";
|
|
|
if (!StringUtils.isEmpty(attachUrl)) {
|
|
|
- productAttachService.submit(persistProduct.getId(), attachUrl);
|
|
|
+ productAttachService.submit(productPrivate.getId(), attachUrl);
|
|
|
}
|
|
|
- if (!StringUtilB2C.equals(persistProduct.getPbranden() , product.getPbranden())) {
|
|
|
+ if (!StringUtilB2C.equals(productPrivate.getPbranden() , product.getPbranden())) {
|
|
|
brand = product.getPbranden();
|
|
|
ResultMap resultMap = StringUtilB2C.validateBrand(brand);
|
|
|
if (resultMap.getCode() != CodeType.OK.code()) {
|
|
|
@@ -1977,7 +1936,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
brand = (String) resultMap.getData();
|
|
|
}
|
|
|
}
|
|
|
- if (!StringUtilB2C.equals(persistProduct.getPcmpcode() , product.getPcmpcode())) {
|
|
|
+ if (!StringUtilB2C.equals(productPrivate.getPcmpcode() , product.getPcmpcode())) {
|
|
|
code = product.getPcmpcode();
|
|
|
ResultMap resultMap = StringUtilB2C.validateCmpCode(code);
|
|
|
if (resultMap.getCode() != CodeType.OK.code()) {
|
|
|
@@ -1986,23 +1945,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
code = (String) resultMap.getData();
|
|
|
}
|
|
|
}
|
|
|
- if (!StringUtilB2C.equals(persistProduct.getKind() , product.getKind())) {
|
|
|
- kind = product.getKind();
|
|
|
- ResultMap resultMap = StringUtilB2C.validateKind(kind);
|
|
|
- if (resultMap.getCode() != CodeType.OK.code()) {
|
|
|
- return resultMap;
|
|
|
- } else {
|
|
|
- kind = (String) resultMap.getData();
|
|
|
- persistProduct.setKind(kind);
|
|
|
- }
|
|
|
+ ResultMap kindResultMap = StringUtilB2C.validateKind(kind);
|
|
|
+ if (kindResultMap.getCode() != CodeType.OK.code()) {
|
|
|
+ return kindResultMap;
|
|
|
+ } else {
|
|
|
+ productPrivate.setKind((String) kindResultMap.getData());
|
|
|
}
|
|
|
//如果修改了品牌、或者型号,需要匹配看,是否为标准
|
|
|
if (!StringUtils.isEmpty(brand) || !StringUtils.isEmpty(code)) {
|
|
|
if (StringUtils.isEmpty(code)) {
|
|
|
- code = persistProduct.getPcmpcode();
|
|
|
+ code = productPrivate.getPcmpcode();
|
|
|
}
|
|
|
if (StringUtils.isEmpty(brand)) {
|
|
|
- brand = persistProduct.getPbranden();
|
|
|
+ brand = productPrivate.getPbranden();
|
|
|
}
|
|
|
List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrandenAndB2cEnabled(SystemSession.getUser().getEnterprise().getUu(), code, brand, IntegerConstant.YES_SHORT);
|
|
|
if (CollectionUtils.isNotEmpty(products)) {
|
|
|
@@ -2310,7 +2265,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public void saveByJdbcTemplate(List<ReleaseProductByBatch> list) {
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
- jdbcTemplate.batchUpdate("insert into products(pr_code,pr_cmpimg,pr_enuu,pr_brand,pr_cmpcode,pr_cmpuuid,pr_kind,pr_kindid,pr_pcmpcode,pr_pbrand,pr_pbranden,pr_pbrandid,pr_pbranduuid,pr_standard,pr_create_time,pr_spec,pr_title,pr_issale, pr_price, pr_minpack, pr_packaging) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
|
|
+ jdbcTemplate.batchUpdate("insert into products(pr_code,pr_cmpimg,pr_enuu,pr_brand,pr_cmpcode,pr_cmpuuid,pr_kind,pr_kindid,pr_pcmpcode,pr_pbrand,pr_pbranden,pr_pbrandid,pr_pbranduuid,pr_standard,pr_create_time,pr_spec,pr_title,pr_issale, pr_price, pr_minpack, pr_packaging, pr_reserve) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
|
|
list, list.size(), new ParameterizedPreparedStatementSetter<ReleaseProductByBatch>() {
|
|
|
|
|
|
@Override
|
|
|
@@ -2336,6 +2291,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ps.setObject(19, t.getCostPrice());
|
|
|
ps.setObject(20, t.getMinPackage());
|
|
|
ps.setObject(21, t.getPackaging());
|
|
|
+ ps.setObject(22, t.getReserve());
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
@@ -2350,11 +2306,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*
|
|
|
* @param reList 临时表的id
|
|
|
* @param ignoreImport 1表示忽略导入,0代表覆盖导入
|
|
|
+ * @param newInOutboundDetail 需要确定的出入库
|
|
|
+ * @param inOutMap 出入库的map
|
|
|
*/
|
|
|
@Override
|
|
|
- public void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport) {
|
|
|
+ public void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap) {
|
|
|
if (CollectionUtils.isNotEmpty(reList)) {
|
|
|
- //忽略导入
|
|
|
Set<Long> prIds = new HashSet<>();
|
|
|
for (ReleaseProductByBatch productByBatch : reList) {
|
|
|
if (productByBatch.getProductid() != null) {
|
|
|
@@ -2363,12 +2320,64 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(prIds)) {
|
|
|
List<Product> products = productDao.findAll(prIds);
|
|
|
- if (ignoreImport == IntegerConstant.YES_SHORT) {
|
|
|
- for (Product product : products) {
|
|
|
-
|
|
|
+ List<Product> freshProducts = new ArrayList<>();
|
|
|
+ InOutboundDetail detail = null;
|
|
|
+ for (Product product : products) {
|
|
|
+ for (ReleaseProductByBatch productByBatch : reList) {
|
|
|
+ if ((productByBatch.getId() != null) &&(productByBatch.getId().longValue() == product.getId().longValue()) ) {
|
|
|
+ // ignoreImport 1表示忽略导入,0代表覆盖导入
|
|
|
+ if (StringUtils.isEmpty(product.getPackaging()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
|
|
|
+ product.setPackaging(productByBatch.getPackaging());
|
|
|
+ }
|
|
|
+ if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
|
|
|
+ product.setMinPackQty(productByBatch.getMinPackage());
|
|
|
+ }
|
|
|
+ if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
|
|
|
+ product.setMinPackQty(productByBatch.getMinPackage());
|
|
|
+ }
|
|
|
+ if ((product.getKind() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
|
|
|
+ product.setKind(productByBatch.getKindName());
|
|
|
+ product.setKindid(productByBatch.getKindUuid());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(product.getSpec()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
|
|
|
+ product.setSpec(productByBatch.getSpec());
|
|
|
+ }
|
|
|
+ if ((ignoreImport == IntegerConstant.NO_SHORT) || (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) < 1)) {
|
|
|
+ Double qty = productByBatch.getReserve();
|
|
|
+ if (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) > 0) {
|
|
|
+ qty = NumberUtil.sub(qty, product.getErpReserve());
|
|
|
+ }
|
|
|
+ if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
|
|
|
+ //做出入库记录
|
|
|
+ product.setErpReserve(productByBatch.getReserve());
|
|
|
+ detail = new InOutboundDetail(product);
|
|
|
+ detail.setQty(qty);
|
|
|
+ detail.setPrice(productByBatch.getCostPrice());
|
|
|
+ newInOutboundDetail.add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ freshProducts.add(product);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ productDao.save(freshProducts);
|
|
|
+ if (CollectionUtils.isNotEmpty(newInOutboundDetail)) {
|
|
|
+ Set<InOutboundDetail> inBoundDetail = new HashSet<>();
|
|
|
+ Set<InOutboundDetail> outBoundDetail = new HashSet<>();
|
|
|
+ for (InOutboundDetail detail1 : newInOutboundDetail) {
|
|
|
+ if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) < 0) {
|
|
|
+ detail1.setQty(Math.abs(detail1.getQty()));
|
|
|
+ outBoundDetail.add(detail1);
|
|
|
+ } else if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) > 0) {
|
|
|
+ inBoundDetail.add(detail1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(inBoundDetail)) {
|
|
|
+ inOutMap.put(InOutBoundType.OTHER_INBOUND, inBoundDetail);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(outBoundDetail)) {
|
|
|
+ inOutMap.put(InOutBoundType.OTHER_OUTBOUND, outBoundDetail);
|
|
|
}
|
|
|
- } else {
|
|
|
- //覆盖导入
|
|
|
}
|
|
|
}
|
|
|
}
|