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

import java.util.List;

import javax.validation.Valid;

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.basicData.TmsTransferStationByViewDTO;
import com.prolog.rdc.tms.model.dto.basicData.TmsTransferStationDTO;
import com.prolog.rdc.tms.model.dto.basicData.TmsTransferStationParsingDTO;
import com.prolog.rdc.tms.model.vo.basicData.TmsTransferStationByQueryVO;
import com.prolog.rdc.tms.model.vo.basicData.TmsTransferStationParsingVO;
import com.prolog.rdc.tms.model.vo.basicData.TmsTransferStationVO;
import com.prolog.rdc.tms.model.vo.basicData.TransferStationDeleteVO;
import com.prolog.rdc.tms.model.vo.basicData.TransferStationDisableVO;
import com.prolog.rdc.tms.model.vo.basicData.TransferStationEnableVO;
import com.prolog.rdc.tms.service.basicData.TransferStationService;

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

/**
 * 
 *
 * 基础数据-中转站控制层
 *
 * @className :TmsTransferStationController
 * @author :zhangsj
 * @creationTime :2022/03/21
 * @description :
 *
 * @modifier :zhangsj
 * @modifyTime :2022/03/21
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@RestController
@Api(tags = "基础数据-中转站控制层")
@RequestMapping("/transferStation")
public class TransferStationController {

	@Autowired
	private TransferStationService transferStationService;

	@PostMapping("/query")
	@UserLog("中转站资料查询")
	@ApiOperation(value = "中转站资料查询", notes = "中转站资料查询")
	public RestMessage<Page<TmsTransferStationDTO>> query(@RequestBody TmsTransferStationByQueryVO vo) {
		try {
			Page<TmsTransferStationDTO> list = transferStationService.query(vo);
			return RestMessage.newInstance(true, "查询成功！", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/view")
	@UserLog("中转站资料查看")
	@ApiOperation(value = "中转站资料查看", notes = "中转站资料查看")
	public RestMessage<TmsTransferStationByViewDTO> view(@RequestBody TmsTransferStationVO vo) {
		try {
			TmsTransferStationByViewDTO dto = transferStationService.view(vo);
			return RestMessage.newInstance(true, "查看成功！", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/update")
	@UserLog("中转站资料修改")
	@ApiOperation(value = "中转站资料修改", notes = "中转站资料修改")
	public RestMessage<String> update(@RequestBody @Valid TmsTransferStationVO vo) {
		try {
			transferStationService.update(vo);
			return RestMessage.newInstance(true, "修改成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/save")
	@UserLog("中转站资料新增")
	@ApiOperation(value = "中转站资料新增", notes = "中转站资料新增")
	public RestMessage<String> save(@RequestBody @Valid TmsTransferStationVO vo) {
		try {
			transferStationService.save(vo);
			return RestMessage.newInstance(true, "新增成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("中转站资料停用")
	@ApiOperation(value = "中转站资料停用", notes = "中转站资料停用")
	@PostMapping("/disable")
	public RestMessage<String> disableExecute(@RequestBody List<TransferStationDisableVO> transferStationDisableVOs) {
		try {
			transferStationService.disableData(transferStationDisableVOs);
			return RestMessage.newInstance(true, "停用成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("中转站资料启用")
	@ApiOperation(value = "中转站资料启用", notes = "中转站资料启用")
	@PostMapping("/enable")
	public RestMessage<String> enableExecute(@RequestBody List<TransferStationEnableVO> transferStationEnableVOs) {
		transferStationService.enableData(transferStationEnableVOs);
		return RestMessage.newInstance(true, "启用成功", null);
	}

	@UserLog("中转站资料删除")
	@ApiOperation(value = "中转站资料删除", notes = "中转站资料删除")
	@PostMapping("/delete")
	public RestMessage<String> deleteExecute(@RequestBody List<TransferStationDeleteVO> transferStationDeleteVOs) {
		try {
			transferStationService.deleteData(transferStationDeleteVOs);
			return RestMessage.newInstance(true, "删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/parsing")
	@UserLog("中转站资料地图解析")
	@ApiOperation(value = "中转站资料地图解析", notes = "中转站资料地图解析")
	public RestMessage<String> parsing(@RequestBody TmsTransferStationParsingVO vo) {
		try {
			transferStationService.parsing(vo);
			return RestMessage.newInstance(true, "操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/parsingPage")
	@UserLog("中转站资料地图解析")
	@ApiOperation(value = "中转站资料地图解析", notes = "中转站资料地图解析")
	public RestMessage<Page<TmsTransferStationParsingDTO>> parsingPage(@RequestBody TmsTransferStationParsingVO vo) {
		try {
			Page<TmsTransferStationParsingDTO> page = transferStationService.parsingPage(vo);
			return RestMessage.newInstance(true, "操作成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
