GoodsServiceImpl.java 56 KB

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