GoodsServiceImpl.java 50 KB

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