1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| ##导入宏定义 $!{define.vm}
##设置表后缀(宏定义) #setTableSuffix("Controller")
##保存文件(宏定义) #save("/controller", "Controller.java")
##包路径(宏定义) #setPackageSuffix("controller")
##定义服务名 #set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定义实体对象名 #set($entityName = $!tool.firstLowerCase($!tableInfo.name))
import cn.jiliapp.parent.domain.dto.PageableDTO; import $!{tableInfo.savePackageName}.domain.bo.$!{tableInfo.name}BO; import $!{tableInfo.savePackageName}.domain.dto.$!{tableInfo.name}DTO; import $!{tableInfo.savePackageName}.domain.page.$!{tableInfo.name}PageDTO; import $!{tableInfo.savePackageName}.domain.vo.$!{tableInfo.name}VO; import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import cn.jiliapp.parent.domain.Pagination; import cn.jiliapp.parent.domain.Rsp; import io.micronaut.core.annotation.Introspected; import io.micronaut.core.annotation.Nullable; import io.micronaut.data.annotation.Query; import io.micronaut.data.model.Pageable; import io.micronaut.data.model.Sort; import io.micronaut.http.MediaType; import io.micronaut.http.annotation.*; import io.micronaut.security.annotation.Secured; import io.micronaut.security.authentication.Authentication; import io.micronaut.validation.Validated; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.inject.Inject; import lombok.extern.slf4j.Slf4j; import javax.validation.Valid; import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import java.util.List; import java.util.Optional; import io.micronaut.security.rules.SecurityRule;
##表注释(宏定义) #tableComment("表控制层") @Tag(name = "$tableInfo.obj.name") @Controller("/v1/$tableInfo.obj.name") @Introspected @Validated @Slf4j public class $!{tableName} { /** * 服务对象 */ @Inject private $!{tableInfo.name}Service $!{serviceName};
@Operation(summary ="[新增]创建记录") @Schema(name="Rsp<$!{tableInfo.name}VO>",oneOf = {$!{tableInfo.name}VO.class}) @Post() @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<$!{tableInfo.name}VO> create( @NotBlank(message = "*[param]为参数必传") @Valid @Body $!{tableInfo.name}DTO param) { $!{tableInfo.name}BO bo=$!{tableInfo.name}Mapper.MAPPER.dto2bo(param); $!{tableInfo.name}VO ret=$!{serviceName}.record(bo); return Rsp.success(ret); } @Operation(summary ="[删除]彻底删除单条记录") @Schema(name="Rsp<Integer>",oneOf = {Integer.class}) @Delete @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Integer> delete(@QueryValue() @Schema(description = "id",example = "1522425618657054720") Long id) { Integer ret=$!{serviceName}.delete(id); return Rsp.success(ret); }
@Operation(summary ="[删除]彻底删除多条记录") @Schema(name="Rsp<Integer>",oneOf = {Integer.class}) @Delete("/multiple") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Integer> delMultiple(@QueryValue() @Schema(description = "id",example = "1522425618657054720") List<Long> idList) { Integer ret=$!{serviceName}.delete(idList); return Rsp.success(ret); } @Operation(summary ="[删除]逻辑删除记录") @Schema(name="Rsp<Integer>",oneOf = {Integer.class}) @Delete("/logic") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Integer> logicDelete(@NotBlank(message = "*[id]为参数必传") @QueryValue @Schema(description = "id",example = "1522425618657054720") Long id) { log.debug("logicDelete"); Integer ret=$!{serviceName}.logicDelete(id); return Rsp.success(ret); }
@Operation(summary ="[删除]逻辑删除多条记录") @Schema(name="Rsp<Integer>",oneOf = {Integer.class}) @Delete("/logic/multiple") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Integer> logicDeleteMultiple(@NotBlank(message = "*[idList]为参数必传") @QueryValue() List<Long> idList) { Integer ret=$!{serviceName}.logicDelete(idList); return Rsp.success(ret); } @Operation(summary ="[更新]恢复逻辑删除记录") @Schema(name="Rsp<Integer>",oneOf = {Integer.class}) @Put("/logic") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Integer> logicDelRecover(@NotBlank(message = "*[id]为参数必传") @QueryValue @Schema(description = "id",example = "1522425618657054720") Long id) { Integer ret=$!{serviceName}.logicDeleteRecover(id); return Rsp.success(ret); }
@Operation(summary ="[更新]更新记录") @Schema(name="Rsp<$!{tableInfo.name}VO>",oneOf = {$!{tableInfo.name}VO.class}) @Put @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<$!{tableInfo.name}VO> updateUser(@NotBlank(message = "*[id]为参数必传") @QueryValue @Schema(description = "id",example = "1522425618657054720") Long id, @Valid @Body $!{tableInfo.name}PageDTO param) { $!{tableInfo.name}BO bo=$!{tableInfo.name}Mapper.MAPPER.pageDto2bo(param); bo.setId(id); $!{tableInfo.name}VO ret=$!{serviceName}.update(bo); return Rsp.success(ret); } @Operation(summary ="[查询]单条记录") @Schema(name="Rsp<$!{tableInfo.name}VO>",oneOf = {$!{tableInfo.name}VO.class}) @Get() @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<$!{tableInfo.name}VO> get$!{tableInfo.name}(@NotBlank(message = "*[id]为参数必传") @QueryValue @Schema(description = "id",example = "1522425618657054720") Long id) { $!{tableInfo.name}VO ret=$!{serviceName}.findById(id); return Rsp.success(ret); }
@Operation(summary ="[查询]分页查询记录") @Schema(name="Rsp<Pagination<$!{tableInfo.name}VO>>",oneOf = {Pagination.class,$!{tableInfo.name}VO.class}) @Get("/page{?pageDTO*}{?pageable*}") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Pagination<$!{tableInfo.name}VO>> getPageList(@QueryValue PageableDTO pageable,@QueryValue $!{tableInfo.name}PageDTO pageDTO) { $!{tableInfo.name}BO bo=$!{tableInfo.name}Mapper.MAPPER.pageDto2bo(pageDTO); Pagination<$!{tableInfo.name}VO> pagination = $!{serviceName}.searchPage(pageable.into(),bo); return Rsp.success(pagination); }
@Operation(summary ="[查询]分页查询[含逻辑删除]记录") @Schema(name="Rsp<Pagination<$!{tableInfo.name}VO>>",oneOf = {Pagination.class,$!{tableInfo.name}VO.class}) @Get("/page/logic{?pageDTO*}{?pageable*}") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<Pagination<$!{tableInfo.name}VO>> getCompleteList(@QueryValue PageableDTO pageable,@QueryValue $!{tableInfo.name}PageDTO pageDTO) { $!{tableInfo.name}BO bo=$!{tableInfo.name}Mapper.MAPPER.pageDto2bo(pageDTO); Pagination<$!{tableInfo.name}VO> pagination = $!{serviceName}.searchPageComplete(pageable.into(),bo); return Rsp.success(pagination); }
@Operation(summary ="[查询]条件查询所有记录") @Schema(name="Rsp<List<$!{tableInfo.name}VO>>",oneOf = {$!{tableInfo.name}VO.class}) @Get("/list{?pageDTO*}") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<List<$!{tableInfo.name}VO>> getList(@QueryValue $!{tableInfo.name}PageDTO pageDTO) { $!{tableInfo.name}BO bo= $!{tableInfo.name}Mapper.MAPPER.pageDto2bo(pageDTO); List<$!{tableInfo.name}VO> ret=$!{serviceName}.findByEntity(bo); return Rsp.success(ret); } @Operation(summary ="[查询]查询所有记录") @Schema(name="Rsp<List<$!{tableInfo.name}VO>>",oneOf = {$!{tableInfo.name}VO.class}) @Get("/list/all") @Secured({SecurityRule.IS_AUTHENTICATED}) public Rsp<List<$!{tableInfo.name}VO>> getAll() { List<$!{tableInfo.name}VO> ret=$!{serviceName}.findAll(); return Rsp.success(ret); }
@Operation(summary ="[查询]查询所有[含逻辑删除]记录") @Schema(name="Rsp<List<$!{tableInfo.name}VO>>",oneOf = {$!{tableInfo.name}VO.class}) @Get("/list/all/logic") @Secured({"viewer",SecurityRule.IS_AUTHENTICATED}) public Rsp<List<$!{tableInfo.name}VO>> getAllLogicList(@Nullable Authentication authentication) { List<$!{tableInfo.name}VO> ret=$!{serviceName}.findComplete(); return Rsp.success(ret); }
}
|