123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891 |
- package com.shop.service;
- import com.alibaba.fastjson.JSON;
- import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
- import com.github.miemiedev.mybatis.paginator.domain.PageList;
- import com.github.miemiedev.mybatis.paginator.domain.Paginator;
- import com.shop.constant.DmConstant;
- import com.shop.constant.MessageModel;
- import com.shop.dao.GoodsDao;
- import com.shop.dao.OrderDao;
- import com.shop.dao.ProductDao;
- import com.shop.exception.ParamException;
- import com.shop.gto.GoodsDto;
- import com.shop.model.*;
- import com.shop.util.AssertUtil;
- import com.shop.util.MessageModelUtil;
- import com.shop.util.ProductAttributeUtil;
- import com.shop.vo.LoginIdentity;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.util.*;
- /**
- * @author DY
- * @create 2018-03-16 16:03
- **/
- @Service
- @Transactional
- public class GoodsService {
- @Autowired
- private GoodsDao goodsDao;
- @Autowired
- private ProductDao productDao;
- @Autowired
- private OrderDao orderDao;
- public MessageModel add_goods(Goods goods, LoginIdentity loginIdentity) {
- MessageModel messageModel = new MessageModel();
- //查询设计师名称和id根据store
- //goods.setBrandDesignerId(loginIdentity.getBrandDesignerId());
- //goods.setBrandDesigner(loginIdentity.getBrandDesigner());
- goods.setStore(loginIdentity.getStore());
- goods.setSortSynthesize(BigDecimal.ZERO);
- //参数验证
- checkParams(goods);
- if(goods.getIsCustom()==1||goods.getIsCustom()==2){
- AssertUtil.isNotEmpty(goods.getDefaultChose(),"请上传基款");
- }
- //查询商品是否存在
- Integer cod = goodsDao.findGoodsIsExistByGoodsSn(goods.getGoodsSn(),loginIdentity.getStore());
- AssertUtil.isTrue(cod != null, "货品已存在...");
- goods.setType(loginIdentity.getType());
- goods.setSales(BigDecimal.ZERO);
- goods.setHits(BigDecimal.ZERO);
- goods.setVersion(DmConstant.VERSION_ZERO);
- goods.setIsMarketable(false);
- goods.setIsTop(false);
- goods.setIsNew(false);
- goods.setIsRecommend(false);
- //排序设为0 默认按时间排序
- goods.setSort(DmConstant.CREATE_TIME);
- //判断此商品是否支持定制
- Integer isCustom = goods.getIsCustom();
- if(goods.getFreight()==null){
- goods.setFreight(BigDecimal.ZERO);
- }
- //先插入商品库得到商品ID
- goodsDao.insert(goods);
- Integer goodsId = goods.getId();
- //插入尺寸表
- insertSize(goods);
- //套 码 类
- if (isCustom == 0) {
- insertProduct(goods, goodsId);
- }
- else{
- //定制+套码(1.纯定制商品属性(必有) 2.套码定制属性(必传) 3.细节定制属性(选传))
- //纯定制
- if (isCustom == 2) {
- insertProduct(goods, goodsId);
- }
- //定制属性
- insertCustomerProduct(goods.getCustomProduct(), goodsId);
- //插入细节定制表
- insertProductCustomer(goods, goodsId);
- }
- return messageModel;
- }
- private void insertCustomerProduct(String product, Integer goodsId) {
- List<ProductNoCustom> customProducts = null;
- //格式化商品大字段
- AssertUtil.isNotEmpty(product,"请传入定制属性");
- if (StringUtils.isNotBlank(product)) {
- customProducts = JSON.parseArray(product, ProductNoCustom.class
- );
- //遍历循环插入goodsId
- for (int i = 0; i < customProducts.size(); i++) {
- ProductNoCustom customProduct = customProducts.get(i);
- customProduct.setGoods(goodsId);
- customProduct.setAllocatedStock(0);
- customProduct.setIsCustom(true);
- }
- //循环插入数据库
- Integer insertCode = productDao.insertProductNoCustom(customProducts);
- AssertUtil.intIsNotEmpty(insertCode, "定制1商品插入失败,请联系客服...");
- }
- }
- private void insertProductCustomer(Goods goods, Integer goodsId) {
- List<ProductCustom> productCustoms = null;
- //格式化商品大字段
- String product = goods.getProductCustom();
- if (StringUtils.isNotBlank(product)) {
- productCustoms = JSON.parseArray(product, ProductCustom.class
- );
- //遍历循环插入goodsId
- for (int i = 0; i < productCustoms.size(); i++) {
- ProductCustom productCustom = productCustoms.get(i);
- productCustom.setGoods(goodsId);
- }
- //循环插入数据库
- Integer insertCode = productDao.insertProductCustom(productCustoms);
- AssertUtil.intIsNotEmpty(insertCode, "商品插入失败,请联系客服...");
- }
- }
- private void insertProduct(Goods goods, Integer goodsId) {
- List<ProductNoCustom> productNoCustoms = null;
- //格式化商品大字段
- String product = goods.getProductNoCustom();
- AssertUtil.isNotEmpty(product, "请传入套码商品");
- if (StringUtils.isNotBlank(product)) {
- productNoCustoms = JSON.parseArray(product, ProductNoCustom.class);}
- //遍历循环插入goodsId
- for (int i = 0; i < productNoCustoms.size(); i++) {
- ProductNoCustom productNoCustom = productNoCustoms.get(i);
- productNoCustom.setIsCustom(false);
- productNoCustom.setGoods(goodsId);
- productNoCustom.setAllocatedStock(0);
- }
- //循环插入数据库
- Integer insertCode = productDao.insertProductNoCustom(productNoCustoms);
- AssertUtil.intIsNotEmpty(insertCode, "商品插入失败,请联系客服...");
- }
- public void insertSize(Goods goods) {
- List<Size> sizes = null;
- Integer goodsId=goods.getId();
- Integer categoryId=goods.getProductCategory();
- String size=goods.getSize();
- AssertUtil.intIsNotEmpty(goodsId,"请选择商品");
- AssertUtil.intIsNotEmpty(categoryId,"请选择商品");
- AssertUtil.isNotEmpty(size, "请传入尺寸");
- //查询上下限
- //SizeClose sizeClose=productDao.findUpAndLowByCategory(categoryId);
- if (StringUtils.isNotBlank(size)) {
- sizes = JSON.parseArray(size, Size.class);}
- //遍历循环插入goodsId
- for (int i = 0; i < sizes.size(); i++) {
- Size size1 = sizes.get(i);
- size1.setGender(goods.getGender());
- size1.setGoods(goodsId);
- /*if(!size1.getBackRise().equals(BigDecimal.ZERO)){
- size1.setBackRiseBig(size1.getBackRise().add(sizeClose.getBackRiseUp()));
- size1.setBackRiseSmall(size1.getBackRise().subtract(sizeClose.getBackRiseLow()));
- }
- if(!size1.getClothesLength().equals(BigDecimal.ZERO)){
- size1.setClothesBig(size1.getClothesLength().add(sizeClose.getClothesUp()));
- size1.setClothesSmall(size1.getClothesLength().subtract(sizeClose.getClothesLow()));
- }
- if(!size1.getShoulder().equals(BigDecimal.ZERO)){
- size1.setShoulderBig(size1.getShoulder().add(sizeClose.getShoulderUp()));
- size1.setShoulderSmall(size1.getShoulder().subtract(sizeClose.getShoulderLow()));
- }
- if(!size1.getBust().equals(BigDecimal.ZERO)){
- size1.setBustBig(size1.getBust().add(sizeClose.getBustUp()));
- size1.setBustSmall(size1.getBust().subtract(sizeClose.getBustLow()));
- }
- if(!size1.getSleeve().equals(BigDecimal.ZERO)){
- size1.setSleeveBig(size1.getSleeve().add(sizeClose.getSleeveUp()));
- size1.setSleeveSmall(size1.getSleeve().subtract(sizeClose.getSleeveLow()));
- }
- if(!size1.getWaistline().equals(BigDecimal.ZERO)){
- size1.setWaistlineBig(size1.getWaistline().add(sizeClose.getWaistlineUp()));
- size1.setWaistlineSmall(size1.getWaistline().subtract(sizeClose.getWaistlineLow()));
- }
- if(!size1.getHipline().equals(BigDecimal.ZERO)){
- size1.setHiplineBig(size1.getHipline().add(sizeClose.getHiplineUp()));
- size1.setHiplineSmall(size1.getHipline().subtract(sizeClose.getHiplineLow()));
- }
- if(!size1.getOutside().equals(BigDecimal.ZERO)){
- size1.setOutsideBig(size1.getOutside().add(sizeClose.getOutsideUp()));
- size1.setOutsideSmall(size1.getOutside().subtract(sizeClose.getOutsideLow()));
- }
- if(!size1.getFoot().equals(BigDecimal.ZERO)){
- size1.setFootBig(size1.getFoot().add(sizeClose.getFootUp()));
- size1.setFootSmall(size1.getFoot().subtract(sizeClose.getFootLow()));
- }
- if(!size1.getSweep().equals(BigDecimal.ZERO)){
- size1.setSweepBig(size1.getSweep().add(sizeClose.getSweepUp()));
- size1.setSweepSmall(size1.getSweep().subtract(sizeClose.getSweepLow()));
- }
- if(!size1.getFrontRise().equals(BigDecimal.ZERO)){
- size1.setFrontRiseBig(size1.getFrontRise().add(sizeClose.getFrontRiseUp()));
- size1.setFrontRiseSmall(size1.getFrontRise().subtract(sizeClose.getFrontRiseLow()));
- }
- if(!size1.getCup().equals(BigDecimal.ZERO)){
- size1.setCupBig(size1.getCup().add(sizeClose.getCupUp()));
- size1.setCupSmall(size1.getCup().subtract(sizeClose.getCupLow()));
- }
- if(!size1.getSkirtLength().equals(BigDecimal.ZERO)){
- size1.setSkirtBig(size1.getSkirtLength().add(sizeClose.getSkirtUp()));
- size1.setSkirtSmall(size1.getSkirtLength().subtract(sizeClose.getSkirtLow()));
- }
- if(!size1.getHip().equals(BigDecimal.ZERO)){
- size1.setHipBig(size1.getHip().add(sizeClose.getHipUp()));
- size1.setHipSmall(size1.getHip().subtract(sizeClose.getHipLow()));
- }
- */
- }
- //循环插入数据库
- Integer insertCode = productDao.insertSize(sizes);
- AssertUtil.intIsNotEmpty(insertCode, "商品尺码插入失败,请联系客服...");
- }
- private void checkParams(Goods goods) {
- AssertUtil.isNotEmpty(goods.getBrandDesigner(),"请添加品牌");
- AssertUtil.intIsNotEmpty(goods.getBrandDesignerId(),"请添加品牌");
- AssertUtil.isNotEmpty(goods.getBrandDesigner(), "请填写品牌设计师名称");
- AssertUtil.intIsNotEmpty(goods.getGender(), "请选择一级分类");
- AssertUtil.intIsNotEmpty(goods.getCategoryParent(), "请选择二级分类");
- AssertUtil.intIsNotEmpty(goods.getProductCategory(), "请选择三级分类");
- AssertUtil.isNotEmpty(goods.getProductSeason(), "请选择季节级分类");
- AssertUtil.isNotEmpty(goods.getName(), "请填写商品名称");
- AssertUtil.isNotEmpty(goods.getMemo(), "请填写商品注意事项...");
- AssertUtil.isNotEmpty(goods.getGoodsSn(), "请填写商品编号");
- AssertUtil.notNull(goods.getPrice(), "请填写商品价格...");
- AssertUtil.isNotEmpty(goods.getMaterialDetail(), "请填写材质详情...");
- AssertUtil.isNotEmpty(goods.getKeyword(), "请填写关键字...");
- AssertUtil.isNotEmpty(goods.getProductIntroduction(), "请填写商品介绍...");
- AssertUtil.isNotEmpty(goods.getImage(), "请上传商品主图");
- AssertUtil.isNotEmpty(goods.getProductImageTop(), "请上传商品副图");
- AssertUtil.isNotEmpty(goods.getProductImageBottom(), "请上传商品详情图");
- AssertUtil.isNotEmpty(goods.getServiceProvide(), "请选择商品服务保障");
- AssertUtil.isNotEmpty(goods.getDeliveryTime(), "请选择商品发货时间");
- AssertUtil.notNull(goods.getIsCustom(), "请选择是否支持定制");
- AssertUtil.isNotEmpty(goods.getSize(), "请填写商品尺寸表");
- AssertUtil.isTrue(goods.getProductCustom() == null && goods.getProductNoCustom() == null, "请上传商品明细");
- }
- /**
- * @author DY
- * @create 2018/3/21 16:08
- * 商品总览
- */
- public Map goods_overview(LoginIdentity loginIdentity) {
- Map map = new HashMap();
- Integer store = loginIdentity.getStore();
- Integer type = loginIdentity.getType();
- //查到上架和已下架,库存紧张.通过审核,未通过审核商品和全部商品
- Integer version = DmConstant.VERSION_MINUS_TWO;
- CountGoods countGoods = productDao.queryIsMarketableProduct(store, type, version);
- AssertUtil.notNull(countGoods,"空空如也...");
- Integer totalProduct = 0;
- Integer up = 0;
- Integer down = 0;
- Integer stock = 0;
- Integer unPassToCheck = 0;
- Integer waitToCheck = 0;
- Integer passToCheck = 0;
- if (countGoods.getTotal() != null) {
- totalProduct = countGoods.getTotal();
- }
- map.put("totalProduct", totalProduct);
- if (countGoods.getUp() != null) {
- up = countGoods.getUp();
- }
- map.put("up", up);
- if (countGoods.getDown() != null) {
- down = countGoods.getDown();
- }
- map.put("down", down);
- if (countGoods.getUnPassToCheck() != null) {
- unPassToCheck = countGoods.getUnPassToCheck();
- }
- map.put("unPassToCheck", unPassToCheck);
- if (countGoods.getWaitToCheck() != null) {
- waitToCheck = countGoods.getWaitToCheck();
- }
- map.put("waitToCheck", waitToCheck);
- if (countGoods.getPassToCheck() != null) {
- passToCheck = countGoods.getPassToCheck();
- }
- map.put("passToCheck", passToCheck);
- //拿到库存紧张的商品数量
- Integer isCustom=0;
- Integer isMarketable=1;
- Integer versionStock=1;
- List<Integer> stockIsLittle = productDao.findProductIsLockStock(store,isCustom, isMarketable,versionStock,type, DmConstant.PRODUCT_STOCK);
- if (stockIsLittle.size()!= 0) {
- stock = stockIsLittle.size();
- }
- map.put("stock", stock);
- return map;
- }
- public MessageModel goods_list(GoodsDto goodsDto, LoginIdentity loginIdentity) {
- //拿到全部商品 已上架 未上架 待审核 未通过
- Map map = goods_overview(loginIdentity);
- Map mapGetFromUtil = getGoodsList(goodsDto, loginIdentity);
- map.putAll(mapGetFromUtil);
- MessageModel messageModel = MessageModelUtil.getSuccessMessageModel(map);
- return messageModel;
- }
- private Map getGoodsList(GoodsDto goodsDto, LoginIdentity loginIdentity) {
- Integer store = loginIdentity.getStore();
- Integer type = loginIdentity.getType();
- goodsDto.setStore(store);
- goodsDto.setType(type);
- //拿到库存紧张的商品数量
- Integer isCustom=0;
- Integer isMarketable=1;
- Integer versionStock=1;
- List<Integer> ids=productDao.findProductIsLockStock(store,isCustom, isMarketable,versionStock,type, DmConstant.PRODUCT_STOCK);
- String str="";
- for(int i=0;i<ids.size();i++){
- str += ids.get(i)+",";
- }
- if(ids.size()!=0){
- str = str.substring(0,str.length() - 1);
- }
- //判断是否查询库存紧张
- if(goodsDto.getStock()!=null){
- goodsDto.setStockIds(str);
- }
- // 構建pageBounds
- PageBounds pageBounds = goodsDto.buildPageBounds();
- List<Goods> goods = goodsDao.queryGoodsList(goodsDto, pageBounds);
- //把库存紧张的货品置为紧张
- for (int i = 0; i < goods.size(); i++) {
- Goods g=goods.get(i);
- Integer goodsId=g.getId();
- for(int j=0;j<ids.size();j++){
- Integer stockId=ids.get(j);
- if(goodsId.equals(stockId)){
- g.setIsStock(true);
- break;
- }
- else{
- g.setIsStock(false);
- }
- }
- }
- // 構建返回結果
- PageList<Goods> goodsPageList = (PageList<Goods>) goods;
- Paginator paginator = goodsPageList.getPaginator();
- Map map = new HashMap();
- map.put("goods_list", goodsPageList);
- map.put("paginator", paginator);
- return map;
- }
- public MessageModel query_goods_check_status(Integer id) {
- AssertUtil.intIsNotEmpty(id, "请选择要查看的商品");
- CheckInformation checkInformation = goodsDao.queryGoodsStatusCheck(id);
- AssertUtil.notNull(checkInformation, "商品不存在,请联系客服...");
- MessageModel messageModel = MessageModelUtil.getSuccessMessageModel(checkInformation);
- return messageModel;
- }
- /**
- * @author DY
- * @create 2018/3/26 17:30
- * 查询可定制类目
- */
- public MessageModel query_custom_names() {
- List<CustomName> customNames = goodsDao.queryCustomNames();
- AssertUtil.listIsNotEmpty(customNames,"查询失败,请联系官方客服....");
- return MessageModelUtil.getSuccessMessageModel(customNames);
- }
- public MessageModel is_marketable_is_new_product_recommend(IsMarketableNewRecommend isMarketableNewRecommend) {
- //参数验证
- checkParams(isMarketableNewRecommend);
- Integer code = goodsDao.updateIsMarketableIsNewIsRecommendByIds(isMarketableNewRecommend);
- AssertUtil.intIsNotEmpty(code, "更新条件失败,请联系客服...");
- return MessageModelUtil.getSuccessMessageModel();
- }
- private void checkParams(IsMarketableNewRecommend isMarketableNewRecommend) {
- AssertUtil.isNotEmpty(isMarketableNewRecommend.getIds(), "清传入商品ids");
- //根据name来确定执行的步骤 null全部执行,1.上架.2.新品.3.推荐
- AssertUtil.isTrue(isMarketableNewRecommend.getIsMarketable() == null && isMarketableNewRecommend.getIsNew() == null && isMarketableNewRecommend.getIsRecommend() == null, "请选择要执行的操作项...提交");
- }
- /**
- * @author DY
- * @create 2018/3/23 12:06
- * 查看商品详情...
- */
- public Map query_goods_detail(Integer id) {
- Map map = new HashMap();
- AssertUtil.intIsNotEmpty(id,"请传入货品Id");
- //拿到货品
- Goods goods = goodsDao.findProductById(id);
- AssertUtil.notNull(goods, "货品不存在,请稍后重试...");
- // 格式化商品图片大字段
- List<ProductImageTop> productImageListTop = null;
- String productImagesTop = goods.getProductImageTop();
- if (StringUtils.isNotBlank(productImagesTop)) {
- productImageListTop = JSON.parseArray(productImagesTop, ProductImageTop.class);
- goods.setProductImageTop(null);
- }
- // 格式化商品图片大字段
- List<ProductImageBottom> productImageListBottom = null;
- String productImagesBottom = goods.getProductImageBottom();
- if (StringUtils.isNotBlank(productImagesBottom)) {
- productImageListBottom = JSON.parseArray(productImagesBottom, ProductImageBottom.class
- );
- goods.setProductImageBottom(null);
- }
- //查询具体商品信息,判断是否定制
- Integer isCustom = goods.getIsCustom();
- List<ProductNoCustom> products = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ZERO);
- //AssertUtil.listIsNotEmpty(products,"查询数据失败,请联系客服...");
- //套码类,只查product表
- if (isCustom == 0) {
- if (products.size() != 0) {
- products = getProductImage(products);
- map.put("products", products);
- }
- } else {
- //定制类查product和custom表
- List<ProductCustom> productCustoms = goodsDao.queryCustomProductsByGoodsId(id);
- List<ProductNoCustom> customProducts = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ONE);
- if(productCustoms.size()!=0){
- List<List<ProductCustom>> lists=getCustomList(productCustoms);
- map.put("productCustoms", lists);
- }
- if (customProducts.size() != 0) {
- customProducts = getSize(customProducts);
- map.put("customProducts", customProducts);
- }
- if (products.size() != 0) {
- products = getProductImage(products);
- map.put("products", products);
- }
- // 格式化默认商品大字段
- List<DefaultClothes> defaultClothesList = null;
- String clothes= goods.getDefaultChose();
- if (StringUtils.isNotBlank(clothes)) {
- defaultClothesList = JSON.parseArray(clothes, DefaultClothes.class
- );
- map.put("defaultClothesList", defaultClothesList);
- }
- }
- //查询尺码表
- List<SizeReturn> sizeList=goodsDao.findSizeByGoodsId(id);
- map.put("sizeList", sizeList);
- map.put("goods", goods);
- map.put("productImageListTop", productImageListTop);
- map.put("productImageListBottom", productImageListBottom);
- return map;
- }
- private List<List<ProductCustom>> getCustomList(List<ProductCustom> productCustoms) {
- Map<Integer, List> map = new LinkedHashMap();
- for (int i = 0; i < productCustoms.size(); i++) {
- ProductCustom item = productCustoms.get(i);
- //格式化图片大字段
- // 格式化商品图片大字段
- List<CustomImage> customImages = null;
- String image = item.getImage();
- if (StringUtils.isNotBlank(image)) {
- customImages = JSON.parseArray(image, CustomImage.class
- );
- }
- item.setImageList(customImages);
- Integer key = item.getCustom();
- //当且仅当集合里有过 1//1才会进这个集合,第一次也不会进,第二次才会进
- if (map.containsKey(key)) {
- map.get(key).add(item);
- } else {
- List list = new ArrayList();
- list.add(item);
- map.put(key, list);
- System.out.println();
- }
- }
- List<List<ProductCustom>> data = new PageList<>();
- for (Map.Entry<Integer, List> entry : map.entrySet()) {
- data.add(entry.getValue());
- }
- return data;
- }
- private List<ProductCustom> getProductCustomImage(List<ProductCustom> productCustoms) {
- for (int i = 0; i < productCustoms.size(); i++) {
- ProductCustom item = productCustoms.get(i);
- //格式化图片大字段
- // 格式化商品图片大字段
- List<CustomImage> customImages = null;
- String image = item.getImage();
- if (StringUtils.isNotBlank(image)) {
- customImages = JSON.parseArray(image, CustomImage.class
- );
- }
- item.setImageList(customImages);
- }
- return productCustoms;
- }
- private List<ProductNoCustom> getProductImage(List<ProductNoCustom> product) {
- for (int i = 0; i < product.size(); i++) {
- ProductNoCustom item = product.get(i);
- //格式化图片大字段
- // 格式化商品图片大字段
- List<CustomImage> customImages = null;
- String image = item.getImages();
- if (StringUtils.isNotBlank(image)) {
- customImages = JSON.parseArray(image, CustomImage.class
- );
- }
- item.setImageList(customImages);
- item.setImages(null);
- }
- return product;
- }
- private List<ProductNoCustom> getSize(List<ProductNoCustom> customProducts) {
- for (int i = 0; i < customProducts.size(); i++) {
- ProductNoCustom item = customProducts.get(i);
- //格式化图片大字段
- List<CustomImage> customImages = null;
- String image = item.getImages();
- if (StringUtils.isNotBlank(image)) {
- customImages = JSON.parseArray(image, CustomImage.class
- );
- item.setImages(null);
- }
- item.setImageList(customImages);
- item.setImages(null);
- // 格式化商品图片大字段
- String size = item.getSize();
- String[] arr = size.split(",");
- List<String> customSizeList = Arrays.asList(arr);
- item.setSizeList(customSizeList);
- }
- return customProducts;
- }
- public MessageModel query_product_scene(Integer gender) {
- AssertUtil.intIsNotEmpty(gender, "请选择性别...");
- List<ProductScene> productSceneList = goodsDao.queryProductScene(gender);
- AssertUtil.listIsNotEmpty(productSceneList,"查询数据失败,请联系客服...");
- return MessageModelUtil.getSuccessMessageModel(productSceneList);
- }
- public MessageModel query_product_category(Integer gender) {
- AssertUtil.intIsNotEmpty(gender, "请选择性别...");
- List<ProductCategory> productCategoryList = goodsDao.query_product_category(gender);
- AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
- return MessageModelUtil.getSuccessMessageModel(productCategoryList);
- }
- public MessageModel query_product_category_two(Integer categoryId) {
- AssertUtil.intIsNotEmpty(categoryId, "请选择分类属性...");
- List<ProductCategory> productCategoryList = goodsDao.query_product_category_two(categoryId);
- AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
- return MessageModelUtil.getSuccessMessageModel(productCategoryList);
- }
- public MessageModel query_size(Integer categoryIdChildren) {
- AssertUtil.intIsNotEmpty(categoryIdChildren, "请选择分类属性...");
- String ids=goodsDao.querySize(categoryIdChildren);
- List<ProductCategory> productCategoryList = goodsDao.queryClothesNameBySize(ids);
- AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
- return MessageModelUtil.getSuccessMessageModel(productCategoryList);
- }
- public MessageModel edit_product(Goods goods) {
- //更新货品
- AssertUtil.intIsNotEmpty(goods.getId(), "请选择要编辑的商品...");
- AssertUtil.notNull(goods.getIsCustom(),"请选择尺码是否定制");
- Integer updateCode = goodsDao.updateGoodsByGoods(goods);
- AssertUtil.intIsNotEmpty(updateCode, "商品编辑失败...");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel delete_goods(String ids) {
- AssertUtil.isNotEmpty(ids, "请选择要删除的商品");
- Integer version = DmConstant.VERSION_MINUS_TWO;
- //删除货品 version置为-2,当且只有version=1时才能删除
- Integer goodsCode = goodsDao.updateGoodsStatusByIds(ids, version);
- AssertUtil.intIsNotEmpty(goodsCode, "删除货品失败,请联系客服...");
- //删除商品
- productDao.updateProductStatusByGoods(ids, version);
- //定制的话删除定制类明細及尺码表
- productDao.updateCustomStatusByGoods(ids, version);
- productDao.updateSizeByIds(ids,version);
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel search_goods_list(GoodsDto goodsDto, LoginIdentity loginIdentity) {
- Map map = getGoodsList(goodsDto, loginIdentity);
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- public MessageModel goods_recycle_list(GoodsDto goodsDto, LoginIdentity loginIdentity) {
- goodsDto.setVersion(DmConstant.VERSION_MINUS_TWO);
- Map map = getGoodsList(goodsDto, loginIdentity);
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- public MessageModel goods_recycle_return(String ids, Integer returnOrDelete) {
- AssertUtil.isNotEmpty(ids, "请选择商品");
- AssertUtil.intIsNotEmpty(returnOrDelete, "请选择还原还是删除...");
- Integer version = null;
- if (returnOrDelete == 1) {
- version = DmConstant.VERSION_ONE;
- } else {
- version = DmConstant.VERSION_MINUS_THREE;
- }
- Integer goodsCode = goodsDao.updateGoodsStatusByIds(ids, version);
- AssertUtil.intIsNotEmpty(goodsCode, "删除货品失败,请联系客服...");
- productDao.updateProductStatusByGoods(ids, version);
- productDao.updateCustomStatusByGoods(ids, version);
- productDao.updateSizeByIds(ids,version);
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel getGoodsAttribute(Integer orderItemId) {
- AssertUtil.notNull(orderItemId, "请选择 子订单ID...");
- //拿到订单信息
- OrderItemDetail orderItemDetail = orderDao.findOrderItemById(orderItemId);
- Boolean isCustom=orderItemDetail.getIsCustom();
- AssertUtil.notNull(orderItemDetail, "参数有误,订单不存在,请检查参数");
- Integer goodsId = orderItemDetail.getGoods();
- Map map = new HashMap();
- List<AttributeDetail> ls = null;
- List<ProductNoCustom> customProducts = goodsDao.queryProductsByGoodsId(goodsId, orderItemDetail.getIsCustom());
- if (customProducts.size() != 0) {
- //对具体属性去重
- if(isCustom){
- ls = ProductAttributeUtil.getCustomProductAttribute(customProducts);
- }
- else{
- ls = ProductAttributeUtil.getProductAttribute(customProducts);
- }
- map.put("customProducts", ls);
- }
- //定制
- if (isCustom) {
- List<ProductCustom> productCustoms = goodsDao.findCustomsByGoodsId(goodsId);
- if (productCustoms.size() != 0) {
- //对图片进行处理
- List<List<ProductCustom>> lists = getCustomList(productCustoms);
- map.put("productCustoms", lists);
- }
- }
- return MessageModelUtil.getSuccessMessageModel(map);
- }
- public MessageModel query_goods_by_attribute(String size,String color,Boolean isCustom,Integer goods) {
- AssertUtil.notNull(isCustom,"请传入是否定制");
- AssertUtil.isNotEmpty(size,"请选择商品尺寸");
- AssertUtil.isNotEmpty(color,"请选择商品颜色");
- AssertUtil.intIsNotEmpty(goods,"请选择货品goods");
- if(isCustom){
- size=null;
- }
- Product p=new Product();
- p.setGoods(goods);
- p.setSize(size);
- p.setColor(color);
- p.setIsCustom(isCustom);
- Product product=productDao.findProductByAttribute(p);
- AssertUtil.notNull(product,"选择的商品不存在...");
- return MessageModelUtil.getSuccessMessageModel(product);
- }
- public MessageModel delete_product(String ids) {
- AssertUtil.isNotEmpty(ids,"请选择要删除的商品");
- Integer code=productDao.deleteProductByIds(ids);
- AssertUtil.intIsNotEmpty(code,"删除商品失败");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel delete_product_custom(String ids) {
- AssertUtil.isNotEmpty(ids,"请选择要删除的商品");
- Integer code=productDao.deleteCustomByIds(ids);
- AssertUtil.intIsNotEmpty(code,"删除细节定制失败");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel update_product(UpdateProduct product) {
- AssertUtil.notNull(product,"请选择要修改的商品");
- Integer code=productDao.updateProduct(product);
- AssertUtil.intIsNotEmpty(code,"商品修改失败");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel update_product_custom(ProductCustom productCustom) {
- AssertUtil.notNull(productCustom,"请选择要修改的商品");
- Integer code=productDao.updateProductCustom(productCustom);
- AssertUtil.intIsNotEmpty(code,"商品修改失败");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel add_product(String product) {
- //格式化商品大字段
- AssertUtil.isNotEmpty(product,"请传入商品属性");
- List<ProductNoCustom> products = null;
- if (StringUtils.isNotBlank(product)) {
- products = JSON.parseArray(product, ProductNoCustom.class
- );
- //循环插入数据库
- Integer insertCode = productDao.insertProductNoCustom(products);
- AssertUtil.intIsNotEmpty(insertCode, "定制1商品插入失败,请联系客服...");
- }
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel add_product_custom(String product) {
- List<ProductCustom> productCustoms = null;
- //格式化商品大字段
- if (StringUtils.isNotBlank(product)) {
- productCustoms = JSON.parseArray(product, ProductCustom.class
- );
- //循环插入数据库
- Integer insertCode = productDao.insertProductCustom(productCustoms);
- AssertUtil.intIsNotEmpty(insertCode, "商品插入失败,请联系客服...");
- }
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel goods_product_delete(Integer goods, Boolean isCustom) {
- AssertUtil.intIsNotEmpty(goods,"请选择货品Id");
- AssertUtil.notNull(isCustom,"请选择商品属性");
- Integer code=productDao.deleteProductByGoods(goods,isCustom);
- AssertUtil.intIsNotEmpty(code,"删除失败...");
- if(isCustom){
- productDao.deleteCustomByGoods(goods);
- productDao.deleteDefaultChose(goods,null);
- }
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel query_size_add() {
- List<ProductCategory> productCategoryList = goodsDao.queryAllClothesNameBySize();
- AssertUtil.listIsNotEmpty(productCategoryList,"查询数据失败,请联系客服...");
- return MessageModelUtil.getSuccessMessageModel(productCategoryList);
- }
- public MessageModel add_size(Goods goods) {
- insertSize(goods);
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel update_size(SizeReturn size) {
- AssertUtil.intIsNotEmpty(size.getId(),"请选择待修改的记录");
- Integer code=goodsDao.update_size(size);
- AssertUtil.intIsNotEmpty(code,"修改记录失败...");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel delete_size(Integer id) {
- AssertUtil.intIsNotEmpty(id,"请选择删除记录...");
- Integer code=goodsDao.delete_size(id);
- AssertUtil.intIsNotEmpty(code,"删除记录失败...");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel edit_default_product(Integer id, String defaultGoods) {
- AssertUtil.intIsNotEmpty(id,"请选择修改的货品id");
- AssertUtil.isNotEmpty(defaultGoods,"请传入要修改的默认商品");
- Integer code=goodsDao.updateDefaultGoodsByGoodsId(id,defaultGoods);
- AssertUtil.intIsNotEmpty(code,"修改失败");
- return MessageModelUtil.getSuccessMessageModel();
- }
- public MessageModel query_product_detail(Integer id) {
- AssertUtil.intIsNotEmpty(id,"请传入货品Id");
- Map map = new HashMap();
- List<ProductNoCustom> products = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ZERO);
- AssertUtil.listIsNotEmpty(products,"查询数据失败,请联系客服...");
- //套码类,只查product表
- if (products.size() != 0) {
- products = getProductImage(products);
- }
- return MessageModelUtil.getSuccessMessageModel(products);
- }
- public List<ProductNoCustom> query_goods_stock(Integer id) {
- AssertUtil.intIsNotEmpty(id,"请传入货品Id");
- List<ProductNoCustom> products = goodsDao.queryProductsByGoodsId(id, DmConstant.CUSTOM_ZERO);
- AssertUtil.listIsNotEmpty(products,"查询数据失败,请联系客服...");
- return products;
- }
- }
|