package com.njcn.device.pq.controller.jb;


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.PowerDistributionareaParam;
import com.njcn.device.pms.pojo.param.TaiZhangParam;
import com.njcn.device.pq.pojo.po.jb.DistributionArea;
import com.njcn.device.pq.service.IPowerDistributionAreaService;
import com.njcn.web.controller.BaseController;
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 java.util.List;

/**
 * <p>
 *  台区信息增删改查
 * </p>
 *
 * @author hongawen
 * @since 2022-10-14
 */
@Slf4j
@RestController
@RequestMapping("/distributionArea")
@Api(tags = "台账-台区信息")
@RequiredArgsConstructor
@Validated
public class PmsPowerDistributionAreaController extends BaseController {

    private final IPowerDistributionAreaService powerDistributionAreaService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("getPowerDistributionAreaList")
    @ApiOperation("分页查询台区所有信息")
    @ApiImplicitParam(name = "baseParam",value = "查询台区信息",required = true)
    public HttpResult<Page<DistributionArea>> getList(@RequestBody TaiZhangParam baseParam){
        String methodDescribe = getMethodDescribe("getList");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, baseParam);
        Page<DistributionArea> res = powerDistributionAreaService.getList(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,res,methodDescribe);
    }

    /**
     * 新增台区信息
     * @author hany
     * @date 2022/10/26
     */
    @PostMapping("/addPowerDistributionArea")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType=OperateType.ADD)
    @ApiOperation("新增台区信息")
    @ApiImplicitParam(name = "newParam", value = "模板实体", required = true)
    @TerminalOperationLogDesc(value = "新增台区信息",module = 3)
    public HttpResult<Object> add(@RequestBody @Validated PowerDistributionareaParam newParam){
        String methodDescribe = getMethodDescribe("add");
        boolean result = powerDistributionAreaService.add(newParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 修改台区信息
     * @author hany
     * @date 2022/10/26
     */
    @PostMapping("/updatePowerDistributionArea")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON,operateType = OperateType.UPDATE)
    @ApiOperation("修改台区信息")
    @ApiImplicitParam(name = "UpdateParam", value = "更新实体", required = true)
    @TerminalOperationLogDesc(value = "修改台区信息",module = 3)
    public HttpResult<Object> update(@RequestBody @Validated PowerDistributionareaParam UpdateParam){
        String methodDescribe = getMethodDescribe("update");
        boolean result = powerDistributionAreaService.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/26
     */
    @PostMapping("/deletePowerDistributionArea")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @ApiOperation("删除台区信息")
    @ApiImplicitParam(name = "ids", value = "ID索引", required = true)
    @TerminalOperationLogDesc(value = "删除台区信息",module = 3)
    public HttpResult<Object> delete(@RequestBody List<String> ids){
        String methodDescribe = getMethodDescribe("delete");
        boolean result = powerDistributionAreaService.delete(ids);
        if(result){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }



}

