package com.usky.fire.controller.web;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.fire.domain.DemGridMember;
import com.usky.fire.service.DemGridMemberService;
import com.usky.fire.service.vo.DemGridMemberVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 网格员信息管理表 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-11-15
 */
@RestController
@RequestMapping("/demGridMember")
public class DemGridMemberController {

    @Autowired
    private DemGridMemberService demGridMemberService;

    /**
     * 网格员信息管理-列表查询
     *
     * @param gridArea      网格区域
     * @param streetTown    街镇
     * @param gridPersonnel 网格人员姓名
     * @param id            主键ID
     * @param pageNum       当前页
     * @param pageSize      每页条数
     * @return
     */
    @GetMapping("gridMemberList")
    public ApiResult<CommonPage<DemGridMember>> gridMemberList(@RequestParam(value = "gridArea", required = false) String gridArea,
                                                               @RequestParam(value = "streetTown", required = false) String streetTown,
                                                               @RequestParam(value = "gridPersonnel", required = false) String gridPersonnel,
                                                               @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                                                               @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demGridMemberService.gridMemberList(gridArea, streetTown, gridPersonnel, id, pageNum, pageSize));
    }

    /**
     * 网格员信息管理-撒点
     *
     * @param gridArea     网格区域
     * @param mapGridName    测绘院地图网格名称
     * @param gridGrade    网格等级(1、大网格 2、中网格 3、小网格)
     * @param seniorGrid    上级网格
     * @return
     */
    @GetMapping("gridMemberScatter")
    public ApiResult<List<DemGridMember>> gridMemberScatter(@RequestParam(value = "gridArea",required = false) String gridArea,
                                                            @RequestParam(value = "mapGridName",required = false) String mapGridName,
                                                            @RequestParam(value = "gridGrade",required = false) Integer gridGrade,
                                                            @RequestParam(value = "seniorGrid",required = false) Integer seniorGrid) {
        return ApiResult.success(demGridMemberService.gridMemberScatter(gridArea, mapGridName, gridGrade, seniorGrid));
    }

    /**
     * 网格人员统计接口
     *
     * @return
     */
    @GetMapping("gridMemderViceStatistic")
    public ApiResult<List<Map<String ,Object>>> gridMemderViceStatistic(){
        return ApiResult.success(demGridMemberService.gridMemderViceStatistic());
    }

    /**
     * 网格员信息管理-列表查询-导出
     *
     * @param gridArea      网格区域
     * @param streetTown    街镇
     * @param gridPersonnel 网格人员姓名
     * @param id            主键ID
     * @param exportTitle    文件名
     * @throws IOException
     */
    @PostMapping("gridMemberListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "gridArea", required = false) String gridArea,
                       @RequestParam(value = "streetTown", required = false) String streetTown,
                       @RequestParam(value = "gridPersonnel", required = false) String gridPersonnel,
                       @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException {
        List<DemGridMemberVO> list = demGridMemberService.gridMemberListExport(gridArea, streetTown, gridPersonnel, id);
        ExcelUtil<DemGridMemberVO> util = new ExcelUtil<DemGridMemberVO>(DemGridMemberVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 网格员信息管理-新增
     *
     * @param demGridMember
     * @return
     */
    @Log(title = "网格员信息管理-新增", businessType = BusinessType.INSERT)
    @PostMapping("addGridMember")
    public ApiResult<Void> addGridMember(@RequestBody DemGridMember demGridMember) {
        demGridMemberService.addGridMember(demGridMember);
        return ApiResult.success();
    }

    /**
     * 网格员信息管理-修改
     *
     * @param demGridMember
     * @return
     */
    @Log(title = "网格员信息管理-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateGridMember")
    public ApiResult<Void> updateGridMember(@RequestBody DemGridMember demGridMember) {
        demGridMemberService.updateGridMember(demGridMember);
        return ApiResult.success();
    }

    /**
     * 网格员信息管理-删除
     *
     * @param id 主键ID
     * @return
     */
    @Log(title = "网格员信息管理-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delGridMember")
    public ApiResult<Void> delGridMember(@RequestParam(value = "id") Integer id) {
        demGridMemberService.delGridMember(id);
        return ApiResult.success();
    }

}

