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.PmsTemProcessTrackParam;
import com.njcn.harmonic.pojo.po.upload.PmsTemProcessApproval;
import com.njcn.harmonic.pojo.po.upload.PmsTemProcessTrackPO;
import com.njcn.harmonic.pojo.po.upload.PmsTemUserPO;
import com.njcn.harmonic.service.upload.PmsTemProcessApprovalService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 电能质量评估问题
 * </p>
 *
 * @author cdf
 * @since 2024-10-09
 */
@RestController
@RequestMapping("/process/processApproval")
@RequiredArgsConstructor
public class PmsTemProcessApprovalController extends BaseController {

    private final PmsTemProcessApprovalService pmsTemProcessApprovalService;

    private final PmsTemUserMapper pmsTemUserMapper;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
    @PostMapping("/create")
    @ApiOperation("新增电能质量评估问题整改数据")
    public HttpResult<Object> createOrUpdate(@RequestBody @Validated PmsTemProcessApprovalParam param) {
        String methodDescribe = getMethodDescribe("createOrUpdate");
        Boolean result = pmsTemProcessApprovalService.createOrUpdate(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 = pmsTemProcessApprovalService.removeByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageList")
    @ApiOperation("分页查询电能质量评估问题整改数据")
    public HttpResult<Page<PmsTemProcessApproval>> pageList(@RequestBody PmsTemProcessApprovalParam.QueryPmsTemProcessApprovalParam param) {
        String methodDescribe = getMethodDescribe("pageList");
        Page<PmsTemProcessApproval> result = pmsTemProcessApprovalService.pageList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getById")
    @ApiOperation("根据id获取详情")
    public HttpResult<PmsTemProcessApproval> getById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getById");
        PmsTemProcessApproval result = pmsTemProcessApprovalService.getById(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");
        pmsTemProcessApprovalService.upGw(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


}

