GoodsServiceImpl.java 113 KB

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