GoodsServiceImpl.java 99 KB

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