GoodsServiceImpl.java 53 KB

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