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.DcVisitInfo;
import com.bs.dc.service.IDcVisitInfoService;
import javax.annotation.Resource;

/**
 * 访客访问信息Controller
 *
 * @author bs
 * @date 2025-10-09
 */
@Api(tags = "访客访问信息")
@RestController
@RequestMapping("/visit/info")
public class DcVisitInfoController extends BaseController {
    @Resource
    private IDcVisitInfoService dcVisitInfoService;

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

    /**
     * 查询访客访问信息列表
     */
    @ApiOperation("查询访客访问信息列表")
    @GetMapping("/list")
    public AjaxResult list(DcVisitInfo dcVisitInfo) {
        LambdaQueryWrapper<DcVisitInfo> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,dcVisitInfo);
        List<DcVisitInfo> list = dcVisitInfoService.list(queryWrapper);
        return success(list);
    }

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

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

    /**
     * 新增访客访问信息
     */
    @ApiOperation("新增访客访问信息")
    @Log(title = "访客访问信息新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcVisitInfo dcVisitInfo) {
        return toAjax(dcVisitInfoService.save(dcVisitInfo));
    }

    /**
     * 修改访客访问信息
     */
    @ApiOperation("修改访客访问信息")
    @Log(title = "访客访问信息修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcVisitInfo dcVisitInfo) {
        return toAjax(dcVisitInfoService.updateById(dcVisitInfo));
    }

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

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


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

        //访问日期
        if(null != (dcVisitInfo.getVisitDate())){
            queryWrapper.eq(DcVisitInfo::getVisitDate,dcVisitInfo.getVisitDate());
        }

        //被访部门
        if(StringUtils.isNotEmpty(dcVisitInfo.getVisitDept())){
            queryWrapper.eq(DcVisitInfo::getVisitDept,dcVisitInfo.getVisitDept());
        }

        //被访人
        if(StringUtils.isNotEmpty(dcVisitInfo.getVisitObject())){
            queryWrapper.eq(DcVisitInfo::getVisitObject,dcVisitInfo.getVisitObject());
        }

        //到访理由
        if(StringUtils.isNotEmpty(dcVisitInfo.getVisitReason())){
            queryWrapper.eq(DcVisitInfo::getVisitReason,dcVisitInfo.getVisitReason());
        }

        //预计离开时间
        if(null != (dcVisitInfo.getDepartureTime())){
            queryWrapper.eq(DcVisitInfo::getDepartureTime,dcVisitInfo.getDepartureTime());
        }

        //领导确认
        if(StringUtils.isNotEmpty(dcVisitInfo.getLeaderConfirm())){
            queryWrapper.eq(DcVisitInfo::getLeaderConfirm,dcVisitInfo.getLeaderConfirm());
        }

        //访问区域
        if(StringUtils.isNotEmpty(dcVisitInfo.getVisitArea())){
            queryWrapper.eq(DcVisitInfo::getVisitArea,dcVisitInfo.getVisitArea());
        }

        //入口名称
        if(StringUtils.isNotEmpty(dcVisitInfo.getEntryName())){
            queryWrapper.eq(DcVisitInfo::getEntryName,dcVisitInfo.getEntryName());
        }

        //车辆类型
        if(StringUtils.isNotEmpty(dcVisitInfo.getCarType())){
            queryWrapper.eq(DcVisitInfo::getCarType,dcVisitInfo.getCarType());
        }

        //车辆数量
        if(null != (dcVisitInfo.getCarNumber())){
            queryWrapper.eq(DcVisitInfo::getCarNumber,dcVisitInfo.getCarNumber());
        }

        //携带物品
        if(StringUtils.isNotEmpty(dcVisitInfo.getBringThings())){
            queryWrapper.eq(DcVisitInfo::getBringThings,dcVisitInfo.getBringThings());
        }

        //物品描述
        if(StringUtils.isNotEmpty(dcVisitInfo.getThingsDesc())){
            queryWrapper.eq(DcVisitInfo::getThingsDesc,dcVisitInfo.getThingsDesc());
        }

        //物品数量
        if(StringUtils.isNotEmpty(dcVisitInfo.getThingsNumber())){
            queryWrapper.eq(DcVisitInfo::getThingsNumber,dcVisitInfo.getThingsNumber());
        }

        //操作人员
        if(StringUtils.isNotEmpty(dcVisitInfo.getOperator())){
            queryWrapper.eq(DcVisitInfo::getOperator,dcVisitInfo.getOperator());
        }

        //操作时间
        if(null != (dcVisitInfo.getOperateTime())){
            queryWrapper.eq(DcVisitInfo::getOperateTime,dcVisitInfo.getOperateTime());
        }

        //状态0录入1确认2驳回
        if(StringUtils.isNotEmpty(dcVisitInfo.getStatus())){
            queryWrapper.eq(DcVisitInfo::getStatus,dcVisitInfo.getStatus());
        }

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

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

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

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

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

        //是否预约
        if(StringUtils.isNotEmpty(dcVisitInfo.getIsBook())){
            queryWrapper.eq(DcVisitInfo::getIsBook,dcVisitInfo.getIsBook());
        }

        }

}
