GoodsServiceImpl.java 57 KB

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