GoodsServiceImpl.java 94 KB

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