package com.pm.web.controller.patrol;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.enums.BusinessType;
import com.pm.common.config.PageData;
import com.pm.common.utils.poi.ExcelUtilPageData;
import com.pm.patrol.service.IPatrolRecordService;
import com.pm.common.core.page.TableDataInfo;

/**
 * 巡更记录Controller
 *
 * @author pm
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/patrol/record")
public class PatrolRecordController extends BaseController {
    
    @Autowired
    private IPatrolRecordService patrolRecordService;

    /**
     * 查询巡更记录列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:record:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = patrolRecordService.selectPatrolRecordList(pd);
        return getDataTable(list);
    }

    /**
     * 获取巡更记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(patrolRecordService.selectPatrolRecordById(id));
    }

    /**
     * 导出巡更记录列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:record:export')")
    @Log(title = "巡更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        try {
            PageData pd = this.getPageData();
            List<PageData> list = patrolRecordService.selectPatrolRecordList(pd);
            String filename = "巡更记录数据";
            String[] titles = {
                    "记录ID,id",
                    "巡更记录ID,record_id",
                    "巡更点编号,point_code",
                    "巡更点名称,point_name",
                    "巡更人员ID,patrol_person_id",
                    "巡更人员姓名,patrol_person_name",
                    "巡更时间,patrol_time",
                    "巡更状态,patrol_status",
                    "GPS经度,gps_longitude",
                    "GPS纬度,gps_latitude",
                    "巡检仪序列号,device_sn",
                    "巡更路线ID,patrol_route_id",
                    "巡更路线名称,patrol_route_name",
                    "当日巡更次数,patrol_count",
                    "异常信息,exception_info",
                    "备注,remark"
            };
            ExcelUtilPageData.exportXLSX(response, null, null, filename, titles, list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}