GoodsServiceImpl.java 108 KB

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