package com.njcn.csdevice.controller.ledger;


import com.njcn.common.pojo.annotation.OperateInfo;
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.csdevice.mapper.CsLedgerMapper;
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csdevice.pojo.param.CsLedgerParam;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.service.ICsLedgerService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 台账表 前端控制器
 * </p>
 *
 * @author xuyang
 * @since 2023-05-31
 */
@RestController
@RequestMapping("/csLedger")
@Slf4j
@Api(tags = "治理终端台账")
@AllArgsConstructor
public class CsLedgerController extends BaseController {

    private final ICsLedgerService csLedgerService;
    private final CsLedgerMapper csLedgerMapper;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/tree")
    @ApiOperation("治理终端台账树")
    public HttpResult<List<CsLedgerVO>> ledgerTree(){
        String methodDescribe = getMethodDescribe("ledgerTree");
        List<CsLedgerVO> list = csLedgerService.getLedgerTree();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/lineTree")
    @ApiOperation("五层设备树(监测点层,根节点为治理设备和便携式设备)")
    @ApiImplicitParam(name = "type", value = "台账树类型")
    public HttpResult<List<CsLedgerVO>> lineTree(@RequestParam(required = false) @Validated String type){
        String methodDescribe = getMethodDescribe("lineTree");
        List<CsLedgerVO> list = csLedgerService.getLineTree(type);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/AppLineTree")
    @ApiOperation("app端监测点树")
    public HttpResult<List<CsLedgerVO>> appLineTree(){
        String methodDescribe = getMethodDescribe("appLineTree");
        List<CsLedgerVO> list = csLedgerService.appLineTree();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deviceTree")
    @ApiOperation("四层设备树(装置层,根节点为治理设备和便携式设备)")
    @ApiImplicitParam(name = "type", value = "台账树类型")
    public HttpResult<List<CsLedgerVO>> getDeviceTree(@RequestParam(required = false) @Validated String type){
        String methodDescribe = getMethodDescribe("getDeviceTree");
        List<CsLedgerVO> list = csLedgerService.getDeviceTree(type);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getztProjectTree")
    @ApiOperation("三层设备树(项目层根节点为治理系统和便携式系统组态)")
    public HttpResult<List<CsLedgerVO>> getztProjectTree(){
        String methodDescribe = getMethodDescribe("getProjectTree");
        List<CsLedgerVO> list = csLedgerService.getztProjectTree();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


//    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
//    @PostMapping("/objTree")
//    @ApiOperation("三层对象用户树")
//    public HttpResult<List<CsLedgerVO>> objTree(){
//        String methodDescribe = getMethodDescribe("getProjectTree");
//        List<CsLedgerVO> list = csLedgerService.objTree();
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
//    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/add")
    @ApiOperation("新增台账信息")
    @ApiImplicitParam(name = "csLedgerParam", value = "新增台账实体", required = true)
    public HttpResult<CsLedger> add(@RequestBody @Validated CsLedgerParam csLedgerParam){
        String methodDescribe = getMethodDescribe("add");
        CsLedger csLedger = csLedgerService.addLedgerTree(csLedgerParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csLedger, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/delete")
    @ApiOperation("删除台账信息")
    @ApiImplicitParam(name = "id", value = "数据id", required = true)
    public HttpResult<String> delete(@RequestParam @Validated String id){
        String methodDescribe = getMethodDescribe("delete");
        csLedgerService.deleteLedgerTree(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/update")
    @ApiOperation("更新台账信息")
    @ApiImplicitParam(name = "csLedgerParam", value = "更新台账实体", required = true)
    public HttpResult<String> update(@RequestBody @Validated CsLedgerParam.Update csLedgerParam){
        String methodDescribe = getMethodDescribe("update");
        csLedgerService.updateLedgerTree(csLedgerParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/findDevByLineId")
    @ApiOperation("根据监测点Id查询装置")
    @ApiImplicitParam(name = "lineId", value = "监测点Id", required = true)
    public HttpResult<String> findDevByLineId(@RequestParam @Validated String lineId){
        String methodDescribe = getMethodDescribe("findDevByLineId");
        String deviceId = csLedgerService.findDevByLineId(lineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deviceId, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getProjectTree")
    @ApiOperation("工程-项目-拓扑图树")
    public HttpResult<List<CsLedgerVO>> getProjectTree(){
        String methodDescribe = getMethodDescribe("getProjectTree");
        List<CsLedgerVO> list = csLedgerService.getProjectTree();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryLine")
    @ApiOperation("按条件查询监测点")
    @ApiImplicitParam(name = "lineParamdto", value = "查询条件", required = true)
    public HttpResult<List<CsLedger>> queryLine(@RequestBody @Validated LineParamDTO lineParamdto){
        String methodDescribe = getMethodDescribe("queryLine");
        List<CsLedger> list = csLedgerService.queryLine(lineParamdto);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryDevDetail")
    @ApiOperation("根据设备号查询工程，项目，设备")
    @ApiImplicitParam(name = "devId", value = "查询条件", required = true)
    public HttpResult<DevDetailDTO> queryDevDetail(@RequestParam @Validated String devId){
        String methodDescribe = getMethodDescribe("queryDevDetail");
        DevDetailDTO details = csLedgerService.queryDevDetail(devId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, details, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getAllLedger")
    @ApiOperation("获取台账树所有数据")
    public HttpResult<List<CsLedgerVO>> getAllLedger(){
        String methodDescribe = getMethodDescribe("getAllLedger");
        List<CsLedgerVO> allList = csLedgerMapper.getAll();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, allList, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/cldTree")
    @ApiOperation("云前置树")
    public HttpResult<CsLedgerVO> cldTree(){
        String methodDescribe = getMethodDescribe("cldTree");
        CsLedgerVO vo = csLedgerService.cldTree();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getInfoByIds")
    @ApiOperation("根据设备集合查询工程，设备信息")
    @ApiImplicitParam(name = "list", value = "查询条件", required = true)
    public HttpResult<List<DevDetailDTO>> getInfoByIds(@RequestBody @Validated List<String> list){
        String methodDescribe = getMethodDescribe("getInfoByIds");
        List<DevDetailDTO> details = csLedgerService.getInfoByIds(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, details, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDevInfoByEngineerIds")
    @ApiOperation("根据工程获取设备信息")
    @ApiImplicitParam(name = "list", value = "查询条件", required = true)
    public HttpResult<List<DevDetailDTO>> getDevInfoByEngineerIds(@RequestBody @Validated List<String> list){
        String methodDescribe = getMethodDescribe("getDevInfoByEngineerIds");
        List<DevDetailDTO> details = csLedgerService.getDevInfoByEngineerIds(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, details, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEngineeringHaveDevs")
    @ApiOperation("根据工程信息获取有设备的工程")
    @ApiImplicitParam(name = "list", value = "查询条件", required = true)
    public HttpResult<List<DevDetailDTO>> getEngineeringHaveDevs(@RequestBody @Validated List<String> list){
        String methodDescribe = getMethodDescribe("getEngineeringHaveDevs");
        List<DevDetailDTO> details = csLedgerService.getEngineeringHaveDevs(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, details, methodDescribe);
    }

}

