package com.njcn.device.pms.controller.ledgerManger;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.pms.annotation.TerminalOperationLogDesc;
import com.njcn.device.pms.pojo.param.PmsBaseParam;
import com.njcn.device.pms.pojo.param.PmsTerminalParam;
import com.njcn.device.pms.pojo.param.TerminalQueryParam;
import com.njcn.device.pms.pojo.po.PmsTerminal;
import com.njcn.device.pms.pojo.vo.PmsTerminalVO;
import com.njcn.device.pms.service.majornetwork.ITerminalService;
import com.njcn.web.pojo.param.BaseParam;
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 com.njcn.web.controller.BaseController;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  监测终端台账增删改查
 * </p>
 *
 * @author hongawen
 * @since 2022-10-14
 */
@Slf4j
@RestController
@RequestMapping("/pms/terminal")
@Api(tags = "台账-监测终端台账")
@RequiredArgsConstructor
@Validated
public class PmsTerminalController extends BaseController {

    private final ITerminalService iTerminalService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("getTerminalList")
    @ApiOperation("分页查询监测终端台账所有信息")
    @ApiImplicitParam(name = "baseParam",value = "查询监测终端台账信息",required = true)
    public HttpResult<Page<PmsTerminal>> getTerminalList(@RequestBody @Validated TerminalQueryParam baseParam){
        String methodDescribe = getMethodDescribe("getTerminalList");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, baseParam);
        Page<PmsTerminal> res = iTerminalService.getTerminalList(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("getTerminalSelectList")
    @ApiOperation("查询监测终端台账所有信息")
    public HttpResult<List<PmsTerminal>> getTerminalSelectList(@RequestBody PmsBaseParam pmsBaseParam){
        String methodDescribe = getMethodDescribe("getTerminalSelectList");
        List<PmsTerminal> res = iTerminalService.getTerminalSelectList(pmsBaseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getTerminalById")
    @ApiOperation("根据ID查询监测终端台账数据")
    @ApiImplicitParam(name = "id",value = "id",required = true)
    public HttpResult<PmsTerminal> getTerminalById(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getTerminalById");
        PmsTerminal pmsTerminal = iTerminalService.getTerminalById(id);
        if (Objects.nonNull(pmsTerminal)){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pmsTerminal, methodDescribe);
        }
        else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getTerminalSelectByIds")
    @ApiOperation("根据ID集合查询监测终端台账数据")
    @ApiImplicitParam(name = "ID集合",value = "ids",required = true)
    public HttpResult<List<PmsTerminal>> getTerminalSelectByIds(@RequestBody List<String> ids){
        String methodDescribe = getMethodDescribe("getTerminalSelectByIds");
        List<PmsTerminal> pmsTerminal = iTerminalService.getTerminalSelectByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pmsTerminal, methodDescribe);
    }

    /**
     * 新增监测终端台账信息
     * @author hany
     * @date 2022/10/26
     */
    @PostMapping("/addTerminal")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType= OperateType.ADD)
    @ApiOperation("新增监测终端台账信息")
    @ApiImplicitParam(name = "terminalParam", value = "新增实体", required = true)
    @TerminalOperationLogDesc(value = "新增监测终端台账信息",module = 1)
    public HttpResult<Object> add(@RequestBody @Validated PmsTerminalParam terminalParam){
        String methodDescribe = getMethodDescribe("add");
        boolean result = iTerminalService.add(terminalParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 修改监测终端台账信息
     * @author hany
     * @date 2022/10/27
     */
    @PostMapping("/updateTerminal")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.UPDATE)
    @ApiOperation("修改监测终端台账信息")
    @ApiImplicitParam(name = "updateParam", value = "更新实体", required = true)
    @TerminalOperationLogDesc(value = "修改监测终端台账信息",module = 1)
    public HttpResult<Object> update(@RequestBody @Validated PmsTerminalParam updateParam){
        String methodDescribe = getMethodDescribe("update");
        boolean result = iTerminalService.update(updateParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 删除监测终端台账信息
     * @param ids id
     * @author hany
     * @date 2022/10/27
     */
    @PostMapping("/deleteTerminal")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @ApiOperation("删除监测终端台账信息")
    @ApiImplicitParam(name = "ids", value = "ID索引", required = true)
    public HttpResult<Object> delete(@RequestBody List<String> ids){
        String methodDescribe = getMethodDescribe("delete");
        boolean result = iTerminalService.delete(ids);
        if(result){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }
}

