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

import com.prolog.product.core.easyexcel.util.ExcelUtils;
import com.prolog.rdc.tms.model.vo.xlsimport.ContainerImportVO;
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.RequestParam;
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.ContainerDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.ContainerViewDTO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerAddVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerDeleteVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerPopVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerUpdateVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerViewVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.ContainerWhetherEnableVO;
import com.prolog.rdc.tms.service.fleetManagement.ContainerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

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

	@Autowired
	private ContainerService service;

	@UserLog("容器资料分页查询")
	@ApiOperation(value = "容器资料分页查询", notes = "容器资料分页查询")
	@PostMapping("/query")
	public RestMessage<Page<ContainerDTO>> query(@RequestBody ContainerVO vo) {
		try {
			Page<ContainerDTO> 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<ContainerDTO>> pop(@RequestBody ContainerPopVO vo) {
		try {
			Page<ContainerDTO> 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("/queryByVehicle")
	public RestMessage<Page<ContainerDTO>> queryByVehicle(@RequestBody ContainerVO vo) {
		return RestMessage.newInstance(true, "查询成功", service.queryByVehicle(vo));
	}

	@UserLog("容器资料查看")
	@ApiOperation(value = "容器资料查看", notes = "容器资料查看")
	@PostMapping("/view")
	public RestMessage<ContainerViewDTO> query(@RequestBody ContainerViewVO vo) {
		try {
			ContainerViewDTO 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 ContainerAddVO 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 ContainerUpdateVO 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 ContainerWhetherEnableVO containerWhetherEnableVO) {
		try {
			service.whetherEnable(containerWhetherEnableVO);
			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 ContainerDeleteVO containerDeleteVO) {
		try {
			service.delete(containerDeleteVO);
			return RestMessage.newInstance(true, "删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("容器批量导入")
	@ApiOperation(value = "容器批量导入", notes = "容器批量导入")
	@PostMapping("/importContainer")
	public RestMessage<Object> importContainer(@RequestParam("file") MultipartFile file) {
		service.importContainer(file);
		return RestMessage.newInstance(true, "导入成功", null);
	}

	@UserLog("容器模板")
	@ApiOperation(value = "容器模板", notes = "容器模板")
	@PostMapping("/downloadTemplate")
	public RestMessage<Object> downloadTemplateExecute(HttpServletResponse response) throws IOException {
		ExcelUtils.export(response, ContainerImportVO.class, "容器模板", null, null, null, true);
		return null;
	}

	@UserLog("容器资料id集合查询")
	@ApiOperation(value = "容器资料id集合查询", notes = "容器资料id集合查询")
	@PostMapping("/findByIdList")
	public RestMessage<List<ContainerDTO>> findByIdList(@RequestBody List<Long> idList) {
		return RestMessage.newInstance(true, "操作成功！", service.findByIdList(idList));
	}
}
