GoodsServiceImpl.java 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  1. package com.kmall.admin.service.impl;
  2. import cn.hutool.http.HttpUtil;
  3. import com.alibaba.druid.support.json.JSONUtils;
  4. import com.alibaba.fastjson.JSON;
  5. import com.google.common.collect.ImmutableBiMap;
  6. import com.google.common.collect.Maps;
  7. import com.kmall.admin.dao.*;
  8. import com.kmall.admin.dto.GoodsDetailsDto;
  9. import com.kmall.admin.dto.GoodsDto;
  10. import com.kmall.admin.dto.GoodsPanoramaDto;
  11. import com.kmall.admin.entity.*;
  12. import com.kmall.admin.entity.mk.MkActivitiesEntity;
  13. import com.kmall.admin.service.*;
  14. import com.kmall.admin.service.mk.MkActivitiesService;
  15. import com.kmall.admin.service.mk.MkActivityFormService;
  16. import com.kmall.admin.service.GoodsService;
  17. import com.kmall.admin.utils.CalculateTax;
  18. import com.kmall.admin.utils.GoodsUtils;
  19. import com.kmall.admin.utils.ShiroUtils;
  20. import com.kmall.api.entity.exportpdf.PDFGoodsDto;
  21. import com.kmall.common.constant.Dict;
  22. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  23. import com.kmall.common.utils.*;
  24. import com.kmall.common.utils.print.ticket.item.Goods;
  25. import org.apache.poi.util.StringUtil;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.math.BigDecimal;
  30. import java.math.RoundingMode;
  31. import java.text.SimpleDateFormat;
  32. import java.util.*;
  33. import java.util.stream.Collectors;
  34. /**
  35. * Service实现类
  36. *
  37. * @author Scott
  38. * @email
  39. * @date 2017-08-21 21:19:49
  40. */
  41. @Service("goodsService")
  42. public class GoodsServiceImpl implements GoodsService {
  43. @Autowired
  44. private MerchDao merchDao;
  45. @Autowired
  46. private GoodsDao goodsDao;
  47. @Autowired
  48. private ProductDao productDao;
  49. @Autowired
  50. private GoodsGalleryDao goodsGalleryDao;
  51. @Autowired
  52. private GoodsSpecificationDao goodsSpecificationDao;
  53. @Autowired
  54. private ProductStoreRelaDao productStoreRelaDao;
  55. @Autowired
  56. private StoreDao storeDao;
  57. @Autowired
  58. private GoodsGroupDao goodsGroupDao;
  59. @Autowired
  60. private CategoryDao categoryDao;
  61. @Autowired
  62. private SupplierDao supplierDao;
  63. @Autowired
  64. private SysCusNationCodeDao sysCusNationCodeDao;
  65. @Autowired
  66. private SysCusUnitCodeDao sysCusUnitCodeDao;
  67. @Autowired
  68. private ExportExceptionDataDao exportExceptionDataDao;
  69. @Autowired
  70. private CartDao cartDao;
  71. @Autowired
  72. private ThirdMerchantBizDao thirdMerchantBizDao;
  73. @Autowired
  74. private MngChangeDao mngChangeDao;
  75. @Autowired
  76. private MerchUserDao merchUserDao;
  77. @Autowired
  78. private StoreMngChangeDao storeMngChangeDao;
  79. @Autowired
  80. private GoodsUtils goodsUtils;
  81. @Autowired
  82. private 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 storeId, String goodsName) {
  584. return goodsDao.queryByName(storeId, 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. GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
  1394. // TODO 算税需要修改
  1395. CalculateTax.calculateFinalTax(goodsEntity,retailPrice);
  1396. BigDecimal tax = goodsRate.multiply(retailPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1397. goods.setGoodstaxes(tax.toString());
  1398. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1399. Map<String,Object> skuActivitiesMap = new HashMap<>();
  1400. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1401. /**
  1402. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1403. * 参数: 当前时间 门店id
  1404. */
  1405. List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
  1406. if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
  1407. skuActivitiesMap.put("goods",goods);
  1408. return skuActivitiesMap;
  1409. }
  1410. // 遍历活动集合,查询有哪些活动是开启的
  1411. boolean daily = false,coupon = false,combinationPrice = false
  1412. ,discount = false,fullGift = false,fullReduction = false
  1413. ,getOneFree = false,promotion = false,halfPrice = false;
  1414. List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
  1415. Map<String,String> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
  1416. // 将所有的营销活动新增到list中
  1417. for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
  1418. topicList.add(mkActivitiesEntity.getMkaTopic());
  1419. String mkaId = mkaIdMap.putIfAbsent(mkActivitiesEntity.getMkaTopic(), mkActivitiesEntity.getMkaId()+"");
  1420. if(StringUtils.isNotEmpty(mkaId)){
  1421. mkaId = "'"+mkaId + "','" + mkActivitiesEntity.getMkaId()+"'";
  1422. mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkaId);
  1423. }
  1424. }
  1425. // 判断有哪些营销活动
  1426. if(topicList.contains("zhjsp")) // 组合价
  1427. combinationPrice = true;
  1428. if(topicList.contains("dz")) // 打折
  1429. discount = true;
  1430. if(topicList.contains("mz")) //满赠
  1431. fullGift = true;
  1432. if(topicList.contains("mj")) // 满减
  1433. fullReduction = true;
  1434. if(topicList.contains("mysy")) // 买一送一
  1435. getOneFree = true;
  1436. if(topicList.contains("rchd")) // 日常活动
  1437. daily = true;
  1438. if(topicList.contains("yhq")) // 优惠券
  1439. coupon = true;
  1440. if(topicList.contains("lscx")) // 临时促销
  1441. promotion = true;
  1442. if(topicList.contains("drjbj"))
  1443. halfPrice = true;
  1444. // 获取未优惠前的商品价格
  1445. retailPrice = goods.getRetailPrice();
  1446. // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
  1447. String brandName = goods.getBrand();
  1448. /**
  1449. * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
  1450. */
  1451. /**
  1452. * 组合价的做法就是将参与组合的条码带到收银端
  1453. * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
  1454. *
  1455. *
  1456. * TODO
  1457. */
  1458. if(combinationPrice){
  1459. String mkaId = mkaIdMap.get("zhjsp");
  1460. Map<String,Object> param = new HashMap<>();
  1461. param.put("mkaId",mkaId);
  1462. param.put("prodBarcode",prodBarcode);
  1463. List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
  1464. if(combinationPriceList != null && combinationPriceList.size() > 0) {
  1465. Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
  1466. combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
  1467. skuActivitiesMap.put("zhjsp",collect);
  1468. }
  1469. }
  1470. format = new SimpleDateFormat("yyyy-MM-dd");
  1471. String nowTime = format.format(new Date());
  1472. /**
  1473. * 满减可能是跟着条码,也可能跟着品牌
  1474. * 根据商品品牌跟商品条码去查询是否有优惠金额
  1475. *
  1476. * 满足金额 购买商品条码 赠品条码
  1477. *
  1478. */
  1479. Map<String,Object> fullReductionMap = new HashMap<>();
  1480. if(fullReduction){
  1481. String mkaId = mkaIdMap.get("mj");
  1482. MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1483. if(fullReductionEntity != null) {
  1484. if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
  1485. // 跟着品牌走
  1486. fullReductionMap.put(brandName,fullReductionEntity);
  1487. }else{
  1488. // 跟着条码走
  1489. fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
  1490. }
  1491. skuActivitiesMap.put("mj",fullReductionMap);
  1492. }
  1493. }
  1494. /**
  1495. * 满赠可能是跟着条码,也可能跟着品牌
  1496. * 根据商品品牌跟商品条码去查询是否有满赠
  1497. * 1.先扫买的商品,然后查询出赠送的商品条码
  1498. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1499. * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
  1500. * TODO
  1501. */
  1502. Map<String,Object> fullGiftMap = new HashMap<>();
  1503. if(fullGift){
  1504. String mkaId = mkaIdMap.get("mz");
  1505. MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1506. if(giftEntity != null) {
  1507. if(giftEntity.getProductBrand() != null){
  1508. // 跟着品牌走
  1509. fullGiftMap.put(brandName,giftEntity);
  1510. }else{
  1511. // 跟着条码走
  1512. fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
  1513. }
  1514. skuActivitiesMap.put("mz",fullGiftMap);
  1515. }
  1516. }
  1517. /**
  1518. * 买一送一可能是跟着条码,也可能跟着品牌
  1519. * 根据商品品牌跟商品条码去查询是否有送的商品
  1520. * 有两个场景
  1521. * 1.先扫买的商品,然后查询出赠送的商品条码
  1522. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1523. * 所以就需要一个map
  1524. * key为购买的商品条码或者商品品牌 value为赠送的商品条码
  1525. * 但是品牌是根据条码查询的,所以最终map里面的结构是
  1526. * key 商品条码 value 赠品条码
  1527. */
  1528. if(getOneFree){
  1529. String mkaId = mkaIdMap.get("mysy");
  1530. MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
  1531. if(getOneFreeGoodsEntity != null){
  1532. if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
  1533. getOneFreeGoodsEntity.setBrand(false);
  1534. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1535. }else{
  1536. getOneFreeGoodsEntity.setBrand(true);
  1537. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1538. }
  1539. }
  1540. }
  1541. // 第二份半价
  1542. if(halfPrice){
  1543. String mkaId = mkaIdMap.get("drjbj");
  1544. MkActivitiesHalfPriceEntity activitiesHalfPriceEntity = halfPriceService.queryByCodeOrBrand(mkaId,prodBarcode);
  1545. if(activitiesHalfPriceEntity != null){
  1546. skuActivitiesMap.put("drjbj",activitiesHalfPriceEntity);
  1547. }
  1548. }
  1549. // --------------------------------------------------------------------------------------
  1550. /**
  1551. * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
  1552. */
  1553. if(coupon){
  1554. String mkaId = mkaIdMap.get("yhq");
  1555. MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
  1556. if(couponEntity != null){ // 优惠券码,优惠金额
  1557. Map<String,Object> returnMap = new HashMap<>();
  1558. returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
  1559. skuActivitiesMap.put("yhq",returnMap);
  1560. }
  1561. }
  1562. /**
  1563. * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
  1564. */
  1565. if(discount){
  1566. String mkaId = mkaIdMap.get("dz");
  1567. MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
  1568. // TODO 可能会直接替代产品价格
  1569. if (discountEntity != null) {
  1570. goods.setActualPaymentAmount(discountEntity.getActivityPrice());
  1571. goods.setRetailPrice(discountEntity.getActivityPrice());
  1572. // TODO 税费需要修改
  1573. tax = goodsRate.multiply(discountEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1574. goods.setGoodstaxes(tax.toString());
  1575. // goods.setDiscountedPrice(retailPrice.subtract(discountEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1576. goods.setActivity("打折");
  1577. }
  1578. }
  1579. /**
  1580. * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
  1581. */
  1582. if(daily){
  1583. String mkaId = mkaIdMap.get("rchd");
  1584. MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
  1585. if(dailyActivitiesEntity != null){
  1586. goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
  1587. goods.setRetailPrice(dailyActivitiesEntity.getActivityPrice());
  1588. // TODO 税费需要修改
  1589. tax = goodsRate.multiply(dailyActivitiesEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1590. goods.setGoodstaxes(tax.toString());
  1591. // goods.setDiscountedPrice(retailPrice.subtract(dailyActivitiesEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1592. goods.setActivity("日常活动");
  1593. }
  1594. }
  1595. /**
  1596. * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
  1597. */
  1598. if(promotion){
  1599. String mkaId = mkaIdMap.get("lscx");
  1600. MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
  1601. // 如果该商品存在临时促销,直接替换活动价格
  1602. if(promotionEntity != null){
  1603. goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
  1604. goods.setRetailPrice(promotionEntity.getActivityPrice());
  1605. // TODO 税费需要修改
  1606. tax = goodsRate.multiply(promotionEntity.getActivityPrice().divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1607. goods.setGoodstaxes(tax.toString());
  1608. // goods.setDiscountedPrice(retailPrice.subtract(promotionEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1609. goods.setActivity("临时促销");
  1610. }
  1611. }
  1612. skuActivitiesMap.put("goods",goods);
  1613. return skuActivitiesMap;
  1614. }
  1615. /**
  1616. * 根据条形码查询商品
  1617. *
  1618. * @param barCode
  1619. * @return
  1620. */
  1621. @Override
  1622. public GoodsEntity queryByBarcode(String barCode) {
  1623. return goodsDao.queryByBarcode(barCode);
  1624. }
  1625. /**
  1626. * 根据sku查询商品
  1627. *
  1628. * @param sku
  1629. * @return
  1630. */
  1631. @Override
  1632. public GoodsEntity queryBySku(String sku) {
  1633. return goodsDao.queryBySku(sku);
  1634. }
  1635. /* @Override
  1636. @Transactional
  1637. public int uploadExcel(MultipartFile file) {
  1638. SysUserEntity user = ShiroUtils.getUserEntity();
  1639. List<String[]> list = ExcelImport.getExcelData(file);
  1640. // 取门店名称
  1641. StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
  1642. if (null == storeEntity) {
  1643. return 0;
  1644. }
  1645. //去除表头两行、底部合计
  1646. if (list != null && list.size() > 3) {
  1647. ProductStoreRelaEntity storeRelaEntity;
  1648. ProductEntity productEntity;
  1649. for (int i = 2; i < list.size() - 1; i++) {
  1650. String[] item = list.get(i);
  1651. String goodsSn = item[0];
  1652. productEntity = productDao.queryObjectBySn(goodsSn);
  1653. if (StringUtils.isNullOrEmpty(goodsSn)) {
  1654. continue;
  1655. }
  1656. if (null == productEntity || null == productEntity.getId()) {
  1657. continue;
  1658. }
  1659. storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
  1660. if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
  1661. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1662. storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
  1663. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1664. productStoreRelaDao.update(storeRelaEntity);
  1665. } else {
  1666. storeRelaEntity = new ProductStoreRelaEntity();
  1667. storeRelaEntity.setGoodsId(productEntity.getGoodsId());
  1668. storeRelaEntity.setProductId(productEntity.getId());
  1669. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1670. storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
  1671. storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
  1672. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1673. storeRelaEntity.setStoreId(storeEntity.getId());
  1674. productStoreRelaDao.save(storeRelaEntity);
  1675. }
  1676. }
  1677. }
  1678. return 1;
  1679. }*/
  1680. public GoodsEntity queryObjectBySn(String goodsSn) {
  1681. return goodsDao.queryObjectBySn(goodsSn);
  1682. }
  1683. @Override
  1684. @Transactional
  1685. public void syncOmsHsCode() {
  1686. List<String> skuList = goodsDao.queryNonSyncOmsHsCodeSkuList();
  1687. if (Objects.nonNull(skuList) && skuList.size()>0){
  1688. String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/pdProductRecord/hsCodeMapBySkuList?skuList=" + skuList);
  1689. Map<String,Map> map = JSON.parseObject(result, Map.class);
  1690. for (String sku : skuList) {
  1691. Map skuInfoMap = map.get(sku);
  1692. if (Objects.nonNull(skuInfoMap)){
  1693. String hsCodeName = (String) skuInfoMap.get("cusGoodsName");
  1694. String hsCode = (String) skuInfoMap.get("cusGoodsCode");
  1695. BigDecimal impConsumTaxRate = (BigDecimal) skuInfoMap.get("impConsumTaxRate");
  1696. BigDecimal valueAddedTaxRate = (BigDecimal) skuInfoMap.get("valueAddedTaxRate");
  1697. BigDecimal legalUnit1Qty = (BigDecimal) skuInfoMap.get("legalUnit1Qty");
  1698. BigDecimal legalUnit2Qty = (BigDecimal) skuInfoMap.get("legalUnit2Qty");
  1699. BigDecimal cosmThresholdValue = (BigDecimal) skuInfoMap.get("cosmThresholdValue");
  1700. if (StringUtils.isNotEmpty(hsCodeName) && StringUtils.isNotEmpty(hsCode)){
  1701. List<GoodsEntity> goodsEntityList = goodsDao.queryListBySku(sku);
  1702. if (Objects.nonNull(goodsEntityList) && goodsEntityList.size()>0){
  1703. for (GoodsEntity goodsEntity : goodsEntityList) {
  1704. goodsEntity.setHsCode(hsCode);
  1705. goodsEntity.setHsCodeName(hsCodeName);
  1706. goodsEntity.setImpConsumTaxRate(impConsumTaxRate);
  1707. goodsEntity.setValueAddedTaxRate(valueAddedTaxRate);
  1708. goodsEntity.setIsSyncHsCode("1");
  1709. goodsEntity.setLegalUnit1Qty(legalUnit1Qty);
  1710. goodsEntity.setLegalUnit2Qty(legalUnit2Qty);
  1711. goodsEntity.setCosmThresholdValue(cosmThresholdValue);
  1712. goodsDao.update(goodsEntity);
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. @Override
  1721. @Transactional
  1722. public void syncOmsGoodsRate() {
  1723. List<GoodsEntity> list = goodsDao.queryNonSyncOmsGoodsRateSkuList();
  1724. if (Objects.nonNull(list) && list.size()>0){
  1725. String result = HttpUtil.get("https://oms.ds-bay.com/oms-controller-mgt/taxBill/queryGoodsRate?thirdPartyMerchCode=CW001");
  1726. Map<String,String> map = JSON.parseObject(result, Map.class);
  1727. for (GoodsEntity goodsEntity : list) {
  1728. String goodsRate = map.get(goodsEntity.getHsCode());
  1729. if (StringUtils.isNotEmpty(goodsRate)){
  1730. goodsEntity.setIsSyncGoodsRate("1");
  1731. goodsEntity.setGoodsRate(new BigDecimal(goodsRate));
  1732. goodsDao.update(goodsEntity);
  1733. }
  1734. }
  1735. }
  1736. }
  1737. @Override
  1738. @Transactional
  1739. public void syncGoodsRate() {
  1740. String storeId = "163"; // 市场部说所有门店价格一致,并且活动一致,可直接取其中一个门店价格进行计算税率
  1741. // 查询出所有商品
  1742. List<GoodsEntity> allGoodsList = goodsDao.queryAllList();
  1743. for (GoodsEntity goodsEntity : allGoodsList) {
  1744. // 同步过海关商品编码才可以算税率
  1745. if ("1".equals(goodsEntity.getIsSyncHsCode())) {
  1746. Map<String, Object> goodsDetailMap = calculateGoodsDetail(goodsEntity.getProdBarcode(), storeId);
  1747. if (Objects.nonNull(goodsDetailMap)) {
  1748. GoodsDetailsDto goods = (GoodsDetailsDto) goodsDetailMap.get("goods");
  1749. // 顾客给的钱 就是税后价
  1750. BigDecimal actualPaymentAmount = goods.getActualPaymentAmount(); //随便拿一个门店的当前时间的价格,如果有活动价会使用活动价
  1751. // BigDecimal calculateTax = CalculateTax.calculateTax(goodsEntity, actualPaymentAmount);// 税费
  1752. // BigDecimal goodsRate = calculateTax.divide(actualPaymentAmount, 4, BigDecimal.ROUND_HALF_UP);
  1753. BigDecimal goodsRate =CalculateTax.calculateGoodsRate(goodsEntity, actualPaymentAmount);
  1754. goodsEntity.setGoodsRate(goodsRate);
  1755. goodsDao.update(goodsEntity);
  1756. }
  1757. }
  1758. }
  1759. }
  1760. }