GoodsServiceImpl.java 133 KB

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