package com.unis.crk.hardware.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.unis.crk.hardware.entity.Hardware;
import com.unis.crk.hardware.entity.vo.HardwareVo;
import com.unis.crk.hardware.entity.vo.UnithardwareVo;
import com.unis.crk.hardware.service.IHardwareService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.unis.crk.utils.ResultUtil;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 硬件类型表 前端控制器
 * </p>
 *
 * @author ghh
 * @since 2021-09-15
 */

@Api(value = "硬件类型表",tags = {"硬件类型表"})
@RestController
@RequestMapping("hardware")
@CrossOrigin
public class HardwareController {

    private final static Logger LOGGER = LoggerFactory.getLogger(HardwareController.class);


    @Autowired
    private IHardwareService hardwareService;


    /**
     * 根据ID查询数据
     * @return
     */
    @ApiOperation(value="查询", notes="根据ID查询数据")
    @PostMapping(value="/getOne")
    public ResultUtil getOne(@RequestBody HardwareVo hardwareVo){
        LOGGER.info("入参为:{}",hardwareVo.getHIID());
        ResultUtil<Hardware> data = new ResultUtil<>();
        if (StringUtils.isEmpty(hardwareVo.getHIID())){
            data.failed("传入的主键为空");
            return data;
        }
        data.success(this.hardwareService.getById(hardwareVo.getHIID()));
        return data;
    }


    /**
     * 查询全部数据
     * @return
     */
    @ApiOperation(value="查询", notes="查询全部数据")
    @GetMapping("getAll")
    public ResultUtil getAll(){
        ResultUtil<List<Hardware>> data = new ResultUtil<>();
        data.success(this.hardwareService.list());
        return data;
    }


    /**
     * 新增一条数据
     * @param param
     * @return
     */
    @ApiOperation(value="新增", notes="新增一条数据")
    @PostMapping("add")
    public ResultUtil add(@RequestBody Hardware param){
        LOGGER.info("入参为:{}", param);
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (ObjectUtils.isEmpty(param)){
            data.failed("所接收对象为null");
            return data;
        }
        data.success(this.hardwareService.save(param));
        return data;
    }


    /**
     * 修改一条数据
     * @param param
     * @return
     */
    @ApiOperation(value="修改", notes="修改一条数据")
    @PatchMapping("edit")
    public ResultUtil edit(@RequestBody Hardware param){
        LOGGER.info("入参为:{}", param);
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (ObjectUtils.isEmpty(param)){
            data.failed("所接收对象为null");
            return data;
        }
        data.success(this.hardwareService.updateById(param));
        return data;
    }



    /**
     * 根据ID删除数据
     * @return
     */
    @ApiOperation(value="删除", notes="根据HIID删除数据")
    @PostMapping(value="/delete")
    public ResultUtil delete(@RequestBody HardwareVo hardwareVo){
        LOGGER.info("入参为:{}", hardwareVo.getHIID());
        ResultUtil<Boolean> data = new ResultUtil<>();
        if (StringUtils.isEmpty(hardwareVo.getHIID())){
            data.failed("所接收id为null");
            return data;
        }
        data.success(this.hardwareService.removeById(hardwareVo.getHIID()));
        return data;
    }
    /**
     * 获取硬件类型下拉
     * @return
     */
    @ApiOperation(value="查询", notes="获取硬件类型下拉")
    @GetMapping("getDropDown")
    public ResultUtil getDropDown(){
        ResultUtil<List> data = new ResultUtil<List>();
        List<Hardware> list = hardwareService.getDropDown();
        data.success(list);
        return data;
    }
}

