GoodsServiceImpl.java 58 KB

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