GoodsServiceImpl.java 57 KB

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