GoodsServiceImpl.java 115 KB

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