GoodsServiceImpl.java 38 KB

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