package com.njcn.csdevice.controller.project;

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.pojo.param.AppLineTopologyDiagramAddParm;
import com.njcn.csdevice.pojo.param.AppLineTopologyDiagramAuditParm;
import com.njcn.csdevice.pojo.param.LinePostionParam;
import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
import com.njcn.csdevice.pojo.vo.AppTopologyDiagramVO;
import com.njcn.csdevice.service.AppLineTopologyDiagramService;
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.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2023/3/30  9:02【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/lineTopologyDiagram")
@Api(tags = "拓扑图-监测点")
@AllArgsConstructor
public class LineTopologyDiagramController extends BaseController {

    private AppLineTopologyDiagramService appLineTopologyDiagramService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addLineDiagram")
    @ApiOperation("新增拓扑图-监测点绑定")
    @ApiImplicitParam(name = "appLineTopologyDiagramAddParm", value = "新增拓扑图参数", required = true)
    public HttpResult<Boolean> addLineDiagram(@RequestBody @Validated AppLineTopologyDiagramAddParm appLineTopologyDiagramAddParm){
        String methodDescribe = getMethodDescribe("addLineDiagram");
        AppLineTopologyDiagramPO appLineTopologyDiagramPO = new AppLineTopologyDiagramPO();
        BeanUtils.copyProperties (appLineTopologyDiagramAddParm,appLineTopologyDiagramPO);
        appLineTopologyDiagramPO.setStatus ("1");
        Boolean flag = appLineTopologyDiagramService.save (appLineTopologyDiagramPO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/auditLineDiagram")
    @ApiOperation("修改/删除拓扑图-监测点绑定")
    @ApiImplicitParam(name = "appLineTopologyDiagramAuditParm", value = "修改/删除拓扑图参数", required = true)
    public HttpResult<Boolean> auditLineDiagram(@RequestBody@Validated AppLineTopologyDiagramAuditParm appLineTopologyDiagramAuditParm){
        String methodDescribe = getMethodDescribe("auditLineDiagram");
        AppLineTopologyDiagramPO appLineTopologyDiagramPO = new AppLineTopologyDiagramPO();
        BeanUtils.copyProperties (appLineTopologyDiagramAuditParm,appLineTopologyDiagramPO);
        Boolean flag = appLineTopologyDiagramService.update (appLineTopologyDiagramPO,null);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryTopologyDiagram")
    @ApiOperation("查询装置拓扑图")
    public HttpResult<AppTopologyDiagramVO> queryTopologyDiagram(@RequestParam(value="devId") String devId){
        String methodDescribe = getMethodDescribe("queryTopologyDiagram");
        AppTopologyDiagramVO appTopologyDiagramVO = appLineTopologyDiagramService.query(devId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, appTopologyDiagramVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addList")
    @ApiOperation("批量新增监测点拓扑图关系")
    @ApiImplicitParam(name = "list", value = "监测点拓扑图数据集", required = true)
    public HttpResult<String> addList(@RequestBody List<AppLineTopologyDiagramPO> list){
        String methodDescribe = getMethodDescribe("addList");
        appLineTopologyDiagramService.saveBatch(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/auditList")
    @ApiOperation("批量修改监测点拓扑图关系")
    @ApiImplicitParam(name = "linePostionParam", value = "监测点拓扑图数据集", required = true)
    public HttpResult<String> auditList(@RequestBody LinePostionParam linePostionParam){
        String methodDescribe = getMethodDescribe("auditList");
        appLineTopologyDiagramService.auditList(linePostionParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
