1
0

GoodsServiceImpl.java 50 KB

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