package com.bs.dc.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 org.apache.commons.lang3.StringUtils;
import com.bs.dc.domain.DcVisitPhoto;
import com.bs.dc.service.IDcVisitPhotoService;
import javax.annotation.Resource;

/**
 * 访客照片信息Controller
 *
 * @author bs
 * @date 2025-10-09
 */
@Api(tags = "访客照片信息")
@RestController
@RequestMapping("/visit/photo")
public class DcVisitPhotoController extends BaseController {
    @Resource
    private IDcVisitPhotoService dcVisitPhotoService;

    /**
     * 分页查询访客照片信息列表
     */
    @ApiOperation("分页查询访客照片信息列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(DcVisitPhoto dcVisitPhoto) {
        startPage();
        LambdaQueryWrapper<DcVisitPhoto> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,dcVisitPhoto);
        List<DcVisitPhoto> list = dcVisitPhotoService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询访客照片信息列表
     */
    @ApiOperation("查询访客照片信息列表")
    @GetMapping("/list")
    public AjaxResult list(DcVisitPhoto dcVisitPhoto) {
        LambdaQueryWrapper<DcVisitPhoto> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,dcVisitPhoto);
        List<DcVisitPhoto> list = dcVisitPhotoService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出访客照片信息列表
     */
    @ApiOperation("导出访客照片信息列表")
    @Log(title = "访客照片信息导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcVisitPhoto dcVisitPhoto) {
        LambdaQueryWrapper<DcVisitPhoto> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,dcVisitPhoto);
        List<DcVisitPhoto> list = dcVisitPhotoService.list(queryWrapper);
        ExcelUtil<DcVisitPhoto> util = new ExcelUtil<DcVisitPhoto>(DcVisitPhoto. class);
        util.exportExcel(response, list, "访客照片信息数据");
    }

    /**
     * 获取访客照片信息详细信息
     */
    @ApiOperation("获取访客照片信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(dcVisitPhotoService.getById(id));
    }

    /**
     * 新增访客照片信息
     */
    @ApiOperation("新增访客照片信息")
    @Log(title = "访客照片信息新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcVisitPhoto dcVisitPhoto) {
        return toAjax(dcVisitPhotoService.save(dcVisitPhoto));
    }

    /**
     * 修改访客照片信息
     */
    @ApiOperation("修改访客照片信息")
    @Log(title = "访客照片信息修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcVisitPhoto dcVisitPhoto) {
        return toAjax(dcVisitPhotoService.updateById(dcVisitPhoto));
    }

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

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


        //Id
        if(StringUtils.isNotEmpty(dcVisitPhoto.getId())){
            queryWrapper.eq(DcVisitPhoto::getId,dcVisitPhoto.getId());
        }

        //对应ID
        if(StringUtils.isNotEmpty(dcVisitPhoto.getBizId())){
            queryWrapper.eq(DcVisitPhoto::getBizId,dcVisitPhoto.getBizId());
        }

        //照片
        if(StringUtils.isNotEmpty(dcVisitPhoto.getPhoto())){
            queryWrapper.eq(DcVisitPhoto::getPhoto,dcVisitPhoto.getPhoto());
        }

        //照片类型
        if(StringUtils.isNotEmpty(dcVisitPhoto.getType())){
            queryWrapper.eq(DcVisitPhoto::getType,dcVisitPhoto.getType());
        }

        //备注
        if(StringUtils.isNotEmpty(dcVisitPhoto.getRemark())){
            queryWrapper.eq(DcVisitPhoto::getRemark,dcVisitPhoto.getRemark());
        }

        //创建人员
        if(null != (dcVisitPhoto.getCreateBy())){
            queryWrapper.eq(DcVisitPhoto::getCreateBy,dcVisitPhoto.getCreateBy());
        }

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

        //修改人员
        if(null != (dcVisitPhoto.getUpdateBy())){
            queryWrapper.eq(DcVisitPhoto::getUpdateBy,dcVisitPhoto.getUpdateBy());
        }

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

        }

}
