package com.ruoyi.web.controller.doubleDefense;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.doubledefense.domain.CheckTaskInventoryRecord;
import com.ruoyi.doubledefense.service.ICheckTaskInventoryRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查记录Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Api(tags = "排查任务清单记录")
@RestController
@RequestMapping("/doubledefense/taskInventoryRecord")
public class CheckTaskInventoryRecordController extends BaseController {
    @Autowired
    private ICheckTaskInventoryRecordService checkTaskInventoryRecordService;

    /**
     * PC查询巡查记录列表
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckTaskInventoryRecord checkTaskInventoryRecord) {
        startPage();

        // 开始时间 endDateGt
        // 结束时间 startDateLt
        Date startDate = checkTaskInventoryRecord.getStartDate();
        Date endDate = checkTaskInventoryRecord.getEndDate();

        if (startDate != null) {
            checkTaskInventoryRecord.setEndDateGt(startDate);
        }
        if (endDate != null) {
            checkTaskInventoryRecord.setStartDateLt(endDate);
        }

        checkTaskInventoryRecord.setStartDate(null);
        checkTaskInventoryRecord.setEndDate(null);

        List<CheckTaskInventoryRecord> list = checkTaskInventoryRecordService.selectCheckTaskInventoryRecordList(checkTaskInventoryRecord);
        return getDataTable(list);
    }

    /**
     * 导出巡查记录列表
     */
    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:record:export')")
    @Log(title = "巡查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckTaskInventoryRecord checkTaskInventoryRecord) {
        List<CheckTaskInventoryRecord> list = checkTaskInventoryRecordService.selectCheckTaskInventoryRecordList(checkTaskInventoryRecord);
        ExcelUtil<CheckTaskInventoryRecord> util = new ExcelUtil<CheckTaskInventoryRecord>(CheckTaskInventoryRecord.class);
        util.exportExcel(response, list, "巡查记录数据");
    }

    /**
     * 获取巡查记录详细信息
     */
//    //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(checkTaskInventoryRecordService.selectCheckTaskInventoryRecordById(id));
    }

    /**
     * 新增巡查记录
     //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:record:add')")
     @Log(title = "巡查记录", businessType = BusinessType.INSERT)
     @PostMapping public AjaxResult add(@RequestBody CheckTaskInventoryRecord checkTaskInventoryRecord) {
     return toAjax(checkTaskInventoryRecordService.insertCheckTaskInventoryRecord(checkTaskInventoryRecord));
     }
     */

    /**
     * 修改巡查记录
     //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:record:edit')")
     @Log(title = "巡查记录", businessType = BusinessType.UPDATE)
     @PutMapping public AjaxResult edit(@RequestBody CheckTaskInventoryRecord checkTaskInventoryRecord) {
     return toAjax(checkTaskInventoryRecordService.updateCheckTaskInventoryRecord(checkTaskInventoryRecord));
     }
     */

    /**
     * 删除巡查记录
     //TODO 20230920PreAuthorize("@("@ss.hasPermi('doubledefense:record:remove')")
     @Log(title = "巡查记录", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable String[] ids) {
     return toAjax(checkTaskInventoryRecordService.deleteCheckTaskInventoryRecordByIds(ids));
     }
     */
}
