GoodsServiceImpl.java 48 KB

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