GoodsServiceImpl.java 57 KB

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