GoodsServiceImpl.java 50 KB

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