GoodsServiceImpl.java 58 KB

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