GoodsServiceImpl.java 70 KB

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