fix: 提交自定义标签
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.controller.admin.customtag;
|
||||
|
||||
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.ydoyun.controller.admin.customtag.vo.*;
|
||||
import cn.iocoder.yudao.module.ydoyun.dal.dataobject.customtag.CustomTagDO;
|
||||
import cn.iocoder.yudao.module.ydoyun.service.customtag.CustomTagService;
|
||||
|
||||
@Tag(name = "管理后台 - 自定义标签")
|
||||
@RestController
|
||||
@RequestMapping("/ydoyun/custom-tag")
|
||||
@Validated
|
||||
public class CustomTagController {
|
||||
|
||||
@Resource
|
||||
private CustomTagService customTagService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建自定义标签")
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:create')")
|
||||
public CommonResult<Long> createCustomTag(@Valid @RequestBody CustomTagSaveReqVO createReqVO) {
|
||||
return success(customTagService.createCustomTag(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新自定义标签")
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:update')")
|
||||
public CommonResult<Boolean> updateCustomTag(@Valid @RequestBody CustomTagSaveReqVO updateReqVO) {
|
||||
customTagService.updateCustomTag(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除自定义标签")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:delete')")
|
||||
public CommonResult<Boolean> deleteCustomTag(@RequestParam("id") Long id) {
|
||||
customTagService.deleteCustomTag(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除自定义标签")
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:delete')")
|
||||
public CommonResult<Boolean> deleteCustomTagList(@RequestParam("ids") List<Long> ids) {
|
||||
customTagService.deleteCustomTagListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得自定义标签")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:query')")
|
||||
public CommonResult<CustomTagRespVO> getCustomTag(@RequestParam("id") Long id) {
|
||||
CustomTagDO customTag = customTagService.getCustomTag(id);
|
||||
return success(BeanUtils.toBean(customTag, CustomTagRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得自定义标签分页")
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:query')")
|
||||
public CommonResult<PageResult<CustomTagRespVO>> getCustomTagPage(@Valid CustomTagPageReqVO pageReqVO) {
|
||||
PageResult<CustomTagDO> pageResult = customTagService.getCustomTagPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, CustomTagRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出自定义标签 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('ydoyun:custom-tag:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportCustomTagExcel(@Valid CustomTagPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<CustomTagDO> list = customTagService.getCustomTagPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "自定义标签.xls", "数据", CustomTagRespVO.class,
|
||||
BeanUtils.toBean(list, CustomTagRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.controller.admin.customtag.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 CustomTagPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "标签名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "标签表达式")
|
||||
private String expression;
|
||||
|
||||
@Schema(description = "标签颜色")
|
||||
private String color;
|
||||
|
||||
@Schema(description = "SQL脚本")
|
||||
private String sqlScript;
|
||||
|
||||
@Schema(description = "标签类型(product/store/supplier)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "是否代入参数(0否 1是)")
|
||||
private Boolean useParams;
|
||||
|
||||
@Schema(description = "参数列表(逗号分隔)")
|
||||
private String params;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.controller.admin.customtag.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 cn.idev.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 自定义标签 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CustomTagRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17700")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("标签名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "标签表达式")
|
||||
@ExcelProperty("标签表达式")
|
||||
private String expression;
|
||||
|
||||
@Schema(description = "标签颜色")
|
||||
@ExcelProperty("标签颜色")
|
||||
private String color;
|
||||
|
||||
@Schema(description = "SQL脚本")
|
||||
@ExcelProperty("SQL脚本")
|
||||
private String sqlScript;
|
||||
|
||||
@Schema(description = "标签类型(product/store/supplier)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "是否代入参数(0否 1是)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("是否代入参数(0否 1是)")
|
||||
private Boolean useParams;
|
||||
|
||||
@Schema(description = "参数列表(逗号分隔)")
|
||||
@ExcelProperty("参数列表(逗号分隔)")
|
||||
private String params;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.controller.admin.customtag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 自定义标签新增/修改 Request VO")
|
||||
@Data
|
||||
public class CustomTagSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17700")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标签名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@NotEmpty(message = "标签名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "标签表达式")
|
||||
private String expression;
|
||||
|
||||
@Schema(description = "标签颜色")
|
||||
private String color;
|
||||
|
||||
@Schema(description = "SQL脚本")
|
||||
private String sqlScript;
|
||||
|
||||
@Schema(description = "标签类型(product/store/supplier)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "是否代入参数(0否 1是)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否代入参数(0否 1是)不能为空")
|
||||
private Boolean useParams;
|
||||
|
||||
@Schema(description = "参数列表(逗号分隔)")
|
||||
private String params;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.dal.dataobject.customtag;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
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("ydoyun_custom_tag")
|
||||
@KeySequence("ydoyun_custom_tag_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CustomTagDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 标签表达式
|
||||
*/
|
||||
private String expression;
|
||||
/**
|
||||
* 标签颜色
|
||||
*/
|
||||
private String color;
|
||||
/**
|
||||
* SQL脚本
|
||||
*/
|
||||
private String sqlScript;
|
||||
|
||||
private String type;
|
||||
/**
|
||||
* 是否代入参数(0否 1是)
|
||||
*/
|
||||
private Boolean useParams;
|
||||
/**
|
||||
* 参数列表(逗号分隔)
|
||||
*/
|
||||
private String params;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.dal.mysql.customtag;
|
||||
|
||||
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.ydoyun.dal.dataobject.customtag.CustomTagDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.ydoyun.controller.admin.customtag.vo.*;
|
||||
|
||||
/**
|
||||
* 自定义标签 Mapper
|
||||
*
|
||||
* @author 衣朵云源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface CustomTagMapper extends BaseMapperX<CustomTagDO> {
|
||||
|
||||
default PageResult<CustomTagDO> selectPage(CustomTagPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CustomTagDO>()
|
||||
.likeIfPresent(CustomTagDO::getName, reqVO.getName())
|
||||
.likeIfPresent(CustomTagDO::getExpression, reqVO.getExpression())
|
||||
.eqIfPresent(CustomTagDO::getColor, reqVO.getColor())
|
||||
.eqIfPresent(CustomTagDO::getType, reqVO.getType())
|
||||
.eqIfPresent(CustomTagDO::getSqlScript, reqVO.getSqlScript())
|
||||
.eqIfPresent(CustomTagDO::getUseParams, reqVO.getUseParams())
|
||||
.eqIfPresent(CustomTagDO::getParams, reqVO.getParams())
|
||||
.betweenIfPresent(CustomTagDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(CustomTagDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,6 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode REPORT_NOT_EXISTS = new ErrorCode(1_024_000_007, "报表配置不存在");
|
||||
|
||||
ErrorCode STORE_NOT_EXISTS = new ErrorCode(1_024_000_008, "门店不存在");
|
||||
ErrorCode STORE_USER_NOT_EXISTS = new ErrorCode(1_024_000_008, "门店用户记录不存在");
|
||||
|
||||
ErrorCode STORE_USER_NOT_EXISTS = new ErrorCode(1_024_000_009, "门店用户记录不存在");
|
||||
ErrorCode CUSTOM_TAG_NOT_EXISTS = new ErrorCode(1_024_000_010, "自定义标签不存在");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.service.customtag;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.ydoyun.controller.admin.customtag.vo.*;
|
||||
import cn.iocoder.yudao.module.ydoyun.dal.dataobject.customtag.CustomTagDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 自定义标签 Service 接口
|
||||
*
|
||||
* @author 衣朵云源码
|
||||
*/
|
||||
public interface CustomTagService {
|
||||
|
||||
/**
|
||||
* 创建自定义标签
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createCustomTag(@Valid CustomTagSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新自定义标签
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateCustomTag(@Valid CustomTagSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除自定义标签
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteCustomTag(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除自定义标签
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteCustomTagListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得自定义标签
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 自定义标签
|
||||
*/
|
||||
CustomTagDO getCustomTag(Long id);
|
||||
|
||||
/**
|
||||
* 获得自定义标签分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 自定义标签分页
|
||||
*/
|
||||
PageResult<CustomTagDO> getCustomTagPage(CustomTagPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package cn.iocoder.yudao.module.ydoyun.service.customtag;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.ydoyun.controller.admin.customtag.vo.*;
|
||||
import cn.iocoder.yudao.module.ydoyun.dal.dataobject.customtag.CustomTagDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.ydoyun.dal.mysql.customtag.CustomTagMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.ydoyun.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 自定义标签 Service 实现类
|
||||
*
|
||||
* @author 衣朵云源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CustomTagServiceImpl implements CustomTagService {
|
||||
|
||||
@Resource
|
||||
private CustomTagMapper customTagMapper;
|
||||
|
||||
@Override
|
||||
public Long createCustomTag(CustomTagSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
CustomTagDO customTag = BeanUtils.toBean(createReqVO, CustomTagDO.class);
|
||||
customTagMapper.insert(customTag);
|
||||
|
||||
// 返回
|
||||
return customTag.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCustomTag(CustomTagSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomTagExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CustomTagDO updateObj = BeanUtils.toBean(updateReqVO, CustomTagDO.class);
|
||||
customTagMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomTag(Long id) {
|
||||
// 校验存在
|
||||
validateCustomTagExists(id);
|
||||
// 删除
|
||||
customTagMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomTagListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
customTagMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateCustomTagExists(Long id) {
|
||||
if (customTagMapper.selectById(id) == null) {
|
||||
throw exception(CUSTOM_TAG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomTagDO getCustomTag(Long id) {
|
||||
return customTagMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CustomTagDO> getCustomTagPage(CustomTagPageReqVO pageReqVO) {
|
||||
return customTagMapper.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.ydoyun.dal.mysql.customtag.CustomTagMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user