package com.prolog.rdc.tms.controller;

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.CarrierMthStrategyPageDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.CarrierMthStrategyViewDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.ShipbillMatchCarrierDTO;
import com.prolog.rdc.tms.model.vo.basicConfigure.CarrierMthStrategyPageVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.CarrierMthStrategySaveVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.CarrierMthStrategyUpdateVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.CarrierMthStrategyViewVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ShipbillMatchCarrierVO;
import com.prolog.rdc.tms.service.CarrierMthStrategyService;

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

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

	@Autowired
	private CarrierMthStrategyService carrierMthStrategyService;

	@UserLog("承运方匹配策略分页查询")
	@ApiOperation(httpMethod = "POST", value = "承运方匹配策略分页查询")
	@PostMapping(value = "/page")
	public RestMessage<Page<CarrierMthStrategyPageDTO>> pageQueryExecute(@RequestBody CarrierMthStrategyPageVO pageVO) {
		try {
			Page<CarrierMthStrategyPageDTO> pageDTOs = carrierMthStrategyService.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 CarrierMthStrategySaveVO carrierMthStrategySaveVO) {
		try {
			carrierMthStrategyService.save(carrierMthStrategySaveVO);
			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 CarrierMthStrategyUpdateVO carrierMthStrategyUpdateVO) {
		try {
			carrierMthStrategyService.update(carrierMthStrategyUpdateVO);
			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 {
			carrierMthStrategyService.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 {
			carrierMthStrategyService.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<CarrierMthStrategyViewDTO> viewExecute(@RequestBody CarrierMthStrategyViewVO viewVO) {
		try {
			CarrierMthStrategyViewDTO viewDTO = carrierMthStrategyService.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_carrier")
	public RestMessage<Map<String, ShipbillMatchCarrierDTO>> shipbillMatchCarrierExecute(@RequestBody List<ShipbillMatchCarrierVO> matchCarrierVOs) {
		try {
			Map<String, ShipbillMatchCarrierDTO> carrierDTOMaps = carrierMthStrategyService.shipbillMatchCarrier(matchCarrierVOs);
			return RestMessage.newInstance(true, "承运方匹配策略查看成功", carrierDTOMaps);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
