GoodsServiceImpl.java 99 KB

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