GoodsServiceImpl.java 58 KB

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