package com.njcn.device.pq.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.pq.pojo.dto.PqIcdPathDTO;
import com.njcn.device.pq.pojo.param.PqIcdPathParam;
import com.njcn.device.pq.pojo.po.PqIcdPath;
import com.njcn.device.pq.service.PqIcdPathService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


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

    private final PqIcdPathService pqIcdPathService;


    /**
     * 根据终端模型获取icd模型，如果模型为空则获取全部icd模型
     */
    @ApiOperation("前置获取icd模型")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
    @PostMapping("/icdPathList")
    public HttpResult<List<PqIcdPathDTO>> icdPathList(@RequestBody List<String> devType) {
        String methodDescribe = getMethodDescribe("icdPathList");
        List<PqIcdPathDTO> list = pqIcdPathService.icdPathList(devType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageIcdList")
    @ApiOperation("分页查询icd信息")
    public HttpResult<Page<PqIcdPath>> pageIcdList(@RequestBody BaseParam param) {
        String methodDescribe = getMethodDescribe("pageIcdList");
        Page<PqIcdPath> list = pqIcdPathService.pageIcdList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @ApiOperation("新增icd模型")
    @PostMapping("/addIcdPath")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.ADD)
    public HttpResult<Boolean> addIcdPath(@RequestBody PqIcdPathParam pqIcdPathParam) {
        String methodDescribe = getMethodDescribe("addIcdPath");
        Boolean result = pqIcdPathService.addIcdPath(pqIcdPathParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @ApiOperation("更新icd模型")
    @PostMapping("/updateIcdPath")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.UPDATE)
    public HttpResult<Boolean> updateIcdPath(@RequestBody PqIcdPathParam.PqIcdPathUpdateParam pqIcdPathUpdateParam) {
        String methodDescribe = getMethodDescribe("updateIcdPath");
        Boolean result = pqIcdPathService.updateIcdPath(pqIcdPathUpdateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @PostMapping("/delIcdPath")
    @ApiOperation(value = "icd模型删除")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    public HttpResult<Boolean> delIcdPath(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delIcdPath");
        Boolean flag = pqIcdPathService.delIcdPath(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


}

