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

/**
 * 访客基本信息Controller
 *
 * @author bs
 * @date 2025-10-07
 */
@Api(tags = "访客基本信息")
@RestController
@RequestMapping("/visit/basic")
public class DcVisitBasicController extends BaseController {
    @Resource
    private IDcVisitBasicService dcVisitBasicService;

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

    /**
     * 查询访客基本信息列表
     */
    @ApiOperation("查询访客基本信息列表")
    @GetMapping("/list")
    public AjaxResult list(DcVisitBasic dcVisitBasic) {
        LambdaQueryWrapper<DcVisitBasic> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,dcVisitBasic);
        List<DcVisitBasic> list = dcVisitBasicService.list(queryWrapper);
        return success(list);
    }

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

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

    /**
     * 新增访客基本信息
     */
    @ApiOperation("新增访客基本信息")
    @Log(title = "访客基本信息新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcVisitBasic dcVisitBasic) {
        return toAjax(dcVisitBasicService.save(dcVisitBasic));
    }

    /**
     * 修改访客基本信息
     */
    @ApiOperation("修改访客基本信息")
    @Log(title = "访客基本信息修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcVisitBasic dcVisitBasic) {
        return toAjax(dcVisitBasicService.updateById(dcVisitBasic));
    }

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

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


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

        //姓名
        if(StringUtils.isNotEmpty(dcVisitBasic.getName())){
            queryWrapper.eq(DcVisitBasic::getName,dcVisitBasic.getName());
        }

        //性别
        if(StringUtils.isNotEmpty(dcVisitBasic.getSex())){
            queryWrapper.eq(DcVisitBasic::getSex,dcVisitBasic.getSex());
        }

        //证件类型
        if(StringUtils.isNotEmpty(dcVisitBasic.getCertType())){
            queryWrapper.eq(DcVisitBasic::getCertType,dcVisitBasic.getCertType());
        }

        //证件号码
        if(StringUtils.isNotEmpty(dcVisitBasic.getCertNumber())){
            queryWrapper.eq(DcVisitBasic::getCertNumber,dcVisitBasic.getCertNumber());
        }

        //单位名称
        if(StringUtils.isNotEmpty(dcVisitBasic.getUnitName())){
            queryWrapper.eq(DcVisitBasic::getUnitName,dcVisitBasic.getUnitName());
        }

        //单位Id
        if(StringUtils.isNotEmpty(dcVisitBasic.getUnitId())){
            queryWrapper.eq(DcVisitBasic::getUnitId,dcVisitBasic.getUnitId());
        }

        //联系电话
        if(StringUtils.isNotEmpty(dcVisitBasic.getContactPhone())){
            queryWrapper.eq(DcVisitBasic::getContactPhone,dcVisitBasic.getContactPhone());
        }

        //车牌号码
        if(StringUtils.isNotEmpty(dcVisitBasic.getVesselNumber())){
            queryWrapper.eq(DcVisitBasic::getVesselNumber,dcVisitBasic.getVesselNumber());
        }

        //联系地址
        if(StringUtils.isNotEmpty(dcVisitBasic.getContactAddr())){
            queryWrapper.eq(DcVisitBasic::getContactAddr,dcVisitBasic.getContactAddr());
        }

        //切换状态操作人员
        if(StringUtils.isNotEmpty(dcVisitBasic.getStatusOperator())){
            queryWrapper.eq(DcVisitBasic::getStatusOperator,dcVisitBasic.getStatusOperator());
        }

        //状态0正常1拉黑
        if(StringUtils.isNotEmpty(dcVisitBasic.getStatus())){
            queryWrapper.eq(DcVisitBasic::getStatus,dcVisitBasic.getStatus());
        }

        //拉黑原因
        if(StringUtils.isNotEmpty(dcVisitBasic.getReason())){
            queryWrapper.eq(DcVisitBasic::getReason,dcVisitBasic.getReason());
        }

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

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

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

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

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

        }

}
