GoodsServiceImpl.java 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140
  1. package com.kmall.admin.service.impl;
  2. import cn.hutool.http.HttpUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.google.common.collect.ImmutableBiMap;
  5. import com.google.common.collect.Lists;
  6. import com.google.common.collect.Maps;
  7. import com.kmall.admin.dao.*;
  8. import com.kmall.admin.dto.GoodsDetailsDto;
  9. import com.kmall.admin.dto.GoodsDto;
  10. import com.kmall.admin.dto.GoodsPanoramaDto;
  11. import com.kmall.admin.entity.*;
  12. import com.kmall.admin.entity.kmall2eccs.KtoEccsEntity;
  13. import com.kmall.admin.entity.mk.MkActivitiesEntity;
  14. import com.kmall.admin.entity.shop.ShopErrorPriceRecordEntity;
  15. import com.kmall.admin.haikong.client.HaiKongWarehouseTemplate;
  16. import com.kmall.admin.haikong.config.HaiKongProperties;
  17. import com.kmall.admin.haikong.constant.Constants;
  18. import com.kmall.admin.haikong.dto.Criteria;
  19. import com.kmall.admin.haikong.dto.WareQueryStockParamDTO;
  20. import com.kmall.admin.haikong.dto.WareQueryStockResponseDTO;
  21. import com.kmall.admin.haikong.utils.XmlUtils;
  22. import com.kmall.admin.haikong.vo.QueryGoodsVO;
  23. import com.kmall.admin.service.*;
  24. import com.kmall.admin.service.kmall2eccs.KtoEccsService;
  25. import com.kmall.admin.service.mk.MkActivitiesService;
  26. import com.kmall.admin.service.mk.MkActivityFormService;
  27. import com.kmall.admin.service.GoodsService;
  28. import com.kmall.admin.service.shop.ShopErrorPriceRecordService;
  29. import com.kmall.admin.utils.CalculateTax;
  30. import com.kmall.admin.utils.GoodsUtils;
  31. import com.kmall.admin.utils.ShiroUtils;
  32. import com.kmall.admin.utils.jackson.JacksonUtil;
  33. import com.kmall.api.entity.exportpdf.PDFGoodsDto;
  34. import com.kmall.common.constant.Dict;
  35. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  36. import com.kmall.common.utils.*;
  37. import com.kmall.manager.manager.express.sf.ServiceException;
  38. import com.kmall.manager.manager.express.sf.XmlUtil;
  39. import com.kmall.manager.manager.redis.JedisCacheManager;
  40. import com.kmall.manager.manager.redis.JedisUtil;
  41. import org.slf4j.Logger;
  42. import org.slf4j.LoggerFactory;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.springframework.core.env.Environment;
  45. import org.springframework.stereotype.Service;
  46. import org.springframework.transaction.annotation.Transactional;
  47. import org.springframework.util.CollectionUtils;
  48. import java.math.BigDecimal;
  49. import java.math.RoundingMode;
  50. import java.text.SimpleDateFormat;
  51. import java.util.*;
  52. import java.util.stream.Collectors;
  53. /**
  54. * Service实现类
  55. *
  56. * @author Scott
  57. * @email
  58. * @date 2017-08-21 21:19:49
  59. */
  60. @Service("goodsService")
  61. public class GoodsServiceImpl implements GoodsService {
  62. private static final Logger log = LoggerFactory.getLogger(GoodsServiceImpl.class);
  63. @Autowired
  64. private MerchDao merchDao;
  65. @Autowired
  66. private GoodsDao goodsDao;
  67. @Autowired
  68. private ProductDao productDao;
  69. @Autowired
  70. private GoodsGalleryDao goodsGalleryDao;
  71. @Autowired
  72. private GoodsSpecificationDao goodsSpecificationDao;
  73. @Autowired
  74. private ProductStoreRelaDao productStoreRelaDao;
  75. @Autowired
  76. private StoreDao storeDao;
  77. @Autowired
  78. private GoodsGroupDao goodsGroupDao;
  79. @Autowired
  80. private CategoryDao categoryDao;
  81. @Autowired
  82. private SupplierDao supplierDao;
  83. @Autowired
  84. private SysCusNationCodeDao sysCusNationCodeDao;
  85. @Autowired
  86. private SysCusUnitCodeDao sysCusUnitCodeDao;
  87. @Autowired
  88. private ExportExceptionDataDao exportExceptionDataDao;
  89. @Autowired
  90. private CartDao cartDao;
  91. @Autowired
  92. private ThirdMerchantBizDao thirdMerchantBizDao;
  93. @Autowired
  94. private MngChangeDao mngChangeDao;
  95. @Autowired
  96. private MerchUserDao merchUserDao;
  97. @Autowired
  98. private StoreMngChangeDao storeMngChangeDao;
  99. @Autowired
  100. private GoodsUtils goodsUtils;
  101. @Autowired
  102. private TaxErrorRecordDao taxErrorRecordDao;
  103. @Autowired
  104. private MkActivityFormService mkActivityFormService; // 活动表
  105. @Autowired
  106. private MkActivitiesService mkActivitiesService; // 营销方式表
  107. @Autowired
  108. private MkDailyActivitiesService dailyActivitiesService; // 日常活动
  109. @Autowired
  110. private MkActivitiesCouponService couponService; // 优惠券
  111. @Autowired
  112. private MkActivitiesCombinationPriceService combinationPriceService; // 组合价
  113. @Autowired
  114. private MkActivitiesDiscountService discountService; // 折扣
  115. @Autowired
  116. private MkActivitiesFullGiftService fullGiftService; // 满赠
  117. @Autowired
  118. private MkActivitiesFullReductionService fullReductionService; // 满减
  119. @Autowired
  120. private MkActivitiesGetOneFreeGoodsService getOneFreeGoodsService; // 买一送一
  121. @Autowired
  122. private MkActivitiesPromotionService promotionService; // 临时促销
  123. @Autowired
  124. private MkActivitiesHalfPriceService halfPriceService; // 第二份半价
  125. @Autowired
  126. private BrandService brandService;
  127. @Autowired
  128. private ShopErrorPriceRecordService shopErrorPriceRecordService;
  129. @Autowired
  130. private KtoEccsService ktoEccsService;
  131. @Autowired
  132. private HaiKongWarehouseTemplate haiKongWarehouseTemplate;
  133. @Autowired
  134. private HaiKongProperties haiKongProperties;
  135. @Autowired
  136. private Environment environment;
  137. @Override
  138. public GoodsEntity queryObject(Integer id) {
  139. Map<String, Object> map = new HashMap<String, Object>();
  140. map.put("goodsId", id);
  141. // List<GoodsAttributeEntity> attributeEntities = goodsAttributeDao.queryList(map);
  142. List<ProductEntity> productEntityList = productDao.queryList(map);
  143. GoodsEntity entity = goodsDao.queryObject(id);
  144. // entity.setAttributeEntityList(attributeEntities);
  145. entity.setProductEntityList(productEntityList);
  146. return entity;
  147. }
  148. @Override
  149. public GoodsEntity queryObjectByProdBarcodeAndBizType(String prodBarcode, Integer storeId){
  150. Map<String, Object> map = new HashMap<String, Object>();
  151. map.put("prodBarcode", prodBarcode);
  152. GoodsEntity entity = goodsDao.queryObjectByProdBarcodeAndBizType(prodBarcode, storeId);
  153. return entity;
  154. }
  155. @Override
  156. public List<GoodsEntity> queryList(Map<String, Object> map) {
  157. return goodsDao.queryList(map);
  158. }
  159. @Override
  160. public List<GoodsEntity> querySame(Map<String, Object> map) {
  161. return goodsDao.querySame(map);
  162. }
  163. @Override
  164. public int queryTotal(Map<String, Object> map) {
  165. return goodsDao.queryTotal(map);
  166. }
  167. @Override
  168. @Transactional
  169. public int save(GoodsEntity goods) {
  170. Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
  171. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  172. builder.put("merchSn", "商户编号");
  173. builder.put("thirdPartyMerchCode", "第三方商户编号");
  174. // builder.put("attributeCategory", "商品分类");
  175. // builder.put("categoryId", "商品二级分类");
  176. builder.put("goodsSn", "商品编码");
  177. builder.put("name", "商品名称");
  178. builder.put("goodsUnit", "商品单位");
  179. builder.put("prodBarcode", "产品条码");
  180. builder.put("goodsBizType", "货品业务类型");
  181. // builder.put("brandId", "品牌");
  182. builder.put("supplierId", "供应商");
  183. // builder.put("freightId", "运费模版");
  184. builder.put("goodsNumber", "商品总库存");
  185. builder.put("primaryPicUrl", "商品主图");
  186. builder.put("listPicUrl", "商品列表图");
  187. builder.put("goodsDesc", "商品描述");
  188. builder.put("isOnSale", "上架");
  189. builder.put("isHot", "热销");
  190. //builder.put("englishName", "商品英文名称");
  191. // builder.put("plu", "PLU");
  192. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  193. if (Integer.valueOf(r.get("code").toString()) != 0) {
  194. throw new RRException(r.get("msg").toString());
  195. } else {
  196. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  197. // 海关信息,普通货物可不添加
  198. builder.put("sku", "SKU");
  199. builder.put("goodsRate", "商品税率");
  200. // builder.put("retailPrice", "零售价");
  201. // builder.put("brand", "产品品牌");
  202. builder.put("unitCode", "计量单位代码");
  203. //builder.put("cusGoodsCode", "海关商品编码");
  204. // builder.put("ciqProdModel", "国检规格型号");
  205. builder.put("oriCntCode", "原产国代码");
  206. // builder.put("cusDeclEle", "海关申报要素");
  207. //builder.put("cusRecCode", "海关备案编号");
  208. }
  209. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  210. if (Integer.valueOf(r.get("code").toString()) != 0) {
  211. throw new RRException(r.get("msg").toString());
  212. }
  213. }
  214. /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
  215. if(thirdMerchantBizEntity == null){
  216. throw new RRException("第三方商户信息不存在");
  217. }
  218. if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
  219. if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
  220. builder.put("goodsNumber", "商品库存");
  221. }
  222. }*/
  223. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  224. if (Integer.valueOf(r.get("code").toString()) != 0) {
  225. throw new RRException(r.get("msg").toString());
  226. }
  227. // 商品轮播图
  228. // List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
  229. // if (galleryEntityList == null || galleryEntityList.size() <= 0) {
  230. // throw new RRException("至少添加一张商品轮播图!");
  231. // }
  232. // List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),null);
  233. // if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
  234. // throw new RRException("不能有重复的产品条码信息!");
  235. // }
  236. SysUserEntity user = ShiroUtils.getUserEntity();
  237. Map<String, Object> map = new HashMap<>();
  238. map.put("isSame", "true");
  239. map.put("sku", goods.getSku());
  240. map.put("goodsSn", goods.getGoodsSn());
  241. map.put("goodsBizType", goods.getGoodsBizType());
  242. List<GoodsEntity> list = querySame(map);
  243. if (list != null && list.size() != 0) {
  244. throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
  245. }
  246. // 添加商品
  247. if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
  248. || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
  249. goods.setIsHot(0);
  250. }
  251. // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
  252. goods.setAddTime(new Date());
  253. goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  254. goods.setIsNew(0);
  255. goods.setCreateUserId(user.getUserId());
  256. goods.setUpdateUserId(user.getUserId());
  257. goods.setUpdateTime(new Date());
  258. goods.setModTime(new Date());
  259. goods.setCreateTime(new Date());
  260. // 新增商品
  261. goodsDao.save(goods);
  262. Long id = goods.getId();
  263. // 添加商品轮播图
  264. // for (int i=0;i<galleryEntityList.size();i++) {
  265. // GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
  266. // galleryEntity.setMerchSn(goods.getMerchSn());
  267. // galleryEntity.setGoodsId(id);
  268. // galleryEntity.setSortOrder((i+1));
  269. // galleryEntity.setFileType("0");//图片
  270. // goodsGalleryDao.save(galleryEntity);
  271. // }
  272. if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
  273. GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
  274. galleryEntity.setMerchSn(goods.getMerchSn());
  275. galleryEntity.setGoodsId(id);
  276. galleryEntity.setSortOrder(0);
  277. galleryEntity.setFileType("1");//视频
  278. goodsGalleryDao.save(galleryEntity);
  279. }
  280. /*
  281. // 添加商品参数
  282. List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
  283. if (attributeEntityList != null && attributeEntityList.size() > 0) {
  284. for (GoodsAttributeEntity item : attributeEntityList) {
  285. if (item.getIsDelete() == 0) {
  286. if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
  287. item.setGoodsId(id);
  288. item.setMerchSn(goods.getMerchSn());
  289. goodsAttributeDao.save(item);
  290. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
  291. throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
  292. } else if (item.getId() == null && item.getAttributeId() == null) {
  293. continue;
  294. }
  295. }
  296. }
  297. }*/
  298. if (goods.getGoodsNumber() != null){
  299. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  300. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(id)));
  301. mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
  302. mngChangeEntity.setChangeReason("新增商户商品总库存");
  303. mngChangeEntity.setChangeType(Dict.changeType.item_0.getItem());
  304. mngChangeEntity.setChangeNum(goods.getGoodsNumber());//变化数
  305. mngChangeEntity.setOriginalNum(0);//原库存数
  306. mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
  307. mngChangeEntity.setCreateTime(new Date());
  308. mngChangeEntity.setModTime(new Date());
  309. mngChangeEntity.setCreaterSn(user.getUsername());
  310. mngChangeEntity.setModerSn(user.getUsername());
  311. mngChangeEntity.setIsValid(0);
  312. mngChangeEntity.setMerchSn(goods.getMerchSn());
  313. mngChangeDao.save(mngChangeEntity);
  314. }
  315. // 添加产品
  316. ProductEntity product = new ProductEntity();
  317. product.setGoodsId(id);
  318. product.setGoodsSn(goods.getGoodsSn());
  319. // 保税商品,普通货物暂不添加商品规格
  320. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  321. // 添加商品规格
  322. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  323. goodsSpecification.setGoodsId(id);
  324. goodsSpecification.setValue(goods.getCiqProdModel());
  325. goodsSpecification.setSpecificationId(1);
  326. goodsSpecificationDao.save(goodsSpecification);
  327. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  328. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  329. }
  330. return productDao.save(product);
  331. }
  332. @Override
  333. @Transactional
  334. public int update(GoodsEntity goods) {
  335. Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
  336. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  337. builder.put("merchSn", "商户编号");
  338. builder.put("thirdPartyMerchCode", "第三方商户编号");
  339. // builder.put("attributeCategory", "商品分类");
  340. // builder.put("categoryId", "商品二级分类");
  341. builder.put("goodsSn", "商品编码");
  342. builder.put("name", "商品名称");
  343. builder.put("goodsUnit", "商品单位");
  344. builder.put("prodBarcode", "产品条码");
  345. builder.put("goodsBizType", "货品业务类型");
  346. // builder.put("brandId", "品牌");
  347. builder.put("supplierId", "供应商");
  348. builder.put("goodsNumber", "商品总库存");
  349. // builder.put("freightId", "运费模版");
  350. builder.put("primaryPicUrl", "商品主图");
  351. builder.put("listPicUrl", "商品列表图");
  352. // builder.put("goodsDesc", "商品描述");
  353. builder.put("isOnSale", "上架");
  354. builder.put("isHot", "热销");
  355. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  356. if (Integer.valueOf(r.get("code").toString()) != 0) {
  357. throw new RRException(r.get("msg").toString());
  358. } else {
  359. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  360. // 海关信息,普通货物可不添加
  361. builder.put("sku", "SKU");
  362. builder.put("goodsRate", "商品税率");
  363. // builder.put("retailPrice", "零售价");
  364. // builder.put("brand", "产品品牌");
  365. builder.put("unitCode", "计量单位代码");
  366. //builder.put("cusGoodsCode", "海关商品编码");
  367. //builder.put("ciqProdModel", "国检规格型号");
  368. builder.put("oriCntCode", "原产国代码");
  369. //builder.put("cusRecCode", "海关备案编号");
  370. //builder.put("cusDeclEle", "海关申报要素");
  371. }
  372. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  373. if (Integer.valueOf(r.get("code").toString()) != 0) {
  374. throw new RRException(r.get("msg").toString());
  375. }
  376. }
  377. /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
  378. if(thirdMerchantBizEntity == null){
  379. throw new RRException("所属第三方商户不存在");
  380. }*/
  381. GoodsEntity goodsEntity = goodsDao.queryObject(goods.getId());
  382. if(goodsEntity != null){
  383. /*if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
  384. if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
  385. builder.put("goodsNumber", "商品库存");
  386. }
  387. }
  388. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  389. if (Integer.valueOf(r.get("code").toString()) != 0) {
  390. throw new RRException(r.get("msg").toString());
  391. }*/
  392. }else{
  393. throw new RRException("商品不存在");
  394. }
  395. // 商品轮播图
  396. List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
  397. if (galleryEntityList == null || galleryEntityList.size() <= 0) {
  398. // throw new RRException("至少保留一张商品轮播图!");
  399. }
  400. // List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),goods.getId());
  401. // if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
  402. // throw new RRException("不能有重复的产品条码信息!");
  403. // }
  404. SysUserEntity user = ShiroUtils.getUserEntity();
  405. Map<String, Object> map = new HashMap<>();
  406. map.put("isSame", "true");
  407. map.put("sku", goods.getSku());
  408. map.put("goodsSn", goods.getGoodsSn());
  409. map.put("goodsBizType", goods.getGoodsBizType());
  410. map.put("id", goods.getId());
  411. List<GoodsEntity> list = querySame(map);
  412. if (list != null && list.size() != 0) {
  413. throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
  414. }
  415. // 修改商品
  416. if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
  417. || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
  418. goods.setIsHot(0);
  419. }
  420. // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
  421. goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  422. goods.setIsNew(0);
  423. goods.setUpdateUserId(user.getUserId());
  424. goods.setUpdateTime(new Date());
  425. goods.setModTime(new Date());
  426. if(goods.getGoodsNumber()==null){
  427. goods.setGoodsNumber(0);
  428. }else{
  429. if(goodsEntity.getGoodsNumber() == null){
  430. goodsEntity.setGoodsNumber(0);
  431. }
  432. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  433. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
  434. mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
  435. mngChangeEntity.setChangeReason("更新商户商品总库存");
  436. mngChangeEntity.setCreateTime(new Date());
  437. mngChangeEntity.setModTime(new Date());
  438. mngChangeEntity.setCreaterSn(user.getUsername());
  439. mngChangeEntity.setModerSn(user.getUsername());
  440. mngChangeEntity.setIsValid(0);
  441. mngChangeEntity.setMerchSn(goods.getMerchSn());
  442. if(goodsEntity.getGoodsNumber() != goods.getGoodsNumber()) {
  443. if (goodsEntity.getGoodsNumber() > goods.getGoodsNumber()) {
  444. mngChangeEntity.setChangeNum(goodsEntity.getGoodsNumber() - goods.getGoodsNumber());//变化数
  445. mngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
  446. } else {
  447. mngChangeEntity.setChangeNum(goods.getGoodsNumber() - goodsEntity.getGoodsNumber());//变化数
  448. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  449. }
  450. mngChangeEntity.setOriginalNum(goodsEntity.getGoodsNumber());//原库存数
  451. mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
  452. mngChangeDao.save(mngChangeEntity);
  453. }
  454. }
  455. // 修改商品
  456. goodsDao.update(goods);
  457. // 保税商品修改各个门店商品价格
  458. List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsEntity.getId());
  459. Long[] storeIds = new Long[productStoreRelaEntityList.size()];
  460. Integer goodsNumber = goods.getGoodsNumber();//商品总库存
  461. Integer storeTotalGoodsNumber = 0;//商品分配库存
  462. if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  463. for (int i = 0; i < productStoreRelaEntityList.size(); i++) {
  464. //修改该商品的所属商户信息,如在该商户门店中有该上架的商品信息,则提示该商品不能修改
  465. ProductStoreRelaEntity relaEntity = productStoreRelaEntityList.get(i);
  466. if(org.apache.commons.lang3.StringUtils.isNotEmpty(relaEntity.getMerchSn()) && relaEntity.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
  467. && goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_1.getItem())) {
  468. }else {
  469. if (goods.getIsOnSale() != Integer.parseInt(Dict.isOnSale.item_0.getItem())) {
  470. throw new RRException("商品编码为【" + goods.getGoodsSn() + "】的商品已上架在商户编号为【" + relaEntity.getMerchSn() + "】的门店中,可先将该商品下架后再进行修改!");
  471. }
  472. }
  473. storeTotalGoodsNumber = storeTotalGoodsNumber + relaEntity.getStockNum();
  474. storeIds[i] = relaEntity.getStoreId();
  475. }
  476. }
  477. if(goodsEntity.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
  478. if (goodsNumber < storeTotalGoodsNumber) {
  479. throw new RRException("该商品已在各门店分配库存" + storeTotalGoodsNumber + ",当前商品总库存不能小于分配库存总额!请先修改门店库存!");
  480. }
  481. }else{
  482. //共享库存商品库存变化,修改该商品的所有库存信息
  483. ProductStoreRelaEntity productStoreRelaEntity = new ProductStoreRelaEntity();
  484. productStoreRelaEntity.setStockNum(goodsNumber);
  485. productStoreRelaEntity.setGoodsId(goods.getId());
  486. productStoreRelaDao.updateStockNumByGoodsId(productStoreRelaEntity);
  487. for (int i = 0; i < productStoreRelaEntityList.size(); i++) {
  488. ProductStoreRelaEntity relaEntity = productStoreRelaEntityList.get(i);
  489. //新增库存操作记录
  490. StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
  491. storeMngChangeEntity.setChangeReason("共享库存变更,更新门店商品库存");
  492. storeMngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(relaEntity.getGoodsId())));
  493. storeMngChangeEntity.setStoreId(Integer.parseInt(String.valueOf(relaEntity.getStoreId())));
  494. storeMngChangeEntity.setMerchSn(goods.getMerchSn());
  495. storeMngChangeEntity.setCreateTime(new Date());
  496. storeMngChangeEntity.setModTime(new Date());
  497. storeMngChangeEntity.setCreaterSn(user.getUsername());
  498. storeMngChangeEntity.setModerSn(user.getUsername());
  499. storeMngChangeEntity.setIsValid(0);
  500. Integer orginalNum = relaEntity.getStockNum()==null?0:relaEntity.getStockNum();//原有库存
  501. if(goodsNumber != orginalNum) {
  502. if (orginalNum > goodsNumber) {
  503. storeMngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
  504. storeMngChangeEntity.setStoreChangeNum(orginalNum - goodsNumber);//变化数
  505. } else {
  506. storeMngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  507. storeMngChangeEntity.setStoreChangeNum(goodsNumber - orginalNum);//变化数
  508. }
  509. storeMngChangeEntity.setStoreOriginalNum(orginalNum);//原库存数
  510. storeMngChangeEntity.setStoreValidNum(goodsNumber);//可用数
  511. storeMngChangeDao.save(storeMngChangeEntity);
  512. }
  513. }
  514. }
  515. Map cartMap = Maps.newHashMap();
  516. cartMap.put("goodsId",goods.getId());
  517. List<CartEntity> cartList = cartDao.queryList(cartMap);
  518. if (cartList != null && cartList.size() > 0) {
  519. for (CartEntity cartEntity : cartList) {
  520. // cartEntity.setRetailPrice(goods.getRetailPrice());
  521. // cartEntity.setMarketPrice(goods.getMarketPrice());
  522. cartEntity.setSku(goods.getSku());
  523. cartEntity.setGoodsName(goods.getName());
  524. cartEntity.setGoodsSn(goods.getGoodsSn());
  525. cartDao.update(cartEntity);
  526. }
  527. }
  528. // 修改商品轮播图
  529. goodsGalleryDao.deleteByGoodsId(goods.getId());
  530. for (int i=0;i<galleryEntityList.size();i++) {
  531. GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
  532. galleryEntity.setMerchSn(goods.getMerchSn());
  533. galleryEntity.setGoodsId(goods.getId());
  534. galleryEntity.setSortOrder((i+1));
  535. galleryEntity.setFileType("0");//图片
  536. goodsGalleryDao.save(galleryEntity);
  537. }
  538. if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
  539. GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
  540. galleryEntity.setMerchSn(goods.getMerchSn());
  541. galleryEntity.setGoodsId(goods.getId());
  542. galleryEntity.setSortOrder(0);
  543. galleryEntity.setFileType("1");//视频
  544. galleryEntity.setImgUrl(goods.getVideoUrl());
  545. goodsGalleryDao.save(galleryEntity);
  546. }
  547. /*// 修改商品参数
  548. List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
  549. if (attributeEntityList != null && attributeEntityList.size() > 0) {
  550. for (GoodsAttributeEntity item : attributeEntityList) {
  551. if (item.getIsDelete() == 0) {
  552. if (item.getId() != null) {
  553. item.setMerchSn(goods.getMerchSn());
  554. goodsAttributeDao.update(item);
  555. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
  556. item.setGoodsId(goods.getId());
  557. item.setMerchSn(goods.getMerchSn());
  558. goodsAttributeDao.save(item);
  559. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
  560. throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
  561. } else if (item.getId() == null && item.getAttributeId() == null) {
  562. continue;
  563. }
  564. } else if (item.getIsDelete() == 1) {
  565. goodsAttributeDao.delete(item.getId());
  566. }
  567. }
  568. }*/
  569. // 修改产品
  570. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goods.getId()),"");
  571. GoodsSpecificationEntity goodsSpecification = null;
  572. // 保税商品,普通货物暂不添加商品规格
  573. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  574. // 添加商品规格
  575. goodsSpecification = goodsSpecificationDao.queryByGoodsId(goods.getId());
  576. if(goodsSpecification != null) {
  577. goodsSpecification.setValue(goods.getCiqProdModel());
  578. goodsSpecificationDao.update(goodsSpecification);
  579. }else{
  580. goodsSpecification = new GoodsSpecificationEntity();
  581. goodsSpecification.setGoodsId(goods.getId());
  582. goodsSpecification.setValue(goods.getCiqProdModel());
  583. goodsSpecification.setSpecificationId(1);
  584. goodsSpecificationDao.save(goodsSpecification);
  585. }
  586. //更新门店商品是否有修改字段
  587. if(storeIds.length > 0){
  588. for(int i=0;i<storeIds.length;i++){
  589. updateLoadGoodsByStoreId(storeIds[i], user);
  590. }
  591. }
  592. if(product == null){
  593. product = new ProductEntity();
  594. product.setGoodsSn(goods.getGoodsSn());
  595. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  596. product.setGoodsSpecificationIds(goodsSpecification.getId()+"");
  597. product.setGoodsId(goods.getId());
  598. product.setGoodsNumber(goods.getGoodsNumber());
  599. product.setGoodsDefault(0);
  600. return productDao.save(product);
  601. }else{
  602. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  603. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  604. return productDao.update(product);
  605. }
  606. }
  607. return 1;
  608. }
  609. @Transactional
  610. @Override
  611. public void updateForImgUrl(GoodsEntity goodsEntity){
  612. // 修改商品
  613. goodsDao.update(goodsEntity);
  614. }
  615. @Override
  616. public List<GoodsEntity> queryByName(String storeId, String goodsName) {
  617. return goodsDao.queryByName(storeId, goodsName);
  618. }
  619. /**
  620. * 更新门店商品是否有修改字段
  621. * @param storeId
  622. * @param user
  623. */
  624. private void updateLoadGoodsByStoreId(Long storeId, SysUserEntity user){
  625. List<MerchUserEntity> list = merchUserDao.queryMerchUserByLoadGoods(storeId);
  626. for(MerchUserEntity entity : list) {
  627. entity.setIsLoadGoods("1");
  628. entity.setModerSn(user.getUsername());
  629. entity.setStoreId(Integer.valueOf(String.valueOf(storeId)));
  630. merchUserDao.updateStoreLoadGoodsById(entity);
  631. }
  632. }
  633. @Override
  634. public int delete(Integer id) {
  635. SysUserEntity user = ShiroUtils.getUserEntity();
  636. GoodsEntity goodsEntity = goodsDao.queryObject(id);
  637. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_1.getItem()));
  638. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  639. goodsEntity.setUpdateUserId(user.getUserId());
  640. goodsEntity.setUpdateTime(new Date());
  641. Map params = Maps.newHashMap();
  642. params.put("goodsId", id);
  643. List<GoodsGroupEntity> groupVos = goodsGroupDao.queryList(params);
  644. if (null != groupVos && groupVos.size() > 0) {
  645. for (GoodsGroupEntity groupVo : groupVos) {
  646. groupVo.setOpenStatus(3);
  647. goodsGroupDao.update(groupVo);
  648. }
  649. }
  650. return goodsDao.update(goodsEntity);
  651. }
  652. @Override
  653. @Transactional
  654. public int deleteBatch(Integer[] ids) {
  655. int result = 0;
  656. for (Integer id : ids) {
  657. result += delete(id);
  658. }
  659. return result;
  660. }
  661. @Override
  662. @Transactional
  663. public int back(Integer[] ids) {
  664. SysUserEntity user = ShiroUtils.getUserEntity();
  665. int result = 0;
  666. for (Integer id : ids) {
  667. GoodsEntity goodsEntity = queryObject(id);
  668. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  669. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  670. goodsEntity.setUpdateUserId(user.getUserId());
  671. goodsEntity.setUpdateTime(new Date());
  672. result += goodsDao.update(goodsEntity);
  673. }
  674. return result;
  675. }
  676. @Override
  677. public int enSale(Integer id) {
  678. SysUserEntity user = ShiroUtils.getUserEntity();
  679. GoodsEntity goodsEntity = queryObject(id);
  680. if (1 == goodsEntity.getIsOnSale()) {
  681. throw new RRException("此商品已处于上架状态!");
  682. }
  683. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  684. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  685. goodsEntity.setUpdateUserId(user.getUserId());
  686. goodsEntity.setUpdateTime(new Date());
  687. return goodsDao.update(goodsEntity);
  688. }
  689. @Override
  690. public int unSale(Integer id) {
  691. SysUserEntity user = ShiroUtils.getUserEntity();
  692. GoodsEntity goodsEntity = queryObject(id);
  693. if (0 == goodsEntity.getIsOnSale()) {
  694. throw new RRException("此商品已处于下架状态!");
  695. }
  696. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  697. goodsEntity.setUpdateUserId(user.getUserId());
  698. goodsEntity.setUpdateTime(new Date());
  699. return goodsDao.update(goodsEntity);
  700. }
  701. @Override
  702. public int enSaleBatch(Integer[] ids) {
  703. int result = 0;
  704. SysUserEntity user = ShiroUtils.getUserEntity();
  705. for (Integer id : ids) {
  706. GoodsEntity goodsEntity = queryObject(id);
  707. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  708. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  709. goodsEntity.setUpdateUserId(user.getUserId());
  710. goodsEntity.setUpdateTime(new Date());
  711. result += goodsDao.update(goodsEntity);
  712. }
  713. return result;
  714. }
  715. @Override
  716. public int unSaleBatch(Integer[] ids) {
  717. int result = 0;
  718. SysUserEntity user = ShiroUtils.getUserEntity();
  719. for (Integer id : ids) {
  720. GoodsEntity goodsEntity = queryObject(id);
  721. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  722. goodsEntity.setUpdateUserId(user.getUserId());
  723. goodsEntity.setUpdateTime(new Date());
  724. result += goodsDao.update(goodsEntity);
  725. }
  726. return result;
  727. }
  728. @Override
  729. @Transactional
  730. public int uploadExcel(List<GoodsDto> goodsEntityList,int exportDataType) {
  731. SysUserEntity user = ShiroUtils.getUserEntity();
  732. String merchSn = user.getMerchSn();
  733. boolean isFail = false;
  734. List<String> failSameSkuList = new ArrayList<>(),
  735. failUnitGoodsSnList = new ArrayList<>(),
  736. failNationGoodsSnList = new ArrayList<>(),
  737. failTypeGoodsSnList = new ArrayList<>(),
  738. failMerchGoodsSnList = new ArrayList<>(),
  739. failMerchUserGoodsSnList = new ArrayList<>();
  740. List<String> failGoodsSnList = new ArrayList<>();
  741. List<String> failGoodsTypeList = new ArrayList<>();
  742. // 定义需要批量插入的list
  743. List<MngChangeEntity> insertMngChangeList = new LinkedList<>();
  744. List<GoodsEntity> insertGoodsList = new LinkedList<>();
  745. // 定义需要批量修改的list
  746. List<ProductEntity> updateProductList = new LinkedList<>();
  747. List<GoodsSpecificationEntity> updateSpecificationList = new LinkedList<>();
  748. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  749. for (int i = 0; i < goodsEntityList.size(); i++) {
  750. GoodsDto goodsDto = goodsEntityList.get(i);
  751. GoodsEntity goodsEntity = new GoodsEntity();
  752. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  753. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  754. builder.put("goodsSn", "商品编码");
  755. builder.put("thirdPartyMerchCode", "第三方商户代码");
  756. builder.put("goodsBizType", "货品业务类型");
  757. builder.put("name", "商品名称");
  758. builder.put("prodBarcode", "产品条码");
  759. builder.put("sku", "sku");
  760. builder.put("isOnSaleStr", "上架");
  761. builder.put("goodsUnit", "商品单位");
  762. builder.put("isHotStr", "是否热销");
  763. builder.put("goodsRate", "商品税率");
  764. builder.put("brand", "产品品牌");
  765. builder.put("uniqueIdentifier", "品牌唯一简码");
  766. builder.put("unitName", "计量单位");
  767. builder.put("oriCntName", "原产国");
  768. builder.put("valueAddedTaxRate", "增值税率");
  769. builder.put("goodsNumber", "库存数");
  770. builder.put("firstLevel", "一级分类");
  771. builder.put("secondLevel", "二级分类");
  772. builder.put("warehouseSn", "仓库编码");
  773. builder.put("consignorSn", "货主编码");
  774. builder.put("warehousSysGoodId", "仓储系统商品ID");
  775. builder.put("inventoryType", "库存类型");
  776. builder.put("legalUnit1Qty", "第一法定单位数量");
  777. builder.put("legalUnit2Qty", "第二法定单位数量");
  778. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  779. if (Integer.valueOf(r.get("code").toString()) != 0) {
  780. throw new RRException(r.get("msg").toString());
  781. }
  782. //业务类型校验
  783. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  784. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  785. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  786. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  787. isFail = true;
  788. failTypeGoodsSnList.add(goodsDto.getSku());
  789. }
  790. }
  791. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  792. if(thirdMerchantBizEntity != null){
  793. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  794. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  795. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  796. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  797. isFail = true;
  798. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn().trim());
  799. }
  800. }
  801. }else{//商户不存在
  802. isFail = true;
  803. failMerchGoodsSnList.add(goodsDto.getGoodsSn().trim());
  804. }
  805. //校验商品信息是否已存在
  806. Map<String, Object> map = new HashMap<>();
  807. map.put("isSame", "true");
  808. map.put("sku", goodsDto.getSku().trim());
  809. map.put("goodsSn", goodsDto.getGoodsSn().trim());
  810. map.put("goodsBizType", goodsDto.getGoodsBizType());
  811. List<GoodsEntity> list = querySame(map);
  812. if (list != null && list.size() != 0) {
  813. if(goodsDto.getSku()!=null) {
  814. failSameSkuList.add(goodsDto.getSku());
  815. }
  816. failGoodsSnList.add(goodsDto.getGoodsSn());
  817. failGoodsTypeList.add(goodsDto.getGoodsBizType());
  818. }
  819. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  820. if(thirdMerchantBizEntity != null) {
  821. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  822. if (supplierEntity == null) {
  823. //导入没有查到供货商,执行新增
  824. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  825. supplierEntity = new SupplierEntity();
  826. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  827. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  828. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  829. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  830. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  831. supplierEntity.setIsShow("0");
  832. // TODO 这里改成批量插入 SupplierEntity
  833. //新增商品供货信息
  834. supplierDao.save(supplierEntity);
  835. goodsEntity.setSupplierId(supplierEntity.getId());
  836. } else {
  837. goodsEntity.setSupplierId(supplierEntity.getId());
  838. }
  839. }
  840. GoodsEntity goodsNew = goodsDao.queryObjectBySnNew(goodsDto.getGoodsSn());
  841. if(goodsNew!=null){
  842. throw new RRException("该商品数据已存在,请勿重复导入:"+goodsNew.getGoodsSn());
  843. }
  844. // 获取品牌唯一简码
  845. checkBrand(goodsDto, goodsEntity);
  846. // 获取二级分类id
  847. checkCategory(goodsDto, goodsEntity);
  848. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  849. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  850. if (sysCusUnitCodeEntity == null) {
  851. isFail = true;
  852. failUnitGoodsSnList.add(goodsDto.getGoodsSn().trim());
  853. } else {
  854. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  855. }
  856. //原产国
  857. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  858. if (sysCusNationCodeEntity == null) {
  859. isFail = true;
  860. failNationGoodsSnList.add(goodsDto.getGoodsSn().trim());
  861. } else {
  862. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  863. }
  864. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  865. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  866. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  867. }else{
  868. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())));
  869. }
  870. }
  871. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  872. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  873. goodsEntity.setGoodsSn(goodsDto.getGoodsSn().trim());
  874. goodsEntity.setSku(goodsDto.getSku().trim());
  875. goodsEntity.setName(goodsDto.getName());
  876. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  877. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  878. goodsEntity.setBrand(goodsDto.getBrand());
  879. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  880. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  881. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  882. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  883. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  884. goodsEntity.setIsNew(0);
  885. goodsEntity.setUpdateUserId(user.getUserId());
  886. goodsEntity.setAddTime(new Date());
  887. goodsEntity.setCreateTime(new Date());
  888. goodsEntity.setUpdateTime(new Date());
  889. goodsEntity.setModTime(new Date());
  890. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  891. //新加字段1208
  892. goodsEntity.setWarehouseSn(goodsDto.getWarehouseSn());
  893. goodsEntity.setConsignorSn(goodsDto.getConsignorSn());
  894. goodsEntity.setWarehousSysGoodId(goodsDto.getWarehousSysGoodId());
  895. goodsEntity.setConsignorSn(goodsDto.getConsignorSn());
  896. goodsEntity.setInventoryType(goodsDto.getInventoryType());
  897. goodsEntity.setDefectiveProductsGrade(goodsDto.getDefectiveProductsGrade());
  898. //goodsEntity.setNetWeight(new BigDecimal(goodsDto.getNetWeight()));
  899. goodsEntity.setLegalUnit1Qty(new BigDecimal(goodsDto.getLegalUnit1Qty()));
  900. goodsEntity.setLegalUnit2Qty(new BigDecimal(goodsDto.getLegalUnit2Qty()));
  901. if(null!=goodsDto.getImpConsumTaxRate()){
  902. goodsEntity.setImpConsumTaxRate(new BigDecimal(goodsDto.getImpConsumTaxRate()));
  903. }
  904. goodsEntity.setValueAddedTaxRate(new BigDecimal(goodsDto.getValueAddedTaxRate()));
  905. if(!isFail){
  906. GoodsEntity goods = goodsDao.queryObjectBySnNew(goodsDto.getGoodsSn());
  907. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  908. mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
  909. mngChangeEntity.setChangeReason("更新商户商品总库存");
  910. mngChangeEntity.setCreateTime(new Date());
  911. mngChangeEntity.setModTime(new Date());
  912. mngChangeEntity.setCreaterSn(user.getUsername());
  913. mngChangeEntity.setModerSn(user.getUsername());
  914. mngChangeEntity.setIsValid(0);
  915. mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
  916. //新增、修改商品表
  917. if(goods!=null) {// 修改商品
  918. mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
  919. mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  920. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  921. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  922. mngChangeEntity.setGoodsId(goods.getId().intValue());
  923. goodsEntity.setId(goods.getId());
  924. goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
  925. // TODO 这里改成批量修改 GoodsEntity
  926. goodsDao.update(goodsEntity);
  927. }else{
  928. mngChangeEntity.setOriginalNum(0);//原库存数
  929. mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  930. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  931. mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
  932. goodsDao.save(goodsEntity);
  933. insertGoodsList.add(goodsEntity);
  934. mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
  935. }
  936. // TODO 这里改成批量插入 MngChangeEntity
  937. insertMngChangeList.add(mngChangeEntity);
  938. // 修改产品
  939. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  940. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  941. // 普通货物暂不添加商品规格
  942. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  943. // 添加商品规格
  944. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  945. if(specificationEntity == null) {
  946. goodsSpecification.setGoodsId(goodsEntity.getId());
  947. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  948. goodsSpecification.setSpecificationId(1);
  949. // TODO 这里改成批量插入 GoodsSpecificationEntity
  950. goodsSpecificationDao.save(goodsSpecification);
  951. }else{
  952. // {
  953. // goodsSpecification.setValue(goodsDto.getCiqProdModel());
  954. goodsSpecification.setId(specificationEntity.getId());
  955. //
  956. // // TODO 这里改成批量更新 GoodsSpecificationEntity
  957. // updateSpecificationList.add(goodsSpecification);
  958. // }
  959. }
  960. if(product == null){
  961. product = new ProductEntity();
  962. product.setGoodsSn(goodsDto.getGoodsSn());
  963. product.setGoodsId(goodsEntity.getId());
  964. product.setGoodsDefault(0);
  965. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  966. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  967. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  968. // TODO 这里改成批量插入 ProductEntity
  969. productDao.save(product);
  970. }else{
  971. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  972. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  973. // TODO 这里改成批量更新 ProductEntity
  974. updateProductList.add(product);
  975. }
  976. }
  977. }
  978. }
  979. if(insertMngChangeList != null && insertMngChangeList.size() > 0 ){
  980. if(insertMngChangeList.size() > 50){
  981. List<List<MngChangeEntity>> partition = Lists.partition(insertMngChangeList, 50);
  982. for (List<MngChangeEntity> mngChangeEntities : partition) {
  983. mngChangeDao.saveBatch(mngChangeEntities);
  984. }
  985. }else{
  986. mngChangeDao.saveBatch(insertMngChangeList);
  987. }
  988. }
  989. // 批量更新数据mall_product
  990. if(updateProductList != null && updateProductList.size() > 0 ){
  991. if(updateProductList.size() > 50){
  992. List<List<ProductEntity>> partition = Lists.partition(updateProductList, 50);
  993. for (List<ProductEntity> productEntities : partition) {
  994. productDao.updateBatch(productEntities);
  995. }
  996. }else{
  997. productDao.updateBatch(updateProductList);
  998. }
  999. }
  1000. // 批量更新数据mall_goods_specification 商品对应规格表值表
  1001. if(updateSpecificationList != null && updateSpecificationList.size() > 0 ){
  1002. if(updateSpecificationList.size() > 50){
  1003. List<List<GoodsSpecificationEntity>> partition = Lists.partition(updateSpecificationList, 50);
  1004. for (List<GoodsSpecificationEntity> goodsSpecificationEntities : partition) {
  1005. goodsSpecificationDao.updateBatch(goodsSpecificationEntities);
  1006. }
  1007. }
  1008. }
  1009. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  1010. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  1011. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  1012. exportExceptionDataEntity.setCreateTime(new Date());
  1013. exportExceptionDataEntity.setModTime(new Date());
  1014. exportExceptionDataEntity.setMerchSn(merchSn);
  1015. exportExceptionDataEntity.setStoreId(user.getStoreId());
  1016. if(exportDataType == 1) {
  1017. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  1018. }else{
  1019. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  1020. }
  1021. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  1022. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  1023. goodsUtils.save(exportExceptionDataEntity);
  1024. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1025. }
  1026. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  1027. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  1028. goodsUtils.save(exportExceptionDataEntity);
  1029. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1030. }
  1031. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  1032. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  1033. goodsUtils.save(exportExceptionDataEntity);
  1034. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1035. }
  1036. // if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  1037. // exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  1038. // goodsUtils.save(exportExceptionDataEntity);
  1039. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1040. // }
  1041. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1042. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1043. goodsUtils.save(exportExceptionDataEntity);
  1044. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1045. }
  1046. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1047. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1048. goodsUtils.save(exportExceptionDataEntity);
  1049. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1050. }
  1051. }else{
  1052. throw new RRException("导入数据为出错,请检查数据是否按要求填写");
  1053. }
  1054. return 1;
  1055. }
  1056. private void checkCategory(GoodsDto goodsDto, GoodsEntity goodsEntity) {
  1057. // 二级分类名称
  1058. String secondLevel = goodsDto.getSecondLevel().trim();
  1059. String firstLevelName = goodsDto.getFirstLevel().trim();
  1060. CategoryEntity categoryNew = categoryDao.queryByName(secondLevel);
  1061. if(categoryNew != null){
  1062. String categoryId = categoryNew.getId().toString();
  1063. String level = categoryNew.getLevel();
  1064. if(categoryId == null){
  1065. throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
  1066. }else if(Dict.Level.item_L2.getItem().equals(level)){
  1067. CategoryEntity firstCategory = categoryDao.queryByName(firstLevelName);
  1068. if(firstCategory==null) {
  1069. throw new RuntimeException("该分类不是一级分类,请检查,对应sku是:" + goodsDto.getSku() + ",分类名称为:" + firstLevelName);
  1070. }
  1071. goodsEntity.setAttributeCategory(firstCategory.getId());
  1072. // 二级分类id在缓存中有,直接存入商品
  1073. goodsEntity.setCategoryId(Integer.parseInt(categoryId));
  1074. }
  1075. }else {
  1076. throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
  1077. }
  1078. }
  1079. private void checkBrand(GoodsDto goodsDto, GoodsEntity goodsEntity) {
  1080. String uniqueIdentifier = goodsDto.getUniqueIdentifier();
  1081. String brandName = goodsDto.getBrand();
  1082. Map<String, String> brandCache = JedisUtil.getMap(uniqueIdentifier);
  1083. if(brandCache != null) {
  1084. String brandId = brandCache.get("brandId");
  1085. if (brandId == null) {
  1086. Map<String, String> brandCacheData = new HashMap<>();
  1087. // 数据库里面查询
  1088. BrandEntity queryBrand = brandService.queryByUniqueIdentifier(uniqueIdentifier.trim());
  1089. if (queryBrand == null) {
  1090. throw new RuntimeException("该品牌不存在,请检查品牌唯一标识符是否正确:"+uniqueIdentifier);
  1091. } else {
  1092. brandCacheData.put("brandId", queryBrand.getId() + "");
  1093. brandCacheData.put("brandName", queryBrand.getName());
  1094. goodsEntity.setBrandId(queryBrand.getId());
  1095. }
  1096. JedisUtil.setMap(uniqueIdentifier, brandCacheData, 0);
  1097. } else {
  1098. goodsEntity.setBrandId(Integer.parseInt(brandId));
  1099. }
  1100. }else{
  1101. Map<String, String> brandCacheData = new HashMap<>();
  1102. // 数据库里面查询
  1103. BrandEntity queryBrand = brandService.queryByUniqueIdentifier(uniqueIdentifier.trim());
  1104. if (queryBrand == null) {
  1105. throw new RuntimeException("该品牌不存在,请检查品牌唯一标识符是否正确:"+uniqueIdentifier);
  1106. } else {
  1107. brandCacheData.put("brandId", queryBrand.getId() + "");
  1108. brandCacheData.put("brandName", queryBrand.getName());
  1109. goodsEntity.setBrandId(queryBrand.getId());
  1110. }
  1111. JedisUtil.setMap(uniqueIdentifier, brandCacheData, 0);
  1112. }
  1113. }
  1114. private CategoryEntity initCategory(String firstLevel, int parentId, Dict.Level item) {
  1115. CategoryEntity firstCategoryEntity = new CategoryEntity();
  1116. firstCategoryEntity.setName(firstLevel);
  1117. firstCategoryEntity.setParentId(parentId);
  1118. firstCategoryEntity.setIsShow(1);
  1119. firstCategoryEntity.setFrontDesc(firstLevel);
  1120. firstCategoryEntity.setType(0);
  1121. firstCategoryEntity.setLevel(item.getItem());
  1122. return firstCategoryEntity;
  1123. }
  1124. @Override
  1125. @Transactional
  1126. public int uploadExcelByCover(List<GoodsDto> goodsEntityList, int exportDataType) {
  1127. SysUserEntity user = ShiroUtils.getUserEntity();
  1128. String merchSn = user.getMerchSn();
  1129. boolean isFail = false;
  1130. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  1131. failSuppGoodsSnList = new ArrayList<>(),
  1132. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
  1133. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  1134. failMerchUserGoodsSnList = new ArrayList<>();
  1135. // List<String> failGoodsSnList = new ArrayList<>();
  1136. List<String> failGoodsTypeList = new ArrayList<>();
  1137. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  1138. for (int i = 0; i < goodsEntityList.size(); i++) {
  1139. GoodsDto goodsDto = goodsEntityList.get(i);
  1140. GoodsEntity goodsEntity = new GoodsEntity();
  1141. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  1142. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  1143. builder.put("goodsSn", "商品编码");
  1144. builder.put("thirdPartyMerchCode", "第三方商户代码");
  1145. builder.put("goodsBizType", "货品业务类型");
  1146. builder.put("name", "商品名称");
  1147. builder.put("isOnSaleStr", "上架");
  1148. builder.put("goodsUnit", "商品单位");
  1149. builder.put("isHotStr", "热销");
  1150. builder.put("prodBarcode", "产品条码");
  1151. builder.put("supplierName", "供应商");
  1152. builder.put("goodsNumber", "商品总库存");
  1153. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  1154. if (Integer.valueOf(r.get("code").toString()) != 0) {
  1155. throw new RRException(r.get("msg").toString());
  1156. } else {
  1157. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1158. // 海关信息,普通货物可不添加
  1159. builder.put("goodsRate", "商品税率");
  1160. builder.put("sku", "SKU");
  1161. // builder.put("brand", "产品品牌");
  1162. builder.put("unitName", "计量单位");
  1163. builder.put("oriCntName", "原产国");
  1164. builder.put("cusGoodsCode", "海关商品编码");
  1165. //builder.put("ciqProdModel", "国检规格型号");
  1166. // builder.put("cusDeclEle", "海关申报要素");
  1167. //builder.put("cusRecCode", "海关备案编号");
  1168. }
  1169. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  1170. if (Integer.valueOf(r.get("code").toString()) != 0) {
  1171. throw new RRException(r.get("msg").toString());
  1172. }
  1173. }
  1174. //业务类型校验
  1175. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  1176. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  1177. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  1178. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  1179. isFail = true;
  1180. failTypeGoodsSnList.add(goodsDto.getSku());
  1181. }
  1182. }
  1183. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  1184. if(thirdMerchantBizEntity != null){
  1185. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  1186. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  1187. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  1188. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  1189. isFail = true;
  1190. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  1191. }
  1192. }
  1193. }else{//商户不存在
  1194. isFail = true;
  1195. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  1196. }
  1197. //校验商品信息是否已存在
  1198. Map<String, Object> map = new HashMap<>();
  1199. map.put("isSame", "true");
  1200. map.put("sku", goodsDto.getSku());
  1201. map.put("goodsSn", goodsDto.getGoodsSn());
  1202. map.put("goodsBizType", goodsDto.getGoodsBizType());
  1203. // List<GoodsEntity> list = querySame(map);
  1204. // if (list != null && list.size() != 0) {
  1205. // isFail = true;
  1206. // if(goodsDto.getSku()!=null) {
  1207. // failSameSkuList.add(goodsDto.getSku());
  1208. // }
  1209. // failGoodsSnList.add(goodsDto.getGoodsSn());
  1210. // failGoodsTypeList.add(goodsDto.getGoodsBizType());
  1211. // }
  1212. //校验产品条码是否存在
  1213. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  1214. //热销商品校验
  1215. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  1216. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  1217. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  1218. isFail = true;
  1219. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  1220. }
  1221. }
  1222. if(thirdMerchantBizEntity != null) {
  1223. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  1224. if (supplierEntity == null) {
  1225. //导入没有查到供货商,执行新增
  1226. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  1227. if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
  1228. isFail = true;
  1229. failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  1230. }
  1231. supplierEntity = new SupplierEntity();
  1232. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  1233. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  1234. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  1235. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  1236. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  1237. supplierEntity.setIsShow("0");
  1238. supplierDao.save(supplierEntity);
  1239. goodsEntity.setSupplierId(supplierEntity.getId());
  1240. } else {
  1241. goodsEntity.setSupplierId(supplierEntity.getId());
  1242. }
  1243. }
  1244. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1245. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  1246. if (sysCusUnitCodeEntity == null) {
  1247. isFail = true;
  1248. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  1249. } else {
  1250. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  1251. }
  1252. //原产国
  1253. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  1254. if (sysCusNationCodeEntity == null) {
  1255. isFail = true;
  1256. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  1257. } else {
  1258. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  1259. }
  1260. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  1261. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  1262. }
  1263. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  1264. }
  1265. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  1266. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  1267. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  1268. goodsEntity.setSku(goodsDto.getSku());
  1269. goodsEntity.setName(goodsDto.getName());
  1270. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  1271. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  1272. goodsEntity.setBrand(goodsDto.getBrand());
  1273. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  1274. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  1275. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  1276. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  1277. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  1278. goodsEntity.setIsNew(0);
  1279. goodsEntity.setUpdateUserId(user.getUserId());
  1280. goodsEntity.setAddTime(new Date());
  1281. goodsEntity.setCreateTime(new Date());
  1282. goodsEntity.setUpdateTime(new Date());
  1283. goodsEntity.setModTime(new Date());
  1284. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  1285. if(!isFail){
  1286. GoodsEntity goods = goodsDao.queryObjectBySnNew(goodsDto.getGoodsSn());
  1287. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  1288. mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
  1289. mngChangeEntity.setChangeReason("更新商户商品总库存");
  1290. mngChangeEntity.setCreateTime(new Date());
  1291. mngChangeEntity.setModTime(new Date());
  1292. mngChangeEntity.setCreaterSn(user.getUsername());
  1293. mngChangeEntity.setModerSn(user.getUsername());
  1294. mngChangeEntity.setIsValid(0);
  1295. mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
  1296. if(goods!=null) {// 修改商品
  1297. mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
  1298. mngChangeEntity.setValidNum(goods.getGoodsNumber() + Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  1299. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  1300. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  1301. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
  1302. goodsEntity.setId(goods.getId());
  1303. goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
  1304. goodsDao.update(goodsEntity);
  1305. }else{
  1306. mngChangeEntity.setOriginalNum(0);//原库存数
  1307. mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  1308. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  1309. mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
  1310. goodsDao.save(goodsEntity);
  1311. mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
  1312. }
  1313. mngChangeDao.save(mngChangeEntity);
  1314. // 修改产品
  1315. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  1316. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  1317. // 普通货物暂不添加商品规格
  1318. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1319. // 添加商品规格
  1320. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  1321. if(specificationEntity == null) {
  1322. goodsSpecification.setGoodsId(goodsEntity.getId());
  1323. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  1324. goodsSpecification.setSpecificationId(1);
  1325. goodsSpecificationDao.save(goodsSpecification);
  1326. }else {
  1327. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  1328. goodsSpecification.setId(specificationEntity.getId());
  1329. goodsSpecificationDao.update(goodsSpecification);
  1330. }
  1331. if(product == null){
  1332. product = new ProductEntity();
  1333. product.setGoodsSn(goodsDto.getGoodsSn());
  1334. product.setGoodsId(goodsEntity.getId());
  1335. product.setGoodsDefault(0);
  1336. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  1337. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1338. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1339. productDao.save(product);
  1340. }else{
  1341. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1342. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1343. productDao.update(product);
  1344. }
  1345. }
  1346. }
  1347. }
  1348. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  1349. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  1350. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  1351. exportExceptionDataEntity.setCreateTime(new Date());
  1352. exportExceptionDataEntity.setModTime(new Date());
  1353. exportExceptionDataEntity.setMerchSn(merchSn);
  1354. exportExceptionDataEntity.setStoreId(user.getStoreId());
  1355. if(exportDataType == 1) {
  1356. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  1357. }else{
  1358. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  1359. }
  1360. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  1361. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  1362. goodsUtils.save(exportExceptionDataEntity);
  1363. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1364. }
  1365. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  1366. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  1367. goodsUtils.save(exportExceptionDataEntity);
  1368. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1369. }
  1370. // if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  1371. // if(failSameSkuList.size()>0) {
  1372. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1373. // failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  1374. // goodsUtils.save(exportExceptionDataEntity);
  1375. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1376. // }else{
  1377. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1378. // failGoodsTypeList + "】的商品信息");
  1379. // goodsUtils.save(exportExceptionDataEntity);
  1380. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1381. // }
  1382. // }
  1383. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  1384. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  1385. goodsUtils.save(exportExceptionDataEntity);
  1386. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1387. }
  1388. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  1389. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  1390. goodsUtils.save(exportExceptionDataEntity);
  1391. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1392. }
  1393. if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  1394. exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  1395. goodsUtils.save(exportExceptionDataEntity);
  1396. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1397. }
  1398. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1399. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1400. goodsUtils.save(exportExceptionDataEntity);
  1401. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1402. }
  1403. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1404. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1405. goodsUtils.save(exportExceptionDataEntity);
  1406. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1407. }
  1408. }else{
  1409. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  1410. }
  1411. return 1;
  1412. }
  1413. @Override
  1414. public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId,String sku) {
  1415. return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId,sku);
  1416. }
  1417. @Override
  1418. public GoodsPanoramaDto searchGoodsPanoramaDtoByKeyword(String keyword) {
  1419. return goodsDao.searchGoodsPanoramaDtoByKeyword(keyword);
  1420. }
  1421. @Override
  1422. public List<GoodsEntity> queryExportList(Map<String, Object> params) {
  1423. return goodsDao.queryExportList(params);
  1424. }
  1425. /**
  1426. * 查出pdf需要的需要
  1427. *
  1428. * @param sku 商品sku
  1429. * @param storeId
  1430. * @param prodBarcode
  1431. * @return
  1432. */
  1433. @Override
  1434. public PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode) {
  1435. return goodsDao.queryForPDFData(sku,storeId,prodBarcode);
  1436. }
  1437. /**
  1438. * 查询产品价格
  1439. * 改进后的逻辑:
  1440. * @param prodBarcode
  1441. * @param storeId
  1442. * @return
  1443. */
  1444. @Override
  1445. @Transactional
  1446. public synchronized Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId, String sku) {
  1447. /**
  1448. * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
  1449. */
  1450. GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId,sku);
  1451. if(goods == null) {
  1452. return null;
  1453. }
  1454. String env = environment.getProperty("haikong.env");
  1455. /*
  1456. * 2. 查询海仓仓库系统,判断库存是否足够
  1457. * */
  1458. sku = org.springframework.util.StringUtils.isEmpty(sku) ? goods.getSku() : sku;
  1459. String wareStockNumberKey = storeId + sku + prodBarcode;
  1460. String warehouseStockMapKey = Constants.WAREHOUSE_STOCK_MAP_KEY + "_" + storeId;
  1461. String redisCacheWareQuantity = JedisUtil.hget(warehouseStockMapKey, wareStockNumberKey);
  1462. Integer wareQuantity = 0;
  1463. Integer exitRegionNumber = goods.getExitRegionNumber();
  1464. String stockNum = goods.getStockNum();
  1465. Integer sellVolume = Objects.isNull(goods.getSellVolume()) ? 1 : goods.getSellVolume();
  1466. if (org.springframework.util.StringUtils.isEmpty(redisCacheWareQuantity)) {
  1467. WareQueryStockResponseDTO wareQueryStockResponseDTO = null;
  1468. String queryWarehouseStockResponse = null;
  1469. // 环境配置
  1470. if (!org.springframework.util.StringUtils.isEmpty(env) && Constants.PROD.equals(env)) {
  1471. WareQueryStockParamDTO wareQueryStockParamDTO = new WareQueryStockParamDTO();
  1472. List<Criteria> criteriaList = new ArrayList<>();
  1473. Criteria criteria = new Criteria();
  1474. criteria.setItemId(goods.getWarehouseSysGoodId());
  1475. criteria.setItemCode(goods.getSku());
  1476. criteria.setOwnerCode(haiKongProperties.getWareCompanyCode());
  1477. criteria.setInventoryType(Constants.InventoryType.ZP.getType());
  1478. criteria.setWarehouseCode(goods.getWarehouseSn());
  1479. criteriaList.add(criteria);
  1480. wareQueryStockParamDTO.setCriteriaList(criteriaList);
  1481. try {
  1482. queryWarehouseStockResponse = haiKongWarehouseTemplate.queryWarehouseStock(wareQueryStockParamDTO);
  1483. } catch (Exception e) {
  1484. log.error("sku:【{}】,调用海控仓库系统查询库存出现异常!", sku, e);
  1485. throw new ServiceException(String.format("sku:【%s】,调用海控仓库系统查询库存出现异常!", sku));
  1486. }
  1487. log.info("调用海控仓库系统,请求参数,门店:{}、商品条码:{}、商品编码:{},响应数据:{}", storeId, prodBarcode, sku, queryWarehouseStockResponse);
  1488. if (org.springframework.util.StringUtils.isEmpty(queryWarehouseStockResponse)) {
  1489. log.error("调用库存系统接口出现错误!返回结果为空!");
  1490. throw new ServiceException("调用库存系统接口出现错误!");
  1491. }
  1492. try {
  1493. wareQueryStockResponseDTO = (WareQueryStockResponseDTO) XmlUtils.toObject(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
  1494. } catch (Exception e) {
  1495. log.error("解析一步达库存系统响应数据出现错误!出现异常:", e);
  1496. }
  1497. if (Objects.isNull(wareQueryStockResponseDTO)) {
  1498. log.error("解析一步达库存系统响应数据出现错误!请求响应结果:{}", queryWarehouseStockResponse);
  1499. throw new ServiceException("解析一步达库存系统响应数据出现错误!");
  1500. }
  1501. if ("failure".equals(wareQueryStockResponseDTO.getFlag())) {
  1502. log.error("请求一步达库存系统返回错误响应!响应数据:{}", queryWarehouseStockResponse);
  1503. throw new ServiceException(String.format("请求一步达库存系统查询库存错误!响应数据:%s", wareQueryStockResponseDTO.getMessage()));
  1504. }
  1505. } else {
  1506. wareQueryStockResponseDTO = new WareQueryStockResponseDTO();
  1507. wareQueryStockResponseDTO.setCode("0");
  1508. wareQueryStockResponseDTO.setFlag("success");
  1509. wareQueryStockResponseDTO.setMessage("");
  1510. WareQueryStockResponseDTO.WareQueryStockResponseItemDTO wareQueryStockResponseItemDTO = new WareQueryStockResponseDTO.WareQueryStockResponseItemDTO();
  1511. wareQueryStockResponseItemDTO.setQuantity(3);
  1512. wareQueryStockResponseItemDTO.setItemCode(sku);
  1513. wareQueryStockResponseItemDTO.setProduceCode(prodBarcode);
  1514. List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> wareQueryStockResponseItemDTOS = new ArrayList<>();
  1515. wareQueryStockResponseItemDTOS.add(wareQueryStockResponseItemDTO);
  1516. wareQueryStockResponseDTO.setItems(wareQueryStockResponseItemDTOS);
  1517. }
  1518. // 校验库存
  1519. List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> items = wareQueryStockResponseDTO.getItems();
  1520. if (CollectionUtils.isEmpty(items)) {
  1521. log.error("查询商品时:【{}】,仓库不存在该商品!", prodBarcode);
  1522. throw new ServiceException(String.format("查询商品时:【%s】,仓库不存在该商品!", prodBarcode));
  1523. }
  1524. WareQueryStockResponseDTO.WareQueryStockResponseItemDTO itemDTO = items.get(0);
  1525. // 仓库可用库存
  1526. wareQuantity = itemDTO.getQuantity();
  1527. JedisUtil.hset(warehouseStockMapKey, wareStockNumberKey, String.valueOf(wareQuantity));
  1528. } else {
  1529. wareQuantity = Integer.parseInt(redisCacheWareQuantity);
  1530. }
  1531. // 保税仓库存 + 展销店库存 - 出区数 >= 购买数
  1532. if (!((wareQuantity + Integer.parseInt(stockNum) - exitRegionNumber) > sellVolume)) {
  1533. // 库存不足
  1534. log.error("商品条码:【{}】,sku:【{}】,门店库存:【{}】,保税仓库存:【{}】,出区数:【{}】,该商品仓库库存不足!", prodBarcode, sku, stockNum, wareQuantity, exitRegionNumber);
  1535. throw new ServiceException(String.format("商品条码:【%s】,sku:【%s】,门店库存:【%s】,保税仓库存:【%s】,出区数:【%s】,该商品仓库库存不足!", prodBarcode, sku, stockNum, wareQuantity, exitRegionNumber));
  1536. } else {
  1537. JedisUtil.hset(warehouseStockMapKey, wareStockNumberKey, String.valueOf(wareQuantity - sellVolume));
  1538. }
  1539. goods.setDiscountedPrice(new BigDecimal(0));
  1540. BigDecimal retailPrice = goods.getRetailPrice();
  1541. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1542. Map<String,Object> skuActivitiesMap = new HashMap<>();
  1543. // 计算税费
  1544. GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
  1545. BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1546. goods.setGoodstaxes(tax.toString());
  1547. goods.setSellVolume(1);
  1548. skuActivitiesMap.put("goods",goods);
  1549. return skuActivitiesMap;
  1550. }
  1551. @Override
  1552. public List<Map<String,Object>> selectSkuDetails(String prodBarcode, String storeId) {
  1553. /**
  1554. * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
  1555. */
  1556. List<GoodsDetailsDto> goodsList = goodsDao.queryGoodsSkuList(prodBarcode,storeId);
  1557. List<Map<String,Object>> mapList = new ArrayList<>();
  1558. if (goodsList == null) {
  1559. return null;
  1560. }
  1561. for(GoodsDetailsDto goods : goodsList){
  1562. mapList.add(selectGetSkuDetails(goods,prodBarcode,storeId));
  1563. }
  1564. return mapList;
  1565. }
  1566. public Map<String,Object> selectGetSkuDetails(GoodsDetailsDto goods,String prodBarcode, String storeId) {
  1567. /**
  1568. * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
  1569. */
  1570. goods.setDiscountedPrice(new BigDecimal(0));
  1571. BigDecimal retailPrice = goods.getRetailPrice();
  1572. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1573. Map<String,Object> skuActivitiesMap = new HashMap<>();
  1574. // 计算税费
  1575. GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
  1576. BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1577. goods.setGoodstaxes(tax.toString());
  1578. skuActivitiesMap.put("goods",goods);
  1579. return skuActivitiesMap;
  1580. }
  1581. /**
  1582. * 根据条形码查询商品
  1583. *
  1584. * @param barCode
  1585. * @return
  1586. */
  1587. @Override
  1588. public GoodsEntity queryByBarcode(String barCode) {
  1589. return goodsDao.queryByBarcode(barCode);
  1590. }
  1591. /**
  1592. * 根据sku查询商品
  1593. *
  1594. * @param sku
  1595. * @return
  1596. */
  1597. @Override
  1598. public GoodsEntity queryBySku(String sku) {
  1599. return goodsDao.queryBySku(sku);
  1600. }
  1601. /* @Override
  1602. @Transactional
  1603. public int uploadExcel(MultipartFile file) {
  1604. SysUserEntity user = ShiroUtils.getUserEntity();
  1605. List<String[]> list = ExcelImport.getExcelData(file);
  1606. // 取门店名称
  1607. StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
  1608. if (null == storeEntity) {
  1609. return 0;
  1610. }
  1611. //去除表头两行、底部合计
  1612. if (list != null && list.size() > 3) {
  1613. ProductStoreRelaEntity storeRelaEntity;
  1614. ProductEntity productEntity;
  1615. for (int i = 2; i < list.size() - 1; i++) {
  1616. String[] item = list.get(i);
  1617. String goodsSn = item[0];
  1618. productEntity = productDao.queryObjectBySn(goodsSn);
  1619. if (StringUtils.isNullOrEmpty(goodsSn)) {
  1620. continue;
  1621. }
  1622. if (null == productEntity || null == productEntity.getId()) {
  1623. continue;
  1624. }
  1625. storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
  1626. if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
  1627. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1628. storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
  1629. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1630. productStoreRelaDao.update(storeRelaEntity);
  1631. } else {
  1632. storeRelaEntity = new ProductStoreRelaEntity();
  1633. storeRelaEntity.setGoodsId(productEntity.getGoodsId());
  1634. storeRelaEntity.setProductId(productEntity.getId());
  1635. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1636. storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
  1637. storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
  1638. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1639. storeRelaEntity.setStoreId(storeEntity.getId());
  1640. productStoreRelaDao.save(storeRelaEntity);
  1641. }
  1642. }
  1643. }
  1644. return 1;
  1645. }*/
  1646. /**
  1647. * 全量拉取
  1648. */
  1649. @Override
  1650. public void syncOmsHsCodeTask() {
  1651. syncOmsHsCodeSegment(goodsDao.queryNonSyncOmsHsCodeSkuList());
  1652. }
  1653. /**
  1654. * 全量计算
  1655. */
  1656. @Override
  1657. public void syncGoodsRateTask() {
  1658. // 查询出所有商品
  1659. List<GoodsEntity> allGoodsList = goodsDao.queryAllList(null,null);
  1660. syncGoodsRate(allGoodsList);
  1661. }
  1662. /**
  1663. * 还原园区库存
  1664. *
  1665. * @param goodsEntities 数据
  1666. */
  1667. @Override
  1668. public int restoreBatch(List<GoodsEntity> goodsEntities) {
  1669. return goodsDao.restoreBatch(goodsEntities);
  1670. }
  1671. /**
  1672. * 查询库存及sku的信息,查询出来的库存是门店的库存
  1673. *
  1674. * @param prodBarcode 条码
  1675. * @param storeId 门店id
  1676. * @param sku sku
  1677. * @return 商品信息
  1678. */
  1679. @Override
  1680. public GoodsEntity queryGoodsStockByBarcodeAndStoreIdAndSku(String prodBarcode, Integer storeId, String sku) {
  1681. return goodsDao.queryGoodsStockByBarcodeAndStoreIdAndSku(prodBarcode, storeId, sku);
  1682. }
  1683. /**
  1684. * 查询库存及sku的信息,查询出来的库存是门店的库存
  1685. *
  1686. * @param queryGoodsVOList 查询条件,包含商品条码、sku、门店id
  1687. * @return 商品信息
  1688. */
  1689. @Override
  1690. public List<GoodsEntity> queryGoodsStockByQueryGoodsVoList(List<QueryGoodsVO> queryGoodsVOList) {
  1691. return goodsDao.queryGoodsStockByQueryGoodsVoList(queryGoodsVOList);
  1692. }
  1693. /**
  1694. * 选择拉取
  1695. * @param ids
  1696. */
  1697. @Override
  1698. public void syncOmsHsCodeGoode(List<Integer> ids) {
  1699. syncOmsHsCodeSegment(goodsDao.syncOmsHsCodeGoode(ids));
  1700. }
  1701. /**
  1702. * 选择计算
  1703. * @param ids
  1704. */
  1705. @Override
  1706. public void syncGoodsRateGoode(List<Integer> ids) {
  1707. syncGoodsRate(goodsDao.syncGoodsRateGoode(ids));
  1708. }
  1709. public void syncOmsHsCodeSegment(List<String> skuList) {
  1710. int segmentLimitSize = 300;
  1711. if (skuList.size() < segmentLimitSize) {
  1712. this.syncOmsHsCode(skuList);
  1713. } else {
  1714. int segmentSize = skuList.size() % segmentLimitSize == 0 ? skuList.size() / segmentLimitSize : (skuList.size() / segmentLimitSize) + 1;
  1715. List<List<String>> segment = new ArrayList<>();
  1716. for (int i = 0; i < segmentSize; i++) {
  1717. int end = (i == segmentSize - 1) ? skuList.size() : i * segmentLimitSize + segmentLimitSize;
  1718. segment.add(new ArrayList<>(skuList.subList(i * segmentLimitSize, end)));
  1719. }
  1720. for (List<String> tmp : segment) {
  1721. this.syncOmsHsCode(tmp);
  1722. }
  1723. }
  1724. }
  1725. @Transactional
  1726. public void syncOmsHsCode(List<String> skuList) {
  1727. if (Objects.nonNull(skuList) && skuList.size()>0){
  1728. String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
  1729. //String result = HttpUtil.get("http://183.3.221.143:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
  1730. //String result = HttpUtil.get("http://127.0.0.1:8080/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
  1731. Map<String,Map> map = JSON.parseObject(result, Map.class);
  1732. for (String sku : skuList) {
  1733. Map skuInfoMap = map.get(sku);
  1734. if (Objects.nonNull(skuInfoMap)){
  1735. String hsCodeName = (String) skuInfoMap.get("cusGoodsName");
  1736. String hsCode = (String) skuInfoMap.get("cusGoodsCode");
  1737. String prodName = (String) skuInfoMap.get("prodName");
  1738. String prodRecordName = (String) skuInfoMap.get("prodRecordName");
  1739. BigDecimal impConsumTaxRate = (BigDecimal) skuInfoMap.get("impConsumTaxRate");
  1740. BigDecimal valueAddedTaxRate = (BigDecimal) skuInfoMap.get("valueAddedTaxRate");
  1741. BigDecimal legalUnit1Qty = (BigDecimal) skuInfoMap.get("legalUnit1Qty");
  1742. BigDecimal legalUnit2Qty = (BigDecimal) skuInfoMap.get("legalUnit2Qty");
  1743. BigDecimal cosmThresholdValue = (BigDecimal) skuInfoMap.get("cosmThresholdValue");
  1744. if (StringUtils.isNotEmpty(hsCodeName) && StringUtils.isNotEmpty(hsCode)){
  1745. List<GoodsEntity> goodsEntityList = goodsDao.queryListBySku(sku);
  1746. if (Objects.nonNull(goodsEntityList) && goodsEntityList.size()>0){
  1747. for (GoodsEntity goodsEntity : goodsEntityList) {
  1748. goodsEntity.setHsCode(hsCode);
  1749. goodsEntity.setHsCodeName(hsCodeName);
  1750. goodsEntity.setImpConsumTaxRate(impConsumTaxRate);
  1751. goodsEntity.setValueAddedTaxRate(valueAddedTaxRate);
  1752. goodsEntity.setIsSyncHsCode("1");
  1753. goodsEntity.setLegalUnit1Qty(legalUnit1Qty);
  1754. goodsEntity.setProdName(prodName);
  1755. goodsEntity.setProdRecordName(prodRecordName);
  1756. goodsEntity.setLegalUnit2Qty(legalUnit2Qty);
  1757. goodsEntity.setCosmThresholdValue(cosmThresholdValue);
  1758. goodsDao.update(goodsEntity);
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. @Transactional
  1767. public void syncGoodsRate(List<GoodsEntity> allGoodsList) {
  1768. String storeId = "163"; // 市场部说所有门店价格一致,并且活动一致,可直接取其中一个门店价格进行计算税率
  1769. for (GoodsEntity goodsEntity : allGoodsList) {
  1770. // 同步过海关商品编码才可以算税率
  1771. if ("1".equals(goodsEntity.getIsSyncHsCode())) {
  1772. // Map<String, Object> goodsDetailMap = calculateGoodsDetail(goodsEntity.getProdBarcode(), storeId);
  1773. // if (Objects.nonNull(goodsDetailMap)) {
  1774. // GoodsDetailsDto goods = (GoodsDetailsDto) goodsDetailMap.get("goods");
  1775. // 顾客给的钱 就是税后价
  1776. // BigDecimal actualPaymentAmount = goods.getActualPaymentAmount(); //随便拿一个门店的当前时间的价格,如果有活动价会使用活动价
  1777. // BigDecimal calculateTax = CalculateTax.calculateTax(goodsEntity, actualPaymentAmount);// 税费
  1778. // BigDecimal goodsRate = calculateTax.divide(actualPaymentAmount, 4, BigDecimal.ROUND_HALF_UP);
  1779. BigDecimal goodsRate =CalculateTax.calculateGoodsRate(goodsEntity);
  1780. goodsEntity.setGoodsRate(goodsRate);
  1781. goodsEntity.setIsSyncHsCode("0");
  1782. goodsDao.update(goodsEntity);
  1783. // }
  1784. }
  1785. }
  1786. }
  1787. @Override
  1788. public void updateTaxErrorRecord(TaxErrorRecordEntity taxErrorRecordEntity) {
  1789. taxErrorRecordDao.update(taxErrorRecordEntity);
  1790. }
  1791. @Override
  1792. public void insertTaxErrorRecord(TaxErrorRecordEntity taxErrorRecordEntity) {
  1793. taxErrorRecordDao.save(taxErrorRecordEntity);
  1794. }
  1795. @Override
  1796. public void updateByEntity(GoodsEntity updateGoods) {
  1797. goodsDao.update(updateGoods);
  1798. }
  1799. @Override
  1800. public void checkGoodsPrice(SysUserEntity user) {
  1801. Map<String, BigDecimal> hsCodeMap = CalculateTax.hsCodeMap;
  1802. Set<String> hdCodeSet = hsCodeMap.keySet();
  1803. List<Map<String,String>> errorPriceSkuList = new LinkedList<>();
  1804. // 保存各种异常价格对象集合
  1805. List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities = new LinkedList<>();
  1806. // 查询所有特殊化妆品的商品
  1807. List<GoodsEntity> queryGoodsDetails = goodsDao.querySpecialCosmetics(hdCodeSet);
  1808. for (GoodsEntity goodsEntity : queryGoodsDetails) {
  1809. calculateShopPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
  1810. calculateDailyPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
  1811. calculeatePromotion(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
  1812. }
  1813. if(shopErrorPriceRecordEntities.size() != 0){
  1814. shopErrorPriceRecordService.saveBatch(shopErrorPriceRecordEntities);
  1815. }
  1816. }
  1817. @Override
  1818. public List<GoodsEntity> queryAllList(Integer page,Integer pageSize) {
  1819. return goodsDao.queryAllList(page,pageSize);
  1820. }
  1821. private void calculeatePromotion(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
  1822. String prodBarcode = goods.getProdBarcode();
  1823. String storeId = goods.getStoreId()+"";
  1824. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1825. /**
  1826. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1827. * 参数: 当前时间 门店id
  1828. */
  1829. MkActivitiesPromotionEntity promotionEntity = promotionService.queryByDateAndBarcode(storeId,format.format(new Date()),"lscx",prodBarcode);
  1830. // 如果该商品存在临时促销,直接替换活动价格
  1831. if(promotionEntity == null){
  1832. return ;
  1833. }
  1834. goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
  1835. goods.setRetailPrice(promotionEntity.getActivityPrice());
  1836. goods.setActivity("临时促销");
  1837. try {
  1838. CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1839. } catch (Exception e) {
  1840. ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
  1841. shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
  1842. shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
  1843. shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
  1844. shopErrorPriceRecordEntity.setPriceType(3); // 3 是临时促销
  1845. shopErrorPriceRecordEntity.setSku(goods.getSku());
  1846. shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
  1847. shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
  1848. shopErrorPriceRecordEntity.setCheckTime(new Date());
  1849. shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
  1850. shopErrorPriceRecordEntity.setCreateTime(new Date());
  1851. shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
  1852. if(e.getMessage().contains("-")){
  1853. String suggestPrice = e.getMessage().split("-")[0];
  1854. String highestPrice = e.getMessage().split("-")[1];
  1855. String lowestPrice = e.getMessage().split("-")[2];
  1856. shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
  1857. shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
  1858. shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
  1859. }
  1860. shopErrorPriceRecordEntity.setMkaId(promotionEntity.getMkaId());
  1861. shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
  1862. }
  1863. }
  1864. private void calculateDailyPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
  1865. String prodBarcode = goods.getProdBarcode();
  1866. String storeId = goods.getStoreId()+"";
  1867. /**
  1868. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1869. * 参数: 当前时间 门店id
  1870. */
  1871. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1872. /**
  1873. * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
  1874. */
  1875. MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByDateAndBarcode(storeId,format.format(new Date()),"rchd",prodBarcode);
  1876. if(dailyActivitiesEntity == null){
  1877. return ;
  1878. }
  1879. goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
  1880. goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
  1881. goods.setActivity("日常活动");
  1882. // 计算税费
  1883. try {
  1884. CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1885. } catch (Exception e) {
  1886. // 记录有异常的sku
  1887. ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
  1888. shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
  1889. shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
  1890. shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
  1891. shopErrorPriceRecordEntity.setPriceType(2); // 2 是日常活动
  1892. shopErrorPriceRecordEntity.setSku(goods.getSku());
  1893. shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
  1894. shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
  1895. shopErrorPriceRecordEntity.setCheckTime(new Date());
  1896. shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
  1897. shopErrorPriceRecordEntity.setCreateTime(new Date());
  1898. shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
  1899. if(e.getMessage().contains("-")){
  1900. String suggestPrice = e.getMessage().split("-")[0];
  1901. String highestPrice = e.getMessage().split("-")[1];
  1902. String lowestPrice = e.getMessage().split("-")[2];
  1903. shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
  1904. shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
  1905. shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
  1906. }
  1907. shopErrorPriceRecordEntity.setMkaId(dailyActivitiesEntity.getMkaId());
  1908. shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
  1909. }
  1910. }
  1911. private void calculateShopPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
  1912. goods.setDiscountedPrice(new BigDecimal(0));
  1913. BigDecimal retailPrice = goods.getRetailPrice();
  1914. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1915. // 计算税费
  1916. try {
  1917. CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1918. } catch (Exception e) {
  1919. // 记录有异常的sku
  1920. ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
  1921. shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
  1922. shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
  1923. shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
  1924. shopErrorPriceRecordEntity.setPriceType(1); // 1 门店商品价格
  1925. shopErrorPriceRecordEntity.setSku(goods.getSku());
  1926. shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
  1927. shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
  1928. shopErrorPriceRecordEntity.setCheckTime(new Date());
  1929. shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
  1930. shopErrorPriceRecordEntity.setCreateTime(new Date());
  1931. shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
  1932. if(e.getMessage().contains("-")){
  1933. String suggestPrice = e.getMessage().split("-")[0];
  1934. String highestPrice = e.getMessage().split("-")[1];
  1935. String lowestPrice = e.getMessage().split("-")[2];
  1936. shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
  1937. shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
  1938. shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
  1939. }
  1940. shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
  1941. }
  1942. }
  1943. /**
  1944. * 根据产品条码和sku查询保税展示补货的商品
  1945. *
  1946. * @param prodBarcode 商品条码
  1947. * @param sku sku
  1948. * @return 商品信息
  1949. */
  1950. @Override
  1951. public GoodsEntity queryGoodsInfoByProductBarcodeAndSku(String prodBarcode, String sku) {
  1952. return goodsDao.queryGoodsInfoByProductBarcodeAndSku(prodBarcode, sku);
  1953. }
  1954. @Override
  1955. public int updateStockNumberByProductCodeAndSku(GoodsEntity goodsEntity) {
  1956. return goodsDao.updateStockNumberByProductCodeAndSku(goodsEntity);
  1957. }
  1958. }