GoodsServiceImpl.java 56 KB

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