package com.bs.ct.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.bs.ct.service.ICtGalleryImagesService;
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 org.apache.commons.lang3.StringUtils;
import com.bs.ct.domain.CtImagesFeedbackRef;
import com.bs.ct.service.ICtImagesFeedbackRefService;
import javax.annotation.Resource;

/**
 * 图片任务反馈关联Controller
 *
 * @author bs
 * @date 2025-04-20
 */
@Api(tags = "图片任务反馈关联")
@RestController
@RequestMapping("/images/ref")
public class CtImagesFeedbackRefController extends BaseController {
    @Resource
    private ICtImagesFeedbackRefService ctImagesFeedbackRefService;
    @Resource
    private ICtGalleryImagesService ctGalleryImagesService;
    /**
     * 分页查询图片任务反馈关联列表
     */
    @ApiOperation("分页查询图片任务反馈关联列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(CtImagesFeedbackRef ctImagesFeedbackRef) {
        startPage();
        LambdaQueryWrapper<CtImagesFeedbackRef> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctImagesFeedbackRef);
        List<CtImagesFeedbackRef> list = ctImagesFeedbackRefService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询图片任务反馈关联列表
     */
    @ApiOperation("查询图片任务反馈关联列表")
    @GetMapping("/list")
    public AjaxResult list(CtImagesFeedbackRef ctImagesFeedbackRef) {
        LambdaQueryWrapper<CtImagesFeedbackRef> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctImagesFeedbackRef);
        List<CtImagesFeedbackRef> list = ctImagesFeedbackRefService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出图片任务反馈关联列表
     */
    @ApiOperation("导出图片任务反馈关联列表")
    @Log(title = "图片任务反馈关联导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtImagesFeedbackRef ctImagesFeedbackRef) {
        LambdaQueryWrapper<CtImagesFeedbackRef> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctImagesFeedbackRef);
        List<CtImagesFeedbackRef> list = ctImagesFeedbackRefService.list(queryWrapper);
        ExcelUtil<CtImagesFeedbackRef> util = new ExcelUtil<CtImagesFeedbackRef>(CtImagesFeedbackRef. class);
        util.exportExcel(response, list, "图片任务反馈关联数据");
    }

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

    /**
     * 新增图片任务反馈关联
     */
    @ApiOperation("新增图片任务反馈关联")
    @Log(title = "图片任务反馈关联新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtImagesFeedbackRef ctImagesFeedbackRef) {
        return toAjax(ctImagesFeedbackRefService.save(ctImagesFeedbackRef));
    }

    /**
     * 修改图片任务反馈关联
     */
    @ApiOperation("修改图片任务反馈关联")
    @Log(title = "图片任务反馈关联修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtImagesFeedbackRef ctImagesFeedbackRef) {
        return toAjax(ctImagesFeedbackRefService.updateById(ctImagesFeedbackRef));
    }

    /**
     * 删除图片任务反馈关联
     */
    @ApiOperation("删除图片任务反馈关联")
    @Log(title = "图片任务反馈关联删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable List<Long> imageIds) {
        return toAjax(ctImagesFeedbackRefService.removeBatchByIds(imageIds));
    }

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


        //图片id
        if(null != (ctImagesFeedbackRef.getImageId())){
            queryWrapper.eq(CtImagesFeedbackRef::getImageId,ctImagesFeedbackRef.getImageId());
        }

        //任务反馈id
        if(null != (ctImagesFeedbackRef.getFeedbackId())){
            queryWrapper.eq(CtImagesFeedbackRef::getFeedbackId,ctImagesFeedbackRef.getFeedbackId());
        }

        //创建人
        if(null != (ctImagesFeedbackRef.getCreateBy())){
            queryWrapper.eq(CtImagesFeedbackRef::getCreateBy,ctImagesFeedbackRef.getCreateBy());
        }

        //创建时间
        if(null != (ctImagesFeedbackRef.getCreateTime())){
            queryWrapper.eq(CtImagesFeedbackRef::getCreateTime,ctImagesFeedbackRef.getCreateTime());
        }

        //修改人
        if(null != (ctImagesFeedbackRef.getUpdateBy())){
            queryWrapper.eq(CtImagesFeedbackRef::getUpdateBy,ctImagesFeedbackRef.getUpdateBy());
        }

        //修改时间
        if(null != (ctImagesFeedbackRef.getUpdateTime())){
            queryWrapper.eq(CtImagesFeedbackRef::getUpdateTime,ctImagesFeedbackRef.getUpdateTime());
        }

        //租户ID
        if(StringUtils.isNotEmpty(ctImagesFeedbackRef.getTenantId())){
            queryWrapper.eq(CtImagesFeedbackRef::getTenantId,ctImagesFeedbackRef.getTenantId());
        }

        }

}
