GoodsServiceImpl.java 49 KB

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