| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | package ${package}.${moduleName}.controller;#if($queryList)import cn.hutool.core.util.StrUtil;#endimport cn.hutool.core.util.ArrayUtil;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;import com.baomidou.mybatisplus.core.toolkit.Wrappers;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import com.pig4cloud.pigx.common.core.util.R;import com.pig4cloud.pigx.common.log.annotation.SysLog;import ${package}.${moduleName}.entity.${ClassName}Entity;import ${package}.${moduleName}.entity.${ChildClassName}Entity;import ${package}.${moduleName}.service.${ClassName}Service;import org.springframework.security.access.prepost.PreAuthorize;import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;import io.swagger.v3.oas.annotations.security.SecurityRequirement;#if($isSpringBoot3)import org.springdoc.core.annotations.ParameterObject;#elseimport org.springdoc.api.annotations.ParameterObject;#endimport org.springframework.http.HttpHeaders;import io.swagger.v3.oas.annotations.tags.Tag;import io.swagger.v3.oas.annotations.Operation;import lombok.RequiredArgsConstructor;import org.springframework.web.bind.annotation.*;import java.util.List;import java.util.Objects;/** * ${tableComment} * * @author ${author} * @date ${datetime} */@RestController@RequiredArgsConstructor@RequestMapping("/${functionName}" )@Tag(description = "${functionName}" , name = "${tableComment}管理" )@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)public class ${ClassName}Controller {    private final  ${ClassName}Service ${className}Service;    /**     * 分页查询     * @param page 分页对象     * @param ${className} ${tableComment}     * @return     */    @Operation(summary = "分页查询" , description = "分页查询" )    @GetMapping("/page" )    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )    public R get${ClassName}Page(@ParameterObject Page page, @ParameterObject ${ClassName}Entity ${className}) {        LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();#foreach ($field in $queryList)#set($getAttrName=$str.getProperty($field.attrName))#set($var="${className}.$getAttrName()")#if($field.attrType == 'String')#set($expression="StrUtil.isNotBlank")#else#set($expression="Objects.nonNull")#end#if($field.queryType == '=')		wrapper.eq($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == 'like' )		wrapper.like($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == '!-' )		wrapper.ne($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == '>' )		wrapper.gt($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == '<' )		wrapper.lt($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == '>=' )		wrapper.ge($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == '<=' )		wrapper.le($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == 'left like' )		wrapper.likeLeft($expression($var),${ClassName}Entity::$getAttrName,$var);#elseif( $field.queryType == 'right like' )		wrapper.likeRight($expression($var),${ClassName}Entity::$getAttrName,$var);#end#end        return R.ok(${className}Service.page(page, wrapper));    }    /**     * 通过id查询${tableComment}     * @param ${pk.attrName} id     * @return R     */    @Operation(summary = "通过id查询" , description = "通过id查询" )    @GetMapping("/{${pk.attrName}}" )    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )    public R getById(@PathVariable("${pk.attrName}" ) ${pk.attrType} ${pk.attrName}) {        return R.ok(${className}Service.getByIdDeep(${pk.attrName}));    }    /**     * 新增${tableComment}     * @param ${className} ${tableComment}     * @return R     */    @Operation(summary = "新增${tableComment}" , description = "新增${tableComment}" )    @SysLog("新增${tableComment}" )    @PostMapping    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_add')" )    public R save(@RequestBody ${ClassName}Entity ${className}) {        return R.ok(${className}Service.saveDeep(${className}));    }    /**     * 修改${tableComment}     * @param ${className} ${tableComment}     * @return R     */    @Operation(summary = "修改${tableComment}" , description = "修改${tableComment}" )    @SysLog("修改${tableComment}" )    @PutMapping    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_edit')" )    public R updateById(@RequestBody ${ClassName}Entity ${className}) {        return R.ok(${className}Service.updateDeep(${className}));    }    /**     * 通过id删除${tableComment}     * @param ids ${pk.attrName}列表     * @return R     */    @Operation(summary = "通过id删除${tableComment}" , description = "通过id删除${tableComment}" )    @SysLog("通过id删除${tableComment}" )    @DeleteMapping    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )    public R removeById(@RequestBody ${pk.attrType}[] ids) {        return R.ok(${className}Service.removeDeep(ids));    }    /**     * 通过id删除${tableComment}子表数据     * @param ids ${pk.attrName}列表     * @return R     */    @Operation(summary = "通过id删除${tableComment}子表数据" , description = "通过id删除${tableComment}子表数据" )    @SysLog("通过id删除${tableComment}子表数据" )    @DeleteMapping("/child")    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )    public R removeChild(@RequestBody ${pk.attrType}[] ids) {        return R.ok(${className}Service.removeChild(ids));    }    /**     * 导出excel 表格     * @param ${className} 查询条件   	 * @param ids 导出指定ID     * @return excel 文件流     */    @ResponseExcel    @GetMapping("/export")    @PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_export')" )    public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {        return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));    }}
 |