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.CtTaskImages;
import com.bs.ct.service.ICtTaskImagesService;
import javax.annotation.Resource;

/**
 * 任务图片信息Controller
 *
 * @author bs
 * @date 2025-02-22
 */
@Api(tags = "任务图片信息")
@RestController
@RequestMapping("/task/images")
public class CtTaskImagesController extends BaseController {
    @Resource
    private ICtTaskImagesService ctTaskImagesService;

    /**
     * 分页查询任务图片信息列表
     */
    @ApiOperation("分页查询任务图片信息列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(CtTaskImages ctTaskImages) {
        startPage();
        LambdaQueryWrapper<CtTaskImages> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctTaskImages);
        List<CtTaskImages> list = ctTaskImagesService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询任务图片信息列表
     */
    @ApiOperation("查询任务图片信息列表")
    @GetMapping("/list")
    public AjaxResult list(CtTaskImages ctTaskImages) {
        LambdaQueryWrapper<CtTaskImages> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctTaskImages);
        List<CtTaskImages> list = ctTaskImagesService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出任务图片信息列表
     */
    @ApiOperation("导出任务图片信息列表")
    @Log(title = "任务图片信息导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtTaskImages ctTaskImages) {
        LambdaQueryWrapper<CtTaskImages> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctTaskImages);
        List<CtTaskImages> list = ctTaskImagesService.list(queryWrapper);
        ExcelUtil<CtTaskImages> util = new ExcelUtil<CtTaskImages>(CtTaskImages. class);
        util.exportExcel(response, list, "任务图片信息数据");
    }

    /**
     * 获取任务图片信息详细信息
     */
    @ApiOperation("获取任务图片信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ctTaskImagesService.getById(id));
    }

    /**
     * 新增任务图片信息
     */
    @ApiOperation("新增任务图片信息")
    @Log(title = "任务图片信息新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtTaskImages ctTaskImages) {
        return toAjax(ctTaskImagesService.save(ctTaskImages));
    }

    /**
     * 修改任务图片信息
     */
    @ApiOperation("修改任务图片信息")
    @Log(title = "任务图片信息修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtTaskImages ctTaskImages) {
        return toAjax(ctTaskImagesService.updateById(ctTaskImages));
    }

    /**
     * 删除任务图片信息
     */
    @ApiOperation("删除任务图片信息")
    @Log(title = "任务图片信息删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(ctTaskImagesService.removeBatchByIds(ids));
    }

    /**
      * 条件设置
      */
    private void condition (LambdaQueryWrapper<CtTaskImages> queryWrapper,CtTaskImages ctTaskImages){


        //id
        if(Validator.isNotEmpty(ctTaskImages.getId())){
            queryWrapper.eq(CtTaskImages::getId,ctTaskImages.getId());
        }

        //任务id
        if(Validator.isNotEmpty(ctTaskImages.getTaskId())){
            queryWrapper.eq(CtTaskImages::getTaskId,ctTaskImages.getTaskId());
        }

        //图片id
        if(Validator.isNotEmpty(ctTaskImages.getImageId())){
            queryWrapper.eq(CtTaskImages::getImageId,ctTaskImages.getImageId());
        }

        //备注
        if(Validator.isNotEmpty(ctTaskImages.getRemarks())){
            queryWrapper.eq(CtTaskImages::getRemarks,ctTaskImages.getRemarks());
        }

        //删除标志（0代表存在 2代表删除）
        if(Validator.isNotEmpty(ctTaskImages.getDelFlag())){
            queryWrapper.eq(CtTaskImages::getDelFlag,ctTaskImages.getDelFlag());
        }

        //创建部门
        if(Validator.isNotEmpty(ctTaskImages.getCreateDept())){
            queryWrapper.eq(CtTaskImages::getCreateDept,ctTaskImages.getCreateDept());
        }

        //创建人
        if(Validator.isNotEmpty(ctTaskImages.getCreateBy())){
            queryWrapper.eq(CtTaskImages::getCreateBy,ctTaskImages.getCreateBy());
        }

        //创建时间
        if(Validator.isNotEmpty(ctTaskImages.getCreateTime())){
            queryWrapper.eq(CtTaskImages::getCreateTime,ctTaskImages.getCreateTime());
        }

        //修改人
        if(Validator.isNotEmpty(ctTaskImages.getUpdateBy())){
            queryWrapper.eq(CtTaskImages::getUpdateBy,ctTaskImages.getUpdateBy());
        }

        //修改时间
        if(Validator.isNotEmpty(ctTaskImages.getUpdateTime())){
            queryWrapper.eq(CtTaskImages::getUpdateTime,ctTaskImages.getUpdateTime());
        }

        //租户ID
        if(Validator.isNotEmpty(ctTaskImages.getTenantId())){
            queryWrapper.eq(CtTaskImages::getTenantId,ctTaskImages.getTenantId());
        }

        }

}
