1
0

GoodsServiceImpl.java 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  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. @Override
  588. public void updateForImgUrl(GoodsEntity goodsEntity){
  589. // 修改商品
  590. goodsDao.update(goodsEntity);
  591. }
  592. @Override
  593. public List<GoodsEntity> queryByName(String storeId, String goodsName) {
  594. return goodsDao.queryByName(storeId, goodsName);
  595. }
  596. /**
  597. * 更新门店商品是否有修改字段
  598. * @param storeId
  599. * @param user
  600. */
  601. private void updateLoadGoodsByStoreId(Long storeId, SysUserEntity user){
  602. List<MerchUserEntity> list = merchUserDao.queryMerchUserByLoadGoods(storeId);
  603. for(MerchUserEntity entity : list) {
  604. entity.setIsLoadGoods("1");
  605. entity.setModerSn(user.getUsername());
  606. entity.setStoreId(Integer.valueOf(String.valueOf(storeId)));
  607. merchUserDao.updateStoreLoadGoodsById(entity);
  608. }
  609. }
  610. @Override
  611. public int delete(Integer id) {
  612. SysUserEntity user = ShiroUtils.getUserEntity();
  613. GoodsEntity goodsEntity = goodsDao.queryObject(id);
  614. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_1.getItem()));
  615. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  616. goodsEntity.setUpdateUserId(user.getUserId());
  617. goodsEntity.setUpdateTime(new Date());
  618. Map params = Maps.newHashMap();
  619. params.put("goodsId", id);
  620. List<GoodsGroupEntity> groupVos = goodsGroupDao.queryList(params);
  621. if (null != groupVos && groupVos.size() > 0) {
  622. for (GoodsGroupEntity groupVo : groupVos) {
  623. groupVo.setOpenStatus(3);
  624. goodsGroupDao.update(groupVo);
  625. }
  626. }
  627. return goodsDao.update(goodsEntity);
  628. }
  629. @Override
  630. @Transactional
  631. public int deleteBatch(Integer[] ids) {
  632. int result = 0;
  633. for (Integer id : ids) {
  634. result += delete(id);
  635. }
  636. return result;
  637. }
  638. @Override
  639. @Transactional
  640. public int back(Integer[] ids) {
  641. SysUserEntity user = ShiroUtils.getUserEntity();
  642. int result = 0;
  643. for (Integer id : ids) {
  644. GoodsEntity goodsEntity = queryObject(id);
  645. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  646. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  647. goodsEntity.setUpdateUserId(user.getUserId());
  648. goodsEntity.setUpdateTime(new Date());
  649. result += goodsDao.update(goodsEntity);
  650. }
  651. return result;
  652. }
  653. @Override
  654. public int enSale(Integer id) {
  655. SysUserEntity user = ShiroUtils.getUserEntity();
  656. GoodsEntity goodsEntity = queryObject(id);
  657. if (1 == goodsEntity.getIsOnSale()) {
  658. throw new RRException("此商品已处于上架状态!");
  659. }
  660. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  661. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  662. goodsEntity.setUpdateUserId(user.getUserId());
  663. goodsEntity.setUpdateTime(new Date());
  664. return goodsDao.update(goodsEntity);
  665. }
  666. @Override
  667. public int unSale(Integer id) {
  668. SysUserEntity user = ShiroUtils.getUserEntity();
  669. GoodsEntity goodsEntity = queryObject(id);
  670. if (0 == goodsEntity.getIsOnSale()) {
  671. throw new RRException("此商品已处于下架状态!");
  672. }
  673. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  674. goodsEntity.setUpdateUserId(user.getUserId());
  675. goodsEntity.setUpdateTime(new Date());
  676. return goodsDao.update(goodsEntity);
  677. }
  678. @Override
  679. public int enSaleBatch(Integer[] ids) {
  680. int result = 0;
  681. SysUserEntity user = ShiroUtils.getUserEntity();
  682. for (Integer id : ids) {
  683. GoodsEntity goodsEntity = queryObject(id);
  684. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  685. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  686. goodsEntity.setUpdateUserId(user.getUserId());
  687. goodsEntity.setUpdateTime(new Date());
  688. result += goodsDao.update(goodsEntity);
  689. }
  690. return result;
  691. }
  692. @Override
  693. public int unSaleBatch(Integer[] ids) {
  694. int result = 0;
  695. SysUserEntity user = ShiroUtils.getUserEntity();
  696. for (Integer id : ids) {
  697. GoodsEntity goodsEntity = queryObject(id);
  698. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  699. goodsEntity.setUpdateUserId(user.getUserId());
  700. goodsEntity.setUpdateTime(new Date());
  701. result += goodsDao.update(goodsEntity);
  702. }
  703. return result;
  704. }
  705. @Override
  706. @Transactional
  707. public int uploadExcel(List<GoodsDto> goodsEntityList,int exportDataType) {
  708. SysUserEntity user = ShiroUtils.getUserEntity();
  709. String merchSn = user.getMerchSn();
  710. boolean isFail = false;
  711. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  712. // failSuppGoodsSnList = new ArrayList<>(),
  713. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
  714. // failProdbarGoodsSnList = new ArrayList<>(),
  715. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  716. // failCateL2GoodsSnList = new ArrayList<>(),
  717. // failCateGoodsSnList = new ArrayList<>(),
  718. // failBrandGoodsSnList = new ArrayList<>(),
  719. // failFreightGoodsSnList = new ArrayList<>(),
  720. failMerchUserGoodsSnList = new ArrayList<>();
  721. List<String> failGoodsSnList = new ArrayList<>();
  722. List<String> failGoodsTypeList = new ArrayList<>();
  723. // List<String> failFreightList = new ArrayList<>();
  724. // 定义需要批量插入的list
  725. List<ProductEntity> insertProductList = new LinkedList<>();
  726. List<GoodsSpecificationEntity> insertSpecificationList = new LinkedList<>();
  727. List<MngChangeEntity> insertMngChangeList = new LinkedList<>();
  728. List<GoodsEntity> insertGoodsList = new LinkedList<>();
  729. List<SupplierEntity> insertSupplierList = new LinkedList<>();
  730. // 定义需要批量修改的list
  731. List<ProductEntity> updateProductList = new LinkedList<>();
  732. List<GoodsSpecificationEntity> updateSpecificationList = new LinkedList<>();
  733. List<GoodsEntity> updateGoodsList = new LinkedList<>();
  734. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  735. for (int i = 0; i < goodsEntityList.size(); i++) {
  736. GoodsDto goodsDto = goodsEntityList.get(i);
  737. GoodsEntity goodsEntity = new GoodsEntity();
  738. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  739. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  740. builder.put("goodsSn", "商品编码");
  741. builder.put("thirdPartyMerchCode", "第三方商户代码");
  742. // builder.put("categoryName", "商品分类");
  743. builder.put("goodsBizType", "货品业务类型");
  744. builder.put("name", "商品名称");
  745. // builder.put("brandName", "商品品牌名称");
  746. // builder.put("defaultFreight", "运费");
  747. builder.put("isOnSaleStr", "上架");
  748. builder.put("goodsUnit", "商品单位");
  749. builder.put("isHotStr", "热销");
  750. builder.put("prodBarcode", "产品条码");
  751. // builder.put("marketPrice", "市场价");
  752. // builder.put("retailPrice", "零售价");
  753. builder.put("supplierName", "供应商");
  754. builder.put("goodsNumber", "商品总库存");
  755. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  756. if (Integer.valueOf(r.get("code").toString()) != 0) {
  757. throw new RRException(r.get("msg").toString());
  758. } else {
  759. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  760. // 海关信息,普通货物可不添加
  761. builder.put("goodsRate", "商品税率");
  762. builder.put("sku", "SKU");
  763. builder.put("brand", "产品品牌");
  764. builder.put("unitName", "计量单位");
  765. builder.put("oriCntName", "原产国");
  766. builder.put("cusGoodsCode", "海关商品编码");
  767. builder.put("ciqProdModel", "国检规格型号");
  768. builder.put("cusDeclEle", "海关申报要素");
  769. builder.put("cusRecCode", "海关备案编号");
  770. }
  771. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  772. if (Integer.valueOf(r.get("code").toString()) != 0) {
  773. throw new RRException(r.get("msg").toString());
  774. }
  775. }
  776. //业务类型校验
  777. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  778. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  779. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  780. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  781. isFail = true;
  782. failTypeGoodsSnList.add(goodsDto.getSku());
  783. }
  784. }
  785. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  786. if(thirdMerchantBizEntity != null){
  787. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  788. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  789. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  790. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  791. isFail = true;
  792. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  793. }
  794. }
  795. }else{//商户不存在
  796. isFail = true;
  797. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  798. }
  799. //校验商品信息是否已存在
  800. Map<String, Object> map = new HashMap<>();
  801. map.put("isSame", "true");
  802. map.put("sku", goodsDto.getSku());
  803. map.put("goodsSn", goodsDto.getGoodsSn());
  804. map.put("goodsBizType", goodsDto.getGoodsBizType());
  805. List<GoodsEntity> list = querySame(map);
  806. if (list != null && list.size() != 0) {
  807. // isFail = true;
  808. if(goodsDto.getSku()!=null) {
  809. failSameSkuList.add(goodsDto.getSku());
  810. }
  811. failGoodsSnList.add(goodsDto.getGoodsSn());
  812. failGoodsTypeList.add(goodsDto.getGoodsBizType());
  813. }
  814. //校验产品条码是否存在
  815. // List<GoodsEntity> prodbarGoods = goodsDao.queryObjectByProdBarcode(goodsDto.getProdBarcode(),merchSn,null);
  816. // if(prodbarGoods != null && prodbarGoods.size() > 0){
  817. // isFail = true;
  818. // failProdbarGoodsSnList.add(goodsDto.getGoodsSn());
  819. // }else{
  820. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  821. // }
  822. //热销商品校验
  823. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  824. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  825. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  826. isFail = true;
  827. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  828. }
  829. }
  830. if(thirdMerchantBizEntity != null) {
  831. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  832. if (supplierEntity == null) {
  833. //导入没有查到供货商,执行新增
  834. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  835. // if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
  836. // isFail = true;
  837. // failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  838. // }
  839. supplierEntity = new SupplierEntity();
  840. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  841. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  842. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  843. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  844. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  845. supplierEntity.setIsShow("0");
  846. // TODO 这里改成批量插入 SupplierEntity
  847. insertSupplierList.add(supplierEntity);
  848. // supplierDao.save(supplierEntity);
  849. // supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  850. goodsEntity.setSupplierId(supplierEntity.getId());
  851. } else {
  852. goodsEntity.setSupplierId(supplierEntity.getId());
  853. }
  854. }
  855. //商品配置校验
  856. /*CategoryEntity categoryEntity = categoryDao.queryObjectByName(goodsDto.getCategoryName(),goodsDto.getMerchSn());
  857. if(categoryEntity==null){
  858. isFail = true;
  859. failCateGoodsSnList.add(goodsDto.getGoodsSn());
  860. }else{
  861. if(categoryEntity.getLevel().equalsIgnoreCase("L2")) {
  862. goodsEntity.setCategoryId(categoryEntity.getId());
  863. goodsEntity.setAttributeCategory(categoryEntity.getParentId());
  864. }else{
  865. isFail = true;
  866. failCateL2GoodsSnList.add(goodsDto.getGoodsSn());
  867. }
  868. }
  869. BrandEntity brandEntity = brandDao.queryObjectByName(goodsDto.getBrandName(),goodsDto.getMerchSn());
  870. if (brandEntity == null) {
  871. isFail = true;
  872. failBrandGoodsSnList.add(goodsDto.getGoodsSn());
  873. } else {
  874. goodsEntity.setBrandId(brandEntity.getId());
  875. }
  876. //运费
  877. FreightEntity freightEntity = freightDao.queryObjectByName(goodsDto.getDefaultFreight(),goodsDto.getMerchSn());
  878. if(freightEntity==null){
  879. isFail = true;
  880. failFreightGoodsSnList.add(goodsDto.getGoodsSn());
  881. failFreightList.add(goodsDto.getDefaultFreight());
  882. }else {
  883. goodsEntity.setFreightId(freightEntity.getId());
  884. }*/
  885. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  886. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  887. if (sysCusUnitCodeEntity == null) {
  888. isFail = true;
  889. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  890. } else {
  891. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  892. }
  893. //原产国
  894. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  895. if (sysCusNationCodeEntity == null) {
  896. isFail = true;
  897. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  898. } else {
  899. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  900. }
  901. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  902. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  903. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  904. }else{
  905. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())));
  906. }
  907. }
  908. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  909. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  910. // goodsEntity.setRetailPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getRetailPrice())));
  911. // goodsEntity.setMarketPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getMarketPrice())));
  912. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  913. goodsEntity.setSku(goodsDto.getSku());
  914. goodsEntity.setName(goodsDto.getName());
  915. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  916. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  917. goodsEntity.setBrand(goodsDto.getBrand());
  918. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  919. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  920. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  921. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  922. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  923. goodsEntity.setIsNew(0);
  924. goodsEntity.setUpdateUserId(user.getUserId());
  925. goodsEntity.setAddTime(new Date());
  926. goodsEntity.setCreateTime(new Date());
  927. goodsEntity.setUpdateTime(new Date());
  928. goodsEntity.setModTime(new Date());
  929. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  930. goodsEntity.setPlu(goodsDto.getPlu());
  931. goodsEntity.setMychemId(goodsDto.getMychemId());
  932. if(!isFail){
  933. GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
  934. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  935. mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
  936. mngChangeEntity.setChangeReason("更新商户商品总库存");
  937. mngChangeEntity.setCreateTime(new Date());
  938. mngChangeEntity.setModTime(new Date());
  939. mngChangeEntity.setCreaterSn(user.getUsername());
  940. mngChangeEntity.setModerSn(user.getUsername());
  941. mngChangeEntity.setIsValid(0);
  942. mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
  943. if(goods!=null) {// 修改商品
  944. mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
  945. mngChangeEntity.setValidNum(goods.getGoodsNumber() + Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  946. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  947. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  948. mngChangeEntity.setGoodsId(goods.getId().intValue());
  949. goodsEntity.setId(goods.getId());
  950. goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
  951. // TODO 这里改成批量修改 GoodsEntity
  952. updateGoodsList.add(goodsEntity);
  953. // goodsDao.update(goodsEntity);
  954. }else{
  955. mngChangeEntity.setOriginalNum(0);//原库存数
  956. mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  957. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  958. mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
  959. // TODO 这里改成批量插入 GoodsEntity
  960. goodsDao.save(goodsEntity);
  961. insertGoodsList.add(goodsEntity);
  962. mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
  963. }
  964. // TODO 这里改成批量插入 MngChangeEntity
  965. // mngChangeDao.save(mngChangeEntity);
  966. insertMngChangeList.add(mngChangeEntity);
  967. // // 保税商品修改各个门店商品价格
  968. // if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  969. // List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsDto.getId());
  970. // if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  971. // for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
  972. // productStoreRela.setMarketPrice(goodsEntity.getMarketPrice());
  973. // productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
  974. // productStoreRelaDao.update(productStoreRela);
  975. // }
  976. // }
  977. // }
  978. // 修改产品
  979. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  980. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  981. // 普通货物暂不添加商品规格
  982. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  983. // 添加商品规格
  984. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  985. if(specificationEntity == null) {
  986. goodsSpecification.setGoodsId(goodsEntity.getId());
  987. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  988. goodsSpecification.setSpecificationId(1);
  989. // TODO 这里改成批量插入 GoodsSpecificationEntity
  990. goodsSpecificationDao.save(goodsSpecification);
  991. // insertSpecificationList.add(goodsSpecification);
  992. }else {
  993. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  994. goodsSpecification.setId(specificationEntity.getId());
  995. // TODO 这里改成批量更新 GoodsSpecificationEntity
  996. // goodsSpecificationDao.update(goodsSpecification);
  997. updateSpecificationList.add(goodsSpecification);
  998. }
  999. if(product == null){
  1000. product = new ProductEntity();
  1001. product.setGoodsSn(goodsDto.getGoodsSn());
  1002. product.setGoodsId(goodsEntity.getId());
  1003. product.setGoodsDefault(0);
  1004. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  1005. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1006. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1007. // TODO 这里改成批量插入 ProductEntity
  1008. insertProductList.add(product);
  1009. // productDao.save(product);
  1010. }else{
  1011. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1012. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1013. // TODO 这里改成批量更新 ProductEntity
  1014. updateProductList.add(product);
  1015. // productDao.update(product);
  1016. }
  1017. }
  1018. }
  1019. }
  1020. // 批量插入数据
  1021. if(insertProductList != null && insertProductList.size() > 0) {
  1022. // 长度限制,如果大于50,就分多次插入
  1023. if(insertProductList.size() > 50){
  1024. List<List<ProductEntity>> partition = Lists.partition(insertProductList, 50);
  1025. for (List<ProductEntity> productEntities : partition) {
  1026. productDao.saveBatch(productEntities);
  1027. }
  1028. }else{
  1029. productDao.saveBatch(insertProductList);;
  1030. }
  1031. }
  1032. // if(insertSpecificationList != null && insertSpecificationList.size() > 0) {
  1033. // goodsSpecificationDao.saveBatch(insertSpecificationList);
  1034. // }
  1035. if(insertMngChangeList != null && insertMngChangeList.size() > 0 ){
  1036. if(insertMngChangeList.size() > 50){
  1037. List<List<MngChangeEntity>> partition = Lists.partition(insertMngChangeList, 50);
  1038. for (List<MngChangeEntity> mngChangeEntities : partition) {
  1039. mngChangeDao.saveBatch(mngChangeEntities);
  1040. }
  1041. }else{
  1042. mngChangeDao.saveBatch(insertMngChangeList);
  1043. }
  1044. }
  1045. // if(insertGoodsList != null && insertGoodsList.size() > 0 ){
  1046. // goodsDao.saveBatch(insertGoodsList);
  1047. // }
  1048. if(insertSupplierList != null && insertSupplierList.size() > 0 ){
  1049. if(insertSupplierList.size() > 50){
  1050. List<List<SupplierEntity>> partition = Lists.partition(insertSupplierList, 50);
  1051. for (List<SupplierEntity> supplierEntities : partition) {
  1052. supplierDao.saveBatch(supplierEntities);
  1053. }
  1054. }else{
  1055. supplierDao.saveBatch(insertSupplierList);
  1056. }
  1057. }
  1058. // 批量更新数据
  1059. if(updateProductList != null && updateProductList.size() > 0 ){
  1060. if(updateProductList.size() > 50){
  1061. List<List<ProductEntity>> partition = Lists.partition(updateProductList, 50);
  1062. for (List<ProductEntity> productEntities : partition) {
  1063. productDao.updateBatch(productEntities);
  1064. }
  1065. }else{
  1066. productDao.updateBatch(updateProductList);
  1067. }
  1068. }
  1069. if(updateSpecificationList != null && updateSpecificationList.size() > 0 ){
  1070. if(updateSpecificationList.size() > 50){
  1071. List<List<GoodsSpecificationEntity>> partition = Lists.partition(updateSpecificationList, 50);
  1072. for (List<GoodsSpecificationEntity> goodsSpecificationEntities : partition) {
  1073. goodsSpecificationDao.updateBatch(goodsSpecificationEntities);
  1074. }
  1075. }else{
  1076. goodsSpecificationDao.updateBatch(updateSpecificationList);
  1077. }
  1078. }
  1079. if(updateGoodsList != null && updateGoodsList.size() > 0 ){
  1080. if(updateGoodsList.size() > 50){
  1081. List<List<GoodsEntity>> partition = Lists.partition(updateGoodsList, 50);
  1082. for (List<GoodsEntity> goodsEntities : partition) {
  1083. goodsDao.updateBatch(goodsEntities);
  1084. }
  1085. }else{
  1086. goodsDao.updateBatch(updateGoodsList);
  1087. }
  1088. }
  1089. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  1090. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  1091. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  1092. exportExceptionDataEntity.setCreateTime(new Date());
  1093. exportExceptionDataEntity.setModTime(new Date());
  1094. exportExceptionDataEntity.setMerchSn(merchSn);
  1095. exportExceptionDataEntity.setStoreId(user.getStoreId());
  1096. if(exportDataType == 1) {
  1097. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  1098. }else{
  1099. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  1100. }
  1101. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  1102. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  1103. goodsUtils.save(exportExceptionDataEntity);
  1104. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1105. }
  1106. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  1107. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  1108. goodsUtils.save(exportExceptionDataEntity);
  1109. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1110. }
  1111. // if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  1112. // if(failSameSkuList.size()>0) {
  1113. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1114. // failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  1115. // goodsUtils.save(exportExceptionDataEntity);
  1116. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1117. // }else{
  1118. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1119. // failGoodsTypeList + "】的商品信息");
  1120. // goodsUtils.save(exportExceptionDataEntity);
  1121. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1122. // }
  1123. // }
  1124. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  1125. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  1126. goodsUtils.save(exportExceptionDataEntity);
  1127. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1128. }
  1129. // if(failProdbarGoodsSnList != null && failProdbarGoodsSnList.size() > 0){
  1130. // exportExceptionDataEntity.setExportExceptionData("不能有重复的产品条码信息!请检查商品编码【"+failProdbarGoodsSnList+"】的商品产品条码信息");
  1131. // goodsUtils.save(exportExceptionDataEntity);
  1132. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1133. // }
  1134. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  1135. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  1136. goodsUtils.save(exportExceptionDataEntity);
  1137. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1138. }
  1139. // if(failCateGoodsSnList != null && failCateGoodsSnList.size() > 0){
  1140. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中维护,商品分类与商户信息对应,请检查该商品商户信息下的分类是否维护,不存在的商品编码【"+failCateGoodsSnList+"】");
  1141. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1142. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1143. // }
  1144. // if(failCateL2GoodsSnList != null && failCateL2GoodsSnList.size() > 0){
  1145. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中查看,商品分类必须为二级分类,不存在的商品编码【"+failCateL2GoodsSnList+"】");
  1146. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1147. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1148. // }
  1149. // if(failBrandGoodsSnList != null && failBrandGoodsSnList.size() > 0){
  1150. // exportExceptionDataEntity.setExportExceptionData("品牌信息请在商城配置》品牌制造商中维护,品牌与商户信息对应,请检查该商品商户信息下的品牌是否维护,不存在的商品编码【" + failBrandGoodsSnList + "】");
  1151. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1152. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1153. // }
  1154. // if(failFreightGoodsSnList != null && failFreightGoodsSnList.size() > 0){
  1155. // exportExceptionDataEntity.setExportExceptionData("运费信息请在商城配置》运费模板中维护,运费与商户信息对应,请检查该商品商户信息下的运费是否维护,不存在的商品编码【"+failFreightGoodsSnList+"】,运费【"+failFreightList+"】");
  1156. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1157. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1158. // }
  1159. // if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  1160. // exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  1161. // goodsUtils.save(exportExceptionDataEntity);
  1162. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1163. // }
  1164. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1165. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1166. goodsUtils.save(exportExceptionDataEntity);
  1167. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1168. }
  1169. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1170. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1171. goodsUtils.save(exportExceptionDataEntity);
  1172. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1173. }
  1174. // 将插入的商品和更新的商品放到一个list中
  1175. List<GoodsEntity> goodsEntities = new LinkedList<>();
  1176. goodsEntities.addAll(insertGoodsList);
  1177. goodsEntities.addAll(updateGoodsList);
  1178. List<KtoEccsEntity> ktoEccsEntities = new LinkedList<>();
  1179. if(goodsEntities.size() > 0){
  1180. for (GoodsEntity goodsEntity : goodsEntities) {
  1181. KtoEccsEntity ktoEccsEntity = new KtoEccsEntity();
  1182. ktoEccsEntity.setRequestData(JSON.toJSONString(goodsEntity));
  1183. ktoEccsEntity.setRequestType("01");
  1184. ktoEccsEntity.setSendStatus("00");
  1185. ktoEccsEntity.setCreaterSn(user.getUserId()+"");
  1186. ktoEccsEntity.setCreateTime(new Date());
  1187. ktoEccsEntities.add(ktoEccsEntity);
  1188. }
  1189. }
  1190. if(ktoEccsEntities.size() > 0){
  1191. if(ktoEccsEntities.size() > 50){
  1192. List<List<KtoEccsEntity>> partition = Lists.partition(ktoEccsEntities, 50);
  1193. for (List<KtoEccsEntity> ktoEccs : partition) {
  1194. ktoEccsService.saveBatch(ktoEccs);
  1195. }
  1196. }else{
  1197. ktoEccsService.saveBatch(ktoEccsEntities);
  1198. }
  1199. }
  1200. }else{
  1201. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  1202. }
  1203. return 1;
  1204. }
  1205. @Override
  1206. @Transactional
  1207. public int uploadExcelByCover(List<GoodsDto> goodsEntityList, int exportDataType) {
  1208. SysUserEntity user = ShiroUtils.getUserEntity();
  1209. String merchSn = user.getMerchSn();
  1210. boolean isFail = false;
  1211. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  1212. failSuppGoodsSnList = new ArrayList<>(),
  1213. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
  1214. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  1215. failMerchUserGoodsSnList = new ArrayList<>();
  1216. // List<String> failGoodsSnList = new ArrayList<>();
  1217. List<String> failGoodsTypeList = new ArrayList<>();
  1218. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  1219. for (int i = 0; i < goodsEntityList.size(); i++) {
  1220. GoodsDto goodsDto = goodsEntityList.get(i);
  1221. GoodsEntity goodsEntity = new GoodsEntity();
  1222. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  1223. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  1224. builder.put("goodsSn", "商品编码");
  1225. builder.put("thirdPartyMerchCode", "第三方商户代码");
  1226. builder.put("goodsBizType", "货品业务类型");
  1227. builder.put("name", "商品名称");
  1228. builder.put("isOnSaleStr", "上架");
  1229. builder.put("goodsUnit", "商品单位");
  1230. builder.put("isHotStr", "热销");
  1231. builder.put("prodBarcode", "产品条码");
  1232. builder.put("supplierName", "供应商");
  1233. builder.put("goodsNumber", "商品总库存");
  1234. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  1235. if (Integer.valueOf(r.get("code").toString()) != 0) {
  1236. throw new RRException(r.get("msg").toString());
  1237. } else {
  1238. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1239. // 海关信息,普通货物可不添加
  1240. builder.put("goodsRate", "商品税率");
  1241. builder.put("sku", "SKU");
  1242. builder.put("brand", "产品品牌");
  1243. builder.put("unitName", "计量单位");
  1244. builder.put("oriCntName", "原产国");
  1245. builder.put("cusGoodsCode", "海关商品编码");
  1246. builder.put("ciqProdModel", "国检规格型号");
  1247. builder.put("cusDeclEle", "海关申报要素");
  1248. builder.put("cusRecCode", "海关备案编号");
  1249. }
  1250. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  1251. if (Integer.valueOf(r.get("code").toString()) != 0) {
  1252. throw new RRException(r.get("msg").toString());
  1253. }
  1254. }
  1255. //业务类型校验
  1256. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  1257. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  1258. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  1259. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  1260. isFail = true;
  1261. failTypeGoodsSnList.add(goodsDto.getSku());
  1262. }
  1263. }
  1264. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  1265. if(thirdMerchantBizEntity != null){
  1266. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  1267. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  1268. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  1269. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  1270. isFail = true;
  1271. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  1272. }
  1273. }
  1274. }else{//商户不存在
  1275. isFail = true;
  1276. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  1277. }
  1278. //校验商品信息是否已存在
  1279. Map<String, Object> map = new HashMap<>();
  1280. map.put("isSame", "true");
  1281. map.put("sku", goodsDto.getSku());
  1282. map.put("goodsSn", goodsDto.getGoodsSn());
  1283. map.put("goodsBizType", goodsDto.getGoodsBizType());
  1284. // List<GoodsEntity> list = querySame(map);
  1285. // if (list != null && list.size() != 0) {
  1286. // isFail = true;
  1287. // if(goodsDto.getSku()!=null) {
  1288. // failSameSkuList.add(goodsDto.getSku());
  1289. // }
  1290. // failGoodsSnList.add(goodsDto.getGoodsSn());
  1291. // failGoodsTypeList.add(goodsDto.getGoodsBizType());
  1292. // }
  1293. //校验产品条码是否存在
  1294. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  1295. //热销商品校验
  1296. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  1297. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  1298. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  1299. isFail = true;
  1300. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  1301. }
  1302. }
  1303. if(thirdMerchantBizEntity != null) {
  1304. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  1305. if (supplierEntity == null) {
  1306. //导入没有查到供货商,执行新增
  1307. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  1308. if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
  1309. isFail = true;
  1310. failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  1311. }
  1312. supplierEntity = new SupplierEntity();
  1313. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  1314. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  1315. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  1316. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  1317. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  1318. supplierEntity.setIsShow("0");
  1319. supplierDao.save(supplierEntity);
  1320. goodsEntity.setSupplierId(supplierEntity.getId());
  1321. } else {
  1322. goodsEntity.setSupplierId(supplierEntity.getId());
  1323. }
  1324. }
  1325. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1326. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  1327. if (sysCusUnitCodeEntity == null) {
  1328. isFail = true;
  1329. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  1330. } else {
  1331. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  1332. }
  1333. //原产国
  1334. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  1335. if (sysCusNationCodeEntity == null) {
  1336. isFail = true;
  1337. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  1338. } else {
  1339. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  1340. }
  1341. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  1342. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  1343. }
  1344. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  1345. }
  1346. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  1347. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  1348. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  1349. goodsEntity.setSku(goodsDto.getSku());
  1350. goodsEntity.setName(goodsDto.getName());
  1351. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  1352. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  1353. goodsEntity.setBrand(goodsDto.getBrand());
  1354. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  1355. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  1356. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  1357. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  1358. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  1359. goodsEntity.setIsNew(0);
  1360. goodsEntity.setUpdateUserId(user.getUserId());
  1361. goodsEntity.setAddTime(new Date());
  1362. goodsEntity.setCreateTime(new Date());
  1363. goodsEntity.setUpdateTime(new Date());
  1364. goodsEntity.setModTime(new Date());
  1365. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  1366. if(!isFail){
  1367. GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
  1368. if(goods!=null) {// 修改商品
  1369. goodsEntity.setId(goods.getId());
  1370. goodsEntity.setVideoUrl(goods.getVideoUrl());
  1371. goodsEntity.setListPicUrl(goods.getListPicUrl());
  1372. goodsEntity.setPrimaryPicUrl(goods.getPrimaryPicUrl());
  1373. goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
  1374. goodsDao.update(goodsEntity);
  1375. }else{
  1376. goodsDao.save(goodsEntity);
  1377. }
  1378. // 修改产品
  1379. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  1380. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  1381. // 普通货物暂不添加商品规格
  1382. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1383. // 添加商品规格
  1384. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  1385. if(specificationEntity == null) {
  1386. goodsSpecification.setGoodsId(goodsEntity.getId());
  1387. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  1388. goodsSpecification.setSpecificationId(1);
  1389. goodsSpecificationDao.save(goodsSpecification);
  1390. }else {
  1391. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  1392. goodsSpecification.setId(specificationEntity.getId());
  1393. goodsSpecificationDao.update(goodsSpecification);
  1394. }
  1395. if(product == null){
  1396. product = new ProductEntity();
  1397. product.setGoodsSn(goodsDto.getGoodsSn());
  1398. product.setGoodsId(goodsEntity.getId());
  1399. product.setGoodsDefault(0);
  1400. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  1401. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1402. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1403. productDao.save(product);
  1404. }else{
  1405. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1406. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1407. productDao.update(product);
  1408. }
  1409. }
  1410. }
  1411. }
  1412. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  1413. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  1414. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  1415. exportExceptionDataEntity.setCreateTime(new Date());
  1416. exportExceptionDataEntity.setModTime(new Date());
  1417. exportExceptionDataEntity.setMerchSn(merchSn);
  1418. exportExceptionDataEntity.setStoreId(user.getStoreId());
  1419. if(exportDataType == 1) {
  1420. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  1421. }else{
  1422. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  1423. }
  1424. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  1425. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  1426. goodsUtils.save(exportExceptionDataEntity);
  1427. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1428. }
  1429. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  1430. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  1431. goodsUtils.save(exportExceptionDataEntity);
  1432. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1433. }
  1434. // if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  1435. // if(failSameSkuList.size()>0) {
  1436. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1437. // failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  1438. // goodsUtils.save(exportExceptionDataEntity);
  1439. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1440. // }else{
  1441. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1442. // failGoodsTypeList + "】的商品信息");
  1443. // goodsUtils.save(exportExceptionDataEntity);
  1444. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1445. // }
  1446. // }
  1447. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  1448. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  1449. goodsUtils.save(exportExceptionDataEntity);
  1450. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1451. }
  1452. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  1453. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  1454. goodsUtils.save(exportExceptionDataEntity);
  1455. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1456. }
  1457. if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  1458. exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  1459. goodsUtils.save(exportExceptionDataEntity);
  1460. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1461. }
  1462. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1463. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1464. goodsUtils.save(exportExceptionDataEntity);
  1465. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1466. }
  1467. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1468. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1469. goodsUtils.save(exportExceptionDataEntity);
  1470. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1471. }
  1472. }else{
  1473. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  1474. }
  1475. return 1;
  1476. }
  1477. @Override
  1478. public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId) {
  1479. return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  1480. }
  1481. @Override
  1482. public GoodsPanoramaDto searchGoodsPanoramaDtoByKeyword(String keyword) {
  1483. return goodsDao.searchGoodsPanoramaDtoByKeyword(keyword);
  1484. }
  1485. @Override
  1486. public List<GoodsEntity> queryExportList(Map<String, Object> params) {
  1487. return goodsDao.queryExportList(params);
  1488. }
  1489. /**
  1490. * 查出pdf需要的需要
  1491. *
  1492. * @param sku 商品sku
  1493. * @param storeId
  1494. * @param prodBarcode
  1495. * @return
  1496. */
  1497. @Override
  1498. public PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode) {
  1499. return goodsDao.queryForPDFData(sku,storeId,prodBarcode);
  1500. }
  1501. /**
  1502. * 查询产品价格
  1503. *
  1504. * @param prodBarcode
  1505. * @param storeId
  1506. * @return
  1507. */
  1508. @Override
  1509. @Transactional
  1510. public Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId) {
  1511. /**
  1512. * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
  1513. */
  1514. GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  1515. if(goods == null) {
  1516. return null;
  1517. }
  1518. goods.setDiscountedPrice(new BigDecimal(0));
  1519. BigDecimal retailPrice = goods.getRetailPrice();
  1520. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1521. Map<String,Object> skuActivitiesMap = new HashMap<>();
  1522. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1523. /**
  1524. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1525. * 参数: 当前时间 门店id
  1526. */
  1527. List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
  1528. if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
  1529. skuActivitiesMap.put("goods",goods);
  1530. return skuActivitiesMap;
  1531. }
  1532. // 遍历活动集合,查询有哪些活动是开启的
  1533. boolean daily = false,coupon = false,combinationPrice = false
  1534. ,discount = false,fullGift = false,fullReduction = false
  1535. ,getOneFree = false,promotion = false,halfPrice = false;
  1536. List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
  1537. Map<String,String> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
  1538. // 将所有的营销活动新增到list中
  1539. for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
  1540. topicList.add(mkActivitiesEntity.getMkaTopic());
  1541. String mkaId = mkaIdMap.putIfAbsent(mkActivitiesEntity.getMkaTopic(), mkActivitiesEntity.getMkaId()+"");
  1542. if(StringUtils.isNotEmpty(mkaId)){
  1543. mkaId = "'"+mkaId + "','" + mkActivitiesEntity.getMkaId()+"'";
  1544. mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkaId);
  1545. }
  1546. }
  1547. // 判断有哪些营销活动
  1548. if(topicList.contains("zhjsp")) // 组合价
  1549. combinationPrice = true;
  1550. if(topicList.contains("dz")) // 打折
  1551. discount = true;
  1552. if(topicList.contains("mz")) //满赠
  1553. fullGift = true;
  1554. if(topicList.contains("mj")) // 满减
  1555. fullReduction = true;
  1556. if(topicList.contains("mysy")) // 买一送一
  1557. getOneFree = true;
  1558. if(topicList.contains("rchd")) // 日常活动
  1559. daily = true;
  1560. if(topicList.contains("yhq")) // 优惠券
  1561. coupon = true;
  1562. if(topicList.contains("lscx")) // 临时促销
  1563. promotion = true;
  1564. if(topicList.contains("drjbj"))
  1565. halfPrice = true;
  1566. // 获取未优惠前的商品价格
  1567. retailPrice = goods.getRetailPrice();
  1568. // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
  1569. String brandName = goods.getBrand();
  1570. /**
  1571. * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
  1572. */
  1573. /**
  1574. * 组合价的做法就是将参与组合的条码带到收银端
  1575. * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
  1576. *
  1577. *
  1578. * TODO
  1579. */
  1580. if(combinationPrice){
  1581. String mkaId = mkaIdMap.get("zhjsp");
  1582. Map<String,Object> param = new HashMap<>();
  1583. param.put("mkaId",mkaId);
  1584. param.put("prodBarcode",prodBarcode);
  1585. List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
  1586. if(combinationPriceList != null && combinationPriceList.size() > 0) {
  1587. Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
  1588. combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
  1589. skuActivitiesMap.put("zhjsp",collect);
  1590. }
  1591. }
  1592. format = new SimpleDateFormat("yyyy-MM-dd");
  1593. String nowTime = format.format(new Date());
  1594. /**
  1595. * 满减可能是跟着条码,也可能跟着品牌
  1596. * 根据商品品牌跟商品条码去查询是否有优惠金额
  1597. *
  1598. * 满足金额 购买商品条码 赠品条码
  1599. *
  1600. */
  1601. Map<String,Object> fullReductionMap = new HashMap<>();
  1602. if(fullReduction){
  1603. String mkaId = mkaIdMap.get("mj");
  1604. MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1605. if(fullReductionEntity != null) {
  1606. if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
  1607. // 跟着品牌走
  1608. fullReductionMap.put(brandName,fullReductionEntity);
  1609. }else{
  1610. // 跟着条码走
  1611. fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
  1612. }
  1613. skuActivitiesMap.put("mj",fullReductionMap);
  1614. }
  1615. }
  1616. /**
  1617. * 满赠可能是跟着条码,也可能跟着品牌
  1618. * 根据商品品牌跟商品条码去查询是否有满赠
  1619. * 1.先扫买的商品,然后查询出赠送的商品条码
  1620. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1621. * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
  1622. * TODO
  1623. */
  1624. Map<String,Object> fullGiftMap = new HashMap<>();
  1625. if(fullGift){
  1626. String mkaId = mkaIdMap.get("mz");
  1627. MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1628. if(giftEntity != null) {
  1629. if(giftEntity.getProductBrand() != null){
  1630. // 跟着品牌走
  1631. fullGiftMap.put(brandName,giftEntity);
  1632. }else{
  1633. // 跟着条码走
  1634. fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
  1635. }
  1636. skuActivitiesMap.put("mz",fullGiftMap);
  1637. }
  1638. }
  1639. /**
  1640. * 买一送一可能是跟着条码,也可能跟着品牌
  1641. * 根据商品品牌跟商品条码去查询是否有送的商品
  1642. * 有两个场景
  1643. * 1.先扫买的商品,然后查询出赠送的商品条码
  1644. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1645. * 所以就需要一个map
  1646. * key为购买的商品条码或者商品品牌 value为赠送的商品条码
  1647. * 但是品牌是根据条码查询的,所以最终map里面的结构是
  1648. * key 商品条码 value 赠品条码
  1649. */
  1650. if(getOneFree){
  1651. String mkaId = mkaIdMap.get("mysy");
  1652. MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
  1653. if(getOneFreeGoodsEntity != null){
  1654. if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
  1655. getOneFreeGoodsEntity.setBrand(false);
  1656. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1657. }else{
  1658. getOneFreeGoodsEntity.setBrand(true);
  1659. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1660. }
  1661. }
  1662. }
  1663. // 第二份半价
  1664. if(halfPrice){
  1665. String mkaId = mkaIdMap.get("drjbj");
  1666. MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
  1667. if(activitiesHalfPriceEntity != null){
  1668. skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
  1669. }
  1670. }
  1671. // --------------------------------------------------------------------------------------
  1672. /**
  1673. * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
  1674. */
  1675. if(coupon){
  1676. String mkaId = mkaIdMap.get("yhq");
  1677. MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
  1678. if(couponEntity != null){ // 优惠券码,优惠金额
  1679. Map<String,Object> returnMap = new HashMap<>();
  1680. returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
  1681. skuActivitiesMap.put("yhq",returnMap);
  1682. }
  1683. }
  1684. /**
  1685. * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
  1686. */
  1687. if(discount){
  1688. String mkaId = mkaIdMap.get("dz");
  1689. MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
  1690. // TODO 可能会直接替代产品价格
  1691. if (discountEntity != null) {
  1692. goods.setActualPaymentAmount(discountEntity.getActivityPrice());
  1693. goods.setRetailPrice(discountEntity.getActivityPrice());
  1694. goods.setActivity("打折");
  1695. }
  1696. }
  1697. /**
  1698. * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
  1699. */
  1700. if(daily){
  1701. String mkaId = mkaIdMap.get("rchd");
  1702. MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
  1703. if(dailyActivitiesEntity != null){
  1704. goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
  1705. goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
  1706. goods.setActivity("日常活动");
  1707. }
  1708. }
  1709. /**
  1710. * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
  1711. */
  1712. if(promotion){
  1713. String mkaId = mkaIdMap.get("lscx");
  1714. MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
  1715. // 如果该商品存在临时促销,直接替换活动价格
  1716. if(promotionEntity != null){
  1717. goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
  1718. goods.setRetailPrice(promotionEntity.getActivityPrice());
  1719. goods.setActivity("临时促销");
  1720. }
  1721. }
  1722. // 计算税费
  1723. GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
  1724. BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1725. goods.setGoodstaxes(tax.toString());
  1726. skuActivitiesMap.put("goods",goods);
  1727. return skuActivitiesMap;
  1728. }
  1729. /**
  1730. * 根据条形码查询商品
  1731. *
  1732. * @param barCode
  1733. * @return
  1734. */
  1735. @Override
  1736. public GoodsEntity queryByBarcode(String barCode) {
  1737. return goodsDao.queryByBarcode(barCode);
  1738. }
  1739. /**
  1740. * 根据sku查询商品
  1741. *
  1742. * @param sku
  1743. * @return
  1744. */
  1745. @Override
  1746. public GoodsEntity queryBySku(String sku) {
  1747. return goodsDao.queryBySku(sku);
  1748. }
  1749. /* @Override
  1750. @Transactional
  1751. public int uploadExcel(MultipartFile file) {
  1752. SysUserEntity user = ShiroUtils.getUserEntity();
  1753. List<String[]> list = ExcelImport.getExcelData(file);
  1754. // 取门店名称
  1755. StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
  1756. if (null == storeEntity) {
  1757. return 0;
  1758. }
  1759. //去除表头两行、底部合计
  1760. if (list != null && list.size() > 3) {
  1761. ProductStoreRelaEntity storeRelaEntity;
  1762. ProductEntity productEntity;
  1763. for (int i = 2; i < list.size() - 1; i++) {
  1764. String[] item = list.get(i);
  1765. String goodsSn = item[0];
  1766. productEntity = productDao.queryObjectBySn(goodsSn);
  1767. if (StringUtils.isNullOrEmpty(goodsSn)) {
  1768. continue;
  1769. }
  1770. if (null == productEntity || null == productEntity.getId()) {
  1771. continue;
  1772. }
  1773. storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
  1774. if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
  1775. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1776. storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
  1777. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1778. productStoreRelaDao.update(storeRelaEntity);
  1779. } else {
  1780. storeRelaEntity = new ProductStoreRelaEntity();
  1781. storeRelaEntity.setGoodsId(productEntity.getGoodsId());
  1782. storeRelaEntity.setProductId(productEntity.getId());
  1783. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1784. storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
  1785. storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
  1786. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1787. storeRelaEntity.setStoreId(storeEntity.getId());
  1788. productStoreRelaDao.save(storeRelaEntity);
  1789. }
  1790. }
  1791. }
  1792. return 1;
  1793. }*/
  1794. public GoodsEntity queryObjectBySn(String goodsSn) {
  1795. return goodsDao.queryObjectBySn(goodsSn);
  1796. }
  1797. @Override
  1798. @Transactional
  1799. public void syncOmsHsCode() {
  1800. List<String> skuList = goodsDao.queryNonSyncOmsHsCodeSkuList();
  1801. if (Objects.nonNull(skuList) && skuList.size()>0){
  1802. String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
  1803. Map<String,Map> map = JSON.parseObject(result, Map.class);
  1804. for (String sku : skuList) {
  1805. Map skuInfoMap = map.get(sku);
  1806. if (Objects.nonNull(skuInfoMap)){
  1807. String hsCodeName = (String) skuInfoMap.get("cusGoodsName");
  1808. String hsCode = (String) skuInfoMap.get("cusGoodsCode");
  1809. String prodName = (String) skuInfoMap.get("prodName");
  1810. String prodRecordName = (String) skuInfoMap.get("prodRecordName");
  1811. BigDecimal impConsumTaxRate = (BigDecimal) skuInfoMap.get("impConsumTaxRate");
  1812. BigDecimal valueAddedTaxRate = (BigDecimal) skuInfoMap.get("valueAddedTaxRate");
  1813. BigDecimal legalUnit1Qty = (BigDecimal) skuInfoMap.get("legalUnit1Qty");
  1814. BigDecimal legalUnit2Qty = (BigDecimal) skuInfoMap.get("legalUnit2Qty");
  1815. BigDecimal cosmThresholdValue = (BigDecimal) skuInfoMap.get("cosmThresholdValue");
  1816. if (StringUtils.isNotEmpty(hsCodeName) && StringUtils.isNotEmpty(hsCode)){
  1817. List<GoodsEntity> goodsEntityList = goodsDao.queryListBySku(sku);
  1818. if (Objects.nonNull(goodsEntityList) && goodsEntityList.size()>0){
  1819. for (GoodsEntity goodsEntity : goodsEntityList) {
  1820. goodsEntity.setHsCode(hsCode);
  1821. goodsEntity.setHsCodeName(hsCodeName);
  1822. goodsEntity.setImpConsumTaxRate(impConsumTaxRate);
  1823. goodsEntity.setValueAddedTaxRate(valueAddedTaxRate);
  1824. goodsEntity.setIsSyncHsCode("1");
  1825. goodsEntity.setLegalUnit1Qty(legalUnit1Qty);
  1826. goodsEntity.setProdName(prodName);
  1827. goodsEntity.setProdRecordName(prodRecordName);
  1828. goodsEntity.setLegalUnit2Qty(legalUnit2Qty);
  1829. goodsEntity.setCosmThresholdValue(cosmThresholdValue);
  1830. goodsDao.update(goodsEntity);
  1831. }
  1832. }
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. @Override
  1839. @Transactional
  1840. public void syncOmsGoodsRate() {
  1841. List<GoodsEntity> list = goodsDao.queryNonSyncOmsGoodsRateSkuList();
  1842. if (Objects.nonNull(list) && list.size()>0){
  1843. String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/taxBill/queryGoodsRate?thirdPartyMerchCode=CW001");
  1844. Map<String,String> map = JSON.parseObject(result, Map.class);
  1845. for (GoodsEntity goodsEntity : list) {
  1846. String goodsRate = map.get(goodsEntity.getHsCode());
  1847. if (StringUtils.isNotEmpty(goodsRate)){
  1848. goodsEntity.setIsSyncGoodsRate("1");
  1849. goodsEntity.setGoodsRate(new BigDecimal(goodsRate));
  1850. goodsDao.update(goodsEntity);
  1851. }
  1852. }
  1853. }
  1854. }
  1855. @Override
  1856. @Transactional
  1857. public void syncGoodsRate() {
  1858. String storeId = "163"; // 市场部说所有门店价格一致,并且活动一致,可直接取其中一个门店价格进行计算税率
  1859. // 查询出所有商品
  1860. List<GoodsEntity> allGoodsList = goodsDao.queryAllList();
  1861. for (GoodsEntity goodsEntity : allGoodsList) {
  1862. // 同步过海关商品编码才可以算税率
  1863. if ("1".equals(goodsEntity.getIsSyncHsCode())) {
  1864. // Map<String, Object> goodsDetailMap = calculateGoodsDetail(goodsEntity.getProdBarcode(), storeId);
  1865. // if (Objects.nonNull(goodsDetailMap)) {
  1866. // GoodsDetailsDto goods = (GoodsDetailsDto) goodsDetailMap.get("goods");
  1867. // 顾客给的钱 就是税后价
  1868. // BigDecimal actualPaymentAmount = goods.getActualPaymentAmount(); //随便拿一个门店的当前时间的价格,如果有活动价会使用活动价
  1869. // BigDecimal calculateTax = CalculateTax.calculateTax(goodsEntity, actualPaymentAmount);// 税费
  1870. // BigDecimal goodsRate = calculateTax.divide(actualPaymentAmount, 4, BigDecimal.ROUND_HALF_UP);
  1871. BigDecimal goodsRate =CalculateTax.calculateGoodsRate(goodsEntity);
  1872. goodsEntity.setGoodsRate(goodsRate);
  1873. goodsDao.update(goodsEntity);
  1874. // }
  1875. }
  1876. }
  1877. }
  1878. @Override
  1879. public void updateTaxErrorRecord(TaxErrorRecordEntity taxErrorRecordEntity) {
  1880. taxErrorRecordDao.update(taxErrorRecordEntity);
  1881. }
  1882. @Override
  1883. public void insertTaxErrorRecord(TaxErrorRecordEntity taxErrorRecordEntity) {
  1884. taxErrorRecordDao.save(taxErrorRecordEntity);
  1885. }
  1886. @Override
  1887. public void updateByEntity(GoodsEntity updateGoods) {
  1888. goodsDao.update(updateGoods);
  1889. }
  1890. @Override
  1891. public void checkGoodsPrice(SysUserEntity user) {
  1892. Map<String, BigDecimal> hsCodeMap = CalculateTax.hsCodeMap;
  1893. Set<String> hdCodeSet = hsCodeMap.keySet();
  1894. List<Map<String,String>> errorPriceSkuList = new LinkedList<>();
  1895. // 保存各种异常价格对象集合
  1896. List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities = new LinkedList<>();
  1897. // 查询所有特殊化妆品的商品
  1898. List<GoodsEntity> queryGoodsDetails = goodsDao.querySpecialCosmetics(hdCodeSet);
  1899. for (GoodsEntity goodsEntity : queryGoodsDetails) {
  1900. calculateShopPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
  1901. calculateDailyPrice(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
  1902. calculeatePromotion(user,goodsEntity,errorPriceSkuList,shopErrorPriceRecordEntities);
  1903. }
  1904. if(shopErrorPriceRecordEntities.size() != 0){
  1905. shopErrorPriceRecordService.saveBatch(shopErrorPriceRecordEntities);
  1906. }
  1907. }
  1908. @Override
  1909. public List<GoodsEntity> queryAllList() {
  1910. return goodsDao.queryAllList();
  1911. }
  1912. private void calculeatePromotion(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
  1913. String prodBarcode = goods.getProdBarcode();
  1914. String storeId = goods.getStoreId()+"";
  1915. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1916. /**
  1917. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1918. * 参数: 当前时间 门店id
  1919. */
  1920. MkActivitiesPromotionEntity promotionEntity = promotionService.queryByDateAndBarcode(storeId,format.format(new Date()),"lscx",prodBarcode);
  1921. // 如果该商品存在临时促销,直接替换活动价格
  1922. if(promotionEntity == null){
  1923. return ;
  1924. }
  1925. goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
  1926. goods.setRetailPrice(promotionEntity.getActivityPrice());
  1927. goods.setActivity("临时促销");
  1928. try {
  1929. CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1930. } catch (Exception e) {
  1931. ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
  1932. shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
  1933. shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
  1934. shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
  1935. shopErrorPriceRecordEntity.setPriceType(3); // 3 是临时促销
  1936. shopErrorPriceRecordEntity.setSku(goods.getSku());
  1937. shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
  1938. shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
  1939. shopErrorPriceRecordEntity.setCheckTime(new Date());
  1940. shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
  1941. shopErrorPriceRecordEntity.setCreateTime(new Date());
  1942. shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
  1943. if(e.getMessage().contains("-")){
  1944. String suggestPrice = e.getMessage().split("-")[0];
  1945. String highestPrice = e.getMessage().split("-")[1];
  1946. String lowestPrice = e.getMessage().split("-")[2];
  1947. shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
  1948. shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
  1949. shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
  1950. }
  1951. shopErrorPriceRecordEntity.setMkaId(promotionEntity.getMkaId());
  1952. shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
  1953. }
  1954. }
  1955. private void calculateDailyPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
  1956. String prodBarcode = goods.getProdBarcode();
  1957. String storeId = goods.getStoreId()+"";
  1958. /**
  1959. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1960. * 参数: 当前时间 门店id
  1961. */
  1962. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1963. /**
  1964. * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
  1965. */
  1966. MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByDateAndBarcode(storeId,format.format(new Date()),"rchd",prodBarcode);
  1967. if(dailyActivitiesEntity == null){
  1968. return ;
  1969. }
  1970. goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
  1971. goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
  1972. goods.setActivity("日常活动");
  1973. // 计算税费
  1974. try {
  1975. CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  1976. } catch (Exception e) {
  1977. // 记录有异常的sku
  1978. ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
  1979. shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
  1980. shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
  1981. shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
  1982. shopErrorPriceRecordEntity.setPriceType(2); // 2 是日常活动
  1983. shopErrorPriceRecordEntity.setSku(goods.getSku());
  1984. shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
  1985. shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
  1986. shopErrorPriceRecordEntity.setCheckTime(new Date());
  1987. shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
  1988. shopErrorPriceRecordEntity.setCreateTime(new Date());
  1989. shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
  1990. if(e.getMessage().contains("-")){
  1991. String suggestPrice = e.getMessage().split("-")[0];
  1992. String highestPrice = e.getMessage().split("-")[1];
  1993. String lowestPrice = e.getMessage().split("-")[2];
  1994. shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
  1995. shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
  1996. shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
  1997. }
  1998. shopErrorPriceRecordEntity.setMkaId(dailyActivitiesEntity.getMkaId());
  1999. shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
  2000. }
  2001. }
  2002. private void calculateShopPrice(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
  2003. goods.setDiscountedPrice(new BigDecimal(0));
  2004. BigDecimal retailPrice = goods.getRetailPrice();
  2005. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  2006. // 计算税费
  2007. try {
  2008. CalculateTax.calculateFinalTax(goods,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
  2009. } catch (Exception e) {
  2010. // 记录有异常的sku
  2011. ShopErrorPriceRecordEntity shopErrorPriceRecordEntity = new ShopErrorPriceRecordEntity();
  2012. shopErrorPriceRecordEntity.setMerchSn(goods.getMerchSn());
  2013. shopErrorPriceRecordEntity.setThirdMerchSn(goods.getThirdPartyMerchCode());
  2014. shopErrorPriceRecordEntity.setShopSn(goods.getStoreId()+"");
  2015. shopErrorPriceRecordEntity.setPriceType(1); // 1 门店商品价格
  2016. shopErrorPriceRecordEntity.setSku(goods.getSku());
  2017. shopErrorPriceRecordEntity.setBarcode(goods.getProdBarcode());
  2018. shopErrorPriceRecordEntity.setVerifier(user.getUserId()+"");
  2019. shopErrorPriceRecordEntity.setCheckTime(new Date());
  2020. shopErrorPriceRecordEntity.setCreaterSn(user.getUserId()+"");
  2021. shopErrorPriceRecordEntity.setCreateTime(new Date());
  2022. shopErrorPriceRecordEntity.setCurrentPrice(goods.getActualPaymentAmount().toString());
  2023. if(e.getMessage().contains("-")){
  2024. String suggestPrice = e.getMessage().split("-")[0];
  2025. String highestPrice = e.getMessage().split("-")[1];
  2026. String lowestPrice = e.getMessage().split("-")[2];
  2027. shopErrorPriceRecordEntity.setSuggestedPrice(suggestPrice);
  2028. shopErrorPriceRecordEntity.setLowestPrice(lowestPrice);
  2029. shopErrorPriceRecordEntity.setHighestPrice(highestPrice);
  2030. }
  2031. shopErrorPriceRecordEntities.add(shopErrorPriceRecordEntity);
  2032. }
  2033. }
  2034. }