提交 2a6b406e 作者: 张小凤

CategoryNew(add)

上级 10d6b13e
package com.mmc.pms.controller.category;
import com.mmc.pms.common.Page;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.model.category.dto.CategoryPrimaryDTO;
import com.mmc.pms.model.category.dto.CategorySubDTO;
import com.mmc.pms.model.category.qo.CategoryQO;
import com.mmc.pms.model.category.vo.CategoryPrimaryVO;
import com.mmc.pms.model.category.vo.CategorySubVO;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import com.mmc.pms.service.category.CategoryService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
/**
* @Author small
* @Date 2023/7/20 16:17
* @Version 1.0
* <p>
* 新版本分类管理
*/
@RestController
@RequestMapping("/category")
@Api(tags = {"后台-新版-分类管理"})
public class CategoryController {
@Autowired
private CategoryService categoryService;
@ApiOperation(value = "一级分类————新增")
@PostMapping("/addPrimaryCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody addPrimaryCategory(HttpServletRequest request, @RequestBody @Validated(value = {Create.class}) CategoryPrimaryVO primaryVO) {
return categoryService.addPrimaryCategory(primaryVO);
}
@ApiOperation(value = "一级分类————编辑")
@PostMapping("/updatePrimaryCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody updatePrimaryCategory(HttpServletRequest request, @RequestBody @Validated(value = {Update.class}) CategoryPrimaryVO primaryVO) {
return categoryService.updatePrimaryCategory(primaryVO);
}
@ApiOperation(value = "一级分类————删除")
@GetMapping("/deletePrimaryCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody deletePrimaryCategory(HttpServletRequest request, @RequestParam(value = "id", required = true) Integer id) {
return categoryService.deletePrimaryCategory(id);
}
@ApiOperation(value = "一级分类————列表/包含二级分类")
@PostMapping("/categoryList")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody<CategoryPrimaryDTO> categoryList(HttpServletRequest request, @Validated(value = {Page.class}) @ApiParam(value = "角色查询QO", required = true) @RequestBody CategoryQO param) {
return ResultBody.success(categoryService.categoryList(param));
}
@ApiOperation(value = "二级分类————新增")
@PostMapping("/addSubCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody addSubCategory(HttpServletRequest request, @RequestBody @Validated(value = {Create.class}) CategorySubVO subVO) {
return categoryService.addSubCategory(subVO);
}
@ApiOperation(value = "二级分类————编辑")
@PostMapping("/updateSubCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody updateSubCategory(HttpServletRequest request, @RequestBody @Validated(value = {Update.class}) CategorySubVO subVO) {
return categoryService.updateSubCategory(subVO);
}
@ApiOperation(value = "二级分类————删除")
@GetMapping("/deleteSubCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody deleteSubCategory(HttpServletRequest request, @RequestParam(value = "id", required = true) Integer id) {
return categoryService.deleteSubCategory(id);
}
@ApiOperation(value = "二级分类————详情")
@GetMapping("/detailSubCategory")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody<CategorySubDTO> detailSubCategory(HttpServletRequest request, @RequestParam(value = "id", required = true) Integer id) {
return categoryService.detailSubCategory(id);
}
}
package com.mmc.pms.dao.category;
import com.mmc.pms.entity.category.CategoryPrimaryDO;
import com.mmc.pms.entity.category.CategorySubDO;
import com.mmc.pms.model.category.qo.CategoryQO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author small
* @Date 2023/7/21 10:20
* @Version 1.0
*/
@Mapper
public interface CategoryDao {
int getCountName(String name);
void addPrimaryCategory(CategoryPrimaryDO primaryDO);
void updateSort(Integer id);
void deletePrimaryCategory(Integer id);
Integer categoryCount(CategoryPrimaryDO primaryDO);
void updatePrimaryCategory(CategoryPrimaryDO primaryDO);
int getCountSubName(String name, Integer categoryPrimaryId);
void addSubCategory(CategorySubDO subDO);
Integer categorySubCount(CategorySubDO subDO);
void updateSubCategory(CategorySubDO subDO);
void deleteSubCategory(Integer id);
CategorySubDO detailSubCategory(Integer id);
List<CategoryPrimaryDO> categoryList(CategoryQO param);
List<CategorySubDO> selectSubList(Integer id);
int categoryListCount(CategoryQO param);
}
package com.mmc.pms.entity.category;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.mmc.pms.model.category.dto.CategoryPrimaryDTO;
import com.mmc.pms.model.category.vo.CategoryPrimaryVO;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
/**
* @Author small
* @Date 2023/7/21 10:15
* @Version 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CategoryPrimaryDO {
@ApiModelProperty(value = "id")
@NotNull(message = "id不能为空", groups = {Update.class})
@Min(value = 1, groups = {Update.class})
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "分类名称", required = true, example = "无人机")
@Size(max = 15, message = "分类名称不能超过15个字", groups = {Update.class, Create.class})
@NotBlank(message = "分类名称不能为空或空字符", groups = {Update.class, Create.class})
private String name;
@ApiModelProperty(value = "描述")
@Size(max = 70, message = "分类描述不能超过70个字", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "icon图标")
private String icon;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间", example = "2023-07-14 10:13:12", required = true)
private Date createTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间", example = "2023-07-14 10:13:12", required = true)
private Date updateTime;
@ApiModelProperty(value = "子分类")
private List<CategorySubDO> subDOList;
public CategoryPrimaryDO(CategoryPrimaryVO primaryVO) {
this.id = primaryVO.getId();
this.name = primaryVO.getName();
this.description = primaryVO.getDescription();
this.icon = primaryVO.getIcon();
}
public CategoryPrimaryDTO buildCategoryPrimaryDTO() {
return CategoryPrimaryDTO.builder()
.id(this.id)
.name(this.name)
.description(this.description)
.icon(this.icon)
.createTime(this.createTime)
.updateTime(this.updateTime)
.subDTOList(this.subDOList)
.build();
}
}
package com.mmc.pms.entity.category;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.mmc.pms.model.category.dto.CategorySubDTO;
import com.mmc.pms.model.category.vo.CategorySubVO;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
/**
* @Author small
* @Date 2023/7/21 10:16
* @Version 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CategorySubDO {
@ApiModelProperty(value = "id")
@NotNull(message = "id不能为空", groups = {Update.class})
@Min(value = 1, groups = {Update.class})
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "分类名称", required = true, example = "无人机")
@Size(max = 15, message = "分类名称不能超过15个字", groups = {Update.class, Create.class})
@NotBlank(message = "分类名称不能为空或空字符", groups = {Update.class, Create.class})
private String name;
@ApiModelProperty(value = "描述")
@Size(max = 70, message = "分类描述不能超过70个字", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "一级id不能为空", required = true, example = "1")
@NotNull(message = "一级id不能为空", groups = {Update.class, Create.class})
private Integer categoryPrimaryId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间", example = "2023-07-14 10:13:12", required = true)
private Date createTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间", example = "2023-07-14 10:13:12", required = true)
private Date updateTime;
public CategorySubDO(CategorySubVO subVO) {
this.id = subVO.getId();
this.name = subVO.getName();
this.description = subVO.getDescription();
this.categoryPrimaryId = subVO.getCategoryPrimaryId();
}
public CategorySubDTO buildCategorySubDTO() {
return CategorySubDTO.builder()
.id(this.id)
.name(this.name)
.description(this.description)
.categoryPrimaryId(this.categoryPrimaryId)
.createTime(this.createTime)
.updateTime(this.updateTime)
.build();
}
}
package com.mmc.pms.model.category.dto;
import com.mmc.pms.entity.category.CategorySubDO;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
/**
* @Author small
* @Date 2023/7/20 16:35
* @Version 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CategoryPrimaryDTO {
@ApiModelProperty(value = "id")
@NotNull(message = "id不能为空", groups = {Update.class})
@Min(value = 1, groups = {Update.class})
private Integer id;
@ApiModelProperty(value = "分类名称", required = true, example = "无人机")
@Size(max = 15, message = "分类名称不能超过15个字", groups = {Update.class, Create.class})
@NotBlank(message = "分类名称不能为空或空字符", groups = {Update.class, Create.class})
private String name;
@ApiModelProperty(value = "描述")
@Size(max = 70, message = "分类描述不能超过70个字", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "icon图标")
private String icon;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间", example = "2023-07-14 10:13:12", required = true)
private Date createTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间", example = "2023-07-14 10:13:12", required = true)
private Date updateTime;
@ApiModelProperty(value = "二级分类")
private List<CategorySubDO> subDTOList;
}
package com.mmc.pms.model.category.dto;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
/**
* @Author small
* @Date 2023/7/21 10:10
* @Version 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CategorySubDTO {
@ApiModelProperty(value = "id")
@NotNull(message = "id不能为空", groups = {Update.class})
@Min(value = 1, groups = {Update.class})
private Integer id;
@ApiModelProperty(value = "分类名称", required = true,example = "无人机")
@Size(max = 15, message = "分类名称不能超过15个字", groups = {Update.class, Create.class})
@NotBlank(message = "分类名称不能为空或空字符", groups = {Update.class, Create.class})
private String name;
@ApiModelProperty(value = "描述")
@Size(max = 70, message = "分类描述不能超过70个字", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "一级id不能为空",required = true,example = "1")
@NotNull(message = "一级id不能为空", groups = {Update.class, Create.class})
private Integer categoryPrimaryId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间", example = "2023-07-14 10:13:12", required = true)
private Date createTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间", example = "2023-07-14 10:13:12", required = true)
private Date updateTime;
}
package com.mmc.pms.model.category.qo;
import com.mmc.pms.common.Page;
import com.mmc.pms.model.group.Freeze;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* @Author small
* @Date 2023/7/21 15:22
* @Version 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CategoryQO {
private static final long serialVersionUID = -3729786590325257669L;
@ApiModelProperty(value = "一级分类id", required = false, example = "1")
private Integer id;
@ApiModelProperty(value = "当前页", required = true, example = "1")
@NotNull(message = "当前页不能为空", groups = {Page.class, Freeze.class})
@Min(value = 1, groups = Page.class)
private Integer pageNo;
@ApiModelProperty(value = "页大小", required = true, example = "10")
@NotNull(message = "页大小不能为空", groups = {Page.class, Freeze.class})
@Min(value = 1, groups = Page.class)
private Integer pageSize;
public void buildCurrentPage() {
this.pageNo = (pageNo - 1) * pageSize;
}
}
package com.mmc.pms.model.category.vo;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* @Author small
* @Date 2023/7/20 16:34
* @Version 1.0
*/
@Data
public class CategoryPrimaryVO {
@ApiModelProperty(value = "id", example = "1")
@NotNull(message = "id不能为空", groups = {Update.class})
@Min(value = 1, groups = {Update.class})
private Integer id;
@ApiModelProperty(value = "分类名称", required = true, example = "无人机")
@Size(max = 15, message = "分类名称不能超过15个字", groups = {Update.class, Create.class})
@NotBlank(message = "分类名称不能为空或空字符", groups = {Update.class, Create.class})
private String name;
@ApiModelProperty(value = "描述", example = "描述一下")
@Size(max = 70, message = "分类描述不能超过70个字", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "icon图标", example = "http://")
private String icon;
}
package com.mmc.pms.model.category.vo;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* @Author small
* @Date 2023/7/21 10:10
* @Version 1.0
*/
@Data
public class CategorySubVO {
@ApiModelProperty(value = "id", example = "1")
@NotNull(message = "id不能为空", groups = {Update.class})
@Min(value = 1, groups = {Update.class})
private Integer id;
@ApiModelProperty(value = "分类名称", required = true, example = "无人机")
@Size(max = 15, message = "分类名称不能超过15个字", groups = {Update.class, Create.class})
@NotBlank(message = "分类名称不能为空或空字符", groups = {Update.class, Create.class})
private String name;
@ApiModelProperty(value = "描述", example = "描述001")
@Size(max = 70, message = "分类描述不能超过70个字", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "一级分类id不能为空", required = true, example = "1")
@NotNull(message = "一级分类id不能为空", groups = {Update.class, Create.class})
private Integer categoryPrimaryId;
}
package com.mmc.pms.service.category;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.model.category.dto.CategoryPrimaryDTO;
import com.mmc.pms.model.category.qo.CategoryQO;
import com.mmc.pms.model.category.vo.CategoryPrimaryVO;
import com.mmc.pms.model.category.vo.CategorySubVO;
import com.mmc.pms.page.PageResult;
/**
* @Author small
* @Date 2023/7/20 16:26
* @Version 1.0
*/
public interface CategoryService {
ResultBody addPrimaryCategory(CategoryPrimaryVO primaryVO);
ResultBody deletePrimaryCategory(Integer id);
ResultBody updatePrimaryCategory(CategoryPrimaryVO primaryVO);
ResultBody addSubCategory(CategorySubVO subVO);
ResultBody updateSubCategory(CategorySubVO subVO);
ResultBody deleteSubCategory(Integer id);
ResultBody detailSubCategory(Integer id);
PageResult<CategoryPrimaryDTO> categoryList(CategoryQO param);
}
package com.mmc.pms.service.category.impl;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.common.ResultEnum;
import com.mmc.pms.dao.category.CategoryDao;
import com.mmc.pms.entity.category.CategoryPrimaryDO;
import com.mmc.pms.entity.category.CategorySubDO;
import com.mmc.pms.model.category.dto.CategoryPrimaryDTO;
import com.mmc.pms.model.category.dto.CategorySubDTO;
import com.mmc.pms.model.category.qo.CategoryQO;
import com.mmc.pms.model.category.vo.CategoryPrimaryVO;
import com.mmc.pms.model.category.vo.CategorySubVO;
import com.mmc.pms.page.PageResult;
import com.mmc.pms.service.category.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author small
* @Date 2023/7/20 16:26
* @Version 1.0
*/
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryDao categoryDao;
@Override
public ResultBody addPrimaryCategory(CategoryPrimaryVO primaryVO) {
int count = categoryDao.getCountName(primaryVO.getName());
if (count > 0) {
return ResultBody.error(ResultEnum.THE_NAME_OF_A_CLASS_MUST_BE_UNIQUE);
}
CategoryPrimaryDO primaryDO = new CategoryPrimaryDO(primaryVO);
categoryDao.addPrimaryCategory(primaryDO);
Integer id = primaryDO.getId();
categoryDao.updateSort(id);
return ResultBody.success();
}
@Override
public ResultBody deletePrimaryCategory(Integer id) {
categoryDao.deletePrimaryCategory(id);
return ResultBody.success();
}
@Override
public ResultBody updatePrimaryCategory(CategoryPrimaryVO primaryVO) {
CategoryPrimaryDO primaryDO = new CategoryPrimaryDO(primaryVO);
Integer count = categoryDao.categoryCount(primaryDO);
if (count > 0) {
return ResultBody.error(ResultEnum.THE_NAME_OF_A_CLASS_MUST_BE_UNIQUE);
}
categoryDao.updatePrimaryCategory(primaryDO);
return ResultBody.success();
}
@Override
public ResultBody addSubCategory(CategorySubVO subVO) {
int count = categoryDao.getCountSubName(subVO.getName(), subVO.getCategoryPrimaryId());
if (count > 0) {
return ResultBody.error(ResultEnum.THE_NAME_OF_THE_SECONDARY_CLASS_MUST_BE_UNIQUE);
}
CategorySubDO subDO = new CategorySubDO(subVO);
categoryDao.addSubCategory(subDO);
return ResultBody.success();
}
@Override
public ResultBody updateSubCategory(CategorySubVO subVO) {
CategorySubDO subDO = new CategorySubDO(subVO);
Integer count = categoryDao.categorySubCount(subDO);
if (count > 0) {
return ResultBody.error(ResultEnum.THE_NAME_OF_THE_SECONDARY_CLASS_MUST_BE_UNIQUE);
}
categoryDao.updateSubCategory(subDO);
return ResultBody.success();
}
@Override
public ResultBody deleteSubCategory(Integer id) {
categoryDao.deleteSubCategory(id);
return ResultBody.success();
}
@Override
public ResultBody<CategorySubDTO> detailSubCategory(Integer id) {
CategorySubDO subDO = categoryDao.detailSubCategory(id);
CategorySubDTO categorySubDTO = subDO.buildCategorySubDTO();
return ResultBody.success(categorySubDTO);
}
@Override
public PageResult<CategoryPrimaryDTO> categoryList(CategoryQO param) {
int count = categoryDao.categoryListCount(param);
if (count == 0) {
return PageResult.buildPage(param.getPageNo(), param.getPageSize(), count);
}
param.buildCurrentPage();
List<CategoryPrimaryDO> categoryPrimaryDOS = categoryDao.categoryList(param);
List<CategoryPrimaryDTO> collect = categoryPrimaryDOS.stream().map(t -> t.buildCategoryPrimaryDTO()).collect(Collectors.toList());
return PageResult.buildPage(param.getPageNo(), param.getPageSize(), count, collect);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mmc.pms.dao.category.CategoryDao">
<resultMap id="CategoryList" type="com.mmc.pms.entity.category.CategoryPrimaryDO">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="description" column="description"/>
<result property="icon" column="icon"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<collection property="subDOList" ofType="com.mmc.pms.entity.category.CategorySubDO"
select="selectSubList"
column="{categoryPrimaryId=id}">
</collection>
</resultMap>
<select id="selectSubList" resultType="com.mmc.pms.entity.category.CategorySubDO">
select id,
`name`,
description,
category_primary_id AS categoryPrimaryId,
create_time AS createTime,
update_time AS updateTime
from category_sub
where category_primary_id = #{categoryPrimaryId}
</select>
<select id="categoryListCount" resultType="int" parameterType="com.mmc.pms.model.category.qo.CategoryQO">
SELECT count(*)
FROM
category_primary
WHERE 1=1
<if test=" id != null and id != '' ">
and id=#{id}
</if>
</select>
<select id="getCountName" resultType="java.lang.Integer">
select count(*)
from category_primary
where 1=1
<if test=" name != null and name != '' ">
and `name` = #{name}
</if>
</select>
<insert id="addPrimaryCategory" useGeneratedKeys="true"
keyProperty="id" parameterType="com.mmc.pms.entity.category.CategoryPrimaryDO">
insert into category_primary(`name`, description, create_time, update_time, icon)
values (#{name}, #{description}, NOW(), NOW(), #{icon})
</insert>
<update id="updateSort">
update category_primary
<set>
<if test="id!=null">
sort = #{id}
</if>
</set>
where id=#{id}
</update>
<delete id="deletePrimaryCategory">
delete
from category_primary
where id = #{id}
</delete>
<select id="categoryCount" resultType="java.lang.Integer">
select count(*)
from category_primary
where 1=1
<if test=" name != null and name != '' ">
and `name` = #{name}
</if>
<if test=" id != null and id != '' ">
and id != #{id}
</if>
</select>
<update id="updatePrimaryCategory"
parameterType="com.mmc.pms.entity.category.CategoryPrimaryDO">
UPDATE category_primary
<set>
<if test=" name != null and name != '' ">
`name` = #{name},
</if>
<if test=" description != null and description != '' ">
description = #{description},
</if>
<if test=" icon != null and icon != '' ">
icon = #{icon},
</if>
update_time=NOW()
</set>
where id = #{id}
</update>
<select id="getCountSubName" resultType="java.lang.Integer">
select count(*)
from category_sub
where 1=1
<if test=" name != null and name != '' ">
and `name` = #{name}
</if>
<if test=" categoryPrimaryId != null and categoryPrimaryId != '' ">
and category_primary_id = #{categoryPrimaryId}
</if>
</select>
<insert id="addSubCategory" useGeneratedKeys="true"
keyProperty="id" parameterType="com.mmc.pms.entity.category.CategorySubDO">
insert into category_sub(`name`, description, create_time, update_time, category_primary_id)
values (#{name}, #{description}, NOW(), NOW(), #{categoryPrimaryId})
</insert>
<select id="categorySubCount" resultType="java.lang.Integer">
select count(*)
from category_sub
where 1=1
<if test=" name != null and name != '' ">
and `name` = #{name}
</if>
<if test=" id != null and id != '' ">
and id != #{id}
</if>
<if test=" categoryPrimaryId != null and categoryPrimaryId != '' ">
and category_primary_id != #{categoryPrimaryId}
</if>
</select>
<update id="updateSubCategory"
parameterType="com.mmc.pms.entity.category.CategorySubDO">
UPDATE category_sub
<set>
<if test=" name != null and name != '' ">
`name` = #{name},
</if>
<if test=" description != null and description != '' ">
description = #{description},
</if>
update_time=NOW()
</set>
where id = #{id}
</update>
<delete id="deleteSubCategory">
delete
from category_sub
where id = #{id}
</delete>
<select id="detailSubCategory" resultType="com.mmc.pms.entity.category.CategorySubDO">
select id,
`name`,
description,
create_time AS createTime,
update_time AS updateTime,
category_primary_id AS categoryPrimaryId
from category_sub
where id = #{id}
</select>
<select id="categoryList" resultMap="CategoryList">
select id, `name`, description, create_time, update_time, icon
from category_primary where 1=1
<if test=" id != null and id != '' ">
and id =#{id}
</if>
order by update_time desc, create_time desc
limit #{pageNo},#{pageSize}
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论