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

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.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.basicConfigure.BusinessFlowQueryDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.BusinessFlowViewDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.ShipbillFitBusinessFlowDTO;
import com.prolog.rdc.tms.model.vo.basicConfigure.BusinessFlowAddVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.BusinessFlowQueryVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.BusinessFlowShipbillVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.BusinessFlowUpdateVO;
import com.prolog.rdc.tms.service.basicConfigure.BusinessFlowService;

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

/**
 * 业务流程控制层
 *
 * @author :lhb
 * @version :1.0.0
 * @className :BusinessFlowController
 * @creationTime :2022/04/29
 * @description :
 * @modifier :
 * @modifyTime :
 * @reviseRemarks:
 */
@RestController
@Api(tags = "基础配置-业务流程控制层")
@RequestMapping("/business_flow")
public class BusinessFlowController {
	@Autowired
	private BusinessFlowService businessFlowService;

	@UserLog("业务流程分页查询")
	@ApiOperation(httpMethod = "POST", value = "业务流程分页查询")
	@PostMapping(value = "/page")
	public RestMessage<Page<BusinessFlowQueryDTO>> queryBusinessFlowExecute(@RequestBody @Valid BusinessFlowQueryVO businessFlowQueryVO) {
		try {
			Page<BusinessFlowQueryDTO> businessFlowQueryDTOs = businessFlowService.queryBusinessFlow(businessFlowQueryVO);
			return RestMessage.newInstance(true, "业务流程查询", businessFlowQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("业务流程新增")
	@ApiOperation(httpMethod = "POST", value = "业务流程新增")
	@PostMapping(value = "/add")
	public RestMessage<String> addExecute(@RequestBody @Valid BusinessFlowAddVO businessFlowAddVO) {
		try {
			businessFlowService.add(businessFlowAddVO);
			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 @Valid BusinessFlowUpdateVO businessFlowUpdateVO) {
		try {
			businessFlowService.update(businessFlowUpdateVO);
			return RestMessage.newInstance(true, "业务流程修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("业务流程删除")
	@ApiOperation(httpMethod = "POST", value = "业务流程删除")
	@PostMapping(value = "/delete")
	public RestMessage<String> deleteExecute(@RequestBody List<Long> ids) {
		try {
			businessFlowService.delete(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<BusinessFlowViewDTO> viewExecute(@RequestParam("id") Long id) {
		try {
			BusinessFlowViewDTO businessFlowViewDTO = businessFlowService.view(id);
			return RestMessage.newInstance(true, "业务流程查看成功", businessFlowViewDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("运单匹配业务流程")
	@ApiOperation(httpMethod = "POST", value = "运单匹配业务流程")
	@PostMapping(value = "/shipbill_match_flow")
	public RestMessage<ShipbillFitBusinessFlowDTO> shipbillMatchFlowQuery(@RequestBody BusinessFlowShipbillVO businessFlowShipbillVO) {
		try {
			ShipbillFitBusinessFlowDTO businessFlowViewDTO = businessFlowService.shipbillMatchQuery(businessFlowShipbillVO);
			return RestMessage.newInstance(true, "运单匹配业务流程成功", businessFlowViewDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
