package com.prolog.rdc.tms.controller.fleetManagement;

import org.springframework.beans.factory.annotation.Autowired;
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 com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.fleetManagement.InsuranceDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.InsuranceViewDTO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsuranceAddVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsuranceDeleteVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsurancePopVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsuranceUpdateVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsuranceVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsuranceViewVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.InsuranceWhetherEnableVO;
import com.prolog.rdc.tms.service.fleetManagement.InsuranceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *
 * 车队管理-保险资料控制层
 *
 * @className :InsuranceController
 * @author :zhangsj
 * @creationTime :2022/03/23
 * @description :
 *
 * @modifier :zhangsj
 * @modifyTime :2022/03/23
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@RestController
@Api(tags = "车队管理-保险资料控制层")
@RequestMapping("/insurance")
public class InsuranceController {

	@Autowired
	private InsuranceService service;

	@UserLog("保险资料分页查询")
	@ApiOperation(value = "保险资料分页查询", notes = "保险资料分页查询")
	@PostMapping("/query")
	public RestMessage<Page<InsuranceDTO>> query(@RequestBody InsuranceVO vo) {
		try {
			Page<InsuranceDTO> list = service.query(vo);
			return RestMessage.newInstance(true, "查询成功", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("保险资料弹窗")
	@ApiOperation(value = "保险资料弹窗", notes = "保险资料弹窗")
	@PostMapping("/pop")
	public RestMessage<Page<InsuranceDTO>> pop(@RequestBody InsurancePopVO vo) {
		try {
			Page<InsuranceDTO> list = service.pop(vo);
			return RestMessage.newInstance(true, "查询成功", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("保险资料查看")
	@ApiOperation(value = "保险资料查看", notes = "保险资料查看")
	@PostMapping("/view")
	public RestMessage<InsuranceViewDTO> query(@RequestBody InsuranceViewVO vo) {
		try {
			InsuranceViewDTO dto = service.view(vo);
			return RestMessage.newInstance(true, "查询成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("保险资料新增")
	@ApiOperation(value = "保险资料新增", notes = "保险资料新增")
	@PostMapping("/save")
	public RestMessage<Object> save(@RequestBody InsuranceAddVO vo) {
		try {
			service.save(vo);
			return RestMessage.newInstance(true, "新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("保险资料修改")
	@ApiOperation(value = "保险资料修改", notes = "保险资料修改")
	@PostMapping("/update")
	public RestMessage<Object> update(@RequestBody InsuranceUpdateVO vo) {
		try {
			service.update(vo);
			return RestMessage.newInstance(true, "修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("保险资料是否启用")
	@ApiOperation(value = "保险资料是否启用", notes = "保险资料是否启用")
	@PostMapping("/whether_to_enable")
	public RestMessage<Object> whetherEnableExecute(@RequestBody InsuranceWhetherEnableVO insuranceWhetherEnableVO) {
		try {
			service.whetherEnable(insuranceWhetherEnableVO);
			return RestMessage.newInstance(true, "操作成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("保险资料删除")
	@ApiOperation(value = "保险资料删除", notes = "保险资料删除")
	@PostMapping("/delete")
	public RestMessage<Object> deleteExecute(@RequestBody InsuranceDeleteVO insuranceDeleteVO) {
		try {
			service.delete(insuranceDeleteVO);
			return RestMessage.newInstance(true, "删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
