GoodsService.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. package com.shop.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
  4. import com.github.miemiedev.mybatis.paginator.domain.PageList;
  5. import com.github.miemiedev.mybatis.paginator.domain.Paginator;
  6. import com.shop.constant.DmConstant;
  7. import com.shop.constant.MessageModel;
  8. import com.shop.dao.GoodsDao;
  9. import com.shop.dao.OrderDao;
  10. import com.shop.dao.ProductDao;
  11. import com.shop.exception.ParamException;
  12. import com.shop.gto.GoodsDto;
  13. import com.shop.model.*;
  14. import com.shop.util.AssertUtil;
  15. import com.shop.util.MessageModelUtil;
  16. import com.shop.util.ProductAttributeUtil;
  17. import com.shop.vo.LoginIdentity;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import java.math.BigDecimal;
  23. import java.util.*;
  24. /**
  25. * @author DY
  26. * @create 2018-03-16 16:03
  27. **/
  28. @Service
  29. @Transactional
  30. public class GoodsService {
  31. @Autowired
  32. private GoodsDao goodsDao;
  33. @Autowired
  34. private ProductDao productDao;
  35. @Autowired
  36. private OrderDao orderDao;
  37. public MessageModel add_goods(Goods goods, LoginIdentity loginIdentity) {
  38. MessageModel messageModel = new MessageModel();
  39. //查询设计师名称和id根据store
  40. //goods.setBrandDesignerId(loginIdentity.getBrandDesignerId());
  41. //goods.setBrandDesigner(loginIdentity.getBrandDesigner());
  42. goods.setStore(loginIdentity.getStore());
  43. goods.setSortSynthesize(BigDecimal.ZERO);
  44. //参数验证
  45. checkParams(goods);
  46. if(goods.getIsCustom()==1||goods.getIsCustom()==2){
  47. AssertUtil.isNotEmpty(goods.getDefaultChose(),"请上传基款");
  48. }
  49. //查询商品是否存在
  50. Integer cod = goodsDao.findGoodsIsExistByGoodsSn(goods.getGoodsSn(),loginIdentity.getStore());
  51. AssertUtil.isTrue(cod != null, "货品已存在...");
  52. goods.setType(loginIdentity.getType());
  53. goods.setSales(BigDecimal.ZERO);
  54. goods.setHits(BigDecimal.ZERO);
  55. goods.setVersion(DmConstant.VERSION_ZERO);
  56. goods.setIsMarketable(false);
  57. goods.setIsTop(false);
  58. goods.setIsNew(false);
  59. goods.setIsRecommend(false);
  60. //排序设为0 默认按时间排序
  61. goods.setSort(DmConstant.CREATE_TIME);
  62. //判断此商品是否支持定制
  63. Integer isCustom = goods.getIsCustom();
  64. if(goods.getFreight()==null){
  65. goods.setFreight(BigDecimal.ZERO);
  66. }
  67. //先插入商品库得到商品ID
  68. goodsDao.insert(goods);
  69. Integer goodsId = goods.getId();
  70. //插入尺寸表
  71. insertSize(goods);
  72. //套 码 类
  73. if (isCustom == 0) {
  74. insertProduct(goods, goodsId);
  75. }
  76. else{
  77. //定制+套码(1.纯定制商品属性(必有) 2.套码定制属性(必传) 3.细节定制属性(选传))
  78. //纯定制
  79. if (isCustom == 2) {
  80. insertProduct(goods, goodsId);
  81. }
  82. //定制属性
  83. insertCustomerProduct(goods.getCustomProduct(), goodsId);
  84. //插入细节定制表
  85. insertProductCustomer(goods, goodsId);
  86. }
  87. return messageModel;
  88. }
  89. private void insertCustomerProduct(String product, Integer goodsId) {
  90. List<ProductNoCustom> customProducts = null;
  91. //格式化商品大字段
  92. AssertUtil.isNotEmpty(product,"请传入定制属性");
  93. if (StringUtils.isNotBlank(product)) {
  94. customProducts = JSON.parseArray(product, ProductNoCustom.class
  95. );
  96. //遍历循环插入goodsId
  97. for (int i = 0; i < customProducts.size(); i++) {
  98. ProductNoCustom customProduct = customProducts.get(i);
  99. customProduct.setGoods(goodsId);
  100. customProduct.setAllocatedStock(0);
  101. customProduct.setIsCustom(true);
  102. }
  103. //循环插入数据库
  104. Integer insertCode = productDao.insertProductNoCustom(customProducts);
  105. AssertUtil.intIsNotEmpty(insertCode, "定制1商品插入失败,请联系客服...");
  106. }
  107. }
  108. private void insertProductCustomer(Goods goods, Integer goodsId) {
  109. List<ProductCustom> productCustoms = null;
  110. //格式化商品大字段
  111. String product = goods.getProductCustom();
  112. if (StringUtils.isNotBlank(product)) {
  113. productCustoms = JSON.parseArray(product, ProductCustom.class
  114. );
  115. //遍历循环插入goodsId
  116. for (int i = 0; i < productCustoms.size(); i++) {
  117. ProductCustom productCustom = productCustoms.get(i);
  118. productCustom.setGoods(goodsId);
  119. }
  120. //循环插入数据库
  121. Integer insertCode = productDao.insertProductCustom(productCustoms);
  122. AssertUtil.intIsNotEmpty(insertCode, "商品插入失败,请联系客服...");
  123. }
  124. }
  125. private void insertProduct(Goods goods, Integer goodsId) {
  126. List<ProductNoCustom> productNoCustoms = null;
  127. //格式化商品大字段
  128. String product = goods.getProductNoCustom();
  129. AssertUtil.isNotEmpty(product, "请传入套码商品");
  130. if (StringUtils.isNotBlank(product)) {
  131. productNoCustoms = JSON.parseArray(product, ProductNoCustom.class);}
  132. //遍历循环插入goodsId
  133. for (int i = 0; i < productNoCustoms.size(); i++) {
  134. ProductNoCustom productNoCustom = productNoCustoms.get(i);
  135. productNoCustom.setIsCustom(false);
  136. productNoCustom.setGoods(goodsId);
  137. productNoCustom.setAllocatedStock(0);
  138. }
  139. //循环插入数据库
  140. Integer insertCode = productDao.insertProductNoCustom(productNoCustoms);
  141. AssertUtil.intIsNotEmpty(insertCode, "商品插入失败,请联系客服...");
  142. }
  143. public void insertSize(Goods goods) {
  144. List<Size> sizes = null;
  145. Integer goodsId=goods.getId();
  146. Integer categoryId=goods.getProductCategory();
  147. String size=goods.getSize();
  148. AssertUtil.intIsNotEmpty(goodsId,"请选择商品");
  149. AssertUtil.intIsNotEmpty(categoryId,"请选择商品");
  150. AssertUtil.isNotEmpty(size, "请传入尺寸");
  151. //查询上下限
  152. //SizeClose sizeClose=productDao.findUpAndLowByCategory(categoryId);
  153. if (StringUtils.isNotBlank(size)) {
  154. sizes = JSON.parseArray(size, Size.class);}
  155. //遍历循环插入goodsId
  156. for (int i = 0; i < sizes.size(); i++) {
  157. Size size1 = sizes.get(i);
  158. size1.setGender(goods.getGender());
  159. size1.setGoods(goodsId);
  160. /*if(!size1.getBackRise().equals(BigDecimal.ZERO)){
  161. size1.setBackRiseBig(size1.getBackRise().add(sizeClose.getBackRiseUp()));
  162. size1.setBackRiseSmall(size1.getBackRise().subtract(sizeClose.getBackRiseLow()));
  163. }
  164. if(!size1.getClothesLength().equals(BigDecimal.ZERO)){
  165. size1.setClothesBig(size1.getClothesLength().add(sizeClose.getClothesUp()));
  166. size1.setClothesSmall(size1.getClothesLength().subtract(sizeClose.getClothesLow()));
  167. }
  168. if(!size1.getShoulder().equals(BigDecimal.ZERO)){
  169. size1.setShoulderBig(size1.getShoulder().add(sizeClose.getShoulderUp()));
  170. size1.setShoulderSmall(size1.getShoulder().subtract(sizeClose.getShoulderLow()));
  171. }
  172. if(!size1.getBust().equals(BigDecimal.ZERO)){
  173. size1.setBustBig(size1.getBust().add(sizeClose.getBustUp()));
  174. size1.setBustSmall(size1.getBust().subtract(sizeClose.getBustLow()));
  175. }
  176. if(!size1.getSleeve().equals(BigDecimal.ZERO)){
  177. size1.setSleeveBig(size1.getSleeve().add(sizeClose.getSleeveUp()));
  178. size1.setSleeveSmall(size1.getSleeve().subtract(sizeClose.getSleeveLow()));
  179. }
  180. if(!size1.getWaistline().equals(BigDecimal.ZERO)){
  181. size1.setWaistlineBig(size1.getWaistline().add(sizeClose.getWaistlineUp()));
  182. size1.setWaistlineSmall(size1.getWaistline().subtract(sizeClose.getWaistlineLow()));
  183. }
  184. if(!size1.getHipline().equals(BigDecimal.ZERO)){
  185. size1.setHiplineBig(size1.getHipline().add(sizeClose.getHiplineUp()));
  186. size1.setHiplineSmall(size1.getHipline().subtract(sizeClose.getHiplineLow()));
  187. }
  188. if(!size1.getOutside().equals(BigDecimal.ZERO)){
  189. size1.setOutsideBig(size1.getOutside().add(sizeClose.getOutsideUp()));
  190. size1.setOutsideSmall(size1.getOutside().subtract(sizeClose.getOutsideLow()));
  191. }
  192. if(!size1.getFoot().equals(BigDecimal.ZERO)){
  193. size1.setFootBig(size1.getFoot().add(sizeClose.getFootUp()));
  194. size1.setFootSmall(size1.getFoot().subtract(sizeClose.getFootLow()));
  195. }
  196. if(!size1.getSweep().equals(BigDecimal.ZERO)){
  197. size1.setSweepBig(size1.getSweep().add(sizeClose.getSweepUp()));
  198. size1.setSweepSmall(size1.getSweep().subtract(sizeClose.getSweepLow()));
  199. }
  200. if(!size1.getFrontRise().equals(BigDecimal.ZERO)){
  201. size1.setFrontRiseBig(size1.getFrontRise().add(sizeClose.getFrontRiseUp()));
  202. size1.setFrontRiseSmall(size1.getFrontRise().subtract(sizeClose.getFrontRiseLow()));
  203. }
  204. if(!size1.getCup().equals(BigDecimal.ZERO)){
  205. size1.setCupBig(size1.getCup().add(sizeClose.getCupUp()));
  206. size1.setCupSmall(size1.getCup().subtract(sizeClose.getCupLow()));
  207. }
  208. if(!size1.getSkirtLength().equals(BigDecimal.ZERO)){
  209. size1.setSkirtBig(size1.getSkirtLength().add(sizeClose.getSkirtUp()));
  210. size1.setSkirtSmall(size1.getSkirtLength().subtract(sizeClose.getSkirtLow()));
  211. }
  212. if(!size1.getHip().equals(BigDecimal.ZERO)){
  213. size1.setHipBig(size1.getHip().add(sizeClose.getHipUp()));
  214. size1.setHipSmall(size1.getHip().subtract(sizeClose.getHipLow()));
  215. }
  216. */
  217. }
  218. //循环插入数据库
  219. Integer insertCode = productDao.insertSize(sizes);
  220. AssertUtil.intIsNotEmpty(insertCode, "商品尺码插入失败,请联系客服...");
  221. }
  222. private void checkParams(Goods goods) {
  223. AssertUtil.isNotEmpty(goods.getBrandDesigner(),"请添加品牌");
  224. AssertUtil.intIsNotEmpty(goods.getBrandDesignerId(),"请添加品牌");
  225. AssertUtil.isNotEmpty(goods.getBrandDesigner(), "请填写品牌设计师名称");
  226. AssertUtil.intIsNotEmpty(goods.getGender(), "请选择一级分类");
  227. AssertUtil.intIsNotEmpty(goods.getCategoryParent(), "请选择二级分类");
  228. AssertUtil.intIsNotEmpty(goods.getProductCategory(), "请选择三级分类");
  229. AssertUtil.isNotEmpty(goods.getProductSeason(), "请选择季节级分类");
  230. AssertUtil.isNotEmpty(goods.getName(), "请填写商品名称");
  231. AssertUtil.isNotEmpty(goods.getMemo(), "请填写商品注意事项...");
  232. AssertUtil.isNotEmpty(goods.getGoodsSn(), "请填写商品编号");
  233. AssertUtil.notNull(goods.getPrice(), "请填写商品价格...");
  234. AssertUtil.isNotEmpty(goods.getMaterialDetail(), "请填写材质详情...");
  235. AssertUtil.isNotEmpty(goods.getKeyword(), "请填写关键字...");
  236. AssertUtil.isNotEmpty(goods.getProductIntroduction(), "请填写商品介绍...");
  237. AssertUtil.isNotEmpty(goods.getImage(), "请上传商品主图");
  238. AssertUtil.isNotEmpty(goods.getProductImageTop(), "请上传商品副图");
  239. AssertUtil.isNotEmpty(goods.getProductImageBottom(), "请上传商品详情图");
  240. AssertUtil.isNotEmpty(goods.getServiceProvide(), "请选择商品服务保障");
  241. AssertUtil.isNotEmpty(goods.getDeliveryTime(), "请选择商品发货时间");
  242. AssertUtil.notNull(goods.getIsCustom(), "请选择是否支持定制");
  243. AssertUtil.isNotEmpty(goods.getSize(), "请填写商品尺寸表");
  244. AssertUtil.isTrue(goods.getProductCustom() == null && goods.getProductNoCustom() == null, "请上传商品明细");
  245. }
  246. /**
  247. * @author DY
  248. * @create 2018/3/21 16:08
  249. * 商品总览
  250. */
  251. public Map goods_overview(LoginIdentity loginIdentity) {
  252. Map map = new HashMap();
  253. Integer store = loginIdentity.getStore();
  254. Integer type = loginIdentity.getType();
  255. //查到上架和已下架,库存紧张.通过审核,未通过审核商品和全部商品
  256. Integer version = DmConstant.VERSION_MINUS_TWO;
  257. CountGoods countGoods = productDao.queryIsMarketableProduct(store, type, version);
  258. AssertUtil.notNull(countGoods,"空空如也...");
  259. Integer totalProduct = 0;
  260. Integer up = 0;
  261. Integer down = 0;
  262. Integer stock = 0;
  263. Integer unPassToCheck = 0;
  264. Integer waitToCheck = 0;
  265. Integer passToCheck = 0;
  266. if (countGoods.getTotal() != null) {
  267. totalProduct = countGoods.getTotal();
  268. }
  269. map.put("totalProduct", totalProduct);
  270. if (countGoods.getUp() != null) {
  271. up = countGoods.getUp();
  272. }
  273. map.put("up", up);
  274. if (countGoods.getDown() != null) {
  275. down = countGoods.getDown();
  276. }
  277. map.put("down", down);
  278. if (countGoods.getUnPassToCheck() != null) {
  279. unPassToCheck = countGoods.getUnPassToCheck();
  280. }
  281. map.put("unPassToCheck", unPassToCheck);
  282. if (countGoods.getWaitToCheck() != null) {
  283. waitToCheck = countGoods.getWaitToCheck();
  284. }
  285. map.put("waitToCheck", waitToCheck);
  286. if (countGoods.getPassToCheck() != null) {
  287. passToCheck = countGoods.getPassToCheck();
  288. }
  289. map.put("passToCheck", passToCheck);
  290. //拿到库存紧张的商品数量
  291. Integer isCustom=0;
  292. Integer isMarketable=1;
  293. Integer versionStock=1;
  294. List<Integer> stockIsLittle = productDao.findProductIsLockStock(store,isCustom, isMarketable,versionStock,type, DmConstant.PRODUCT_STOCK);
  295. if (stockIsLittle.size()!= 0) {
  296. stock = stockIsLittle.size();
  297. }
  298. map.put("stock", stock);
  299. return map;
  300. }
  301. public MessageModel goods_list(GoodsDto goodsDto, LoginIdentity loginIdentity) {
  302. //拿到全部商品 已上架 未上架 待审核 未通过
  303. Map map = goods_overview(loginIdentity);
  304. Map mapGetFromUtil = getGoodsList(goodsDto, loginIdentity);
  305. map.putAll(mapGetFromUtil);
  306. MessageModel messageModel = MessageModelUtil.getSuccessMessageModel(map);
  307. return messageModel;
  308. }
  309. private Map getGoodsList(GoodsDto goodsDto, LoginIdentity loginIdentity) {
  310. Integer store = loginIdentity.getStore();
  311. Integer type = loginIdentity.getType();
  312. goodsDto.setStore(store);
  313. goodsDto.setType(type);
  314. //拿到库存紧张的商品数量
  315. Integer isCustom=0;
  316. Integer isMarketable=1;
  317. Integer versionStock=1;
  318. List<Integer> ids=productDao.findProductIsLockStock(store,isCustom, isMarketable,versionStock,type, DmConstant.PRODUCT_STOCK);
  319. String str="";
  320. for(int i=0;i<ids.size();i++){
  321. str += ids.get(i)+",";
  322. }
  323. if(ids.size()!=0){
  324. str = str.substring(0,str.length() - 1);
  325. }
  326. //判断是否查询库存紧张
  327. if(goodsDto.getStock()!=null){
  328. goodsDto.setStockIds(str);
  329. }
  330. // 構建pageBounds
  331. PageBounds pageBounds = goodsDto.buildPageBounds();
  332. List<Goods> goods = goodsDao.queryGoodsList(goodsDto, pageBounds);
  333. //把库存紧张的货品置为紧张
  334. for (int i = 0; i < goods.size(); i++) {
  335. Goods g=goods.get(i);
  336. Integer goodsId=g.getId();
  337. for(int j=0;j<ids.size();j++){
  338. Integer stockId=ids.get(j);
  339. if(goodsId.equals(stockId)){
  340. g.setIsStock(true);
  341. break;
  342. }
  343. else{
  344. g.setIsStock(false);
  345. }
  346. }
  347. }
  348. // 構建返回結果
  349. PageList<Goods> goodsPageList = (PageList<Goods>) goods;
  350. Paginator paginator = goodsPageList.getPaginator();
  351. Map map = new HashMap();
  352. map.put("goods_list", goodsPageList);
  353. map.put("paginator", paginator);
  354. return map;
  355. }
  356. public MessageModel query_goods_check_status(Integer id) {
  357. AssertUtil.intIsNotEmpty(id, "请选择要查看的商品");
  358. CheckInformation checkInformation = goodsDao.queryGoodsStatusCheck(id);
  359. AssertUtil.notNull(checkInformation, "商品不存在,请联系客服...");
  360. MessageModel messageModel = MessageModelUtil.getSuccessMessageModel(checkInformation);
  361. return messageModel;
  362. }
  363. /**
  364. * @author DY
  365. * @create 2018/3/26 17:30
  366. * 查询可定制类目
  367. */
  368. public MessageModel query_custom_names() {
  369. List<CustomName> customNames = goodsDao.queryCustomNames();
  370. AssertUtil.listIsNotEmpty(customNames,"查询失败,请联系官方客服....");
  371. return MessageModelUtil.getSuccessMessageModel(customNames);
  372. }
  373. public MessageModel is_marketable_is_new_product_recommend(IsMarketableNewRecommend isMarketableNewRecommend) {
  374. //参数验证
  375. checkParams(isMarketableNewRecommend);
  376. Integer code = goodsDao.updateIsMarketableIsNewIsRecommendByIds(isMarketableNewRecommend);
  377. AssertUtil.intIsNotEmpty(code, "更新条件失败,请联系客服...");
  378. return MessageModelUtil.getSuccessMessageModel();
  379. }
  380. private void checkParams(IsMarketableNewRecommend isMarketableNewRecommend) {
  381. AssertUtil.isNotEmpty(isMarketableNewRecommend.getIds(), "清传入商品ids");
  382. //根据name来确定执行的步骤 null全部执行,1.上架.2.新品.3.推荐
  383. AssertUtil.isTrue(isMarketableNewRecommend.getIsMarketable() == null && isMarketableNewRecommend.getIsNew() == null && isMarketableNewRecommend.getIsRecommend() == null, "请选择要执行的操作项...提交");
  384. }
  385. /**
  386. * @author DY
  387. * @create 2018/3/23 12:06
  388. * 查看商品详情...
  389. */
  390. public Map query_goods_detail(Integer id) {
  391. Map map = new HashMap();
  392. AssertUtil.intIsNotEmpty(id,"请传入货品Id");
  393. //拿到货品
  394. Goods goods = goodsDao.findProductById(id);
  395. AssertUtil.notNull(goods, "货品不存在,请稍后重试...");
  396. // 格式化商品图片大字段
  397. List<ProductImageTop> productImageListTop = null;
  398. String productImagesTop = goods.getProductImageTop();
  399. if (StringUtils.isNotBlank(productImagesTop)) {
  400. productImageListTop = JSON.parseArray(productImagesTop, ProductImageTop.class);
  401. goods.setProductImageTop(null);
  402. }
  403. // 格式化商品图片大字段
  404. List<ProductImageBottom> productImageListBottom = null;
  405. String productImagesBottom = goods.getProductImageBottom();
  406. if (StringUtils.isNotBlank(productImagesBottom)) {
  407. productImageListBottom = JSON.parseArray(productImagesBottom, ProductImageBottom.class
  408. );
  409. goods.setProductImageBottom(null);
  410. }
  411. //查询具体商品信息,判断是否定制
  412. Integer isCustom = goods.getIsCustom();
  413. List<ProductNoCustom> products = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ZERO);
  414. //AssertUtil.listIsNotEmpty(products,"查询数据失败,请联系客服...");
  415. //套码类,只查product表
  416. if (isCustom == 0) {
  417. if (products.size() != 0) {
  418. products = getProductImage(products);
  419. map.put("products", products);
  420. }
  421. } else {
  422. //定制类查product和custom表
  423. List<ProductCustom> productCustoms = goodsDao.queryCustomProductsByGoodsId(id);
  424. List<ProductNoCustom> customProducts = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ONE);
  425. if(productCustoms.size()!=0){
  426. List<List<ProductCustom>> lists=getCustomList(productCustoms);
  427. map.put("productCustoms", lists);
  428. }
  429. if (customProducts.size() != 0) {
  430. customProducts = getSize(customProducts);
  431. map.put("customProducts", customProducts);
  432. }
  433. if (products.size() != 0) {
  434. products = getProductImage(products);
  435. map.put("products", products);
  436. }
  437. // 格式化默认商品大字段
  438. List<DefaultClothes> defaultClothesList = null;
  439. String clothes= goods.getDefaultChose();
  440. if (StringUtils.isNotBlank(clothes)) {
  441. defaultClothesList = JSON.parseArray(clothes, DefaultClothes.class
  442. );
  443. map.put("defaultClothesList", defaultClothesList);
  444. }
  445. }
  446. //查询尺码表
  447. List<SizeReturn> sizeList=goodsDao.findSizeByGoodsId(id);
  448. map.put("sizeList", sizeList);
  449. map.put("goods", goods);
  450. map.put("productImageListTop", productImageListTop);
  451. map.put("productImageListBottom", productImageListBottom);
  452. return map;
  453. }
  454. private List<List<ProductCustom>> getCustomList(List<ProductCustom> productCustoms) {
  455. Map<Integer, List> map = new LinkedHashMap();
  456. for (int i = 0; i < productCustoms.size(); i++) {
  457. ProductCustom item = productCustoms.get(i);
  458. //格式化图片大字段
  459. // 格式化商品图片大字段
  460. List<CustomImage> customImages = null;
  461. String image = item.getImage();
  462. if (StringUtils.isNotBlank(image)) {
  463. customImages = JSON.parseArray(image, CustomImage.class
  464. );
  465. }
  466. item.setImageList(customImages);
  467. Integer key = item.getCustom();
  468. //当且仅当集合里有过 1//1才会进这个集合,第一次也不会进,第二次才会进
  469. if (map.containsKey(key)) {
  470. map.get(key).add(item);
  471. } else {
  472. List list = new ArrayList();
  473. list.add(item);
  474. map.put(key, list);
  475. System.out.println();
  476. }
  477. }
  478. List<List<ProductCustom>> data = new PageList<>();
  479. for (Map.Entry<Integer, List> entry : map.entrySet()) {
  480. data.add(entry.getValue());
  481. }
  482. return data;
  483. }
  484. private List<ProductCustom> getProductCustomImage(List<ProductCustom> productCustoms) {
  485. for (int i = 0; i < productCustoms.size(); i++) {
  486. ProductCustom item = productCustoms.get(i);
  487. //格式化图片大字段
  488. // 格式化商品图片大字段
  489. List<CustomImage> customImages = null;
  490. String image = item.getImage();
  491. if (StringUtils.isNotBlank(image)) {
  492. customImages = JSON.parseArray(image, CustomImage.class
  493. );
  494. }
  495. item.setImageList(customImages);
  496. }
  497. return productCustoms;
  498. }
  499. private List<ProductNoCustom> getProductImage(List<ProductNoCustom> product) {
  500. for (int i = 0; i < product.size(); i++) {
  501. ProductNoCustom item = product.get(i);
  502. //格式化图片大字段
  503. // 格式化商品图片大字段
  504. List<CustomImage> customImages = null;
  505. String image = item.getImages();
  506. if (StringUtils.isNotBlank(image)) {
  507. customImages = JSON.parseArray(image, CustomImage.class
  508. );
  509. }
  510. item.setImageList(customImages);
  511. item.setImages(null);
  512. }
  513. return product;
  514. }
  515. private List<ProductNoCustom> getSize(List<ProductNoCustom> customProducts) {
  516. for (int i = 0; i < customProducts.size(); i++) {
  517. ProductNoCustom item = customProducts.get(i);
  518. //格式化图片大字段
  519. List<CustomImage> customImages = null;
  520. String image = item.getImages();
  521. if (StringUtils.isNotBlank(image)) {
  522. customImages = JSON.parseArray(image, CustomImage.class
  523. );
  524. item.setImages(null);
  525. }
  526. item.setImageList(customImages);
  527. item.setImages(null);
  528. // 格式化商品图片大字段
  529. String size = item.getSize();
  530. String[] arr = size.split(",");
  531. List<String> customSizeList = Arrays.asList(arr);
  532. item.setSizeList(customSizeList);
  533. }
  534. return customProducts;
  535. }
  536. public MessageModel query_product_scene(Integer gender) {
  537. AssertUtil.intIsNotEmpty(gender, "请选择性别...");
  538. List<ProductScene> productSceneList = goodsDao.queryProductScene(gender);
  539. AssertUtil.listIsNotEmpty(productSceneList,"查询数据失败,请联系客服...");
  540. return MessageModelUtil.getSuccessMessageModel(productSceneList);
  541. }
  542. public MessageModel query_product_category(Integer gender) {
  543. AssertUtil.intIsNotEmpty(gender, "请选择性别...");
  544. List<ProductCategory> productCategoryList = goodsDao.query_product_category(gender);
  545. AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
  546. return MessageModelUtil.getSuccessMessageModel(productCategoryList);
  547. }
  548. public MessageModel query_product_category_two(Integer categoryId) {
  549. AssertUtil.intIsNotEmpty(categoryId, "请选择分类属性...");
  550. List<ProductCategory> productCategoryList = goodsDao.query_product_category_two(categoryId);
  551. AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
  552. return MessageModelUtil.getSuccessMessageModel(productCategoryList);
  553. }
  554. public MessageModel query_size(Integer categoryIdChildren) {
  555. AssertUtil.intIsNotEmpty(categoryIdChildren, "请选择分类属性...");
  556. String ids=goodsDao.querySize(categoryIdChildren);
  557. List<ProductCategory> productCategoryList = goodsDao.queryClothesNameBySize(ids);
  558. AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
  559. return MessageModelUtil.getSuccessMessageModel(productCategoryList);
  560. }
  561. public MessageModel edit_product(Goods goods) {
  562. //更新货品
  563. AssertUtil.intIsNotEmpty(goods.getId(), "请选择要编辑的商品...");
  564. AssertUtil.notNull(goods.getIsCustom(),"请选择尺码是否定制");
  565. Integer updateCode = goodsDao.updateGoodsByGoods(goods);
  566. AssertUtil.intIsNotEmpty(updateCode, "商品编辑失败...");
  567. return MessageModelUtil.getSuccessMessageModel();
  568. }
  569. public MessageModel delete_goods(String ids) {
  570. AssertUtil.isNotEmpty(ids, "请选择要删除的商品");
  571. Integer version = DmConstant.VERSION_MINUS_TWO;
  572. //删除货品 version置为-2,当且只有version=1时才能删除
  573. Integer goodsCode = goodsDao.updateGoodsStatusByIds(ids, version);
  574. AssertUtil.intIsNotEmpty(goodsCode, "删除货品失败,请联系客服...");
  575. //删除商品
  576. productDao.updateProductStatusByGoods(ids, version);
  577. //定制的话删除定制类明細及尺码表
  578. productDao.updateCustomStatusByGoods(ids, version);
  579. productDao.updateSizeByIds(ids,version);
  580. return MessageModelUtil.getSuccessMessageModel();
  581. }
  582. public MessageModel search_goods_list(GoodsDto goodsDto, LoginIdentity loginIdentity) {
  583. Map map = getGoodsList(goodsDto, loginIdentity);
  584. return MessageModelUtil.getSuccessMessageModel(map);
  585. }
  586. public MessageModel goods_recycle_list(GoodsDto goodsDto, LoginIdentity loginIdentity) {
  587. goodsDto.setVersion(DmConstant.VERSION_MINUS_TWO);
  588. Map map = getGoodsList(goodsDto, loginIdentity);
  589. return MessageModelUtil.getSuccessMessageModel(map);
  590. }
  591. public MessageModel goods_recycle_return(String ids, Integer returnOrDelete) {
  592. AssertUtil.isNotEmpty(ids, "请选择商品");
  593. AssertUtil.intIsNotEmpty(returnOrDelete, "请选择还原还是删除...");
  594. Integer version = null;
  595. if (returnOrDelete == 1) {
  596. version = DmConstant.VERSION_ONE;
  597. } else {
  598. version = DmConstant.VERSION_MINUS_THREE;
  599. }
  600. Integer goodsCode = goodsDao.updateGoodsStatusByIds(ids, version);
  601. AssertUtil.intIsNotEmpty(goodsCode, "删除货品失败,请联系客服...");
  602. productDao.updateProductStatusByGoods(ids, version);
  603. productDao.updateCustomStatusByGoods(ids, version);
  604. productDao.updateSizeByIds(ids,version);
  605. return MessageModelUtil.getSuccessMessageModel();
  606. }
  607. public MessageModel getGoodsAttribute(Integer orderItemId) {
  608. AssertUtil.notNull(orderItemId, "请选择 子订单ID...");
  609. //拿到订单信息
  610. OrderItemDetail orderItemDetail = orderDao.findOrderItemById(orderItemId);
  611. Boolean isCustom=orderItemDetail.getIsCustom();
  612. AssertUtil.notNull(orderItemDetail, "参数有误,订单不存在,请检查参数");
  613. Integer goodsId = orderItemDetail.getGoods();
  614. Map map = new HashMap();
  615. List<AttributeDetail> ls = null;
  616. List<ProductNoCustom> customProducts = goodsDao.queryProductsByGoodsId(goodsId, orderItemDetail.getIsCustom());
  617. if (customProducts.size() != 0) {
  618. //对具体属性去重
  619. if(isCustom){
  620. ls = ProductAttributeUtil.getCustomProductAttribute(customProducts);
  621. }
  622. else{
  623. ls = ProductAttributeUtil.getProductAttribute(customProducts);
  624. }
  625. map.put("customProducts", ls);
  626. }
  627. //定制
  628. if (isCustom) {
  629. List<ProductCustom> productCustoms = goodsDao.findCustomsByGoodsId(goodsId);
  630. if (productCustoms.size() != 0) {
  631. //对图片进行处理
  632. List<List<ProductCustom>> lists = getCustomList(productCustoms);
  633. map.put("productCustoms", lists);
  634. }
  635. }
  636. return MessageModelUtil.getSuccessMessageModel(map);
  637. }
  638. public MessageModel query_goods_by_attribute(String size,String color,Boolean isCustom,Integer goods) {
  639. AssertUtil.notNull(isCustom,"请传入是否定制");
  640. AssertUtil.isNotEmpty(size,"请选择商品尺寸");
  641. AssertUtil.isNotEmpty(color,"请选择商品颜色");
  642. AssertUtil.intIsNotEmpty(goods,"请选择货品goods");
  643. if(isCustom){
  644. size=null;
  645. }
  646. Product p=new Product();
  647. p.setGoods(goods);
  648. p.setSize(size);
  649. p.setColor(color);
  650. p.setIsCustom(isCustom);
  651. Product product=productDao.findProductByAttribute(p);
  652. AssertUtil.notNull(product,"选择的商品不存在...");
  653. return MessageModelUtil.getSuccessMessageModel(product);
  654. }
  655. public MessageModel delete_product(String ids) {
  656. AssertUtil.isNotEmpty(ids,"请选择要删除的商品");
  657. Integer code=productDao.deleteProductByIds(ids);
  658. AssertUtil.intIsNotEmpty(code,"删除商品失败");
  659. return MessageModelUtil.getSuccessMessageModel();
  660. }
  661. public MessageModel delete_product_custom(String ids) {
  662. AssertUtil.isNotEmpty(ids,"请选择要删除的商品");
  663. Integer code=productDao.deleteCustomByIds(ids);
  664. AssertUtil.intIsNotEmpty(code,"删除细节定制失败");
  665. return MessageModelUtil.getSuccessMessageModel();
  666. }
  667. public MessageModel update_product(UpdateProduct product) {
  668. AssertUtil.notNull(product,"请选择要修改的商品");
  669. Integer code=productDao.updateProduct(product);
  670. AssertUtil.intIsNotEmpty(code,"商品修改失败");
  671. return MessageModelUtil.getSuccessMessageModel();
  672. }
  673. public MessageModel update_product_custom(ProductCustom productCustom) {
  674. AssertUtil.notNull(productCustom,"请选择要修改的商品");
  675. Integer code=productDao.updateProductCustom(productCustom);
  676. AssertUtil.intIsNotEmpty(code,"商品修改失败");
  677. return MessageModelUtil.getSuccessMessageModel();
  678. }
  679. public MessageModel add_product(String product) {
  680. //格式化商品大字段
  681. AssertUtil.isNotEmpty(product,"请传入商品属性");
  682. List<ProductNoCustom> products = null;
  683. if (StringUtils.isNotBlank(product)) {
  684. products = JSON.parseArray(product, ProductNoCustom.class
  685. );
  686. //循环插入数据库
  687. Integer insertCode = productDao.insertProductNoCustom(products);
  688. AssertUtil.intIsNotEmpty(insertCode, "定制1商品插入失败,请联系客服...");
  689. }
  690. return MessageModelUtil.getSuccessMessageModel();
  691. }
  692. public MessageModel add_product_custom(String product) {
  693. List<ProductCustom> productCustoms = null;
  694. //格式化商品大字段
  695. if (StringUtils.isNotBlank(product)) {
  696. productCustoms = JSON.parseArray(product, ProductCustom.class
  697. );
  698. //循环插入数据库
  699. Integer insertCode = productDao.insertProductCustom(productCustoms);
  700. AssertUtil.intIsNotEmpty(insertCode, "商品插入失败,请联系客服...");
  701. }
  702. return MessageModelUtil.getSuccessMessageModel();
  703. }
  704. public MessageModel goods_product_delete(Integer goods, Boolean isCustom) {
  705. AssertUtil.intIsNotEmpty(goods,"请选择货品Id");
  706. AssertUtil.notNull(isCustom,"请选择商品属性");
  707. Integer code=productDao.deleteProductByGoods(goods,isCustom);
  708. AssertUtil.intIsNotEmpty(code,"删除失败...");
  709. if(isCustom){
  710. productDao.deleteCustomByGoods(goods);
  711. productDao.deleteDefaultChose(goods,null);
  712. }
  713. return MessageModelUtil.getSuccessMessageModel();
  714. }
  715. public MessageModel query_size_add() {
  716. List<ProductCategory> productCategoryList = goodsDao.queryAllClothesNameBySize();
  717. AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
  718. return MessageModelUtil.getSuccessMessageModel(productCategoryList);
  719. }
  720. public MessageModel add_size(Goods goods) {
  721. insertSize(goods);
  722. return MessageModelUtil.getSuccessMessageModel();
  723. }
  724. public MessageModel update_size(SizeReturn size) {
  725. AssertUtil.intIsNotEmpty(size.getId(),"请选择待修改的记录");
  726. Integer code=goodsDao.update_size(size);
  727. AssertUtil.intIsNotEmpty(code,"修改记录失败...");
  728. return MessageModelUtil.getSuccessMessageModel();
  729. }
  730. public MessageModel delete_size(Integer id) {
  731. AssertUtil.intIsNotEmpty(id,"请选择删除记录...");
  732. Integer code=goodsDao.delete_size(id);
  733. AssertUtil.intIsNotEmpty(code,"删除记录失败...");
  734. return MessageModelUtil.getSuccessMessageModel();
  735. }
  736. public MessageModel edit_default_product(Integer id, String defaultGoods) {
  737. AssertUtil.intIsNotEmpty(id,"请选择修改的货品id");
  738. AssertUtil.isNotEmpty(defaultGoods,"请传入要修改的默认商品");
  739. Integer code=goodsDao.updateDefaultGoodsByGoodsId(id,defaultGoods);
  740. AssertUtil.intIsNotEmpty(code,"修改失败");
  741. return MessageModelUtil.getSuccessMessageModel();
  742. }
  743. public MessageModel query_product_detail(Integer id) {
  744. AssertUtil.intIsNotEmpty(id,"请传入货品Id");
  745. Map map = new HashMap();
  746. List<ProductNoCustom> products = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ZERO);
  747. AssertUtil.listIsNotEmpty(products,"查询数据失败,请联系客服...");
  748. //套码类,只查product表
  749. if (products.size() != 0) {
  750. products = getProductImage(products);
  751. }
  752. return MessageModelUtil.getSuccessMessageModel(products);
  753. }
  754. public List<ProductNoCustom> query_goods_stock(Integer id) {
  755. AssertUtil.intIsNotEmpty(id,"请传入货品Id");
  756. List<ProductNoCustom> products = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ZERO);
  757. AssertUtil.listIsNotEmpty(products,"查询数据失败,请联系客服...");
  758. return products;
  759. }
  760. }