package com.bs.ct.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.bs.common.annotation.Log; import com.bs.common.core.controller.BaseController; import com.bs.common.core.domain.AjaxResult; import com.bs.common.core.page.TableDataInfo; import com.bs.common.enums.BusinessType; import com.bs.common.utils.poi.ExcelUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import cn.hutool.core.lang.Validator; import com.bs.ct.domain.CtGalleryCata; import com.bs.ct.service.ICtGalleryCataService; import javax.annotation.Resource; /** * 图库目录Controller * * @author bs * @date 2025-02-22 */ @Api(tags = "图库目录") @RestController @RequestMapping("/gallery/cata") public class CtGalleryCataController extends BaseController { @Resource private ICtGalleryCataService ctGalleryCataService; /** * 分页查询图库目录列表 */ @ApiOperation("分页查询图库目录列表") @GetMapping("/pageList") public TableDataInfo pageList(CtGalleryCata ctGalleryCata) { startPage(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); condition(queryWrapper,ctGalleryCata); List list = ctGalleryCataService.list(queryWrapper); return getDataTable(list); } /** * 查询图库目录列表 */ @ApiOperation("查询图库目录列表") @GetMapping("/list") public AjaxResult list(CtGalleryCata ctGalleryCata) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); condition(queryWrapper,ctGalleryCata); List list = ctGalleryCataService.list(queryWrapper); return success(list); } /** * 导出图库目录列表 */ @ApiOperation("导出图库目录列表") @Log(title = "图库目录导出", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, CtGalleryCata ctGalleryCata) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); condition(queryWrapper,ctGalleryCata); List list = ctGalleryCataService.list(queryWrapper); ExcelUtil util = new ExcelUtil(CtGalleryCata. class); util.exportExcel(response, list, "图库目录数据"); } /** * 获取图库目录详细信息 */ @ApiOperation("获取图库目录详细信息") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(ctGalleryCataService.getById(id)); } /** * 新增图库目录 */ @ApiOperation("新增图库目录") @Log(title = "图库目录新增", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody CtGalleryCata ctGalleryCata) { return toAjax(ctGalleryCataService.save(ctGalleryCata)); } /** * 修改图库目录 */ @ApiOperation("修改图库目录") @Log(title = "图库目录修改", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody CtGalleryCata ctGalleryCata) { return toAjax(ctGalleryCataService.updateById(ctGalleryCata)); } /** * 删除图库目录 */ @ApiOperation("删除图库目录") @Log(title = "图库目录删除", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable List ids) { return toAjax(ctGalleryCataService.removeBatchByIds(ids)); } /** * 条件设置 */ private void condition (LambdaQueryWrapper queryWrapper,CtGalleryCata ctGalleryCata){ //id if(Validator.isNotEmpty(ctGalleryCata.getId())){ queryWrapper.eq(CtGalleryCata::getId,ctGalleryCata.getId()); } //目录名称 if(Validator.isNotEmpty(ctGalleryCata.getCataName())){ queryWrapper.eq(CtGalleryCata::getCataName,ctGalleryCata.getCataName()); } //父级id if(Validator.isNotEmpty(ctGalleryCata.getParentId())){ queryWrapper.eq(CtGalleryCata::getParentId,ctGalleryCata.getParentId()); } //类型 if(Validator.isNotEmpty(ctGalleryCata.getType())){ queryWrapper.eq(CtGalleryCata::getType,ctGalleryCata.getType()); } //备注 if(Validator.isNotEmpty(ctGalleryCata.getRemarks())){ queryWrapper.eq(CtGalleryCata::getRemarks,ctGalleryCata.getRemarks()); } //删除标志(0代表存在 2代表删除) if(Validator.isNotEmpty(ctGalleryCata.getDelFlag())){ queryWrapper.eq(CtGalleryCata::getDelFlag,ctGalleryCata.getDelFlag()); } //创建部门 if(Validator.isNotEmpty(ctGalleryCata.getCreateDept())){ queryWrapper.eq(CtGalleryCata::getCreateDept,ctGalleryCata.getCreateDept()); } //创建人 if(Validator.isNotEmpty(ctGalleryCata.getCreateBy())){ queryWrapper.eq(CtGalleryCata::getCreateBy,ctGalleryCata.getCreateBy()); } //创建时间 if(Validator.isNotEmpty(ctGalleryCata.getCreateTime())){ queryWrapper.eq(CtGalleryCata::getCreateTime,ctGalleryCata.getCreateTime()); } //修改人 if(Validator.isNotEmpty(ctGalleryCata.getUpdateBy())){ queryWrapper.eq(CtGalleryCata::getUpdateBy,ctGalleryCata.getUpdateBy()); } //修改时间 if(Validator.isNotEmpty(ctGalleryCata.getUpdateTime())){ queryWrapper.eq(CtGalleryCata::getUpdateTime,ctGalleryCata.getUpdateTime()); } //租户ID if(Validator.isNotEmpty(ctGalleryCata.getTenantId())){ queryWrapper.eq(CtGalleryCata::getTenantId,ctGalleryCata.getTenantId()); } } }