GoodsServiceImpl.java 97 KB

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