|
|
@@ -7,14 +7,15 @@ import com.uas.platform.b2c.common.account.service.EnterpriseService;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.constant.IntegerConstant;
|
|
|
import com.uas.platform.b2c.core.constant.ShortConstant;
|
|
|
+import com.uas.platform.b2c.core.constant.SplitChar;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
|
|
|
+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.GoodsHistoryService;
|
|
|
-import com.uas.platform.b2c.prod.commodity.service.GoodsService;
|
|
|
-import com.uas.platform.b2c.prod.commodity.service.ProductService;
|
|
|
+import com.uas.platform.b2c.prod.commodity.service.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.type.ProductConstant;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
@@ -23,6 +24,9 @@ import com.uas.platform.b2c.prod.product.component.dao.ComponentSubmitDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.Component;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.ComponentSubmit;
|
|
|
import com.uas.platform.b2c.prod.product.kind.model.Kind;
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreIn;
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreStatus;
|
|
|
+import com.uas.platform.b2c.prod.store.service.StoreInService;
|
|
|
import com.uas.platform.b2c.trade.order.dao.OrderDetailDao;
|
|
|
import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
import com.uas.platform.b2c.trade.order.model.OrderDetail;
|
|
|
@@ -46,22 +50,21 @@ import com.uas.platform.core.model.Type;
|
|
|
import com.uas.platform.core.persistence.criteria.LogicalExpression;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
-import oracle.jdbc.oracore.OracleType;
|
|
|
+import org.apache.commons.beanutils.ConvertUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.jdbc.core.CallableStatementCallback;
|
|
|
-import org.springframework.jdbc.core.CallableStatementCreator;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.StatementCallback;
|
|
|
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
@@ -70,7 +73,6 @@ import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.lang.reflect.Field;
|
|
|
-import java.sql.CallableStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.sql.Statement;
|
|
|
@@ -121,6 +123,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductModifyHistoryDao productModifyHistoryDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ReleaseProductByBatchService releaseProductByBatchService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private GoodsHistoryService goodsHistoryService;
|
|
|
|
|
|
@@ -172,11 +177,25 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StoreInService storeInService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UASBatchPutOnPropertyService uasBatchPutOnPropertyService;
|
|
|
+
|
|
|
+ @Value("#{sys.productServiceIp}")
|
|
|
+ private String productServiceIp;
|
|
|
+
|
|
|
private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
|
|
|
@Override
|
|
|
public Page<V_ProductPrivate> getAllProducts(final PageInfo page, String keyword, String type) {
|
|
|
page.expression(PredicateUtils.eq("enUU", SystemSession.getUser().getEnterprise().getUu(), true));
|
|
|
+ page.expression(PredicateUtils.isNotNull("pcmpcode"));
|
|
|
+ page.expression(PredicateUtils.isNotNull("pbranden"));
|
|
|
if (StringUtils.isEmpty(type)) {
|
|
|
type = "nStandard";
|
|
|
}
|
|
|
@@ -223,7 +242,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
// 拿私有物料信息
|
|
|
- ProductPrivate productPrivate = productPrivateDao.findByPrId(product.getId());
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
if (null != productPrivate) {
|
|
|
product.setB2cEnabled(productPrivate.getB2cEnabled());
|
|
|
product.setBatchCount(productPrivate.getBatchCount());
|
|
|
@@ -349,12 +368,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
List<ProductPerson> productPersonList = productPersonDao.findByProductIdAndUserUU(id,SystemSession.getUser().getUserUU());
|
|
|
if (!CollectionUtils.isEmpty(productPersonList)) {
|
|
|
- Map<String,Object> requestMap = new HashMap<>();
|
|
|
- requestMap.put("userUU",productPersonList.get(0).getUserUU());
|
|
|
- requestMap.put("productId",productPersonList.get(0).getProductId());
|
|
|
- String res = restTemplate.postForEntity("http://192.168.253.12:24000/product/assign/delete", null, String.class, requestMap).getBody();
|
|
|
-// Long ppid = productPersonList.get(0).getId();
|
|
|
-// productPersonDao.delete(ppid);
|
|
|
+// Map<String,Object> requestMap = new HashMap<>();
|
|
|
+// requestMap.put("userUU",productPersonList.get(0).getUserUU());
|
|
|
+// requestMap.put("productId",productPersonList.get(0).getProductId());
|
|
|
+// String res = restTemplate.postForEntity( productServiceIp+"/product/assign/delete", null, String.class, requestMap).getBody();
|
|
|
+ Long ppid = productPersonList.get(0).getId();
|
|
|
+ productPersonDao.delete(ppid);
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
@@ -392,8 +411,10 @@ public class ProductServiceImpl implements ProductService {
|
|
|
//删除外键关联的匹配结果列表,不然删除product失败
|
|
|
Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
productMatchResultDao.delete(productMatchResultSet);
|
|
|
- goodsService.deleteGoods(goodses);
|
|
|
- ProductPrivate productPrivate = productPrivateDao.findByPrId(product.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(goodses)) {
|
|
|
+ goodsService.deleteGoods(goodses);
|
|
|
+ }
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
if (productPrivate == null) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
}
|
|
|
@@ -414,11 +435,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @param type 批量删除的类型
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResultMap deleteBatch(String type) {
|
|
|
+ public ResultMap deleteBatch(String type, Integer isPerson) {
|
|
|
Integer standard = null;
|
|
|
List<ProductPerson> personList = new ArrayList<>();
|
|
|
Integer fail = 0;
|
|
|
Integer success = 0;
|
|
|
+ Integer isHave = 0;
|
|
|
Long uu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
if(ProductConstant.STANDARD.equals(type)) {
|
|
|
standard = IntegerConstant.YES_SHORT;
|
|
|
@@ -428,6 +450,14 @@ public class ProductServiceImpl implements ProductService {
|
|
|
List<Product> products = productDao.findProductByEnuuAndStandard(uu, standard);
|
|
|
Set<String> uuids = new HashSet<>();
|
|
|
for (Product product : products) {
|
|
|
+ if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
+ List<ProductPerson> productPersonList = productPersonDao.findByProductIdAndUserUU(product.getId(),SystemSession.getUser().getUserUU());
|
|
|
+ if (!CollectionUtils.isEmpty(productPersonList)) {
|
|
|
+ Long ppid = productPersonList.get(0).getId();
|
|
|
+ productPersonDao.delete(ppid);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
try {
|
|
|
personList = productPersonDao.findByProductId(product.getId());
|
|
|
if (CollectionUtils.isNotEmpty(personList)) {
|
|
|
@@ -461,11 +491,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
productMatchResultDao.delete(productMatchResultSet);
|
|
|
goodsService.deleteGoods(goodses);
|
|
|
- productDao.delete(product.getId());
|
|
|
+ //productDao.delete(product.getId());
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
+ if (productPrivate.getB2cEnabled().equals(IntegerConstant.NO_SHORT)) {
|
|
|
+ fail++;
|
|
|
+ isHave++;
|
|
|
+ } else {
|
|
|
+ success++;
|
|
|
+ }
|
|
|
+ productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
+ productPrivateDao.save(productPrivate);
|
|
|
if (!StringUtils.isEmpty(product.getCmpUuId())) {
|
|
|
uuids.add(product.getCmpUuId());
|
|
|
}
|
|
|
- success++;
|
|
|
}else {
|
|
|
fail++;
|
|
|
}
|
|
|
@@ -483,7 +521,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if(success != 0) {
|
|
|
message += ",";
|
|
|
}
|
|
|
- message += "删除失败" + fail + "条,原因:该产品可能已经被其他单据引用,无法删除";
|
|
|
+ message += "删除失败" + (fail-isHave) + "条,原因:该产品可能已经被其他单据或个人物料库引用,无法删除";
|
|
|
}
|
|
|
//如果是全部都不能删除,才能设置失败的状态码
|
|
|
if((products.size() != 0) && (products.size() == fail.intValue())) {
|
|
|
@@ -707,6 +745,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResultMap matchNonStandardProduct() {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
final Long uu = SystemSession.getUser().getUserUU();
|
|
|
final Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
ProductStoreStatus status = productStoreStatusDao.findByEnuu(enUU);
|
|
|
@@ -733,16 +772,25 @@ public class ProductServiceImpl implements ProductService {
|
|
|
status = productStoreStatusDao.save(storeStatus);
|
|
|
}
|
|
|
|
|
|
-// int total = productDao.getCountByEnuuAndStatusAndEnabled(enUU, ShortConstant.NO_SHORT, IntegerConstant.YES_SHORT);
|
|
|
- int total = productDao.getCountByEnuuAndStatus(enUU, ShortConstant.NO_SHORT);
|
|
|
+ int total = productDao.getCountByEnuuAndStatusAndEnabled(enUU, ShortConstant.NO_SHORT, IntegerConstant.YES_SHORT);
|
|
|
int success = 0;
|
|
|
int fail = 0;
|
|
|
- Map<String, Long> queryMap = new HashMap<>();
|
|
|
- queryMap.put("enUU", enUU);
|
|
|
- String successUrl = "http://192.168.253.129:8099/product/match/nonProduct";
|
|
|
- String result = restTemplate.postForEntity(successUrl, queryMap, String.class).getBody();
|
|
|
- ModelMap map = FastjsonUtils.fromJson(result, ModelMap.class);
|
|
|
- fail = total - (int) map.get("success");
|
|
|
+
|
|
|
+ String sql = "/*#mycat:db_type=master*/ call PRODUCT_MATCHES_V1(%s, %s, @out); select @out";
|
|
|
+ final String formatSql = String.format(sql, enUU, uu);
|
|
|
+ success = jdbcTemplate.execute(new StatementCallback<Integer>() {
|
|
|
+ @Override
|
|
|
+ public Integer doInStatement(Statement statement) throws SQLException, DataAccessException {
|
|
|
+ statement.execute(formatSql);
|
|
|
+ ResultSet rs = statement.getResultSet();
|
|
|
+ if (null != rs) {
|
|
|
+ rs.next();
|
|
|
+ return rs.getInt(1);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ fail = total - success;
|
|
|
|
|
|
status.setStatus(Status.FINISH.value());
|
|
|
productStoreStatusDao.save(status);
|
|
|
@@ -801,10 +849,10 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (result == null) {
|
|
|
return new ResultMap(CodeType.NO_INFO, "匹配结果信息丢失");
|
|
|
}
|
|
|
- List<Product> standardList = productDao.findProductByPcmpcodeAndPbrandenAndEnUUAndStandard(result.getCmpcode(), result.getBranden(), enUU, IntegerConstant.YES_SHORT);
|
|
|
+ List<V_ProductPrivate> standardList = v_productPrivateDao.findProductByPcmpcodeAndPbrandenAndEnUUAndStandard(result.getCmpcode(), result.getBranden(), enUU, IntegerConstant.YES_SHORT, IntegerConstant.YES_SHORT);
|
|
|
Product standardProduct = null;
|
|
|
if (!CollectionUtils.isEmpty(standardList)) {
|
|
|
- standardProduct = standardList.get(0);
|
|
|
+ standardProduct = productDao.findOne(standardList.get(0).getId());
|
|
|
}
|
|
|
List<List<Goods>> repeatList = new ArrayList<>();
|
|
|
// 已有对应标准信息,需要判断在售商品是否重复
|
|
|
@@ -838,7 +886,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (standardProduct == null) {
|
|
|
standardProduct = afterProduct;
|
|
|
} else {
|
|
|
- ProductPrivate productPrivate = productPrivateDao.findByPrId(product.getId());
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
if (productPrivate == null) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
}
|
|
|
@@ -846,7 +894,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
productPrivate.setBatchCount(0);
|
|
|
productPrivateDao.save(productPrivate);
|
|
|
}
|
|
|
- restTemplate.postForEntity("http://192.168.253.129:8099/product/update", afterProduct, String.class);
|
|
|
+// restTemplate.postForEntity(productServiceIp + "/product/update", afterProduct, String.class);
|
|
|
+ productDao.save(afterProduct);
|
|
|
updateInfoAfterTurnStandard(matchId, standardProduct);
|
|
|
return ResultMap.success(null);
|
|
|
}
|
|
|
@@ -865,7 +914,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
goodsHistoryDao.save(goodsHistoryList);
|
|
|
Product beforeProduct = productDao.findOne(beforeId);
|
|
|
- ProductPrivate productPrivate = productPrivateDao.findByPrId(beforeProduct.getId());
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(beforeProduct.getId());
|
|
|
if (productPrivate == null) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
}
|
|
|
@@ -877,7 +926,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return new ResultMap(CodeType.NO_INFO, "匹配结果信息丢失");
|
|
|
}
|
|
|
Product standardProduct = updateProductAfterMatch(beforeProduct, result);
|
|
|
- restTemplate.postForEntity("http://192.168.253.129:8099/product/update", standardProduct, String.class);
|
|
|
+// restTemplate.postForEntity(productServiceIp + "/product/update", standardProduct, String.class);
|
|
|
+ productDao.save(standardProduct);
|
|
|
|
|
|
Product afterProduct = productDao.findOne(afterId);
|
|
|
updateInfoAfterTurnStandard(beforeId, afterProduct);
|
|
|
@@ -938,7 +988,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
goodsDao.save(saveList);
|
|
|
- ProductPrivate productPrivate = productPrivateDao.findByPrId(product.getId());
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
if (productPrivate == null) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
}
|
|
|
@@ -1087,7 +1137,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
product.setKinden(matchResult.getKinden());
|
|
|
product.setKindid(matchResult.getKindid());
|
|
|
List<Product> products = productDao.findProductByPcmpcodeAndPbrandenAndEnUUAndStandard(product.getPcmpcode(), product.getPbranden(), product.getEnUU(), IntegerConstant.YES_SHORT);
|
|
|
- ProductPrivate productPrivate = productPrivateDao.findByPrId(product.getId());
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
if (productPrivate == null) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
}
|
|
|
@@ -1305,12 +1355,208 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Product getProductById(Long id) {
|
|
|
- if(id == null) {
|
|
|
+ public V_ProductPrivate getProductById(Long id) {
|
|
|
+ if (id == null) {
|
|
|
return null;
|
|
|
- }else {
|
|
|
- return productDao.findOne(id);
|
|
|
+ } else {
|
|
|
+ return v_productPrivateDao.findOne(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户批量上架
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap batchPutOn(Integer standard, String ids) {
|
|
|
+ List<Long> prIdLong = null;
|
|
|
+ if (StringUtils.isEmpty(ids) && StringUtils.isEmpty(standard)) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR.code(), "没有选择需要操作的信息", null);
|
|
|
+ } else {
|
|
|
+ if (!StringUtils.isEmpty(ids)) {
|
|
|
+ Long[] idArray = (Long[]) ConvertUtils.convert(ids.split(SplitChar.COMMA), Long.class);
|
|
|
+ prIdLong = Arrays.asList(idArray);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long uu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ ResultMap registerAddress = enterpriseService.getCurrencyByRegisterAddress();
|
|
|
+ String currency = null;
|
|
|
+ List<Goods> goodsList = new ArrayList<>();
|
|
|
+ Set<String> uuids = new HashSet<>();
|
|
|
+ if (registerAddress.getCode() != CodeType.OK.code()) {
|
|
|
+ currency = StringConstant.RMB;
|
|
|
+ } else {
|
|
|
+ currency = registerAddress.getData().toString();
|
|
|
+ }
|
|
|
+ StoreIn storeIn = storeInService.findByEnUU(uu);
|
|
|
+ String storeName = null, storeid = null;
|
|
|
+ if (storeIn == null || storeIn.getStatus() != StoreStatus.OPENED) {
|
|
|
+ storeName = sysConf.getEnName();
|
|
|
+ storeid = sysConf.getStoreid();
|
|
|
+ } else {
|
|
|
+ storeName = storeIn.getStoreName();
|
|
|
+ storeid = storeIn.getUuid();
|
|
|
+ }
|
|
|
+ UASBatchPutOnProperty property = uasBatchPutOnPropertyService.get();
|
|
|
+ if (property == null) {
|
|
|
+ return new ResultMap(CodeType.NOT_COMPLETE_INFO.code(), "请先设置上架参数", null);
|
|
|
+ }
|
|
|
+ String sql = null;
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if ((prIdLong != null) && (prIdLong.size() != 0)) {
|
|
|
+ sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where ifnull(pp.pr_batchcount, 0) = 0 and p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and p.pr_id in (:ids) and p.pr_id not in (select DISTINCT go_productid from trade$goods where go_productid is not null and go_status != 612);";
|
|
|
+ map.put("ids", prIdLong);
|
|
|
+ } else {
|
|
|
+ // 暂时不会进入当前循环,速度比较低
|
|
|
+ sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where ifnull(pp.pr_batchcount, 0) = 0 and p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled,0) = 1 and if(p.pr_standard, 0) = (:standard) and p.pr_enuu = (:enuu) and p.pr_id not in (select DISTINCT go_productid from trade$goods where go_productid is not null and go_status != 612);";
|
|
|
+ map.put("enuu", uu);
|
|
|
+ map.put("standard", standard);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> longList = namedParameterJdbcTemplate.queryForList(sql, map, Long.class);
|
|
|
+ if (longList.size() == 0) {
|
|
|
+ return new ResultMap(CodeType.OK.code(), "没有可上架的信息", null);
|
|
|
+ }
|
|
|
+ List<Product> sourceAppNotPutOn = productDao.findProductInIds(longList);
|
|
|
+ List<ProductDetail> productDetails = productDetailDao.findByProductIds(longList);
|
|
|
+ for (Product product : sourceAppNotPutOn) {
|
|
|
+ for (ProductDetail detail : productDetails) {
|
|
|
+ if (product.getId().longValue() == detail.getProductId().longValue()) {
|
|
|
+ product.setProductDetail(detail);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
|
|
|
+ goodsList.addAll(goodses);
|
|
|
+ List<Goods> result = new ArrayList<Goods>();
|
|
|
+ goodsService.publishERPProductByBatch(goodsList, uuids, result);
|
|
|
+ List<Long> prids = new ArrayList<>();
|
|
|
+ for (Goods goods : result) {
|
|
|
+ prids.add(goods.getProductid());
|
|
|
+ }
|
|
|
+ List<ProductPrivate> productPrivates = productPrivateDao.findByPrIds(prids);
|
|
|
+ for (ProductPrivate productPrivate : productPrivates) {
|
|
|
+ productPrivate.setBatchCount(IntegerConstant.YES_SHORT);
|
|
|
+ }
|
|
|
+ productPrivateDao.save(productPrivates);
|
|
|
+ for (String uuid : uuids) {
|
|
|
+ goodsService.updateComponentTradeInfos(uuid);
|
|
|
+ }
|
|
|
+ String message = "";
|
|
|
+ if (result.size() != 0) {
|
|
|
+ message = "成功上架" + result.size() + "个";
|
|
|
+ }
|
|
|
+ if ((sourceAppNotPutOn.size() - result.size()) != 0) {
|
|
|
+ if (!StringUtils.isEmpty(message)) {
|
|
|
+ message = message + " ,";
|
|
|
+ }
|
|
|
+ message = "失败" + (sourceAppNotPutOn.size()- result.size()) + "个, 失败原因:产品上架必填字段为空, 请完善";
|
|
|
+ }
|
|
|
+ return new ResultMap(CodeType.OK.code(), message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品信息转 库存信息
|
|
|
+ *
|
|
|
+ * @param products 上架的产品
|
|
|
+ * @param storeName 店铺名称
|
|
|
+ * @param storeid 店铺id
|
|
|
+ * @param currency 币别信息
|
|
|
+ * @param property 批量上架的配置信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Goods> productDetailPutOn(List<Product> products, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
+ List<Goods> goodses = new ArrayList<>();
|
|
|
+ for (Product product : products) {
|
|
|
+ ResultMap resultMap = productsConvertGoods(product, storeName, storeid, currency, property);
|
|
|
+ if (resultMap.getCode() == CodeType.OK.code()) {
|
|
|
+ goodses.add((Goods) resultMap.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return goodses;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物料转 goods 信息
|
|
|
+ *
|
|
|
+ * @param product
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ResultMap productsConvertGoods(Product product, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
+ ProductDetail detail = product.getProductDetail();
|
|
|
+ Goods g = new Goods();
|
|
|
+ g.setProductid(product.getId());
|
|
|
+ g.setUnit(product.getUnit());
|
|
|
+ g.setImg(product.getCmpImg());
|
|
|
+ g.setUuid(product.getCmpUuId());
|
|
|
+ g.setCode(product.getPcmpcode());
|
|
|
+ g.setBrandNameCn(product.getPbrand() == null ? product.getPbranden() : product.getPbrand());
|
|
|
+ g.setBrandid(product.getPbrandid());
|
|
|
+ g.setBranduuid(product.getPbranduuid());
|
|
|
+ g.setBrandNameEn(product.getPbranden() == null ? product.getPbrand() : product.getPbranden());
|
|
|
+ g.setKindNameCn(product.getKind());
|
|
|
+ g.setKindUuid(product.getKindid());
|
|
|
+ g.setCurrencyName(currency);
|
|
|
+ g.setStoreName(storeName);
|
|
|
+ g.setStoreid(storeid);
|
|
|
+ g.setMaxDelivery(property.getMaxDelivery());
|
|
|
+ g.setMinDelivery(property.getMinDelivery());
|
|
|
+ g.setProdNum(product.getProdNum());
|
|
|
+ List<String> tags = goodsDao.findTagByProductid(product.getId());
|
|
|
+ Integer i = 1;
|
|
|
+ String tag = StringConstant.SELF_TAG;
|
|
|
+ while(tags.contains(tag + i)) {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ g.setTag(tag + i);
|
|
|
+ g.setBreakUp(Boolean.FALSE);
|
|
|
+ g.setReserve(product.getErpReserve());
|
|
|
+ String packaging = (detail == null || detail.getPackaging() == null) ? product.getPackaging(): detail.getPackaging();
|
|
|
+ if (packaging == null) {
|
|
|
+ packaging = StringConstant.DEFAULTPACKAGING;
|
|
|
+ }
|
|
|
+ g.setPackaging(packaging);
|
|
|
+
|
|
|
+ String produceDate = (detail == null || detail.getProduceDate() == null) ? product.getProduceDate() : detail.getProduceDate();
|
|
|
+ g.setProduceDate(produceDate);
|
|
|
+
|
|
|
+ Double minPackQty = (detail == null || detail.getMinPackQty() == null) ? product.getMinPackQty() : detail.getMinPackQty();
|
|
|
+ Double minBuyQty = detail != null ? detail.getMinBuyQty() : null;
|
|
|
+ int minPackQtyCom = NumberUtil.compare(minPackQty, DoubleConstant.zero);
|
|
|
+ int minBuyQtyCom = NumberUtil.compare(minBuyQty, DoubleConstant.zero);
|
|
|
+ if (minPackQtyCom == 0 && minBuyQtyCom == 0) {
|
|
|
+ return new ResultMap(CodeType.NOT_COMPLETE_INFO, "上架必填信息缺失");
|
|
|
+ } else {
|
|
|
+ if (minPackQtyCom == 0 || minBuyQtyCom == 0) {
|
|
|
+ minPackQty = minBuyQtyCom == 0 ? minPackQty : minBuyQty;
|
|
|
+ minBuyQty = minPackQty;
|
|
|
+ }
|
|
|
+ double remainder = minBuyQty % minPackQty;
|
|
|
+ minBuyQty = NumberUtil.sub(minBuyQty, remainder);
|
|
|
+ int k = NumberUtil.compare(minBuyQty, minPackQty);
|
|
|
+ if (k < 0) {
|
|
|
+ minBuyQty = minPackQty;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ g.setMinPackQty(minPackQty);
|
|
|
+ g.setMinBuyQty(minBuyQty);
|
|
|
+ double price = NumberUtil.mul(detail.getPrice(), property.getFluctuateRate());
|
|
|
+ price = NumberUtil.fractionNumCeil(price, IntegerConstant.PRICE_FRACTION);
|
|
|
+ List<GoodsQtyPrice> list = new ArrayList<>();
|
|
|
+ GoodsQtyPrice price1 = new GoodsQtyPrice();
|
|
|
+ price1.setStart(g.getMinBuyQty());
|
|
|
+ price1.setEnd(DoubleConstant.maxReserve);
|
|
|
+ if (currency.equals(StringConstant.RMB)) {
|
|
|
+ price1.setRMBPrice(price);
|
|
|
+ } else {
|
|
|
+ price1.setUSDPrice(price);
|
|
|
}
|
|
|
+ list.add(price1);
|
|
|
+ g.setPrices(list);
|
|
|
+ return new ResultMap(CodeType.OK.code(), "成功", g);
|
|
|
}
|
|
|
}
|
|
|
|