package com.njcn.advance.controller.govern.voltage;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.advance.pojo.param.govern.voltage.SgProductLineParam;
import com.njcn.advance.pojo.vo.govern.voltage.SgProductLineVO;
import com.njcn.advance.service.govern.voltage.ISgProductLineService;
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 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;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2024-03-14
 */
@Slf4j
@Validated
@Api(tags = "暂降治理生产线控制器")
@RestController
@RequestMapping("/sgProductLine")
@RequiredArgsConstructor
public class SgProductLineController extends BaseController {

    private final ISgProductLineService sgProductLineService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/list")
    @ApiOperation("查询用户生产线数据")
    @ApiImplicitParam(name = "sgProductLineQueryParam", value = "查询参数", required = true)
    public HttpResult<Page<SgProductLineVO>> list(@RequestBody SgProductLineParam.SgProductLineQueryParam sgProductLineQueryParam) {
        String methodDescribe = getMethodDescribe("list");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, sgProductLineQueryParam);
        Page<SgProductLineVO> result = sgProductLineService.sgProductLineListByUserId(sgProductLineQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/querySgProductLineByUserId")
    @ApiOperation("根据用户id查询所有的生产线信息")
    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
    public HttpResult<List<SgProductLineVO>> querySgProductLineByUserId(String userId) {
        String methodDescribe = getMethodDescribe("querySgProductLineByUserId");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, userId);
        List<SgProductLineVO> result = sgProductLineService.querySgProductLineByUserId(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增生产线")
    @ApiImplicitParam(name = "sgProductLineParam", value = "生产线数据", required = true)
    public HttpResult<String> add(@RequestBody @Validated SgProductLineParam sgProductLineParam) {
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，生产线数据：{}", methodDescribe, sgProductLineParam);
        String productLineId = sgProductLineService.addProductLine(sgProductLineParam);
        if (StrUtil.isNotBlank(productLineId)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, productLineId, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/update")
    @ApiOperation("更新生产线")
    @ApiImplicitParam(name = "updateParam", value = "生产线数据", required = true)
    public HttpResult<Object> update(@RequestBody @Validated SgProductLineParam.SgProductLineUpdateParam updateParam) {
        String methodDescribe = getMethodDescribe("update");
        LogUtil.njcnDebug(log, "{}，生产线数据：{}", methodDescribe, updateParam);
        boolean result = sgProductLineService.updateSgProductLine(updateParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/delete")
    @ApiOperation("删除生产线")
    @ApiImplicitParam(name = "ids", value = "生产线索引", required = true, dataTypeClass = List.class)
    public HttpResult<Object> delete(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delete");
        LogUtil.njcnDebug(log, "{}，生产线ID数据为：{}", methodDescribe, String.join(StrUtil.COMMA, ids));
        boolean result = sgProductLineService.deleteSgProductData(ids);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }









}

