GoodsServiceImpl.java 99 KB

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