GoodsServiceImpl.java 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  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. @Override
  580. public List<GoodsEntity> queryByName(String goodsName) {
  581. return goodsDao.queryByName(goodsName);
  582. }
  583. /**
  584. * 更新门店商品是否有修改字段
  585. * @param storeId
  586. * @param user
  587. */
  588. private void updateLoadGoodsByStoreId(Long storeId, SysUserEntity user){
  589. List<MerchUserEntity> list = merchUserDao.queryMerchUserByLoadGoods(storeId);
  590. for(MerchUserEntity entity : list) {
  591. entity.setIsLoadGoods("1");
  592. entity.setModerSn(user.getUsername());
  593. entity.setStoreId(Integer.valueOf(String.valueOf(storeId)));
  594. merchUserDao.updateStoreLoadGoodsById(entity);
  595. }
  596. }
  597. @Override
  598. public int delete(Integer id) {
  599. SysUserEntity user = ShiroUtils.getUserEntity();
  600. GoodsEntity goodsEntity = goodsDao.queryObject(id);
  601. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_1.getItem()));
  602. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  603. goodsEntity.setUpdateUserId(user.getUserId());
  604. goodsEntity.setUpdateTime(new Date());
  605. Map params = Maps.newHashMap();
  606. params.put("goodsId", id);
  607. List<GoodsGroupEntity> groupVos = goodsGroupDao.queryList(params);
  608. if (null != groupVos && groupVos.size() > 0) {
  609. for (GoodsGroupEntity groupVo : groupVos) {
  610. groupVo.setOpenStatus(3);
  611. goodsGroupDao.update(groupVo);
  612. }
  613. }
  614. return goodsDao.update(goodsEntity);
  615. }
  616. @Override
  617. @Transactional
  618. public int deleteBatch(Integer[] ids) {
  619. int result = 0;
  620. for (Integer id : ids) {
  621. result += delete(id);
  622. }
  623. return result;
  624. }
  625. @Override
  626. @Transactional
  627. public int back(Integer[] ids) {
  628. SysUserEntity user = ShiroUtils.getUserEntity();
  629. int result = 0;
  630. for (Integer id : ids) {
  631. GoodsEntity goodsEntity = queryObject(id);
  632. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  633. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  634. goodsEntity.setUpdateUserId(user.getUserId());
  635. goodsEntity.setUpdateTime(new Date());
  636. result += goodsDao.update(goodsEntity);
  637. }
  638. return result;
  639. }
  640. @Override
  641. public int enSale(Integer id) {
  642. SysUserEntity user = ShiroUtils.getUserEntity();
  643. GoodsEntity goodsEntity = queryObject(id);
  644. if (1 == goodsEntity.getIsOnSale()) {
  645. throw new RRException("此商品已处于上架状态!");
  646. }
  647. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  648. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  649. goodsEntity.setUpdateUserId(user.getUserId());
  650. goodsEntity.setUpdateTime(new Date());
  651. return goodsDao.update(goodsEntity);
  652. }
  653. @Override
  654. public int unSale(Integer id) {
  655. SysUserEntity user = ShiroUtils.getUserEntity();
  656. GoodsEntity goodsEntity = queryObject(id);
  657. if (0 == goodsEntity.getIsOnSale()) {
  658. throw new RRException("此商品已处于下架状态!");
  659. }
  660. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  661. goodsEntity.setUpdateUserId(user.getUserId());
  662. goodsEntity.setUpdateTime(new Date());
  663. return goodsDao.update(goodsEntity);
  664. }
  665. @Override
  666. public int enSaleBatch(Integer[] ids) {
  667. int result = 0;
  668. SysUserEntity user = ShiroUtils.getUserEntity();
  669. for (Integer id : ids) {
  670. GoodsEntity goodsEntity = queryObject(id);
  671. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  672. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  673. goodsEntity.setUpdateUserId(user.getUserId());
  674. goodsEntity.setUpdateTime(new Date());
  675. result += goodsDao.update(goodsEntity);
  676. }
  677. return result;
  678. }
  679. @Override
  680. public int unSaleBatch(Integer[] ids) {
  681. int result = 0;
  682. SysUserEntity user = ShiroUtils.getUserEntity();
  683. for (Integer id : ids) {
  684. GoodsEntity goodsEntity = queryObject(id);
  685. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  686. goodsEntity.setUpdateUserId(user.getUserId());
  687. goodsEntity.setUpdateTime(new Date());
  688. result += goodsDao.update(goodsEntity);
  689. }
  690. return result;
  691. }
  692. @Override
  693. @Transactional
  694. public int uploadExcel(List<GoodsDto> goodsEntityList,int exportDataType) {
  695. SysUserEntity user = ShiroUtils.getUserEntity();
  696. String merchSn = user.getMerchSn();
  697. boolean isFail = false;
  698. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  699. // failSuppGoodsSnList = new ArrayList<>(),
  700. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
  701. // failProdbarGoodsSnList = new ArrayList<>(),
  702. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  703. // failCateL2GoodsSnList = new ArrayList<>(),
  704. // failCateGoodsSnList = new ArrayList<>(),
  705. // failBrandGoodsSnList = new ArrayList<>(),
  706. // failFreightGoodsSnList = new ArrayList<>(),
  707. failMerchUserGoodsSnList = new ArrayList<>();
  708. List<String> failGoodsSnList = new ArrayList<>();
  709. List<String> failGoodsTypeList = new ArrayList<>();
  710. // List<String> failFreightList = new ArrayList<>();
  711. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  712. for (int i = 0; i < goodsEntityList.size(); i++) {
  713. GoodsDto goodsDto = goodsEntityList.get(i);
  714. GoodsEntity goodsEntity = new GoodsEntity();
  715. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  716. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  717. builder.put("goodsSn", "商品编码");
  718. builder.put("thirdPartyMerchCode", "第三方商户代码");
  719. // builder.put("categoryName", "商品分类");
  720. builder.put("goodsBizType", "货品业务类型");
  721. builder.put("name", "商品名称");
  722. // builder.put("brandName", "商品品牌名称");
  723. // builder.put("defaultFreight", "运费");
  724. builder.put("isOnSaleStr", "上架");
  725. builder.put("goodsUnit", "商品单位");
  726. builder.put("isHotStr", "热销");
  727. builder.put("prodBarcode", "产品条码");
  728. // builder.put("marketPrice", "市场价");
  729. // builder.put("retailPrice", "零售价");
  730. builder.put("supplierName", "供应商");
  731. builder.put("goodsNumber", "商品总库存");
  732. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  733. if (Integer.valueOf(r.get("code").toString()) != 0) {
  734. throw new RRException(r.get("msg").toString());
  735. } else {
  736. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  737. // 海关信息,普通货物可不添加
  738. builder.put("goodsRate", "商品税率");
  739. builder.put("sku", "SKU");
  740. builder.put("brand", "产品品牌");
  741. builder.put("unitName", "计量单位");
  742. builder.put("oriCntName", "原产国");
  743. builder.put("cusGoodsCode", "海关商品编码");
  744. builder.put("ciqProdModel", "国检规格型号");
  745. builder.put("cusDeclEle", "海关申报要素");
  746. builder.put("cusRecCode", "海关备案编号");
  747. }
  748. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  749. if (Integer.valueOf(r.get("code").toString()) != 0) {
  750. throw new RRException(r.get("msg").toString());
  751. }
  752. }
  753. //业务类型校验
  754. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  755. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  756. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  757. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  758. isFail = true;
  759. failTypeGoodsSnList.add(goodsDto.getSku());
  760. }
  761. }
  762. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  763. if(thirdMerchantBizEntity != null){
  764. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  765. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  766. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  767. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  768. isFail = true;
  769. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  770. }
  771. }
  772. }else{//商户不存在
  773. isFail = true;
  774. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  775. }
  776. //校验商品信息是否已存在
  777. Map<String, Object> map = new HashMap<>();
  778. map.put("isSame", "true");
  779. map.put("sku", goodsDto.getSku());
  780. map.put("goodsSn", goodsDto.getGoodsSn());
  781. map.put("goodsBizType", goodsDto.getGoodsBizType());
  782. List<GoodsEntity> list = querySame(map);
  783. if (list != null && list.size() != 0) {
  784. // isFail = true;
  785. if(goodsDto.getSku()!=null) {
  786. failSameSkuList.add(goodsDto.getSku());
  787. }
  788. failGoodsSnList.add(goodsDto.getGoodsSn());
  789. failGoodsTypeList.add(goodsDto.getGoodsBizType());
  790. }
  791. //校验产品条码是否存在
  792. // List<GoodsEntity> prodbarGoods = goodsDao.queryObjectByProdBarcode(goodsDto.getProdBarcode(),merchSn,null);
  793. // if(prodbarGoods != null && prodbarGoods.size() > 0){
  794. // isFail = true;
  795. // failProdbarGoodsSnList.add(goodsDto.getGoodsSn());
  796. // }else{
  797. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  798. // }
  799. //热销商品校验
  800. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  801. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  802. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  803. isFail = true;
  804. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  805. }
  806. }
  807. if(thirdMerchantBizEntity != null) {
  808. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  809. if (supplierEntity == null) {
  810. //导入没有查到供货商,执行新增
  811. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  812. // if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
  813. // isFail = true;
  814. // failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  815. // }
  816. supplierEntity = new SupplierEntity();
  817. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  818. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  819. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  820. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  821. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  822. supplierEntity.setIsShow("0");
  823. supplierDao.save(supplierEntity);
  824. // supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  825. goodsEntity.setSupplierId(supplierEntity.getId());
  826. } else {
  827. goodsEntity.setSupplierId(supplierEntity.getId());
  828. }
  829. }
  830. //商品配置校验
  831. /*CategoryEntity categoryEntity = categoryDao.queryObjectByName(goodsDto.getCategoryName(),goodsDto.getMerchSn());
  832. if(categoryEntity==null){
  833. isFail = true;
  834. failCateGoodsSnList.add(goodsDto.getGoodsSn());
  835. }else{
  836. if(categoryEntity.getLevel().equalsIgnoreCase("L2")) {
  837. goodsEntity.setCategoryId(categoryEntity.getId());
  838. goodsEntity.setAttributeCategory(categoryEntity.getParentId());
  839. }else{
  840. isFail = true;
  841. failCateL2GoodsSnList.add(goodsDto.getGoodsSn());
  842. }
  843. }
  844. BrandEntity brandEntity = brandDao.queryObjectByName(goodsDto.getBrandName(),goodsDto.getMerchSn());
  845. if (brandEntity == null) {
  846. isFail = true;
  847. failBrandGoodsSnList.add(goodsDto.getGoodsSn());
  848. } else {
  849. goodsEntity.setBrandId(brandEntity.getId());
  850. }
  851. //运费
  852. FreightEntity freightEntity = freightDao.queryObjectByName(goodsDto.getDefaultFreight(),goodsDto.getMerchSn());
  853. if(freightEntity==null){
  854. isFail = true;
  855. failFreightGoodsSnList.add(goodsDto.getGoodsSn());
  856. failFreightList.add(goodsDto.getDefaultFreight());
  857. }else {
  858. goodsEntity.setFreightId(freightEntity.getId());
  859. }*/
  860. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  861. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  862. if (sysCusUnitCodeEntity == null) {
  863. isFail = true;
  864. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  865. } else {
  866. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  867. }
  868. //原产国
  869. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  870. if (sysCusNationCodeEntity == null) {
  871. isFail = true;
  872. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  873. } else {
  874. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  875. }
  876. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  877. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  878. }
  879. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  880. }
  881. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  882. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  883. // goodsEntity.setRetailPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getRetailPrice())));
  884. // goodsEntity.setMarketPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getMarketPrice())));
  885. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  886. goodsEntity.setSku(goodsDto.getSku());
  887. goodsEntity.setName(goodsDto.getName());
  888. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  889. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  890. goodsEntity.setBrand(goodsDto.getBrand());
  891. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  892. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  893. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  894. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  895. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  896. goodsEntity.setIsNew(0);
  897. goodsEntity.setUpdateUserId(user.getUserId());
  898. goodsEntity.setAddTime(new Date());
  899. goodsEntity.setCreateTime(new Date());
  900. goodsEntity.setUpdateTime(new Date());
  901. goodsEntity.setModTime(new Date());
  902. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  903. goodsEntity.setPlu(goodsDto.getPlu());
  904. goodsEntity.setMychemId(goodsDto.getMychemId());
  905. if(!isFail){
  906. GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
  907. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  908. mngChangeEntity.setThirdPartyMerchCode(goodsEntity.getThirdPartyMerchCode());
  909. mngChangeEntity.setChangeReason("更新商户商品总库存");
  910. mngChangeEntity.setCreateTime(new Date());
  911. mngChangeEntity.setModTime(new Date());
  912. mngChangeEntity.setCreaterSn(user.getUsername());
  913. mngChangeEntity.setModerSn(user.getUsername());
  914. mngChangeEntity.setIsValid(0);
  915. mngChangeEntity.setMerchSn(goodsEntity.getMerchSn());
  916. if(goods!=null) {// 修改商品
  917. mngChangeEntity.setOriginalNum(goods.getGoodsNumber());//原库存数
  918. mngChangeEntity.setValidNum(goods.getGoodsNumber() + Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  919. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  920. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  921. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
  922. goodsEntity.setId(goods.getId());
  923. goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
  924. goodsDao.update(goodsEntity);
  925. }else{
  926. mngChangeEntity.setOriginalNum(0);//原库存数
  927. mngChangeEntity.setValidNum(Integer.parseInt(goodsDto.getGoodsNumber()));//可用数
  928. mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
  929. mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
  930. goodsDao.save(goodsEntity);
  931. mngChangeEntity.setGoodsId(goodsEntity.getId().intValue());
  932. }
  933. mngChangeDao.save(mngChangeEntity);
  934. // // 保税商品修改各个门店商品价格
  935. // if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  936. // List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsDto.getId());
  937. // if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  938. // for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
  939. // productStoreRela.setMarketPrice(goodsEntity.getMarketPrice());
  940. // productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
  941. // productStoreRelaDao.update(productStoreRela);
  942. // }
  943. // }
  944. // }
  945. // 修改产品
  946. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  947. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  948. // 普通货物暂不添加商品规格
  949. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  950. // 添加商品规格
  951. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  952. if(specificationEntity == null) {
  953. goodsSpecification.setGoodsId(goodsEntity.getId());
  954. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  955. goodsSpecification.setSpecificationId(1);
  956. goodsSpecificationDao.save(goodsSpecification);
  957. }else {
  958. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  959. goodsSpecification.setId(specificationEntity.getId());
  960. goodsSpecificationDao.update(goodsSpecification);
  961. }
  962. if(product == null){
  963. product = new ProductEntity();
  964. product.setGoodsSn(goodsDto.getGoodsSn());
  965. product.setGoodsId(goodsEntity.getId());
  966. product.setGoodsDefault(0);
  967. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  968. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  969. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  970. productDao.save(product);
  971. }else{
  972. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  973. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  974. productDao.update(product);
  975. }
  976. }
  977. }
  978. }
  979. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  980. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  981. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  982. exportExceptionDataEntity.setCreateTime(new Date());
  983. exportExceptionDataEntity.setModTime(new Date());
  984. exportExceptionDataEntity.setMerchSn(merchSn);
  985. exportExceptionDataEntity.setStoreId(user.getStoreId());
  986. if(exportDataType == 1) {
  987. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  988. }else{
  989. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  990. }
  991. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  992. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  993. goodsUtils.save(exportExceptionDataEntity);
  994. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  995. }
  996. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  997. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  998. goodsUtils.save(exportExceptionDataEntity);
  999. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1000. }
  1001. // if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  1002. // if(failSameSkuList.size()>0) {
  1003. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1004. // failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  1005. // goodsUtils.save(exportExceptionDataEntity);
  1006. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1007. // }else{
  1008. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1009. // failGoodsTypeList + "】的商品信息");
  1010. // goodsUtils.save(exportExceptionDataEntity);
  1011. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1012. // }
  1013. // }
  1014. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  1015. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  1016. goodsUtils.save(exportExceptionDataEntity);
  1017. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1018. }
  1019. // if(failProdbarGoodsSnList != null && failProdbarGoodsSnList.size() > 0){
  1020. // exportExceptionDataEntity.setExportExceptionData("不能有重复的产品条码信息!请检查商品编码【"+failProdbarGoodsSnList+"】的商品产品条码信息");
  1021. // goodsUtils.save(exportExceptionDataEntity);
  1022. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1023. // }
  1024. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  1025. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  1026. goodsUtils.save(exportExceptionDataEntity);
  1027. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1028. }
  1029. // if(failCateGoodsSnList != null && failCateGoodsSnList.size() > 0){
  1030. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中维护,商品分类与商户信息对应,请检查该商品商户信息下的分类是否维护,不存在的商品编码【"+failCateGoodsSnList+"】");
  1031. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1032. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1033. // }
  1034. // if(failCateL2GoodsSnList != null && failCateL2GoodsSnList.size() > 0){
  1035. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中查看,商品分类必须为二级分类,不存在的商品编码【"+failCateL2GoodsSnList+"】");
  1036. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1037. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1038. // }
  1039. // if(failBrandGoodsSnList != null && failBrandGoodsSnList.size() > 0){
  1040. // exportExceptionDataEntity.setExportExceptionData("品牌信息请在商城配置》品牌制造商中维护,品牌与商户信息对应,请检查该商品商户信息下的品牌是否维护,不存在的商品编码【" + failBrandGoodsSnList + "】");
  1041. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1042. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1043. // }
  1044. // if(failFreightGoodsSnList != null && failFreightGoodsSnList.size() > 0){
  1045. // exportExceptionDataEntity.setExportExceptionData("运费信息请在商城配置》运费模板中维护,运费与商户信息对应,请检查该商品商户信息下的运费是否维护,不存在的商品编码【"+failFreightGoodsSnList+"】,运费【"+failFreightList+"】");
  1046. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1047. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1048. // }
  1049. // if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  1050. // exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  1051. // goodsUtils.save(exportExceptionDataEntity);
  1052. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1053. // }
  1054. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1055. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1056. goodsUtils.save(exportExceptionDataEntity);
  1057. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1058. }
  1059. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1060. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1061. goodsUtils.save(exportExceptionDataEntity);
  1062. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1063. }
  1064. }else{
  1065. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  1066. }
  1067. return 1;
  1068. }
  1069. @Override
  1070. @Transactional
  1071. public int uploadExcelByCover(List<GoodsDto> goodsEntityList, int exportDataType) {
  1072. SysUserEntity user = ShiroUtils.getUserEntity();
  1073. String merchSn = user.getMerchSn();
  1074. boolean isFail = false;
  1075. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  1076. failSuppGoodsSnList = new ArrayList<>(),
  1077. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),
  1078. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  1079. failMerchUserGoodsSnList = new ArrayList<>();
  1080. // List<String> failGoodsSnList = new ArrayList<>();
  1081. List<String> failGoodsTypeList = new ArrayList<>();
  1082. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  1083. for (int i = 0; i < goodsEntityList.size(); i++) {
  1084. GoodsDto goodsDto = goodsEntityList.get(i);
  1085. GoodsEntity goodsEntity = new GoodsEntity();
  1086. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  1087. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  1088. builder.put("goodsSn", "商品编码");
  1089. builder.put("thirdPartyMerchCode", "第三方商户代码");
  1090. builder.put("goodsBizType", "货品业务类型");
  1091. builder.put("name", "商品名称");
  1092. builder.put("isOnSaleStr", "上架");
  1093. builder.put("goodsUnit", "商品单位");
  1094. builder.put("isHotStr", "热销");
  1095. builder.put("prodBarcode", "产品条码");
  1096. builder.put("supplierName", "供应商");
  1097. builder.put("goodsNumber", "商品总库存");
  1098. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  1099. if (Integer.valueOf(r.get("code").toString()) != 0) {
  1100. throw new RRException(r.get("msg").toString());
  1101. } else {
  1102. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1103. // 海关信息,普通货物可不添加
  1104. builder.put("goodsRate", "商品税率");
  1105. builder.put("sku", "SKU");
  1106. builder.put("brand", "产品品牌");
  1107. builder.put("unitName", "计量单位");
  1108. builder.put("oriCntName", "原产国");
  1109. builder.put("cusGoodsCode", "海关商品编码");
  1110. builder.put("ciqProdModel", "国检规格型号");
  1111. builder.put("cusDeclEle", "海关申报要素");
  1112. builder.put("cusRecCode", "海关备案编号");
  1113. }
  1114. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  1115. if (Integer.valueOf(r.get("code").toString()) != 0) {
  1116. throw new RRException(r.get("msg").toString());
  1117. }
  1118. }
  1119. //业务类型校验
  1120. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  1121. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  1122. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  1123. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  1124. isFail = true;
  1125. failTypeGoodsSnList.add(goodsDto.getSku());
  1126. }
  1127. }
  1128. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  1129. if(thirdMerchantBizEntity != null){
  1130. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  1131. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  1132. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  1133. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  1134. isFail = true;
  1135. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  1136. }
  1137. }
  1138. }else{//商户不存在
  1139. isFail = true;
  1140. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  1141. }
  1142. //校验商品信息是否已存在
  1143. Map<String, Object> map = new HashMap<>();
  1144. map.put("isSame", "true");
  1145. map.put("sku", goodsDto.getSku());
  1146. map.put("goodsSn", goodsDto.getGoodsSn());
  1147. map.put("goodsBizType", goodsDto.getGoodsBizType());
  1148. // List<GoodsEntity> list = querySame(map);
  1149. // if (list != null && list.size() != 0) {
  1150. // isFail = true;
  1151. // if(goodsDto.getSku()!=null) {
  1152. // failSameSkuList.add(goodsDto.getSku());
  1153. // }
  1154. // failGoodsSnList.add(goodsDto.getGoodsSn());
  1155. // failGoodsTypeList.add(goodsDto.getGoodsBizType());
  1156. // }
  1157. //校验产品条码是否存在
  1158. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  1159. //热销商品校验
  1160. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  1161. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  1162. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  1163. isFail = true;
  1164. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  1165. }
  1166. }
  1167. if(thirdMerchantBizEntity != null) {
  1168. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  1169. if (supplierEntity == null) {
  1170. //导入没有查到供货商,执行新增
  1171. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  1172. if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
  1173. isFail = true;
  1174. failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  1175. }
  1176. supplierEntity = new SupplierEntity();
  1177. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  1178. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  1179. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  1180. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  1181. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  1182. supplierEntity.setIsShow("0");
  1183. supplierDao.save(supplierEntity);
  1184. goodsEntity.setSupplierId(supplierEntity.getId());
  1185. } else {
  1186. goodsEntity.setSupplierId(supplierEntity.getId());
  1187. }
  1188. }
  1189. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1190. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  1191. if (sysCusUnitCodeEntity == null) {
  1192. isFail = true;
  1193. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  1194. } else {
  1195. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  1196. }
  1197. //原产国
  1198. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  1199. if (sysCusNationCodeEntity == null) {
  1200. isFail = true;
  1201. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  1202. } else {
  1203. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  1204. }
  1205. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  1206. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  1207. }
  1208. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  1209. }
  1210. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  1211. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  1212. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  1213. goodsEntity.setSku(goodsDto.getSku());
  1214. goodsEntity.setName(goodsDto.getName());
  1215. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  1216. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  1217. goodsEntity.setBrand(goodsDto.getBrand());
  1218. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  1219. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  1220. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  1221. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  1222. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  1223. goodsEntity.setIsNew(0);
  1224. goodsEntity.setUpdateUserId(user.getUserId());
  1225. goodsEntity.setAddTime(new Date());
  1226. goodsEntity.setCreateTime(new Date());
  1227. goodsEntity.setUpdateTime(new Date());
  1228. goodsEntity.setModTime(new Date());
  1229. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  1230. if(!isFail){
  1231. GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
  1232. if(goods!=null) {// 修改商品
  1233. goodsEntity.setId(goods.getId());
  1234. goodsEntity.setVideoUrl(goods.getVideoUrl());
  1235. goodsEntity.setListPicUrl(goods.getListPicUrl());
  1236. goodsEntity.setPrimaryPicUrl(goods.getPrimaryPicUrl());
  1237. goodsEntity.setGoodsNumber(goods.getGoodsNumber()+Integer.parseInt(goodsDto.getGoodsNumber()));
  1238. goodsDao.update(goodsEntity);
  1239. }else{
  1240. goodsDao.save(goodsEntity);
  1241. }
  1242. // 修改产品
  1243. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  1244. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  1245. // 普通货物暂不添加商品规格
  1246. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  1247. // 添加商品规格
  1248. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  1249. if(specificationEntity == null) {
  1250. goodsSpecification.setGoodsId(goodsEntity.getId());
  1251. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  1252. goodsSpecification.setSpecificationId(1);
  1253. goodsSpecificationDao.save(goodsSpecification);
  1254. }else {
  1255. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  1256. goodsSpecification.setId(specificationEntity.getId());
  1257. goodsSpecificationDao.update(goodsSpecification);
  1258. }
  1259. if(product == null){
  1260. product = new ProductEntity();
  1261. product.setGoodsSn(goodsDto.getGoodsSn());
  1262. product.setGoodsId(goodsEntity.getId());
  1263. product.setGoodsDefault(0);
  1264. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  1265. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1266. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1267. productDao.save(product);
  1268. }else{
  1269. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  1270. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  1271. productDao.update(product);
  1272. }
  1273. }
  1274. }
  1275. }
  1276. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  1277. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  1278. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  1279. exportExceptionDataEntity.setCreateTime(new Date());
  1280. exportExceptionDataEntity.setModTime(new Date());
  1281. exportExceptionDataEntity.setMerchSn(merchSn);
  1282. exportExceptionDataEntity.setStoreId(user.getStoreId());
  1283. if(exportDataType == 1) {
  1284. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  1285. }else{
  1286. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  1287. }
  1288. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  1289. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  1290. goodsUtils.save(exportExceptionDataEntity);
  1291. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1292. }
  1293. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  1294. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  1295. goodsUtils.save(exportExceptionDataEntity);
  1296. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1297. }
  1298. // if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  1299. // if(failSameSkuList.size()>0) {
  1300. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1301. // failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  1302. // goodsUtils.save(exportExceptionDataEntity);
  1303. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1304. // }else{
  1305. // exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  1306. // failGoodsTypeList + "】的商品信息");
  1307. // goodsUtils.save(exportExceptionDataEntity);
  1308. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1309. // }
  1310. // }
  1311. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  1312. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  1313. goodsUtils.save(exportExceptionDataEntity);
  1314. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1315. }
  1316. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  1317. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  1318. goodsUtils.save(exportExceptionDataEntity);
  1319. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1320. }
  1321. if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  1322. exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  1323. goodsUtils.save(exportExceptionDataEntity);
  1324. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1325. }
  1326. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1327. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1328. goodsUtils.save(exportExceptionDataEntity);
  1329. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1330. }
  1331. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1332. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1333. goodsUtils.save(exportExceptionDataEntity);
  1334. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1335. }
  1336. }else{
  1337. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  1338. }
  1339. return 1;
  1340. }
  1341. @Override
  1342. public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId) {
  1343. return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  1344. }
  1345. @Override
  1346. public GoodsPanoramaDto searchGoodsPanoramaDtoByKeyword(String keyword) {
  1347. return goodsDao.searchGoodsPanoramaDtoByKeyword(keyword);
  1348. }
  1349. @Override
  1350. public List<GoodsEntity> queryExportList(Map<String, Object> params) {
  1351. return goodsDao.queryExportList(params);
  1352. }
  1353. /**
  1354. * 查出pdf需要的需要
  1355. *
  1356. * @param sku 商品sku
  1357. * @param storeId
  1358. * @param prodBarcode
  1359. * @return
  1360. */
  1361. @Override
  1362. public PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode) {
  1363. return goodsDao.queryForPDFData(sku,storeId,prodBarcode);
  1364. }
  1365. /**
  1366. * 查询产品价格
  1367. *
  1368. * @param prodBarcode
  1369. * @param storeId
  1370. * @return
  1371. */
  1372. @Override
  1373. @Transactional
  1374. public Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId) {
  1375. /**
  1376. * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
  1377. */
  1378. GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  1379. if(goods == null) {
  1380. return null;
  1381. }
  1382. goods.setDiscountedPrice(new BigDecimal(0));
  1383. BigDecimal goodsRate = null;
  1384. try {
  1385. goodsRate = new BigDecimal(goods.getGoodsRate());
  1386. } catch (Exception e) {
  1387. goodsRate = new BigDecimal(0);
  1388. }
  1389. BigDecimal retailPrice = goods.getRetailPrice();
  1390. BigDecimal tax = goodsRate.multiply(retailPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1391. goods.setGoodstaxes(tax.toString());
  1392. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1393. Map<String,Object> skuActivitiesMap = new HashMap<>();
  1394. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1395. /**
  1396. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1397. * 参数: 当前时间 门店id
  1398. */
  1399. List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
  1400. if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
  1401. skuActivitiesMap.put("goods",goods);
  1402. return skuActivitiesMap;
  1403. }
  1404. // 遍历活动集合,查询有哪些活动是开启的
  1405. boolean daily = false,coupon = false,combinationPrice = false
  1406. ,discount = false,fullGift = false,fullReduction = false
  1407. ,getOneFree = false,promotion = false,halfPrice = false;
  1408. List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
  1409. Map<String,Long> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
  1410. // 将所有的营销活动新增到list中
  1411. for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
  1412. topicList.add(mkActivitiesEntity.getMkaTopic());
  1413. mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkActivitiesEntity.getMkaId());
  1414. }
  1415. // 判断有哪些营销活动
  1416. if(topicList.contains("zhjsp")) // 组合价
  1417. combinationPrice = true;
  1418. if(topicList.contains("dz")) // 打折
  1419. discount = true;
  1420. if(topicList.contains("mz")) //满赠
  1421. fullGift = true;
  1422. if(topicList.contains("mj")) // 满减
  1423. fullReduction = true;
  1424. if(topicList.contains("mysy")) // 买一送一
  1425. getOneFree = true;
  1426. if(topicList.contains("rchd")) // 日常活动
  1427. daily = true;
  1428. if(topicList.contains("yhq")) // 优惠券
  1429. coupon = true;
  1430. if(topicList.contains("lscx")) // 临时促销
  1431. promotion = true;
  1432. if(topicList.contains("drjbj"))
  1433. halfPrice = true;
  1434. // 获取未优惠前的商品价格
  1435. retailPrice = goods.getRetailPrice();
  1436. // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
  1437. String brandName = goods.getBrand();
  1438. /**
  1439. * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
  1440. */
  1441. /**
  1442. * 组合价的做法就是将参与组合的条码带到收银端
  1443. * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
  1444. *
  1445. *
  1446. * TODO
  1447. */
  1448. if(combinationPrice){
  1449. Long mkaId = mkaIdMap.get("zhjsp");
  1450. Map<String,Object> param = new HashMap<>();
  1451. param.put("mkaId",mkaId);
  1452. param.put("prodBarcode",prodBarcode);
  1453. List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
  1454. if(combinationPriceList != null && combinationPriceList.size() > 0) {
  1455. Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
  1456. combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
  1457. skuActivitiesMap.put("zhjsp",collect);
  1458. }
  1459. }
  1460. format = new SimpleDateFormat("yyyy-MM-dd");
  1461. String nowTime = format.format(new Date());
  1462. /**
  1463. * 满减可能是跟着条码,也可能跟着品牌
  1464. * 根据商品品牌跟商品条码去查询是否有优惠金额
  1465. *
  1466. * 满足金额 购买商品条码 赠品条码
  1467. *
  1468. */
  1469. Map<String,Object> fullReductionMap = new HashMap<>();
  1470. if(fullReduction){
  1471. Long mkaId = mkaIdMap.get("mj");
  1472. MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1473. if(fullReductionEntity != null) {
  1474. if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
  1475. // 跟着品牌走
  1476. fullReductionMap.put(brandName,fullReductionEntity);
  1477. }else{
  1478. // 跟着条码走
  1479. fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
  1480. }
  1481. skuActivitiesMap.put("mj",fullReductionMap);
  1482. }
  1483. }
  1484. /**
  1485. * 满赠可能是跟着条码,也可能跟着品牌
  1486. * 根据商品品牌跟商品条码去查询是否有满赠
  1487. * 1.先扫买的商品,然后查询出赠送的商品条码
  1488. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1489. * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
  1490. * TODO
  1491. */
  1492. Map<String,Object> fullGiftMap = new HashMap<>();
  1493. if(fullGift){
  1494. Long mkaId = mkaIdMap.get("mz");
  1495. MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1496. if(giftEntity != null) {
  1497. if(giftEntity.getProductBrand() != null){
  1498. // 跟着品牌走
  1499. fullGiftMap.put(brandName,giftEntity);
  1500. }else{
  1501. // 跟着条码走
  1502. fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
  1503. }
  1504. skuActivitiesMap.put("mz",fullGiftMap);
  1505. }
  1506. }
  1507. /**
  1508. * 买一送一可能是跟着条码,也可能跟着品牌
  1509. * 根据商品品牌跟商品条码去查询是否有送的商品
  1510. * 有两个场景
  1511. * 1.先扫买的商品,然后查询出赠送的商品条码
  1512. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1513. * 所以就需要一个map
  1514. * key为购买的商品条码或者商品品牌 value为赠送的商品条码
  1515. * 但是品牌是根据条码查询的,所以最终map里面的结构是
  1516. * key 商品条码 value 赠品条码
  1517. */
  1518. if(getOneFree){
  1519. Long mkaId = mkaIdMap.get("mysy");
  1520. MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
  1521. if(getOneFreeGoodsEntity != null){
  1522. if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
  1523. getOneFreeGoodsEntity.setBrand(false);
  1524. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1525. }else{
  1526. getOneFreeGoodsEntity.setBrand(true);
  1527. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1528. }
  1529. }
  1530. }
  1531. // 第二份半价
  1532. if(halfPrice){
  1533. Long mkaId = mkaIdMap.get("drjbj");
  1534. MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
  1535. if(activitiesHalfPriceEntity != null){
  1536. skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
  1537. }
  1538. }
  1539. // --------------------------------------------------------------------------------------
  1540. /**
  1541. * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
  1542. */
  1543. if(coupon){
  1544. Long mkaId = mkaIdMap.get("yhq");
  1545. MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
  1546. if(couponEntity != null){ // 优惠券码,优惠金额
  1547. Map<String,Object> returnMap = new HashMap<>();
  1548. returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
  1549. skuActivitiesMap.put("yhq",returnMap);
  1550. }
  1551. }
  1552. /**
  1553. * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
  1554. */
  1555. if(discount){
  1556. Long mkaId = mkaIdMap.get("dz");
  1557. MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
  1558. // TODO 可能会直接替代产品价格
  1559. if (discountEntity != null) {
  1560. goods.setActualPaymentAmount(discountEntity.getActivityPrice());
  1561. goods.setRetailPrice(discountEntity.getActivityPrice());
  1562. tax = goodsRate.multiply(discountEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1563. goods.setGoodstaxes(tax.toString());
  1564. // goods.setDiscountedPrice(retailPrice.subtract(discountEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1565. goods.setActivity("打折");
  1566. }
  1567. }
  1568. /**
  1569. * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
  1570. */
  1571. if(daily){
  1572. Long mkaId = mkaIdMap.get("rchd");
  1573. MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
  1574. if(dailyActivitiesEntity != null){
  1575. goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
  1576. goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
  1577. tax = goodsRate.multiply(dailyActivitiesEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1578. goods.setGoodstaxes(tax.toString());
  1579. // goods.setDiscountedPrice(retailPrice.subtract(dailyActivitiesEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1580. goods.setActivity("日常活动");
  1581. }
  1582. }
  1583. /**
  1584. * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
  1585. */
  1586. if(promotion){
  1587. Long mkaId = mkaIdMap.get("lscx");
  1588. MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
  1589. // 如果该商品存在临时促销,直接替换活动价格
  1590. if(promotionEntity != null){
  1591. goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
  1592. goods.setRetailPrice(promotionEntity.getActivityPrice());
  1593. tax = goodsRate.multiply(promotionEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1594. goods.setGoodstaxes(tax.toString());
  1595. // goods.setDiscountedPrice(retailPrice.subtract(promotionEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1596. goods.setActivity("临时促销");
  1597. }
  1598. }
  1599. skuActivitiesMap.put("goods",goods);
  1600. return skuActivitiesMap;
  1601. }
  1602. /**
  1603. * 根据条形码查询商品
  1604. *
  1605. * @param barCode
  1606. * @return
  1607. */
  1608. @Override
  1609. public GoodsEntity queryByBarcode(String barCode) {
  1610. return goodsDao.queryByBarcode(barCode);
  1611. }
  1612. /**
  1613. * 根据sku查询商品
  1614. *
  1615. * @param sku
  1616. * @return
  1617. */
  1618. @Override
  1619. public GoodsEntity queryBySku(String sku) {
  1620. return goodsDao.queryBySku(sku);
  1621. }
  1622. /* @Override
  1623. @Transactional
  1624. public int uploadExcel(MultipartFile file) {
  1625. SysUserEntity user = ShiroUtils.getUserEntity();
  1626. List<String[]> list = ExcelImport.getExcelData(file);
  1627. // 取门店名称
  1628. StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
  1629. if (null == storeEntity) {
  1630. return 0;
  1631. }
  1632. //去除表头两行、底部合计
  1633. if (list != null && list.size() > 3) {
  1634. ProductStoreRelaEntity storeRelaEntity;
  1635. ProductEntity productEntity;
  1636. for (int i = 2; i < list.size() - 1; i++) {
  1637. String[] item = list.get(i);
  1638. String goodsSn = item[0];
  1639. productEntity = productDao.queryObjectBySn(goodsSn);
  1640. if (StringUtils.isNullOrEmpty(goodsSn)) {
  1641. continue;
  1642. }
  1643. if (null == productEntity || null == productEntity.getId()) {
  1644. continue;
  1645. }
  1646. storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
  1647. if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
  1648. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1649. storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
  1650. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1651. productStoreRelaDao.update(storeRelaEntity);
  1652. } else {
  1653. storeRelaEntity = new ProductStoreRelaEntity();
  1654. storeRelaEntity.setGoodsId(productEntity.getGoodsId());
  1655. storeRelaEntity.setProductId(productEntity.getId());
  1656. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1657. storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
  1658. storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
  1659. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1660. storeRelaEntity.setStoreId(storeEntity.getId());
  1661. productStoreRelaDao.save(storeRelaEntity);
  1662. }
  1663. }
  1664. }
  1665. return 1;
  1666. }*/
  1667. public GoodsEntity queryObjectBySn(String goodsSn) {
  1668. return goodsDao.queryObjectBySn(goodsSn);
  1669. }
  1670. }