package com.njcn.device.device.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.DataStateEnum;
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.device.service.PqDevTypeService;
import com.njcn.device.pq.pojo.param.PqDevTypeParam;
import com.njcn.device.pq.pojo.po.PqDevType;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 前置程序控制器
 *
 * @author cdf
 * @since 2022-01-07
 */
@Slf4j
@Api(tags = "装置型号管理")
@RestController
@RequestMapping("/devType")
@RequiredArgsConstructor
public class PqDevTypeController extends BaseController {

    private final PqDevTypeService pqDevTypeService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDevTypeList")
    @ApiOperation("查询装置型号全部信息")
    public HttpResult<List<PqDevType>> getDevTypeList() {
        String methodDescribe = getMethodDescribe("getDevTypeList");
        List<PqDevType> list = pqDevTypeService.list(new LambdaQueryWrapper<PqDevType>()
                .eq(PqDevType::getState, DataStateEnum.ENABLE.getCode())
                .orderByDesc(PqDevType::getCreateTime)
        );
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageDevTypeList")
    @ApiOperation("分页查询装置型号信息")
    public HttpResult<Page<PqDevType>> pageDevTypeList(@RequestBody BaseParam param) {
        String methodDescribe = getMethodDescribe("pageDevTypeList");
        Page<PqDevType> list = pqDevTypeService.pageDevTypeList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @ApiOperation("新增装置型号")
    @PostMapping("/addDevType")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.ADD)
    public HttpResult<Boolean> addDevType(@RequestBody PqDevTypeParam param) {
        String methodDescribe = getMethodDescribe("addDevType");
        Boolean result = pqDevTypeService.addDevType(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @ApiOperation("更新装置型号")
    @PostMapping("/updateDevType")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.UPDATE)
    public HttpResult<Boolean> updateDevType(@RequestBody PqDevTypeParam.PqDevTypeUpdateParam param) {
        String methodDescribe = getMethodDescribe("updateDevType");
        Boolean result = pqDevTypeService.updateDevType(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @PostMapping("/delDevType")
    @ApiOperation(value = "删除新装置型号")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    public HttpResult<Boolean> delIDevType(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delIDevType");
        Boolean flag = pqDevTypeService.delIDevType(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


}

