GoodsServiceImpl.java 74 KB

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