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

/**
 * 图库目录共享Controller
 *
 * @author bs
 * @date 2025-02-22
 */
@Api(tags = "图库目录共享")
@RestController
@RequestMapping("/gallery/cata/share")
public class CtGalleryCataShareController extends BaseController {
    @Resource
    private ICtGalleryCataShareService ctGalleryCataShareService;

    /**
     * 分页查询图库目录共享列表
     */
    @ApiOperation("分页查询图库目录共享列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(CtGalleryCataShare ctGalleryCataShare) {
        startPage();
        LambdaQueryWrapper<CtGalleryCataShare> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctGalleryCataShare);
        List<CtGalleryCataShare> list = ctGalleryCataShareService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询图库目录共享列表
     */
    @ApiOperation("查询图库目录共享列表")
    @GetMapping("/list")
    public AjaxResult list(CtGalleryCataShare ctGalleryCataShare) {
        LambdaQueryWrapper<CtGalleryCataShare> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctGalleryCataShare);
        List<CtGalleryCataShare> list = ctGalleryCataShareService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出图库目录共享列表
     */
    @ApiOperation("导出图库目录共享列表")
    @Log(title = "图库目录共享导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtGalleryCataShare ctGalleryCataShare) {
        LambdaQueryWrapper<CtGalleryCataShare> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,ctGalleryCataShare);
        List<CtGalleryCataShare> list = ctGalleryCataShareService.list(queryWrapper);
        ExcelUtil<CtGalleryCataShare> util = new ExcelUtil<CtGalleryCataShare>(CtGalleryCataShare. class);
        util.exportExcel(response, list, "图库目录共享数据");
    }

    /**
     * 获取图库目录共享详细信息
     */
    @ApiOperation("获取图库目录共享详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ctGalleryCataShareService.getById(id));
    }

    /**
     * 新增图库目录共享
     */
    @ApiOperation("新增图库目录共享")
    @Log(title = "图库目录共享新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtGalleryCataShare ctGalleryCataShare) {
        return toAjax(ctGalleryCataShareService.save(ctGalleryCataShare));
    }

    /**
     * 修改图库目录共享
     */
    @ApiOperation("修改图库目录共享")
    @Log(title = "图库目录共享修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtGalleryCataShare ctGalleryCataShare) {
        return toAjax(ctGalleryCataShareService.updateById(ctGalleryCataShare));
    }

    /**
     * 删除图库目录共享
     */
    @ApiOperation("删除图库目录共享")
    @Log(title = "图库目录共享删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(ctGalleryCataShareService.removeBatchByIds(ids));
    }

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


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

        //共享类型目录共享、图片共享
        if(Validator.isNotEmpty(ctGalleryCataShare.getType())){
            queryWrapper.eq(CtGalleryCataShare::getType,ctGalleryCataShare.getType());
        }

        //目录id
        if(Validator.isNotEmpty(ctGalleryCataShare.getCataId())){
            queryWrapper.eq(CtGalleryCataShare::getCataId,ctGalleryCataShare.getCataId());
        }

        //共享用户
        if(Validator.isNotEmpty(ctGalleryCataShare.getUserId())){
            queryWrapper.eq(CtGalleryCataShare::getUserId,ctGalleryCataShare.getUserId());
        }

        //开始时间
        if(Validator.isNotEmpty(ctGalleryCataShare.getBeginDate())){
            queryWrapper.eq(CtGalleryCataShare::getBeginDate,ctGalleryCataShare.getBeginDate());
        }

        //结束时间
        if(Validator.isNotEmpty(ctGalleryCataShare.getEndDate())){
            queryWrapper.eq(CtGalleryCataShare::getEndDate,ctGalleryCataShare.getEndDate());
        }

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

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

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

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

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

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

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

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

        }

}
