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

import cn.hutool.core.collection.CollUtil;
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.device.pms.pojo.dto.PmsTractionStationDTO;
import com.njcn.device.pms.pojo.param.PmsTractionStationParam;
import com.njcn.device.pms.pojo.param.TractionStationParam;
import com.njcn.device.pms.pojo.po.TractionStation;
import com.njcn.device.pms.service.majornetwork.ITractionStationService;
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/tractionStation")
@Api(tags = "台账-牵引站信息")
@RequiredArgsConstructor
@Validated
public class PmsTractionStationController extends BaseController {

    private final ITractionStationService iTractionStationService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTractionStationList")
    @ApiOperation("获取牵引站列表")
    public HttpResult<List<TractionStation>> getTractionStationList() {
        String methodDescribe = getMethodDescribe("getTractionStationList");
        List<TractionStation> result = iTractionStationService.getTractionStationList();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTractionStationPageList")
    @ApiOperation("分页获取牵引站列表")
    @ApiImplicitParam(name = "baseParam", value = "基本查询体", required = true)
    public HttpResult<Page<TractionStation>> getTractionStationPageList(@RequestBody BaseParam baseParam) {
        String methodDescribe = getMethodDescribe("getTractionStationPageList");
        Page<TractionStation> result = iTractionStationService.getTractionStationPageList(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getTractionStationById")
    @ApiOperation("根据id获取牵引站信息")
    @ApiImplicitParam(name = "tractionStationId", value = "电站id", required = true)
    public HttpResult<TractionStation> getTractionStationById(@RequestParam("tractionStationId") String tractionStationId) {
        String methodDescribe = getMethodDescribe("getTractionStationById");
        TractionStation res = iTractionStationService.getTractionStationById(tractionStationId);
        if (Objects.nonNull(res)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);

    }

    /**
     * 新增牵引站信息
     *
     * @author hany
     * @date 2022/10/28
     */
    @PostMapping("/addTractionStation")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @ApiOperation("新增牵引站信息")
    @ApiImplicitParam(name = "tractionStationParam", value = "新增实体", required = true)
    public HttpResult<Object> add(@RequestBody @Validated TractionStationParam tractionStationParam) {
        String methodDescribe = getMethodDescribe("add");
        boolean result = iTractionStationService.add(tractionStationParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 修改牵引站信息
     *
     * @author hany
     * @date 2022/10/28
     */
    @PostMapping("/updateTractionStation")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @ApiOperation("修改牵引站信息")
    @ApiImplicitParam(name = "updateParam", value = "更新实体", required = true)
    public HttpResult<Object> update(@RequestBody @Validated TractionStationParam updateParam) {
        String methodDescribe = getMethodDescribe("update");
        boolean result = iTractionStationService.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/28
     */
    @PostMapping("/deleteTractionStation")
    @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 = iTractionStationService.delete(ids);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 获取牵引站详细信息
     *
     * @param param 条件参数
     * @return com.njcn.common.pojo.response.HttpResult<java.util.List < com.njcn.device.pms.pojo.dto.PmsTractionStationDTO>>
     * @author yzh
     * @date 2022/11/8
     */
    @PostMapping("/getPmsTractionStationInfo")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取牵引站详细信息")
    @ApiImplicitParam(name = "param", value = "条件参数", required = true)
    public HttpResult<List<PmsTractionStationDTO>> getPmsTractionStationInfo(@RequestBody PmsTractionStationParam param) {
        String methodDescribe = getMethodDescribe("getPmsTractionStationInfo");
        List<PmsTractionStationDTO> result = iTractionStationService.getPmsTractionStationInfo(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}

