新增模版管理界面
This commit is contained in:
parent
ee10b3a2c0
commit
bde0f89835
@ -0,0 +1,103 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.template;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.template.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.template.TemplateDO;
|
||||
import cn.iocoder.yudao.module.system.service.template.TemplateService;
|
||||
|
||||
@Tag(name = "管理后台 - 模板")
|
||||
@RestController
|
||||
@RequestMapping("/system/template")
|
||||
@Validated
|
||||
public class TemplateController {
|
||||
|
||||
@Resource
|
||||
private TemplateService templateService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建模板")
|
||||
public CommonResult<Integer> createTemplate(@Valid @RequestBody TemplateSaveReqVO createReqVO) {
|
||||
return success(templateService.createTemplate(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新模板")
|
||||
public CommonResult<Boolean> updateTemplate(@Valid @RequestBody TemplateSaveReqVO updateReqVO) {
|
||||
templateService.updateTemplate(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除模板")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
public CommonResult<Boolean> deleteTemplate(@RequestParam("id") Integer id) {
|
||||
templateService.deleteTemplate(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除模板")
|
||||
public CommonResult<Boolean> deleteTemplateList(@RequestParam("ids") List<Integer> ids) {
|
||||
templateService.deleteTemplateListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得模板")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<TemplateRespVO> getTemplate(@RequestParam("id") Integer id) {
|
||||
TemplateDO template = templateService.getTemplate(id);
|
||||
return success(BeanUtils.toBean(template, TemplateRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得模板列表")
|
||||
public CommonResult<List<TemplateRespVO>> getTemplateList(@RequestParam("type") String type, @RequestParam("orgid") Integer orgid) {
|
||||
List<TemplateDO> list = templateService.getTemplateList(type, orgid);
|
||||
return success(BeanUtils.toBean(list, TemplateRespVO.class));
|
||||
}
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得模板分页")
|
||||
public CommonResult<PageResult<TemplateRespVO>> getTemplatePage(@Valid TemplatePageReqVO pageReqVO) {
|
||||
PageResult<TemplateDO> pageResult = templateService.getTemplatePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, TemplateRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出模板 Excel")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportTemplateExcel(@Valid TemplatePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<TemplateDO> list = templateService.getTemplatePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "模板.xls", "数据", TemplateRespVO.class,
|
||||
BeanUtils.toBean(list, TemplateRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.template.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 模板分页 Request VO")
|
||||
@Data
|
||||
public class TemplatePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "类型", example = "2")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "组织ID", example = "14054")
|
||||
private Integer orgid;
|
||||
|
||||
@Schema(description = "内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createtime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] updatetime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.template.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 模板 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class TemplateRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "10555")
|
||||
@ExcelProperty("主键ID")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "类型", example = "2")
|
||||
@ExcelProperty("类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "组织ID", example = "14054")
|
||||
@ExcelProperty("组织ID")
|
||||
private Integer orgid;
|
||||
|
||||
@Schema(description = "内容")
|
||||
@ExcelProperty("内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createtime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatetime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.template.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 模板新增/修改 Request VO")
|
||||
@Data
|
||||
public class TemplateSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "10555")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "类型", example = "2")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "组织ID", example = "14054")
|
||||
private Integer orgid;
|
||||
|
||||
@Schema(description = "内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createtime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatetime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.template;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 模板 DO
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
@TableName("tb_template")
|
||||
@KeySequence("tb_template_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TemplateDO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@TableField("type")
|
||||
private String type;
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
@TableField("orgid")
|
||||
private Integer orgid;
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@TableField("content")
|
||||
private String content;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("createtime")
|
||||
private LocalDateTime createtime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("updatetime")
|
||||
private LocalDateTime updatetime;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.template;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.template.TemplateDO;
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.template.vo.*;
|
||||
|
||||
/**
|
||||
* 模板 Mapper
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
@Mapper
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
public interface TemplateMapper extends BaseMapperX<TemplateDO> {
|
||||
|
||||
default PageResult<TemplateDO> selectPage(TemplatePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<TemplateDO>()
|
||||
.eqIfPresent(TemplateDO::getType, reqVO.getType())
|
||||
.eqIfPresent(TemplateDO::getOrgid, reqVO.getOrgid())
|
||||
.eqIfPresent(TemplateDO::getContent, reqVO.getContent())
|
||||
.betweenIfPresent(TemplateDO::getCreatetime, reqVO.getCreatetime())
|
||||
.betweenIfPresent(TemplateDO::getUpdatetime, reqVO.getUpdatetime())
|
||||
.orderByDesc(TemplateDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package cn.iocoder.yudao.module.system.service.template;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.template.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.template.TemplateDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 模板 Service 接口
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
public interface TemplateService {
|
||||
|
||||
/**
|
||||
* 创建模板
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createTemplate(@Valid TemplateSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新模板
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateTemplate(@Valid TemplateSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除模板
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteTemplate(Integer id);
|
||||
|
||||
/**
|
||||
* 批量删除模板
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteTemplateListByIds(List<Integer> ids);
|
||||
|
||||
/**
|
||||
* 获得模板
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 模板
|
||||
*/
|
||||
TemplateDO getTemplate(Integer id);
|
||||
/*
|
||||
* 按照类型和机构查询对应的模版
|
||||
* */
|
||||
List<TemplateDO> getTemplateList(String type, Integer orgid);
|
||||
|
||||
/**
|
||||
* 获得模板分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 模板分页
|
||||
*/
|
||||
PageResult<TemplateDO> getTemplatePage(TemplatePageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,105 @@
|
||||
package cn.iocoder.yudao.module.system.service.template;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.template.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.template.TemplateDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.template.TemplateMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
|
||||
/**
|
||||
* 模板 Service 实现类
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class TemplateServiceImpl implements TemplateService {
|
||||
|
||||
@Resource
|
||||
private TemplateMapper templateMapper;
|
||||
|
||||
@Override
|
||||
public Integer createTemplate(TemplateSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
TemplateDO template = BeanUtils.toBean(createReqVO, TemplateDO.class);
|
||||
templateMapper.insert(template);
|
||||
// 返回
|
||||
return template.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTemplate(TemplateSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTemplateExists(updateReqVO.getId());
|
||||
// 更新
|
||||
TemplateDO updateObj = BeanUtils.toBean(updateReqVO, TemplateDO.class);
|
||||
templateMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTemplate(Integer id) {
|
||||
// 校验存在
|
||||
validateTemplateExists(id);
|
||||
// 删除
|
||||
templateMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTemplateListByIds(List<Integer> ids) {
|
||||
// 校验存在
|
||||
validateTemplateExists(ids);
|
||||
// 删除
|
||||
templateMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateTemplateExists(List<Integer> ids) {
|
||||
List<TemplateDO> list = templateMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTemplateExists(Integer id) {
|
||||
if (templateMapper.selectById(id) == null) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateDO getTemplate(Integer id) {
|
||||
return templateMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateDO> getTemplateList(String type, Integer orgid) {
|
||||
// 使用 QueryWrapper 构造查询条件
|
||||
QueryWrapper<TemplateDO> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
// 添加 type 条件(如果 type 不为空)
|
||||
if (type != null && !type.isEmpty()) {
|
||||
queryWrapper.eq("type", type);
|
||||
}
|
||||
|
||||
// 添加 orgid 条件(如果 orgid 不为空)
|
||||
if (orgid != null) {
|
||||
queryWrapper.eq("orgid", orgid);
|
||||
}
|
||||
|
||||
// 执行查询并返回结果
|
||||
return templateMapper.selectList(queryWrapper);
|
||||
}
|
||||
@Override
|
||||
public PageResult<TemplateDO> getTemplatePage(TemplatePageReqVO pageReqVO) {
|
||||
return templateMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?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="cn.iocoder.yudao.module.system.dal.mysql.template.TemplateMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user