11 changed files with 354 additions and 7 deletions
@ -0,0 +1,116 @@ |
|||||
|
package com.qs.serve.modules.goods.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.qs.serve.common.model.annotation.SysLog; |
||||
|
import com.qs.serve.common.model.dto.PageVo; |
||||
|
import com.qs.serve.common.model.dto.R; |
||||
|
import com.qs.serve.common.model.enums.BizType; |
||||
|
import com.qs.serve.common.model.enums.SystemModule; |
||||
|
import com.qs.serve.common.util.PageUtil; |
||||
|
import com.qs.serve.common.util.CopierUtil; |
||||
|
import com.qs.serve.common.util.StringUtils; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
||||
|
import com.qs.serve.modules.goods.entity.bo.GoodsCategoryRuleBo; |
||||
|
import com.qs.serve.modules.goods.service.GoodsCategoryService; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategoryRule; |
||||
|
import com.qs.serve.modules.goods.service.GoodsCategoryRuleService; |
||||
|
|
||||
|
import javax.validation.Valid; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 商品 品牌规则 |
||||
|
* @author YenHex |
||||
|
* @since 2023-09-18 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@AllArgsConstructor |
||||
|
@RestController |
||||
|
@RequestMapping("goods/categoryRule") |
||||
|
public class GoodsCategoryRuleController { |
||||
|
|
||||
|
private GoodsCategoryRuleService goodsCategoryRuleService; |
||||
|
|
||||
|
/** |
||||
|
* 列表 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
//@GetMapping("/list")
|
||||
|
public R<List<GoodsCategoryRule>> getList(GoodsCategoryRule param){ |
||||
|
LambdaQueryWrapper<GoodsCategoryRule> lqw = new LambdaQueryWrapper<>(param); |
||||
|
List<GoodsCategoryRule> list = goodsCategoryRuleService.list(lqw); |
||||
|
return R.ok(list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 翻页 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/page") |
||||
|
public R<PageVo<GoodsCategoryRule>> getPage(GoodsCategoryRule param){ |
||||
|
LambdaQueryWrapper<GoodsCategoryRule> lqw = new LambdaQueryWrapper<>(param); |
||||
|
PageUtil.startPage(); |
||||
|
List<GoodsCategoryRule> list = goodsCategoryRuleService.list(lqw); |
||||
|
return R.byPageHelperList(list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* ID查询 |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/getById/{id}") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "品牌规则", biz = BizType.QUERY) |
||||
|
public R<GoodsCategoryRule> getById(@PathVariable("id") String id){ |
||||
|
GoodsCategoryRule goodsCategoryRule = goodsCategoryRuleService.getById(id); |
||||
|
return R.ok(goodsCategoryRule); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/updateById") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "品牌规则", biz = BizType.UPDATE) |
||||
|
public R<?> updateById(@RequestBody @Valid GoodsCategoryRuleBo param){ |
||||
|
goodsCategoryRuleService.modify(param); |
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 新增 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/save") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "品牌规则", biz = BizType.INSERT) |
||||
|
public R<?> save(@RequestBody @Valid GoodsCategoryRuleBo param){ |
||||
|
goodsCategoryRuleService.modify(param); |
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* @param ids |
||||
|
* @return |
||||
|
*/ |
||||
|
@DeleteMapping("/deleteById/{ids}") |
||||
|
@SysLog(module = SystemModule.GOODS, title = "品牌规则", biz = BizType.DELETE) |
||||
|
public R<?> deleteById(@PathVariable("ids") String ids){ |
||||
|
List<Long> idsLong = StringUtils.splitIdLong(ids); |
||||
|
boolean result = goodsCategoryRuleService.removeByIds(idsLong); |
||||
|
return R.isTrue(result); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,102 @@ |
|||||
|
package com.qs.serve.modules.goods.entity; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* 品牌规则 实体类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-09-18 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName(value = "goods_category_rule",autoResultMap = true) |
||||
|
public class GoodsCategoryRule implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** id */ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
|
||||
|
/** 标题 */ |
||||
|
@NotBlank(message = "标题不能为空") |
||||
|
@Length(max = 255,message = "标题长度不能超过255字") |
||||
|
private String label; |
||||
|
|
||||
|
/** 品牌id */ |
||||
|
@NotBlank(message = "品牌id不能为空") |
||||
|
private String[] brandIds; |
||||
|
|
||||
|
/** 品牌名称 */ |
||||
|
@NotBlank(message = "品牌名称不能为空") |
||||
|
private String[] brandNames; |
||||
|
|
||||
|
/** 启用状态 */ |
||||
|
@NotNull(message = "启用状态不能为空") |
||||
|
private Integer enableFlag; |
||||
|
|
||||
|
/** 备注 */ |
||||
|
@Length(max = 255,message = "备注长度不能超过255字") |
||||
|
private String remark; |
||||
|
|
||||
|
/** 创建时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private LocalDateTime createTime; |
||||
|
|
||||
|
/** 最后更新时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private LocalDateTime updateTime; |
||||
|
|
||||
|
/** 所属租户 */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String tenantId; |
||||
|
|
||||
|
/** 逻辑删除标记(0:显示;1:隐藏) */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String delFlag; |
||||
|
|
||||
|
/** 创建人 */ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private String createBy; |
||||
|
|
||||
|
/** 更新人 */ |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private String updateBy; |
||||
|
|
||||
|
|
||||
|
public static GoodsCategoryRule toNewObject(GoodsCategoryRule source){ |
||||
|
GoodsCategoryRule categoryRule = new GoodsCategoryRule(); |
||||
|
categoryRule.setId(source.getId()); |
||||
|
categoryRule.setLabel(source.getLabel()); |
||||
|
categoryRule.setBrandIds(source.getBrandIds()); |
||||
|
categoryRule.setBrandNames(source.getBrandNames()); |
||||
|
categoryRule.setEnableFlag(source.getEnableFlag()); |
||||
|
categoryRule.setRemark(source.getRemark()); |
||||
|
categoryRule.setCreateTime(source.getCreateTime()); |
||||
|
categoryRule.setUpdateTime(source.getUpdateTime()); |
||||
|
categoryRule.setTenantId(source.getTenantId()); |
||||
|
categoryRule.setDelFlag(source.getDelFlag()); |
||||
|
categoryRule.setCreateBy(source.getCreateBy()); |
||||
|
categoryRule.setUpdateBy(source.getUpdateBy()); |
||||
|
return categoryRule; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,33 @@ |
|||||
|
package com.qs.serve.modules.goods.entity.bo; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/9/18 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class GoodsCategoryRuleBo { |
||||
|
|
||||
|
/** id */ |
||||
|
private Long id; |
||||
|
|
||||
|
/** 标题 */ |
||||
|
private String label; |
||||
|
|
||||
|
/** 品牌id */ |
||||
|
private String[] brandIds; |
||||
|
|
||||
|
/** 启用状态 */ |
||||
|
private Integer enableFlag; |
||||
|
|
||||
|
/** 备注 */ |
||||
|
private String remark; |
||||
|
|
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.goods.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategoryRule; |
||||
|
|
||||
|
/** |
||||
|
* 品牌规则 Mapper |
||||
|
* @author YenHex |
||||
|
* @date 2023-09-18 |
||||
|
*/ |
||||
|
public interface GoodsCategoryRuleMapper extends BaseMapper<GoodsCategoryRule> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,17 @@ |
|||||
|
package com.qs.serve.modules.goods.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategoryRule; |
||||
|
import com.qs.serve.modules.goods.entity.bo.GoodsCategoryRuleBo; |
||||
|
|
||||
|
/** |
||||
|
* 品牌规则 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2023-09-18 |
||||
|
*/ |
||||
|
public interface GoodsCategoryRuleService extends IService<GoodsCategoryRule> { |
||||
|
|
||||
|
GoodsCategoryRule modify(GoodsCategoryRuleBo goodsCategoryRuleBo); |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,55 @@ |
|||||
|
package com.qs.serve.modules.goods.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.common.util.CopierUtil; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
||||
|
import com.qs.serve.modules.goods.entity.bo.GoodsCategoryRuleBo; |
||||
|
import com.qs.serve.modules.goods.mapper.GoodsCategoryMapper; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategoryRule; |
||||
|
import com.qs.serve.modules.goods.service.GoodsCategoryRuleService; |
||||
|
import com.qs.serve.modules.goods.mapper.GoodsCategoryRuleMapper; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 品牌规则 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-09-18 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class GoodsCategoryRuleServiceImpl extends ServiceImpl<GoodsCategoryRuleMapper,GoodsCategoryRule> implements GoodsCategoryRuleService { |
||||
|
|
||||
|
private GoodsCategoryMapper goodsCategoryMapper; |
||||
|
|
||||
|
@Override |
||||
|
public GoodsCategoryRule modify(GoodsCategoryRuleBo param) { |
||||
|
LambdaQueryWrapper<GoodsCategory> brandCategory = new LambdaQueryWrapper<>(); |
||||
|
brandCategory.in(GoodsCategory::getId, Arrays.asList(param.getBrandIds())); |
||||
|
brandCategory.eq(GoodsCategory::getLevel,1); |
||||
|
List<GoodsCategory> categoryList = goodsCategoryMapper.selectList(brandCategory); |
||||
|
List<String> ids = new ArrayList<>(); |
||||
|
List<String> names = new ArrayList<>(); |
||||
|
for (GoodsCategory category : categoryList) { |
||||
|
ids.add(category.getId()+""); |
||||
|
names.add(category.getName()); |
||||
|
} |
||||
|
GoodsCategoryRule entity = CopierUtil.copy(param,new GoodsCategoryRule()); |
||||
|
entity.setBrandIds(ids.toArray(new String[ids.size()])); |
||||
|
entity.setBrandNames(names.toArray(new String[names.size()])); |
||||
|
if(param.getId()!=null){ |
||||
|
this.updateById(entity); |
||||
|
}else { |
||||
|
this.save(entity); |
||||
|
} |
||||
|
return entity; |
||||
|
} |
||||
|
} |
||||
|
|
Loading…
Reference in new issue