package com.njcn.device.pq.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.device.line.mapper.DeptLineMapper;
import com.njcn.device.line.service.DeptLineService;
import com.njcn.device.pq.pojo.po.DeptLine;
import com.njcn.device.pq.pojo.vo.LineDeviceStateVO;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.DeptLineParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author denghuajun
 * @date 2022/1/12 16:33
 *  部门监测点相关
 */
@Validated
@Slf4j
@Api(tags = "部门监测点相关")
@RestController
@RequestMapping("/deptLine")
@RequiredArgsConstructor
public class DeptLineController extends BaseController {

    private final DeptLineService deptLineService;
    private final DeptLineMapper deptLineMapper;

    /**
     * 部门绑定监测点
     *
     * @param deptLineParam 部门监测点
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/deptBindLine")
    @ApiOperation("部门绑定监测点")
    @ApiImplicitParam(name = "deptLineParam", value = "部门绑定监测点", required = true)
    public HttpResult deptBindLine(@RequestBody @Validated DeptLineParam deptLineParam) {
        String methodDescribe = getMethodDescribe("deptBindLine");
        LogUtil.njcnDebug(log, "{}，部门监测点数据为：{}", methodDescribe, deptLineParam);
        deptLineService.deptBindLine(deptLineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    /**
     * 部门解除绑定监测点
     *
     * @param deptLineParam 部门监测点
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/deptDeleteBindLine")
    @ApiOperation("部门解除绑定监测点")
    @ApiImplicitParam(name = "deptLineParam", value = "部门绑定监测点", required = true)
    public HttpResult deptDeleteBindLine(@RequestBody @Validated DeptLineParam deptLineParam) {
        String methodDescribe = getMethodDescribe("deptDeleteBindLine");
        LogUtil.njcnDebug(log, "{}，部门监测点数据为：{}", methodDescribe, deptLineParam);
        deptLineService.deptDeleteBindLine(deptLineParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    /**
     * 根据部门ids集合查询是否绑定监测点
     *
     * @param ids 部门id
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/selectDeptBindLines")
    @ApiOperation("查询是否绑定监测点")
    @ApiImplicitParam(name = "ids", value = "部门id", required = true)
    public HttpResult selectDeptBindLines(@RequestParam("ids") List<String> ids) {
        String methodDescribe = getMethodDescribe("selectDeptBindLines");
        deptLineService.selectDeptBindLines(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    /**
     * 根据部门id解除绑定监测点
     *
     * @param id 部门id
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/removeBind")
    @ApiOperation("部门解除绑定监测点")
    @ApiImplicitParam(name = "id", value = "部门id", required = true)
    public HttpResult<Integer> removeBind(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("removeBind");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptLineService.removeBind(id), methodDescribe);
    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getLineByDeptId")
    @ApiOperation("部门Id获取绑定监测点")
    @ApiImplicitParam(name = "id", value = "部门id", required = true)
    public HttpResult<List<String>> getLineByDeptId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineByDeptId");
        List<String> list = deptLineService.getLineByDeptId(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getLineByDeptIdAndNewStation")
    @ApiOperation("根据部门id获取绑定的监测点且再根据（监测点详情进行过滤）")
    public HttpResult<List<String>> getLineByDeptIdAndNewStation(@RequestParam(value = "id",required = false) String id) {
        String methodDescribe = getMethodDescribe("getLineByDeptIdAndNewStation");
        List<String> list = deptLineService.getLineByDeptIdAndNewStation(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getLineDetailByDeptId")
    @ApiOperation("部门Id获取绑定监测点详情")
    @ApiImplicitParam(name = "id", value = "部门id", required = true)
    public HttpResult<List<LineDeviceStateVO>> getLineDetailByDeptId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineDetailByDeptId");
        List<LineDeviceStateVO> list = deptLineService.getLineDetailByDeptId(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @PostMapping("/getLineByDeptRelation")
    @ApiOperation("获取部门和监测点的关系（分稳态暂态）")
    @ApiImplicitParam(name = "devDataType", value = "数据类型（0：暂态系统；1：稳态系统；）", required = true)
    public HttpResult<Map<String,List<String>> > getLineByDeptRelation(@RequestParam("devDataType") Integer devDataType) {
        String methodDescribe = getMethodDescribe("getLineByDeptRelation");
        Map<String,List<String>> map= deptLineService.getLineByDeptRelation(devDataType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, map, methodDescribe);
    }

    @PostMapping("/getLineByLineIds")
    @ApiOperation("根据监测点获取部门id")
    public HttpResult<DeptLine> getLineByLineIds(@RequestParam("id") String ids) {
        String methodDescribe = getMethodDescribe("getLineByLineIds");
        DeptLine lineByLineIds = deptLineService.getLineByLineIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineByLineIds, methodDescribe);
    }

    @PostMapping("/getDeptListByLineId")
    @ApiOperation("根据监测点获取部门id(集合)")
    public HttpResult<List<DeptLine>> getDeptListByLineId(@RequestParam("id") String ids) {
        String methodDescribe = getMethodDescribe("getDeptListByLineId");
        List<DeptLine> lineByLineIds = deptLineService.getDeptListByLineId(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineByLineIds, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getLineNodeByDeptId")
    @ApiOperation("部门Id获取所有子集部门绑定监测点")
    @ApiImplicitParam(name = "id", value = "部门id", required = true)
    public HttpResult<List<String>> getLineNodeByDeptId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineNodeByDeptId");
        List<String> list = deptLineService.getLineNodeByDeptId(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getAllData")
    @ApiOperation("获取部门监测点表数据(仅查询在运监测点)")
    public HttpResult<List<DeptLine>> getAllData() {
        String methodDescribe = getMethodDescribe("getAllData");
        List<DeptLine> list = deptLineMapper.getOnlineMonitor();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
