GoodsServiceImpl.java 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. package com.kmall.admin.service.impl;
  2. import com.google.common.collect.ImmutableBiMap;
  3. import com.google.common.collect.Maps;
  4. import com.kmall.admin.dao.*;
  5. import com.kmall.admin.dto.GoodsDto;
  6. import com.kmall.admin.entity.*;
  7. import com.kmall.admin.service.GoodsService;
  8. import com.kmall.admin.utils.ShiroUtils;
  9. import com.kmall.common.constant.Dict;
  10. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  11. import com.kmall.common.utils.*;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import java.math.BigDecimal;
  16. import java.util.*;
  17. /**
  18. * Service实现类
  19. *
  20. * @author Scott
  21. * @email
  22. * @date 2017-08-21 21:19:49
  23. */
  24. @Service("goodsService")
  25. public class GoodsServiceImpl implements GoodsService {
  26. @Autowired
  27. private GoodsDao goodsDao;
  28. @Autowired
  29. private ProductDao productDao;
  30. @Autowired
  31. private GoodsGalleryDao goodsGalleryDao;
  32. @Autowired
  33. private GoodsSpecificationDao goodsSpecificationDao;
  34. @Autowired
  35. private ProductStoreRelaDao productStoreRelaDao;
  36. @Autowired
  37. private StoreDao storeDao;
  38. @Autowired
  39. private GoodsGroupDao goodsGroupDao;
  40. @Autowired
  41. private CategoryDao categoryDao;
  42. @Autowired
  43. private SupplierDao supplierDao;
  44. @Autowired
  45. private SysCusNationCodeDao sysCusNationCodeDao;
  46. @Autowired
  47. private SysCusUnitCodeDao sysCusUnitCodeDao;
  48. @Autowired
  49. private ExportExceptionDataDao exportExceptionDataDao;
  50. @Autowired
  51. private CartDao cartDao;
  52. @Autowired
  53. private ThirdMerchantBizDao thirdMerchantBizDao;
  54. @Autowired
  55. private MngChangeDao mngChangeDao;
  56. @Override
  57. public GoodsEntity queryObject(Integer id) {
  58. Map<String, Object> map = new HashMap<String, Object>();
  59. map.put("goodsId", id);
  60. // List<GoodsAttributeEntity> attributeEntities = goodsAttributeDao.queryList(map);
  61. List<ProductEntity> productEntityList = productDao.queryList(map);
  62. GoodsEntity entity = goodsDao.queryObject(id);
  63. // entity.setAttributeEntityList(attributeEntities);
  64. entity.setProductEntityList(productEntityList);
  65. return entity;
  66. }
  67. @Override
  68. public GoodsEntity queryObjectByProdBarcodeAndBizType(String prodBarcode, Integer storeId){
  69. Map<String, Object> map = new HashMap<String, Object>();
  70. map.put("prodBarcode", prodBarcode);
  71. GoodsEntity entity = goodsDao.queryObjectByProdBarcodeAndBizType(prodBarcode, storeId);
  72. return entity;
  73. }
  74. @Override
  75. public List<GoodsEntity> queryList(Map<String, Object> map) {
  76. return goodsDao.queryList(map);
  77. }
  78. @Override
  79. public List<GoodsEntity> querySame(Map<String, Object> map) {
  80. return goodsDao.querySame(map);
  81. }
  82. @Override
  83. public int queryTotal(Map<String, Object> map) {
  84. return goodsDao.queryTotal(map);
  85. }
  86. @Override
  87. @Transactional
  88. public int save(GoodsEntity goods) {
  89. Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
  90. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  91. builder.put("merchSn", "商户编号");
  92. builder.put("thirdPartyMerchCode", "第三方商户编号");
  93. // builder.put("attributeCategory", "商品分类");
  94. // builder.put("categoryId", "商品二级分类");
  95. builder.put("goodsSn", "商品编码");
  96. builder.put("name", "商品名称");
  97. builder.put("goodsUnit", "商品单位");
  98. builder.put("prodBarcode", "产品条码");
  99. builder.put("goodsBizType", "货品业务类型");
  100. // builder.put("brandId", "品牌");
  101. builder.put("supplierId", "供应商");
  102. // builder.put("freightId", "运费模版");
  103. builder.put("goodsNumber", "商品库存");
  104. builder.put("primaryPicUrl", "商品主图");
  105. builder.put("listPicUrl", "商品列表图");
  106. builder.put("goodsDesc", "商品描述");
  107. builder.put("isOnSale", "上架");
  108. builder.put("isHot", "热销");
  109. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  110. if (Integer.valueOf(r.get("code").toString()) != 0) {
  111. throw new RRException(r.get("msg").toString());
  112. } else {
  113. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  114. // 海关信息,普通货物可不添加
  115. builder.put("sku", "SKU");
  116. builder.put("goodsRate", "商品税率");
  117. // builder.put("retailPrice", "零售价");
  118. builder.put("brand", "产品品牌");
  119. builder.put("unitCode", "计量单位代码");
  120. builder.put("cusGoodsCode", "海关商品编码");
  121. builder.put("ciqProdModel", "国检规格型号");
  122. builder.put("oriCntCode", "原产国代码");
  123. builder.put("cusDeclEle", "海关申报要素");
  124. builder.put("cusRecCode", "海关备案编号");
  125. }
  126. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  127. if (Integer.valueOf(r.get("code").toString()) != 0) {
  128. throw new RRException(r.get("msg").toString());
  129. }
  130. }
  131. /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
  132. if(thirdMerchantBizEntity == null){
  133. throw new RRException("第三方商户信息不存在");
  134. }
  135. if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
  136. if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
  137. builder.put("goodsNumber", "商品库存");
  138. }
  139. }*/
  140. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  141. if (Integer.valueOf(r.get("code").toString()) != 0) {
  142. throw new RRException(r.get("msg").toString());
  143. }
  144. // 商品轮播图
  145. List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
  146. if (galleryEntityList == null || galleryEntityList.size() <= 0) {
  147. throw new RRException("至少添加一张商品轮播图!");
  148. }
  149. List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),null);
  150. if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
  151. throw new RRException("不能有重复的产品条码信息!");
  152. }
  153. SysUserEntity user = ShiroUtils.getUserEntity();
  154. Map<String, Object> map = new HashMap<>();
  155. map.put("isSame", "true");
  156. map.put("sku", goods.getSku());
  157. map.put("goodsSn", goods.getGoodsSn());
  158. map.put("goodsBizType", goods.getGoodsBizType());
  159. List<GoodsEntity> list = querySame(map);
  160. if (list != null && list.size() != 0) {
  161. throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
  162. }
  163. // 添加商品
  164. if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
  165. || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
  166. goods.setIsHot(0);
  167. }
  168. // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
  169. goods.setAddTime(new Date());
  170. goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  171. goods.setIsNew(0);
  172. goods.setCreateUserId(user.getUserId());
  173. goods.setUpdateUserId(user.getUserId());
  174. goods.setUpdateTime(new Date());
  175. goods.setModTime(new Date());
  176. goods.setCreateTime(new Date());
  177. // 新增商品
  178. goodsDao.save(goods);
  179. Long id = goods.getId();
  180. // 添加商品轮播图
  181. for (int i=0;i<galleryEntityList.size();i++) {
  182. GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
  183. galleryEntity.setMerchSn(goods.getMerchSn());
  184. galleryEntity.setGoodsId(id);
  185. galleryEntity.setSortOrder((i+1));
  186. galleryEntity.setFileType("0");//图片
  187. goodsGalleryDao.save(galleryEntity);
  188. }
  189. if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
  190. GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
  191. galleryEntity.setMerchSn(goods.getMerchSn());
  192. galleryEntity.setGoodsId(id);
  193. galleryEntity.setSortOrder(0);
  194. galleryEntity.setFileType("1");//视频
  195. goodsGalleryDao.save(galleryEntity);
  196. }
  197. /*
  198. // 添加商品参数
  199. List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
  200. if (attributeEntityList != null && attributeEntityList.size() > 0) {
  201. for (GoodsAttributeEntity item : attributeEntityList) {
  202. if (item.getIsDelete() == 0) {
  203. if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
  204. item.setGoodsId(id);
  205. item.setMerchSn(goods.getMerchSn());
  206. goodsAttributeDao.save(item);
  207. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
  208. throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
  209. } else if (item.getId() == null && item.getAttributeId() == null) {
  210. continue;
  211. }
  212. }
  213. }
  214. }*/
  215. if (goods.getGoodsNumber() != null){
  216. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  217. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(id)));
  218. mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
  219. mngChangeEntity.setChangeReason("新增商户商品总库存");
  220. mngChangeEntity.setChangeType(Dict.changeType.item_0.getItem());
  221. mngChangeEntity.setChangeNum(goods.getGoodsNumber());//变化数
  222. mngChangeEntity.setOriginalNum(0);//原库存数
  223. mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
  224. mngChangeEntity.setCreateTime(new Date());
  225. mngChangeEntity.setModTime(new Date());
  226. mngChangeEntity.setCreaterSn(user.getUsername());
  227. mngChangeEntity.setModerSn(user.getUsername());
  228. mngChangeEntity.setIsValid(0);
  229. mngChangeEntity.setMerchSn(goods.getMerchSn());
  230. mngChangeDao.save(mngChangeEntity);
  231. }
  232. // 添加产品
  233. ProductEntity product = new ProductEntity();
  234. product.setGoodsId(id);
  235. product.setGoodsSn(goods.getGoodsSn());
  236. // 保税商品,普通货物暂不添加商品规格
  237. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  238. // 添加商品规格
  239. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  240. goodsSpecification.setGoodsId(id);
  241. goodsSpecification.setValue(goods.getCiqProdModel());
  242. goodsSpecification.setSpecificationId(1);
  243. goodsSpecificationDao.save(goodsSpecification);
  244. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  245. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  246. }
  247. return productDao.save(product);
  248. }
  249. @Override
  250. @Transactional
  251. public int update(GoodsEntity goods) {
  252. Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
  253. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  254. builder.put("merchSn", "商户编号");
  255. builder.put("thirdPartyMerchCode", "第三方商户编号");
  256. // builder.put("attributeCategory", "商品分类");
  257. // builder.put("categoryId", "商品二级分类");
  258. builder.put("goodsSn", "商品编码");
  259. builder.put("name", "商品名称");
  260. builder.put("goodsUnit", "商品单位");
  261. builder.put("prodBarcode", "产品条码");
  262. builder.put("goodsBizType", "货品业务类型");
  263. // builder.put("brandId", "品牌");
  264. builder.put("supplierId", "供应商");
  265. builder.put("goodsNumber", "商品库存");
  266. // builder.put("freightId", "运费模版");
  267. builder.put("primaryPicUrl", "商品主图");
  268. builder.put("listPicUrl", "商品列表图");
  269. builder.put("goodsDesc", "商品描述");
  270. builder.put("isOnSale", "上架");
  271. builder.put("isHot", "热销");
  272. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  273. if (Integer.valueOf(r.get("code").toString()) != 0) {
  274. throw new RRException(r.get("msg").toString());
  275. } else {
  276. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  277. // 海关信息,普通货物可不添加
  278. builder.put("sku", "SKU");
  279. builder.put("goodsRate", "商品税率");
  280. // builder.put("retailPrice", "零售价");
  281. builder.put("brand", "产品品牌");
  282. builder.put("unitCode", "计量单位代码");
  283. builder.put("cusGoodsCode", "海关商品编码");
  284. builder.put("ciqProdModel", "国检规格型号");
  285. builder.put("oriCntCode", "原产国代码");
  286. builder.put("cusRecCode", "海关备案编号");
  287. builder.put("cusDeclEle", "海关申报要素");
  288. }
  289. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  290. if (Integer.valueOf(r.get("code").toString()) != 0) {
  291. throw new RRException(r.get("msg").toString());
  292. }
  293. }
  294. /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
  295. if(thirdMerchantBizEntity == null){
  296. throw new RRException("所属第三方商户不存在");
  297. }*/
  298. GoodsEntity goodsEntity = goodsDao.queryObject(goods.getId());
  299. if(goodsEntity != null){
  300. /*if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
  301. if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
  302. builder.put("goodsNumber", "商品库存");
  303. }
  304. }
  305. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  306. if (Integer.valueOf(r.get("code").toString()) != 0) {
  307. throw new RRException(r.get("msg").toString());
  308. }*/
  309. }else{
  310. throw new RRException("商品不存在");
  311. }
  312. // 商品轮播图
  313. List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
  314. if (galleryEntityList == null || galleryEntityList.size() <= 0) {
  315. throw new RRException("至少保留一张商品轮播图!");
  316. }
  317. Integer goodsNumber = goods.getGoodsNumber();//商品总库存
  318. Integer storeTotalGoodsNumber = 0;//商品分配库存
  319. List<ProductStoreRelaEntity> proStoreList = productStoreRelaDao.queryByGoodsId(goodsEntity.getId());
  320. for(ProductStoreRelaEntity relaEntity: proStoreList){
  321. storeTotalGoodsNumber = storeTotalGoodsNumber + relaEntity.getStockNum();
  322. }
  323. if(goodsNumber < storeTotalGoodsNumber){
  324. throw new RRException("该商品已在各门店分配库存"+storeTotalGoodsNumber+",当前商品总库存不能小于分配库存总额!请先修改门店库存!");
  325. }
  326. List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),goods.getId());
  327. if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
  328. throw new RRException("不能有重复的产品条码信息!");
  329. }
  330. SysUserEntity user = ShiroUtils.getUserEntity();
  331. Map<String, Object> map = new HashMap<>();
  332. map.put("isSame", "true");
  333. map.put("sku", goods.getSku());
  334. map.put("goodsSn", goods.getGoodsSn());
  335. map.put("goodsBizType", goods.getGoodsBizType());
  336. map.put("id", goods.getId());
  337. List<GoodsEntity> list = querySame(map);
  338. if (list != null && list.size() != 0) {
  339. throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
  340. }
  341. // 修改商品
  342. if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
  343. || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
  344. goods.setIsHot(0);
  345. }
  346. // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
  347. goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  348. goods.setIsNew(0);
  349. goods.setUpdateUserId(user.getUserId());
  350. goods.setUpdateTime(new Date());
  351. goods.setModTime(new Date());
  352. if(goods.getGoodsNumber()==null){
  353. goods.setGoodsNumber(0);
  354. }else{
  355. if(goodsEntity.getGoodsNumber() == null){
  356. goodsEntity.setGoodsNumber(0);
  357. }
  358. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  359. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
  360. mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
  361. mngChangeEntity.setChangeReason("更新商户商品总库存");
  362. mngChangeEntity.setCreateTime(new Date());
  363. mngChangeEntity.setModTime(new Date());
  364. mngChangeEntity.setCreaterSn(user.getUsername());
  365. mngChangeEntity.setModerSn(user.getUsername());
  366. mngChangeEntity.setIsValid(0);
  367. mngChangeEntity.setMerchSn(goods.getMerchSn());
  368. if(goodsEntity.getGoodsNumber() != goods.getGoodsNumber()) {
  369. if (goodsEntity.getGoodsNumber() > goods.getGoodsNumber()) {
  370. mngChangeEntity.setChangeNum(goodsEntity.getGoodsNumber() - goods.getGoodsNumber());//变化数
  371. mngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
  372. } else {
  373. mngChangeEntity.setChangeNum(goods.getGoodsNumber() - goodsEntity.getGoodsNumber());//变化数
  374. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  375. }
  376. mngChangeEntity.setOriginalNum(goodsEntity.getGoodsNumber());//原库存数
  377. mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
  378. mngChangeDao.save(mngChangeEntity);
  379. }
  380. }
  381. // 修改商品
  382. goodsDao.update(goods);
  383. // 保税商品修改各个门店商品价格
  384. List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goods.getId());
  385. if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  386. for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
  387. //修改该商品的所属商户信息,如在该商户门店中有该上架的商品信息,则提示该商品不能修改
  388. /*if(org.apache.commons.lang3.StringUtils.isNotEmpty(productStoreRela.getMerchSn()) && productStoreRela.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
  389. && goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_1.getItem())) {
  390. if (goods.getRetailPrice() != null) {
  391. productStoreRela.setRetailPrice(goods.getRetailPrice());
  392. }
  393. if (goods.getMarketPrice() != null) {
  394. productStoreRela.setMarketPrice(goods.getMarketPrice());
  395. }
  396. productStoreRelaDao.update(productStoreRela);
  397. }else {
  398. if (goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_0.getItem())) {
  399. if (goods.getRetailPrice() != null) {
  400. productStoreRela.setRetailPrice(goods.getRetailPrice());
  401. }
  402. if (goods.getMarketPrice() != null) {
  403. productStoreRela.setMarketPrice(goods.getMarketPrice());
  404. }
  405. productStoreRela.setMerchSn("");
  406. productStoreRelaDao.update(productStoreRela);
  407. } else {
  408. throw new RRException("商品编码为【" + goods.getGoodsSn() + "】的商品已上架在商户编号为【" + productStoreRela.getMerchSn() + "】的门店中,可先将该商品下架后再进行修改!");
  409. }
  410. }*/
  411. if(org.apache.commons.lang3.StringUtils.isNotEmpty(productStoreRela.getMerchSn()) && productStoreRela.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
  412. && goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_1.getItem())) {
  413. }else {
  414. if (goods.getIsOnSale() != Integer.parseInt(Dict.isOnSale.item_0.getItem())) {
  415. throw new RRException("商品编码为【" + goods.getGoodsSn() + "】的商品已上架在商户编号为【" + productStoreRela.getMerchSn() + "】的门店中,可先将该商品下架后再进行修改!");
  416. }
  417. }
  418. }
  419. }
  420. Map cartMap = Maps.newHashMap();
  421. cartMap.put("goodsId",goods.getId());
  422. List<CartEntity> cartList = cartDao.queryList(cartMap);
  423. if (cartList != null && cartList.size() > 0) {
  424. for (CartEntity cartEntity : cartList) {
  425. // cartEntity.setRetailPrice(goods.getRetailPrice());
  426. // cartEntity.setMarketPrice(goods.getMarketPrice());
  427. cartEntity.setSku(goods.getSku());
  428. cartEntity.setGoodsName(goods.getName());
  429. cartEntity.setGoodsSn(goods.getGoodsSn());
  430. cartDao.update(cartEntity);
  431. }
  432. }
  433. // 修改商品轮播图
  434. goodsGalleryDao.deleteByGoodsId(goods.getId());
  435. for (int i=0;i<galleryEntityList.size();i++) {
  436. GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
  437. galleryEntity.setMerchSn(goods.getMerchSn());
  438. galleryEntity.setGoodsId(goods.getId());
  439. galleryEntity.setSortOrder((i+1));
  440. galleryEntity.setFileType("0");//图片
  441. goodsGalleryDao.save(galleryEntity);
  442. }
  443. if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
  444. GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
  445. galleryEntity.setMerchSn(goods.getMerchSn());
  446. galleryEntity.setGoodsId(goods.getId());
  447. galleryEntity.setSortOrder(0);
  448. galleryEntity.setFileType("1");//视频
  449. galleryEntity.setImgUrl(goods.getVideoUrl());
  450. goodsGalleryDao.save(galleryEntity);
  451. }
  452. /*// 修改商品参数
  453. List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
  454. if (attributeEntityList != null && attributeEntityList.size() > 0) {
  455. for (GoodsAttributeEntity item : attributeEntityList) {
  456. if (item.getIsDelete() == 0) {
  457. if (item.getId() != null) {
  458. item.setMerchSn(goods.getMerchSn());
  459. goodsAttributeDao.update(item);
  460. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
  461. item.setGoodsId(goods.getId());
  462. item.setMerchSn(goods.getMerchSn());
  463. goodsAttributeDao.save(item);
  464. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
  465. throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
  466. } else if (item.getId() == null && item.getAttributeId() == null) {
  467. continue;
  468. }
  469. } else if (item.getIsDelete() == 1) {
  470. goodsAttributeDao.delete(item.getId());
  471. }
  472. }
  473. }*/
  474. // 修改产品
  475. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goods.getId()),"");
  476. GoodsSpecificationEntity goodsSpecification = null;
  477. // 保税商品,普通货物暂不添加商品规格
  478. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  479. // 添加商品规格
  480. goodsSpecification = goodsSpecificationDao.queryByGoodsId(goods.getId());
  481. if(goodsSpecification != null) {
  482. goodsSpecification.setValue(goods.getCiqProdModel());
  483. goodsSpecificationDao.update(goodsSpecification);
  484. }else{
  485. goodsSpecification = new GoodsSpecificationEntity();
  486. goodsSpecification.setGoodsId(goods.getId());
  487. goodsSpecification.setValue(goods.getCiqProdModel());
  488. goodsSpecification.setSpecificationId(1);
  489. goodsSpecificationDao.save(goodsSpecification);
  490. }
  491. if(product == null){
  492. product = new ProductEntity();
  493. product.setGoodsSn(goods.getGoodsSn());
  494. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  495. product.setGoodsSpecificationIds(goodsSpecification.getId()+"");
  496. product.setGoodsId(goods.getId());
  497. product.setGoodsNumber(goods.getGoodsNumber());
  498. product.setGoodsDefault(0);
  499. return productDao.save(product);
  500. }else{
  501. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  502. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  503. return productDao.update(product);
  504. }
  505. }
  506. return 1;
  507. }
  508. @Override
  509. public int delete(Integer id) {
  510. SysUserEntity user = ShiroUtils.getUserEntity();
  511. GoodsEntity goodsEntity = goodsDao.queryObject(id);
  512. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_1.getItem()));
  513. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  514. goodsEntity.setUpdateUserId(user.getUserId());
  515. goodsEntity.setUpdateTime(new Date());
  516. Map params = Maps.newHashMap();
  517. params.put("goodsId", id);
  518. List<GoodsGroupEntity> groupVos = goodsGroupDao.queryList(params);
  519. if (null != groupVos && groupVos.size() > 0) {
  520. for (GoodsGroupEntity groupVo : groupVos) {
  521. groupVo.setOpenStatus(3);
  522. goodsGroupDao.update(groupVo);
  523. }
  524. }
  525. return goodsDao.update(goodsEntity);
  526. }
  527. @Override
  528. @Transactional
  529. public int deleteBatch(Integer[] ids) {
  530. int result = 0;
  531. for (Integer id : ids) {
  532. result += delete(id);
  533. }
  534. return result;
  535. }
  536. @Override
  537. @Transactional
  538. public int back(Integer[] ids) {
  539. SysUserEntity user = ShiroUtils.getUserEntity();
  540. int result = 0;
  541. for (Integer id : ids) {
  542. GoodsEntity goodsEntity = queryObject(id);
  543. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  544. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  545. goodsEntity.setUpdateUserId(user.getUserId());
  546. goodsEntity.setUpdateTime(new Date());
  547. result += goodsDao.update(goodsEntity);
  548. }
  549. return result;
  550. }
  551. @Override
  552. public int enSale(Integer id) {
  553. SysUserEntity user = ShiroUtils.getUserEntity();
  554. GoodsEntity goodsEntity = queryObject(id);
  555. if (1 == goodsEntity.getIsOnSale()) {
  556. throw new RRException("此商品已处于上架状态!");
  557. }
  558. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  559. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  560. goodsEntity.setUpdateUserId(user.getUserId());
  561. goodsEntity.setUpdateTime(new Date());
  562. return goodsDao.update(goodsEntity);
  563. }
  564. @Override
  565. public int unSale(Integer id) {
  566. SysUserEntity user = ShiroUtils.getUserEntity();
  567. GoodsEntity goodsEntity = queryObject(id);
  568. if (0 == goodsEntity.getIsOnSale()) {
  569. throw new RRException("此商品已处于下架状态!");
  570. }
  571. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  572. goodsEntity.setUpdateUserId(user.getUserId());
  573. goodsEntity.setUpdateTime(new Date());
  574. return goodsDao.update(goodsEntity);
  575. }
  576. @Override
  577. public int enSaleBatch(Integer[] ids) {
  578. int result = 0;
  579. SysUserEntity user = ShiroUtils.getUserEntity();
  580. for (Integer id : ids) {
  581. GoodsEntity goodsEntity = queryObject(id);
  582. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  583. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  584. goodsEntity.setUpdateUserId(user.getUserId());
  585. goodsEntity.setUpdateTime(new Date());
  586. result += goodsDao.update(goodsEntity);
  587. }
  588. return result;
  589. }
  590. @Override
  591. public int unSaleBatch(Integer[] ids) {
  592. int result = 0;
  593. SysUserEntity user = ShiroUtils.getUserEntity();
  594. for (Integer id : ids) {
  595. GoodsEntity goodsEntity = queryObject(id);
  596. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  597. goodsEntity.setUpdateUserId(user.getUserId());
  598. goodsEntity.setUpdateTime(new Date());
  599. result += goodsDao.update(goodsEntity);
  600. }
  601. return result;
  602. }
  603. @Override
  604. public int uploadExcel(List<GoodsDto> goodsEntityList,int exportDataType) {
  605. SysUserEntity user = ShiroUtils.getUserEntity();
  606. String merchSn = user.getMerchSn();
  607. boolean isFail = false;
  608. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  609. failSuppGoodsSnList = new ArrayList<>(),
  610. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),failProdbarGoodsSnList = new ArrayList<>(),
  611. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  612. // failCateL2GoodsSnList = new ArrayList<>(),
  613. // failCateGoodsSnList = new ArrayList<>(),
  614. // failBrandGoodsSnList = new ArrayList<>(),
  615. // failFreightGoodsSnList = new ArrayList<>(),
  616. failMerchUserGoodsSnList = new ArrayList<>();
  617. List<String> failGoodsSnList = new ArrayList<>();
  618. List<String> failGoodsTypeList = new ArrayList<>();
  619. // List<String> failFreightList = new ArrayList<>();
  620. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  621. for (int i = 0; i < goodsEntityList.size(); i++) {
  622. GoodsDto goodsDto = goodsEntityList.get(i);
  623. GoodsEntity goodsEntity = new GoodsEntity();
  624. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  625. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  626. builder.put("goodsSn", "商品编码");
  627. builder.put("thirdPartyMerchCode", "第三方商户代码");
  628. // builder.put("categoryName", "商品分类");
  629. builder.put("goodsBizType", "货品业务类型");
  630. builder.put("name", "商品名称");
  631. // builder.put("brandName", "商品品牌名称");
  632. // builder.put("defaultFreight", "运费");
  633. builder.put("isOnSaleStr", "上架");
  634. builder.put("goodsUnit", "商品单位");
  635. builder.put("isHotStr", "热销");
  636. builder.put("prodBarcode", "产品条码");
  637. // builder.put("marketPrice", "市场价");
  638. // builder.put("retailPrice", "零售价");
  639. builder.put("supplierName", "供应商");
  640. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  641. if (Integer.valueOf(r.get("code").toString()) != 0) {
  642. throw new RRException(r.get("msg").toString());
  643. } else {
  644. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  645. // 海关信息,普通货物可不添加
  646. builder.put("goodsRate", "商品税率");
  647. builder.put("sku", "SKU");
  648. builder.put("brand", "产品品牌");
  649. builder.put("unitName", "计量单位");
  650. builder.put("oriCntName", "原产国");
  651. builder.put("cusGoodsCode", "海关商品编码");
  652. builder.put("ciqProdModel", "国检规格型号");
  653. builder.put("cusDeclEle", "海关申报要素");
  654. builder.put("cusRecCode", "海关备案编号");
  655. }
  656. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  657. if (Integer.valueOf(r.get("code").toString()) != 0) {
  658. throw new RRException(r.get("msg").toString());
  659. }
  660. }
  661. //业务类型校验
  662. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  663. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  664. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  665. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  666. isFail = true;
  667. failTypeGoodsSnList.add(goodsDto.getSku());
  668. }
  669. }
  670. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  671. if(thirdMerchantBizEntity != null){
  672. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  673. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  674. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  675. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  676. isFail = true;
  677. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  678. }
  679. }
  680. }else{//商户不存在
  681. isFail = true;
  682. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  683. }
  684. //校验商品信息是否已存在
  685. Map<String, Object> map = new HashMap<>();
  686. map.put("isSame", "true");
  687. map.put("sku", goodsDto.getSku());
  688. map.put("goodsSn", goodsDto.getGoodsSn());
  689. map.put("goodsBizType", goodsDto.getGoodsBizType());
  690. List<GoodsEntity> list = querySame(map);
  691. if (list != null && list.size() != 0) {
  692. isFail = true;
  693. if(goodsDto.getSku()!=null) {
  694. failSameSkuList.add(goodsDto.getSku());
  695. }
  696. failGoodsSnList.add(goodsDto.getGoodsSn());
  697. failGoodsTypeList.add(goodsDto.getGoodsBizType());
  698. }
  699. //校验产品条码是否存在
  700. List<GoodsEntity> prodbarGoods = goodsDao.queryObjectByProdBarcode(goodsDto.getProdBarcode(),merchSn,null);
  701. if(prodbarGoods != null && prodbarGoods.size() > 0){
  702. isFail = true;
  703. failProdbarGoodsSnList.add(goodsDto.getGoodsSn());
  704. }else{
  705. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  706. }
  707. //热销商品校验
  708. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  709. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  710. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  711. isFail = true;
  712. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  713. }
  714. }
  715. if(thirdMerchantBizEntity != null) {
  716. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  717. if (supplierEntity == null) {
  718. isFail = true;
  719. failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  720. } else {
  721. goodsEntity.setSupplierId(supplierEntity.getId());
  722. }
  723. }
  724. //商品配置校验
  725. /*CategoryEntity categoryEntity = categoryDao.queryObjectByName(goodsDto.getCategoryName(),goodsDto.getMerchSn());
  726. if(categoryEntity==null){
  727. isFail = true;
  728. failCateGoodsSnList.add(goodsDto.getGoodsSn());
  729. }else{
  730. if(categoryEntity.getLevel().equalsIgnoreCase("L2")) {
  731. goodsEntity.setCategoryId(categoryEntity.getId());
  732. goodsEntity.setAttributeCategory(categoryEntity.getParentId());
  733. }else{
  734. isFail = true;
  735. failCateL2GoodsSnList.add(goodsDto.getGoodsSn());
  736. }
  737. }
  738. BrandEntity brandEntity = brandDao.queryObjectByName(goodsDto.getBrandName(),goodsDto.getMerchSn());
  739. if (brandEntity == null) {
  740. isFail = true;
  741. failBrandGoodsSnList.add(goodsDto.getGoodsSn());
  742. } else {
  743. goodsEntity.setBrandId(brandEntity.getId());
  744. }
  745. //运费
  746. FreightEntity freightEntity = freightDao.queryObjectByName(goodsDto.getDefaultFreight(),goodsDto.getMerchSn());
  747. if(freightEntity==null){
  748. isFail = true;
  749. failFreightGoodsSnList.add(goodsDto.getGoodsSn());
  750. failFreightList.add(goodsDto.getDefaultFreight());
  751. }else {
  752. goodsEntity.setFreightId(freightEntity.getId());
  753. }*/
  754. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  755. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  756. if (sysCusUnitCodeEntity == null) {
  757. isFail = true;
  758. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  759. } else {
  760. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  761. }
  762. //原产国
  763. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  764. if (sysCusNationCodeEntity == null) {
  765. isFail = true;
  766. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  767. } else {
  768. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  769. }
  770. goodsEntity.setGoodsRate(BigDecimal.valueOf(Integer.valueOf(goodsDto.getGoodsRate())));
  771. }
  772. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  773. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  774. // goodsEntity.setRetailPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getRetailPrice())));
  775. // goodsEntity.setMarketPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getMarketPrice())));
  776. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  777. goodsEntity.setSku(goodsDto.getSku());
  778. goodsEntity.setName(goodsDto.getName());
  779. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  780. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  781. goodsEntity.setBrand(goodsDto.getBrand());
  782. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  783. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  784. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  785. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  786. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  787. goodsEntity.setIsNew(0);
  788. goodsEntity.setUpdateUserId(user.getUserId());
  789. goodsEntity.setAddTime(new Date());
  790. goodsEntity.setCreateTime(new Date());
  791. goodsEntity.setUpdateTime(new Date());
  792. goodsEntity.setModTime(new Date());
  793. if(!isFail){
  794. GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
  795. if(goods!=null) {// 修改商品
  796. goodsEntity.setId(goods.getId());
  797. goodsDao.update(goodsEntity);
  798. }else{
  799. goodsDao.save(goodsEntity);
  800. }
  801. // // 保税商品修改各个门店商品价格
  802. // if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  803. // List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsDto.getId());
  804. // if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  805. // for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
  806. // productStoreRela.setMarketPrice(goodsEntity.getMarketPrice());
  807. // productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
  808. // productStoreRelaDao.update(productStoreRela);
  809. // }
  810. // }
  811. // }
  812. // 修改产品
  813. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  814. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  815. // 普通货物暂不添加商品规格
  816. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  817. // 添加商品规格
  818. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  819. if(specificationEntity == null) {
  820. goodsSpecification.setGoodsId(goodsEntity.getId());
  821. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  822. goodsSpecification.setSpecificationId(1);
  823. goodsSpecificationDao.save(goodsSpecification);
  824. }else {
  825. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  826. goodsSpecification.setId(specificationEntity.getId());
  827. goodsSpecificationDao.update(goodsSpecification);
  828. }
  829. if(product == null){
  830. product = new ProductEntity();
  831. product.setGoodsSn(goodsDto.getGoodsSn());
  832. product.setGoodsId(goodsEntity.getId());
  833. product.setGoodsDefault(0);
  834. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  835. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  836. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  837. productDao.save(product);
  838. }else{
  839. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  840. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  841. productDao.update(product);
  842. }
  843. }
  844. }
  845. }
  846. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  847. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  848. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  849. exportExceptionDataEntity.setCreateTime(new Date());
  850. exportExceptionDataEntity.setModTime(new Date());
  851. exportExceptionDataEntity.setMerchSn(merchSn);
  852. exportExceptionDataEntity.setStoreId(user.getStoreId());
  853. if(exportDataType == 1) {
  854. exportExceptionDataEntity.setExportDataType("1");
  855. }else{
  856. exportExceptionDataEntity.setExportDataType("2");
  857. }
  858. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  859. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  860. exportExceptionDataDao.save(exportExceptionDataEntity);
  861. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  862. }
  863. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  864. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  865. exportExceptionDataDao.save(exportExceptionDataEntity);
  866. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  867. }
  868. if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  869. if(failSameSkuList.size()>0) {
  870. exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  871. failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  872. exportExceptionDataDao.save(exportExceptionDataEntity);
  873. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  874. }else{
  875. exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  876. failGoodsTypeList + "】的商品信息");
  877. exportExceptionDataDao.save(exportExceptionDataEntity);
  878. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  879. }
  880. }
  881. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  882. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  883. exportExceptionDataDao.save(exportExceptionDataEntity);
  884. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  885. }
  886. if(failProdbarGoodsSnList != null && failProdbarGoodsSnList.size() > 0){
  887. exportExceptionDataEntity.setExportExceptionData("不能有重复的产品条码信息!请检查商品编码【"+failProdbarGoodsSnList+"】的商品产品条码信息");
  888. exportExceptionDataDao.save(exportExceptionDataEntity);
  889. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  890. }
  891. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  892. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  893. exportExceptionDataDao.save(exportExceptionDataEntity);
  894. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  895. }
  896. // if(failCateGoodsSnList != null && failCateGoodsSnList.size() > 0){
  897. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中维护,商品分类与商户信息对应,请检查该商品商户信息下的分类是否维护,不存在的商品编码【"+failCateGoodsSnList+"】");
  898. // exportExceptionDataDao.save(exportExceptionDataEntity);
  899. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  900. // }
  901. // if(failCateL2GoodsSnList != null && failCateL2GoodsSnList.size() > 0){
  902. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中查看,商品分类必须为二级分类,不存在的商品编码【"+failCateL2GoodsSnList+"】");
  903. // exportExceptionDataDao.save(exportExceptionDataEntity);
  904. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  905. // }
  906. // if(failBrandGoodsSnList != null && failBrandGoodsSnList.size() > 0){
  907. // exportExceptionDataEntity.setExportExceptionData("品牌信息请在商城配置》品牌制造商中维护,品牌与商户信息对应,请检查该商品商户信息下的品牌是否维护,不存在的商品编码【" + failBrandGoodsSnList + "】");
  908. // exportExceptionDataDao.save(exportExceptionDataEntity);
  909. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  910. // }
  911. // if(failFreightGoodsSnList != null && failFreightGoodsSnList.size() > 0){
  912. // exportExceptionDataEntity.setExportExceptionData("运费信息请在商城配置》运费模板中维护,运费与商户信息对应,请检查该商品商户信息下的运费是否维护,不存在的商品编码【"+failFreightGoodsSnList+"】,运费【"+failFreightList+"】");
  913. // exportExceptionDataDao.save(exportExceptionDataEntity);
  914. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  915. // }
  916. if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  917. exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  918. exportExceptionDataDao.save(exportExceptionDataEntity);
  919. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  920. }
  921. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  922. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  923. exportExceptionDataDao.save(exportExceptionDataEntity);
  924. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  925. }
  926. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  927. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  928. exportExceptionDataDao.save(exportExceptionDataEntity);
  929. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  930. }
  931. }else{
  932. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  933. }
  934. return 1;
  935. }
  936. /* @Override
  937. @Transactional
  938. public int uploadExcel(MultipartFile file) {
  939. SysUserEntity user = ShiroUtils.getUserEntity();
  940. List<String[]> list = ExcelImport.getExcelData(file);
  941. // 取门店名称
  942. StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
  943. if (null == storeEntity) {
  944. return 0;
  945. }
  946. //去除表头两行、底部合计
  947. if (list != null && list.size() > 3) {
  948. ProductStoreRelaEntity storeRelaEntity;
  949. ProductEntity productEntity;
  950. for (int i = 2; i < list.size() - 1; i++) {
  951. String[] item = list.get(i);
  952. String goodsSn = item[0];
  953. productEntity = productDao.queryObjectBySn(goodsSn);
  954. if (StringUtils.isNullOrEmpty(goodsSn)) {
  955. continue;
  956. }
  957. if (null == productEntity || null == productEntity.getId()) {
  958. continue;
  959. }
  960. storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
  961. if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
  962. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  963. storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
  964. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  965. productStoreRelaDao.update(storeRelaEntity);
  966. } else {
  967. storeRelaEntity = new ProductStoreRelaEntity();
  968. storeRelaEntity.setGoodsId(productEntity.getGoodsId());
  969. storeRelaEntity.setProductId(productEntity.getId());
  970. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  971. storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
  972. storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
  973. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  974. storeRelaEntity.setStoreId(storeEntity.getId());
  975. productStoreRelaDao.save(storeRelaEntity);
  976. }
  977. }
  978. }
  979. return 1;
  980. }*/
  981. public GoodsEntity queryObjectBySn(String goodsSn) {
  982. return goodsDao.queryObjectBySn(goodsSn);
  983. }
  984. }