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

import java.util.List;
import java.util.Map;

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.basicConfigure.LineMthStrategyPageDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.LineMthStrategyViewDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.ShipbillMatchLineDTO;
import com.prolog.rdc.tms.model.vo.basicConfigure.LineMthStrategyPageVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.LineMthStrategySaveVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.LineMthStrategyUpdateVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.LineMthStrategyViewVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ShipbillMatchLineVO;
import com.prolog.rdc.tms.service.basicConfigure.LineMthStrategyService;

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

/**
 * 线路匹配策略业务控制层
 *
 * @author :lhb
 * @version :1.0.0
 * @className :LineMthStrategyController
 * @creationTime :2022/05/07
 * @description :
 * @modifier :
 * @modifyTime :
 * @reviseRemarks:
 */
@RestController
@Api(tags = "策略中心-线路匹配策略业务控制层")
@RequestMapping("/line_match_strategy")
public class LineMthStrategyController {

	@Autowired
	private LineMthStrategyService lineMthStrategyService;

	@UserLog("线路匹配策略分页查询")
	@ApiOperation(httpMethod = "POST", value = "线路匹配策略分页查询")
	@PostMapping(value = "/page")
	public RestMessage<Page<LineMthStrategyPageDTO>> pageQueryExecute(@RequestBody LineMthStrategyPageVO pageVO) {
		try {
			Page<LineMthStrategyPageDTO> pageDTOs = lineMthStrategyService.pageQuery(pageVO);
			return RestMessage.newInstance(true, "线路匹配策略分页查询成功", pageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("线路匹配策略保存")
	@ApiOperation(httpMethod = "POST", value = "线路匹配策略保存")
	@PostMapping(value = "/save")
	public RestMessage<String> saveExecute(@RequestBody LineMthStrategySaveVO lineMthStrategySaveVO) {
		try {
			lineMthStrategyService.save(lineMthStrategySaveVO);
			return RestMessage.newInstance(true, "线路匹配策略保存成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("线路匹配策略修改")
	@ApiOperation(httpMethod = "POST", value = "线路匹配策略修改")
	@PostMapping(value = "/update")
	public RestMessage<String> updateExecute(@RequestBody LineMthStrategyUpdateVO lineMthStrategyUpdateVO) {
		try {
			lineMthStrategyService.update(lineMthStrategyUpdateVO);
			return RestMessage.newInstance(true, "线路匹配策略修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("线路匹配策略停用")
	@ApiOperation(httpMethod = "POST", value = "线路匹配策略停用")
	@PostMapping(value = "/stop")
	public RestMessage<String> stopExecute(@RequestBody List<Long> ids) {
		try {
			lineMthStrategyService.stop(ids);
			return RestMessage.newInstance(true, "线路匹配策略停用成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("线路匹配策略启用")
	@ApiOperation(httpMethod = "POST", value = "线路匹配策略启用")
	@PostMapping(value = "/enable")
	public RestMessage<String> enableExecute(@RequestBody List<Long> ids) {
		try {
			lineMthStrategyService.enable(ids);
			return RestMessage.newInstance(true, "线路匹配策略启用成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("线路匹配策略查看")
	@ApiOperation(httpMethod = "POST", value = "线路匹配策略查看")
	@PostMapping(value = "/view")
	public RestMessage<LineMthStrategyViewDTO> viewExecute(@RequestBody LineMthStrategyViewVO viewVO) {
		try {
			LineMthStrategyViewDTO viewDTO = lineMthStrategyService.view(viewVO);
			return RestMessage.newInstance(true, "线路匹配策略查看成功", viewDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("根据运单匹配线路策略")
	@ApiOperation(httpMethod = "POST", value = "根据运单匹配线路策略")
	@PostMapping(value = "/shipbill_match_line")
	public RestMessage<ShipbillMatchLineDTO> shipbillMatchLineExecute(@RequestBody ShipbillMatchLineVO matchLineVO) {
		try {
			ShipbillMatchLineDTO lineDTO = lineMthStrategyService.shipbillMatchLine(matchLineVO);
			return RestMessage.newInstance(true, "匹配线路策略成功", lineDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("运单批量匹配线路策略")
	@ApiOperation(httpMethod = "POST", value = "运单批量匹配线路策略")
	@PostMapping(value = "/shipbill_match_line_batch")
	public RestMessage<Map<String, ShipbillMatchLineDTO>> shipbillMatchLineBatchExecute(@RequestBody List<ShipbillMatchLineVO> matchLineVOs) {
		try {
			Map<String, ShipbillMatchLineDTO> lineDTOs = lineMthStrategyService.shipbillMatchLineBatch(matchLineVOs);
			return RestMessage.newInstance(true, "匹配线路策略成功", lineDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
