Browse Source

调整

mssql
Yen 3 years ago
parent
commit
0d3d725485
  1. 7
      src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java
  2. 12
      src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java
  3. 10
      src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsSpuTasteBo.java
  4. 16
      src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java
  5. 5
      src/main/java/com/qs/serve/modules/goods/mapper/GoodsSpuMapper.java
  6. 3
      src/main/java/com/qs/serve/modules/goods/service/GoodsSpuService.java
  7. 38
      src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java
  8. 21
      src/main/resources/mapper/bms/GoodsSpuMapper.xml

7
src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java

@ -19,6 +19,7 @@ import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo;
import com.qs.serve.modules.goods.service.GoodsSkuService; import com.qs.serve.modules.goods.service.GoodsSkuService;
import com.qs.serve.modules.goods.service.GoodsSkuSpecValueService; import com.qs.serve.modules.goods.service.GoodsSkuSpecValueService;
import com.qs.serve.modules.goods.service.GoodsSpuSpecService; import com.qs.serve.modules.goods.service.GoodsSpuSpecService;
import io.netty.util.internal.StringUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
@ -55,8 +56,7 @@ public class GoodsSpuController {
@PreAuthorize("hasRole('goods:spu:query')") @PreAuthorize("hasRole('goods:spu:query')")
public R<PageVo<GoodsSpu>> getPage(GoodsSpu param){ public R<PageVo<GoodsSpu>> getPage(GoodsSpu param){
PageUtil.startPage(); PageUtil.startPage();
LambdaQueryWrapper<GoodsSpu> spuWrapper = new LambdaQueryWrapper<>(param); List<GoodsSpu> list = goodsSpuService.selectSpuList(param);
List<GoodsSpu> list = goodsSpuService.list(spuWrapper);
return R.byPageHelperList(list); return R.byPageHelperList(list);
} }
@ -124,6 +124,9 @@ public class GoodsSpuController {
@PreAuthorize("hasRole('goods:spu:insert')") @PreAuthorize("hasRole('goods:spu:insert')")
public R<?> saveTasteSpu(@RequestBody @Valid GoodsSpuBo param){ public R<?> saveTasteSpu(@RequestBody @Valid GoodsSpuBo param){
param.setId(null); param.setId(null);
if(StringUtil.isNullOrEmpty(param.getCategoryId())){
return R.error("参数缺少");
}
goodsSpuService.editTasteSpu(param); goodsSpuService.editTasteSpu(param);
return R.ok(); return R.ok();
} }

12
src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java

@ -41,20 +41,14 @@ public class GoodsSpu implements Serializable {
@Length(max = 200,message = "商品名字长度不能超过200字") @Length(max = 200,message = "商品名字长度不能超过200字")
private String name; private String name;
/** 品牌id */ /** 一级分类、品牌ID */
private Long brandId;
/** 系列id */
private Long seriesId;
/** 一级分类ID */
@NotNull(message = "一级分类ID不能为空") @NotNull(message = "一级分类ID不能为空")
private String categoryFirst; private String categoryFirst;
/** 二级分类ID */ /** 二级分类、类目ID */
private String categorySecond; private String categorySecond;
/** 三级分类ID */ /** 三级分类、系列ID */
private String categoryThird; private String categoryThird;
/** 最后一级分类 */ /** 最后一级分类 */

10
src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsSpuTasteBo.java

@ -30,18 +30,10 @@ public class GoodsSpuTasteBo {
@Length(max = 200,message = "商品名字长度不能超过200字") @Length(max = 200,message = "商品名字长度不能超过200字")
private String name; private String name;
/** 分类编码 */ /** 分类编码(系列编码) */
@NotNull(message = "分类编码不能为空") @NotNull(message = "分类编码不能为空")
private String categoryCode; private String categoryCode;
/** 品牌编码 */
@NotNull(message = "品牌编码不能为空")
private String brandCode;
/** 系列编码 */
@NotNull(message = "系列编码不能为空")
private String seriesCode;
/** 商品组图片 */ /** 商品组图片 */
private String[] picUrls; private String[] picUrls;

16
src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java

@ -1,5 +1,6 @@
package com.qs.serve.modules.goods.entity.vo; package com.qs.serve.modules.goods.entity.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.qs.serve.modules.goods.entity.GoodsSku; import com.qs.serve.modules.goods.entity.GoodsSku;
import lombok.Data; import lombok.Data;
@ -20,12 +21,6 @@ public class GoodsSpuVo {
/** 商品名字 */ /** 商品名字 */
private String name; private String name;
/** 品牌id */
private Long brandId;
/** 系列id */
private Long seriesId;
/** 一级分类ID */ /** 一级分类ID */
private String categoryFirst; private String categoryFirst;
@ -56,4 +51,13 @@ public class GoodsSpuVo {
/** sku与规格 关联列表 */ /** sku与规格 关联列表 */
private List<GoodsSkuSpecValueVo> skuSpecValueList; private List<GoodsSkuSpecValueVo> skuSpecValueList;
/** 一级类目:品牌名称 */
private String cateFirstLabel;
/** 二级类目:类目名称 */
private String cateSecondLabel;
/** 三级类目:系列名称 */
private String cateThirdLabel;
} }

5
src/main/java/com/qs/serve/modules/goods/mapper/GoodsSpuMapper.java

@ -2,6 +2,9 @@ package com.qs.serve.modules.goods.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qs.serve.modules.goods.entity.GoodsSpu; import com.qs.serve.modules.goods.entity.GoodsSpu;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* spu Mapper * spu Mapper
@ -10,5 +13,7 @@ import com.qs.serve.modules.goods.entity.GoodsSpu;
*/ */
public interface GoodsSpuMapper extends BaseMapper<GoodsSpu> { public interface GoodsSpuMapper extends BaseMapper<GoodsSpu> {
List<GoodsSpu> selectSpuList(@Param("query") GoodsSpu goodsSpu);
} }

3
src/main/java/com/qs/serve/modules/goods/service/GoodsSpuService.java

@ -8,6 +8,7 @@ import com.qs.serve.modules.goods.entity.bo.GoodsSpuEditBo;
import com.qs.serve.modules.goods.entity.bo.GoodsSpuTasteBo; import com.qs.serve.modules.goods.entity.bo.GoodsSpuTasteBo;
import com.qs.serve.modules.goods.entity.vo.GoodSkuBatchResult; import com.qs.serve.modules.goods.entity.vo.GoodSkuBatchResult;
import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -18,6 +19,8 @@ import java.util.List;
*/ */
public interface GoodsSpuService extends IService<GoodsSpu> { public interface GoodsSpuService extends IService<GoodsSpu> {
List<GoodsSpu> selectSpuList(GoodsSpu goodsSpu);
GoodsSpuVo getVoById(Long id); GoodsSpuVo getVoById(Long id);
GoodsSpu getByCode(String code); GoodsSpu getByCode(String code);

38
src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java

@ -31,8 +31,6 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> implements GoodsSpuService { public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> implements GoodsSpuService {
private GoodsSeriesService goodsSeriesService;
private GoodsBrandService goodsBrandService;
private GoodsUnitService goodsUnitService; private GoodsUnitService goodsUnitService;
private GoodsSkuService goodsSkuService; private GoodsSkuService goodsSkuService;
private GoodsSpuSpecService goodsSpuSpecService; private GoodsSpuSpecService goodsSpuSpecService;
@ -41,6 +39,11 @@ public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> im
private GoodsCategoryService goodsCategoryService; private GoodsCategoryService goodsCategoryService;
private BmsFactoryService bmsFactoryService; private BmsFactoryService bmsFactoryService;
@Override
public List<GoodsSpu> selectSpuList(GoodsSpu goodsSpu) {
return baseMapper.selectSpuList(goodsSpu);
}
@Override @Override
public GoodsSpu getByCode(String code) { public GoodsSpu getByCode(String code) {
LambdaQueryWrapper<GoodsSpu> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GoodsSpu> lqw = new LambdaQueryWrapper<>();
@ -55,6 +58,7 @@ public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> im
List<GoodsSku> skuList = goodsSkuService.getBySpuId(id); List<GoodsSku> skuList = goodsSkuService.getBySpuId(id);
goodsSpuVo.setSkuList(skuList); goodsSpuVo.setSkuList(skuList);
List<GoodsSkuSpecValueVo> skuSpecValueList = goodsSkuSpecValueService.listSpecValueBySpuId(id); List<GoodsSkuSpecValueVo> skuSpecValueList = goodsSkuSpecValueService.listSpecValueBySpuId(id);
goodsSpuVo.setSkuSpecValueList(skuSpecValueList);
List<GoodsSpuSpecVo> specList = goodsSpuSpecService.listSpuSpecs(id); List<GoodsSpuSpecVo> specList = goodsSpuSpecService.listSpuSpecs(id);
//封装规格的值 //封装规格的值
for (GoodsSpuSpecVo specVo : specList) { for (GoodsSpuSpecVo specVo : specList) {
@ -80,6 +84,24 @@ public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> im
} }
} }
goodsSpuVo.setSpecList(specList); goodsSpuVo.setSpecList(specList);
List<String> categoryIds = new ArrayList<>();
categoryIds.add(goodsSpuVo.getCategoryFirst());
categoryIds.add(goodsSpuVo.getCategorySecond());
categoryIds.add(goodsSpuVo.getCategoryThird());
List<GoodsCategory> categories = goodsCategoryService.listByIds(categoryIds);
for (GoodsCategory category : categories) {
if(goodsSpuVo.getCategoryFirst().equals(category.getId().toString())){
goodsSpuVo.setCateFirstLabel(category.getName());
continue;
}
if(goodsSpuVo.getCategorySecond().equals(category.getId().toString())){
goodsSpuVo.setCateSecondLabel(category.getName());
continue;
}
if(goodsSpuVo.getCategoryThird().equals(category.getId().toString())){
goodsSpuVo.setCateThirdLabel(category.getName());
}
}
return goodsSpuVo; return goodsSpuVo;
} }
@ -105,8 +127,10 @@ public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> im
if(param.getId()!=null){ if(param.getId()!=null){
spu.setSpuCode(null); spu.setSpuCode(null);
} }
if(StringUtils.hasText(param.getCategoryId())){
GoodsCategory category = goodsCategoryService.getById(param.getCategoryId()); GoodsCategory category = goodsCategoryService.getById(param.getCategoryId());
relateCate(spu,category); relateCate(spu,category);
}
this.saveOrUpdate(spu); this.saveOrUpdate(spu);
insertSpuSpec(spu.getId()); insertSpuSpec(spu.getId());
} }
@ -150,16 +174,6 @@ public class GoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper,GoodsSpu> im
skuBatchResult.setErrorCode(1); skuBatchResult.setErrorCode(1);
return skuBatchResult; return skuBatchResult;
} }
//设置品牌
GoodsBrand goodsBrand = goodsBrandService.getByCode(tasteProduct.getBrandCode());
if(goodsBrand!=null){
spu.setBrandId(goodsBrand.getId());
}
//设置系列
GoodsSeries goodsSeries = goodsSeriesService.getByCode(tasteProduct.getSeriesCode());
if(goodsSeries!=null){
spu.setSeriesId(goodsSeries.getId());
}
spu.setTasteValue(tasteProduct.getProductTasteValue()); spu.setTasteValue(tasteProduct.getProductTasteValue());
if(spu.getId()==null){ if(spu.getId()==null){
this.save(spu); this.save(spu);

21
src/main/resources/mapper/bms/GoodsSpuMapper.xml

@ -8,8 +8,6 @@
<result property="id" column="id"/> <result property="id" column="id"/>
<result property="spuCode" column="spu_code"/> <result property="spuCode" column="spu_code"/>
<result property="name" column="name"/> <result property="name" column="name"/>
<result property="brandId" column="brand_id"/>
<result property="seriesId" column="series_id"/>
<result property="categoryFirst" column="category_first"/> <result property="categoryFirst" column="category_first"/>
<result property="categorySecond" column="category_second"/> <result property="categorySecond" column="category_second"/>
<result property="categoryThird" column="category_third"/> <result property="categoryThird" column="category_third"/>
@ -25,6 +23,9 @@
<result property="updateBy" column="update_by"/> <result property="updateBy" column="update_by"/>
<result property="tenantId" column="tenant_id"/> <result property="tenantId" column="tenant_id"/>
<result property="delFlag" column="del_flag"/> <result property="delFlag" column="del_flag"/>
<result property="cateFirstLabel" column="cate_first_label"/>
<result property="cateSecondLabel" column="cate_second_label"/>
<result property="cateThirdLabel" column="cate_third_label"/>
</resultMap> </resultMap>
@ -32,8 +33,6 @@
goods_spu.`id`, goods_spu.`id`,
goods_spu.`spu_code`, goods_spu.`spu_code`,
goods_spu.`name`, goods_spu.`name`,
goods_spu.`brand_id`,
goods_spu.`series_id`,
goods_spu.`category_first`, goods_spu.`category_first`,
goods_spu.`category_second`, goods_spu.`category_second`,
goods_spu.`category_third`, goods_spu.`category_third`,
@ -51,19 +50,20 @@
goods_spu.`tenant_id`, goods_spu.`tenant_id`,
goods_spu.`del_flag` </sql> goods_spu.`del_flag` </sql>
<select id="selectGoodsSpuList" parameterType="com.qs.serve.modules.goods.entity.GoodsSpu" resultMap="goodsSpuMap"> <select id="selectSpuList" parameterType="com.qs.serve.modules.goods.entity.GoodsSpu" resultMap="goodsSpuMap">
SELECT SELECT
`goods_brand`.`name` AS `brand_name`, `cate1`.`name` AS `cate_first_label`,
`goods_series`.`name` AS `series_name`, `cate2`.`name` AS `cate_second_label`,
`cate3`.`name` AS `cate_third_label`,
<include refid="goodsSpuSql"/> <include refid="goodsSpuSql"/>
FROM `goods_spu` `goods_spu` FROM `goods_spu` `goods_spu`
LEFT JOIN `goods_category` `cate1` ON `cate1`.`id` = `goods_spu`.`category_first`
LEFT JOIN `goods_category` `cate2` ON `cate2`.`id` = `goods_spu`.`category_second`
LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third`
<where> <where>
<if test="query.id != null"> and `goods_spu`.`id` = #{query.id}</if> <if test="query.id != null"> and `goods_spu`.`id` = #{query.id}</if>
<if test="query.spuCode != null and query.spuCode != ''"> and `goods_spu`.`spu_code` = #{query.spuCode}</if> <if test="query.spuCode != null and query.spuCode != ''"> and `goods_spu`.`spu_code` = #{query.spuCode}</if>
<if test="query.name != null and query.name != ''"> and `goods_spu`.`name` = #{query.name}</if> <if test="query.name != null and query.name != ''"> and `goods_spu`.`name` = #{query.name}</if>
<if test="query.brandId != null"> and `goods_spu`.`brand_id` = #{query.brandId}</if>
<if test="query.seriesId != null"> and `goods_spu`.`series_id` = #{query.seriesId}</if>
<if test="query.categoryFirst != null"> and `goods_spu`.`category_first` = #{query.categoryFirst}</if> <if test="query.categoryFirst != null"> and `goods_spu`.`category_first` = #{query.categoryFirst}</if>
<if test="query.categorySecond != null"> and `goods_spu`.`category_second` = #{query.categorySecond}</if> <if test="query.categorySecond != null"> and `goods_spu`.`category_second` = #{query.categorySecond}</if>
<if test="query.categoryThird != null"> and `goods_spu`.`category_third` = #{query.categoryThird}</if> <if test="query.categoryThird != null"> and `goods_spu`.`category_third` = #{query.categoryThird}</if>
@ -71,7 +71,6 @@
<if test="query.shelf != null and query.shelf != ''"> and `goods_spu`.`shelf` = #{query.shelf}</if> <if test="query.shelf != null and query.shelf != ''"> and `goods_spu`.`shelf` = #{query.shelf}</if>
<if test="query.sort != null"> and `goods_spu`.`sort` = #{query.sort}</if> <if test="query.sort != null"> and `goods_spu`.`sort` = #{query.sort}</if>
<if test="query.saleNum != null"> and `goods_spu`.`sale_num` = #{query.saleNum}</if> <if test="query.saleNum != null"> and `goods_spu`.`sale_num` = #{query.saleNum}</if>
<if test="query.specType != null and query.specType != ''"> and `goods_spu`.`spec_type` = #{query.specType}</if>
<if test="query.tasteValue != null and query.tasteValue != ''"> and `goods_spu`.`taste_value` = #{query.tasteValue}</if> <if test="query.tasteValue != null and query.tasteValue != ''"> and `goods_spu`.`taste_value` = #{query.tasteValue}</if>
<if test="query.createTime != null"> and `goods_spu`.`create_time` = #{query.createTime}</if> <if test="query.createTime != null"> and `goods_spu`.`create_time` = #{query.createTime}</if>
<if test="query.updateTime != null"> and `goods_spu`.`update_time` = #{query.updateTime}</if> <if test="query.updateTime != null"> and `goods_spu`.`update_time` = #{query.updateTime}</if>

Loading…
Cancel
Save