GoodsServiceImpl.java 54 KB

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