GoodsServiceImpl.java 72 KB

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