package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.exception.CommonException;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.cecep.talroad.vo.query.BMainThreeSupervisionEnforcRecordQuery;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.security.InvalidParameterException;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.common.security.annotation.RequiresPermissions;

import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.domain.BMainThreeSupervisionEnforcRecord;
import cn.cecep.talroad.vo.BMainThreeSupervisionEnforcRecordVo;
import cn.cecep.talroad.service.IBMainThreeSupervisionEnforcRecordService;


/**
 * * 开发公司：中节能天融科技有限公司
 * 三监联动执法信息记录Controller 控制层
 *
 * @author szhpt
 * @date 2023-03-29*/
@Api(tags = "三监联动执法信息记录")
@RestController
@RequestMapping("/threeSupervision/record")
public class BMainThreeSupervisionEnforcRecordController extends BasesController
{
    @Autowired
    private IBMainThreeSupervisionEnforcRecordService bMainThreeSupervisionEnforcRecordService;

    /**
     * 查询三监联动执法信息记录列表
     */
    @ApiOperation(value = "查询三监联动执法信息记录")
    @GetMapping("/list")
    public AjaxResults<IPage<BMainThreeSupervisionEnforcRecord>> list(BMainThreeSupervisionEnforcRecordQuery bMainThreeSupervisionEnforcRecord)
    {
        Page<BMainThreeSupervisionEnforcRecord> page = new Page<>(bMainThreeSupervisionEnforcRecord.getPageNum(), bMainThreeSupervisionEnforcRecord.getPageSize());
        IPage<BMainThreeSupervisionEnforcRecord> list = bMainThreeSupervisionEnforcRecordService.page(page, BMainThreeSupervisionEnforcRecordQuery.createLambdaQueryWrapper(bMainThreeSupervisionEnforcRecord));
        return AjaxResults.success(list);
    }


    /**
     * 导出三监联动执法信息记录列表
     */
    @ApiOperation(value = "导出三监联动执法信息记录")
    @Log(title = "三监联动执法信息记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BMainThreeSupervisionEnforcRecord bMainThreeSupervisionEnforcRecord)
    {
        List<BMainThreeSupervisionEnforcRecord> list = bMainThreeSupervisionEnforcRecordService.selectBMainThreeSupervisionEnforcRecordList(bMainThreeSupervisionEnforcRecord);
        ExcelUtil<BMainThreeSupervisionEnforcRecord> util = new ExcelUtil<BMainThreeSupervisionEnforcRecord>(BMainThreeSupervisionEnforcRecord.class);
        util.exportExcel(response, list, "三监联动执法信息记录数据");
    }

    /**
     * 获取三监联动执法信息记录详细信息
     */
    @ApiOperation(value = "获取三监联动执法信息记录详细信息")
    @PostMapping(value = "/{recordId}")
    public AjaxResults<BMainThreeSupervisionEnforcRecord> getInfo(@PathVariable("id") Integer id) {
        return AjaxResults.success(bMainThreeSupervisionEnforcRecordService.getById(id));
    }
    /**
     * 新增三监联动执法信息记录
     */
    @ApiOperation(value = "新增三监联动执法信息记录")
    @Log(title = "三监联动执法信息记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResults<Boolean> add(@RequestBody BMainThreeSupervisionEnforcRecord bMainThreeSupervisionEnforcRecord) {
        return toAjax(bMainThreeSupervisionEnforcRecordService.save(bMainThreeSupervisionEnforcRecord));
    }
    /**
     * 修改三监联动执法信息记录
     */
    @ApiOperation(value = "修改三监联动执法信息记录")
    @Log(title = "三监联动执法信息记录", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResults<Boolean> edit(@RequestBody BMainThreeSupervisionEnforcRecordVo bMainThreeSupervisionEnforcRecordVo) {
        if(ObjectUtil.isEmpty(bMainThreeSupervisionEnforcRecordVo)){
            throw new InvalidParameterException("参数为空");
        }
        if(ObjectUtil.isEmpty(bMainThreeSupervisionEnforcRecordVo.getRecordId())){
            throw new InvalidParameterException("参数id为空");
        }
        BMainThreeSupervisionEnforcRecord bMainThreeSupervisionEnforcRecord = bMainThreeSupervisionEnforcRecordService.getById(bMainThreeSupervisionEnforcRecordVo.getRecordId());
        if(ObjectUtil.isEmpty(bMainThreeSupervisionEnforcRecord)){
            throw new CommonException(StrUtil.format("根据id{}查询不到数据", bMainThreeSupervisionEnforcRecordVo.getRecordId()));
        }
        //赋值
        BeanUtil.copyProperties(bMainThreeSupervisionEnforcRecordVo,bMainThreeSupervisionEnforcRecord);
        return toAjax(bMainThreeSupervisionEnforcRecordService.saveOrUpdate(bMainThreeSupervisionEnforcRecord));
    }

    /**
     * 删除三监联动执法信息记录
     */
    @ApiOperation(value = "删除三监联动执法信息记录")
    @RequiresPermissions("talroad:record:remove")
    @Log(title = "三监联动执法信息记录", businessType = BusinessType.DELETE)
    @PostMapping("/{recordIds}")
    public AjaxResults<Boolean> remove(@PathVariable String[] recordIds) {
        return toAjax(bMainThreeSupervisionEnforcRecordService.removeByIds(Arrays.asList(recordIds)));
    }
}
