package com.njcn.harmonic.controller.upload;


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.harmonic.mapper.upload.PmsTemUserMapper;
import com.njcn.harmonic.pojo.param.upload.PmsTemProcessApprovalParam;
import com.njcn.harmonic.pojo.param.upload.PmsTemProcessTestRunParam;
import com.njcn.harmonic.pojo.po.upload.PmsTemProcessApproval;
import com.njcn.harmonic.pojo.po.upload.PmsTemProcessTestRun;
import com.njcn.harmonic.pojo.po.upload.PmsTemUserPO;
import com.njcn.harmonic.service.upload.IPmsTemProcessTestRunService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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 cdf
 * @since 2024-11-04
 */
@RestController
@RequestMapping("/process/pmsTemProcessTestRun")
@RequiredArgsConstructor
public class PmsTemProcessTestRunController extends BaseController {

    private final IPmsTemProcessTestRunService iPmsTemProcessTestRunService;

    private final PmsTemUserMapper pmsTemUserMapper;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/create")
    @ApiOperation("新增电能质量全过程试运行扩展数据")
    public HttpResult<Object> create(@RequestBody @Validated PmsTemProcessTestRunParam param) {
        String methodDescribe = getMethodDescribe("create");
        Boolean result = iPmsTemProcessTestRunService.create(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/update")
    @ApiOperation("新增电能质量全过程试运行扩展数据")
    public HttpResult<Object> update(@RequestBody @Validated PmsTemProcessTestRunParam.UpdatePmsTemProcessTestRunParamParam param) {
        String methodDescribe = getMethodDescribe("update");
        Boolean result = iPmsTemProcessTestRunService.update(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.DELETE)
    @PostMapping("/del")
    @ApiOperation("删除电能质量全过程试运行扩展数据")
    public HttpResult<Object> del(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("del");
        Boolean result = iPmsTemProcessTestRunService.del(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageList")
    @ApiOperation("分页查询电能质量全过程试运行扩展数据")
    public HttpResult<Page<PmsTemProcessTestRun>> pageList(@RequestBody PmsTemProcessTestRunParam.QueryPmsTemProcessTestRunParam param) {
        String methodDescribe = getMethodDescribe("pageList");
        Page<PmsTemProcessTestRun> result = iPmsTemProcessTestRunService.pageList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getById")
    @ApiOperation("根据id获取详情")
    public HttpResult<PmsTemProcessTestRun> getById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getById");
        PmsTemProcessTestRun result = iPmsTemProcessTestRunService.queryById(id);
        if(Objects.nonNull(result.getTempUserDossierId())){
            PmsTemUserPO temUserPO = pmsTemUserMapper.selectById(result.getTempUserDossierId());
            result.setMaintOrg(temUserPO.getMaintOrg());
            result.setMaintOrgName(temUserPO.getMaintOrgName());
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }




    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/upGw")
    @ApiOperation("上送国网")
    public HttpResult<Boolean> upGw(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("upGw");
        iPmsTemProcessTestRunService.upGw(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


}

