package com.unis.base.app.controller;

import com.unis.base.app.service.EquipmentService;
import com.unis.base.client.EquipmentFeign;
import com.unis.base.common.vo.DSbxxsjyQueryVO;
import com.unis.base.common.vo.DSbxxsjyVO;
import com.unis.base.common.vo.EquipmentRecordsVO;
import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author WangZL
 * @version 1.0
 * @Title EquipmentController
 * @ProjectName 设备信息 Controller
 * @Description
 * @date 2019/07/22 17点26分
 */
@RestController
@Api(value = "设备信息", tags = "设备信息")
@Slf4j
public class EquipmentController {

	@Autowired
	private EquipmentFeign equipmentFeign;

	@Autowired
	private EquipmentService equipmentService;

	@ApiOperation(value = "获取设备信息列表", notes = "参数：设备编号，设备名称，库点编号，库点名称，设备类型，设备状态, 机构ID")
	@PostMapping(value = "/equipmentList")
	public ResponseWrapper getDSbxxsjyList(@RequestBody DSbxxsjyQueryVO dSbxxsjyQueryVO){
		return equipmentFeign.getDSbxxsjyList(dSbxxsjyQueryVO);
	}

	@ApiOperation(value = "分页获取设备信息列表", notes = "参数：设备编号，设备名称，库点编号，库点名称，设备类型，设备状态, 机构ID")
	@PostMapping(value = "/equipmentPage/{pageNum}/{pageSize}")
	public ResponseWrapper getDSbxxsjyPage(@RequestBody DSbxxsjyQueryVO dSbxxsjyQueryVO, @PathVariable("pageNum")Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
		return equipmentFeign.getDSbxxsjyPage(dSbxxsjyQueryVO,pageNum,pageSize);
	}

	@ApiOperation(value = "根据设备编码获取设备信息", notes = "参数：库点编号")
	@GetMapping(value = "/equipment/{sbbh}")
	public ResponseWrapper getDSbxxsjyInfoBysbbh(@PathVariable("sbbh")String sbbh) {
        return equipmentFeign.getDSbxxsjyInfoBysbbh(sbbh);
	}

	@ApiOperation(value = "更新设备信息", notes = "参数：设备编号")
	@PutMapping(value = "/equipment")
	public ResponseWrapper update(@RequestBody DSbxxsjyVO dSbxxsjyVO) {
		dSbxxsjyVO.setRefresher(CurrentUtil.getUserName());
		dSbxxsjyVO.setRefreshTime(new Date());
        return equipmentFeign.update(dSbxxsjyVO);
	}

	@DeleteMapping(value="/equipment/{sbbh}")
	@ApiOperation(value = "根据设备编号删除设备信息", notes = "参数：设备编号")
	public ResponseWrapper delete(@PathVariable("sbbh")String sbbh) {
        return equipmentFeign.delete(sbbh);
    }

	@PostMapping(value = "/equipment")
	@ApiOperation(value = "新增设备信息", notes = "参数：设备仪器名称，库点代码")
    public ResponseWrapper insert(@RequestBody DSbxxsjyVO dSbxxsjyVO) {
		dSbxxsjyVO.setCreator(CurrentUtil.getUserName());
		dSbxxsjyVO.setCreateDate(new Date());
        return equipmentFeign.insert(dSbxxsjyVO);
    }

	@PostMapping(value = "/equipmentFilingStatus")
	@ApiOperation(value = "设备信息-更改备案状态", notes = "参数：备案信息")
	public ResponseWrapper updateFilingStatus(@RequestBody EquipmentRecordsVO equipmentRecordsVO) {
		return equipmentFeign.updateFilingStatus(equipmentRecordsVO);
	}

	@PostMapping(value = "/equipmentInsertList")
	@ApiOperation(value = "设备信息-新增列表", notes = "参数：设备信息列表")
	public ResponseWrapper insertList(@RequestBody List<DSbxxsjyVO> dSbxxsjyVOList) {
		return equipmentService.insertList(dSbxxsjyVOList);
	}

	@ApiOperation(value = "设备信息-根据库点获取设备信息列表", notes = "参数：库点代码")
	@PostMapping(value = "/equipmentListByKddm/{kddm}")
	public ResponseWrapper getEquipmentListByKddm(@PathVariable("kddm")String kddm){
		return equipmentFeign.getEquipmentListByKddm(kddm);
	}

	@PostMapping(value = "/equipmentBatch")
	@ApiOperation(value = "新增设备信息", notes = "参数：设备仪器名称，库点代码")
    public ResponseWrapper insertBatch(@RequestBody DSbxxsjyVO dSbxxsjyVO) {

		return equipmentFeign.insertBatch(dSbxxsjyVO);
	}

	@PutMapping(value = "/equipmentBatch")
	@ApiOperation(value = "批量修改", notes = "参数：设备仪器名称，库点代码")
	public ResponseWrapper updateBatch(@RequestBody DSbxxsjyVO dSbxxsjyVO) {

		return equipmentFeign.updateBatch(dSbxxsjyVO);
	}
}
