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

/**
 * 图库图片标签Controller
 *
 * @author bs
 * @date 2025-02-22
 */
@Api(tags = "图库图片标签")
@RestController
@RequestMapping("/gallery/images/tag")
public class CtGalleryImagesTagController extends BaseController {
    @Resource
    private ICtGalleryImagesTagService ctGalleryImagesTagService;

    /**
     * 分页查询图库图片标签列表
     */
    @ApiOperation("分页查询图库图片标签列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(CtGalleryImagesTag ctGalleryImagesTag) {
        startPage();
        LambdaQueryWrapper<CtGalleryImagesTag> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctGalleryImagesTag);
        List<CtGalleryImagesTag> list = ctGalleryImagesTagService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询图库图片标签列表
     */
    @ApiOperation("查询图库图片标签列表")
    @GetMapping("/list")
    public AjaxResult list(CtGalleryImagesTag ctGalleryImagesTag) {
        LambdaQueryWrapper<CtGalleryImagesTag> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctGalleryImagesTag);
        List<CtGalleryImagesTag> list = ctGalleryImagesTagService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出图库图片标签列表
     */
    @ApiOperation("导出图库图片标签列表")
    @Log(title = "图库图片标签导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtGalleryImagesTag ctGalleryImagesTag) {
        LambdaQueryWrapper<CtGalleryImagesTag> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctGalleryImagesTag);
        List<CtGalleryImagesTag> list = ctGalleryImagesTagService.list(queryWrapper);
        ExcelUtil<CtGalleryImagesTag> util = new ExcelUtil<CtGalleryImagesTag>(CtGalleryImagesTag. class);
        util.exportExcel(response, list, "图库图片标签数据");
    }

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

    /**
     * 新增图库图片标签
     */
    @ApiOperation("新增图库图片标签")
    @Log(title = "图库图片标签新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtGalleryImagesTag ctGalleryImagesTag) {
        return toAjax(ctGalleryImagesTagService.save(ctGalleryImagesTag));
    }

    /**
     * 修改图库图片标签
     */
    @ApiOperation("修改图库图片标签")
    @Log(title = "图库图片标签修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtGalleryImagesTag ctGalleryImagesTag) {
        return toAjax(ctGalleryImagesTagService.updateById(ctGalleryImagesTag));
    }

    /**
     * 删除图库图片标签
     */
    @ApiOperation("删除图库图片标签")
    @Log(title = "图库图片标签删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(ctGalleryImagesTagService.removeBatchByIds(ids));
    }

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


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

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

        //标签名称
        if(Validator.isNotEmpty(ctGalleryImagesTag.getTagName())){
            queryWrapper.eq(CtGalleryImagesTag::getTagName,ctGalleryImagesTag.getTagName());
        }

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

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

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

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

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

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

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

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

        }

}
