GoodsServiceImpl.java 58 KB

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