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

import java.util.List;

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.IntfErrorLogDTO;
import com.prolog.rdc.tms.model.dto.basicData.CargoOwnerApprovalQueryDTO;
import com.prolog.rdc.tms.model.dto.basicData.CargoOwnerByEncodingNameDTO;
import com.prolog.rdc.tms.model.dto.basicData.CargoOwnerByIdsDTO;
import com.prolog.rdc.tms.model.dto.basicData.CargoOwnerCheckDTO;
import com.prolog.rdc.tms.model.dto.basicData.CargoOwnerPagingQueryDTO;
import com.prolog.rdc.tms.model.dto.basicData.CargoOwnerPopupDTO;
import com.prolog.rdc.tms.model.dto.basicData.UserCargoOwnerPopupDTO;
import com.prolog.rdc.tms.model.vo.IntfCargoOwnerSaveVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerAddVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerApprovalQueryVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerApprovalVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerBatchDeleteVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerByEncodingNameVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerByIdsVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerCheckVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerCopyVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerGeocodingVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerModifyVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerPagingQueryVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerPopupVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerProcessApprovalVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerSummitApprovalVO;
import com.prolog.rdc.tms.model.vo.basicData.CargoOwnerWhetherEnableVO;
import com.prolog.rdc.tms.model.vo.basicData.UserCargoOwnerPopupVO;
import com.prolog.rdc.tms.service.basicData.CargoOwnerService;

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

/**
 * 
 *
 * 基础数据-货主管理控制层
 *
 * @className :BaseCargoOwnerController
 * @author :fanzw
 * @creationTime :2022/02/25
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/02/25
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "基础数据-货主管理控制层")
@RestController
@RequestMapping("/cargo_owner")
public class CargoOwnerController {

	@Autowired
	private CargoOwnerService baseCargoOwnerService;

	@UserLog("货主资料分页查询")
	@ApiOperation(value = "货主资料分页查询", notes = "货主资料分页查询")
	@PostMapping("/paging_query")
	public RestMessage<Page<CargoOwnerPagingQueryDTO>> pageCargoOwnerExecute(@RequestBody CargoOwnerPagingQueryVO cargoOwnerPagingQueryVO) {
		try {
			Page<CargoOwnerPagingQueryDTO> cargoOwnerPagingQueryDTOs = baseCargoOwnerService.pageCargoOwnerData(cargoOwnerPagingQueryVO);
			return RestMessage.newInstance(true, "查询成功", cargoOwnerPagingQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料查看")
	@ApiOperation(value = "货主资料查看", notes = "货主资料查看")
	@PostMapping("/check")
	public RestMessage<CargoOwnerCheckDTO> getCargoOwnerExecute(@RequestBody CargoOwnerCheckVO cargoOwnerCheckVO) {
		try {
			CargoOwnerCheckDTO cargoOwnerCheckDTO = baseCargoOwnerService.getCargoOwnerData(cargoOwnerCheckVO);
			return RestMessage.newInstance(true, "查询成功", cargoOwnerCheckDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料弹窗")
	@ApiOperation(value = "货主资料弹窗", notes = "货主资料弹窗")
	@PostMapping("/popup")
	public RestMessage<Page<CargoOwnerPopupDTO>> popupCargoOwnerExecute(@RequestBody CargoOwnerPopupVO cargoOwnerPopupVO) {
		try {
			Page<CargoOwnerPopupDTO> cargoOwnerPopupDTOs = baseCargoOwnerService.popupCargoOwnerData(cargoOwnerPopupVO);
			return RestMessage.newInstance(true, "查询成功", cargoOwnerPopupDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("用户货主资料弹窗")
	@ApiOperation(value = "用户货主资料弹窗", notes = "用户货主资料弹窗")
	@PostMapping("/user/popup")
	public RestMessage<Page<UserCargoOwnerPopupDTO>> popupUserCargoOwnerExecute(@RequestBody UserCargoOwnerPopupVO userCargoOwnerPopupVO) {
		try {
			Page<UserCargoOwnerPopupDTO> userCargoOwnerPopupDTOs = baseCargoOwnerService.popupUserCargoOwnerData(userCargoOwnerPopupVO);
			return RestMessage.newInstance(true, "查询成功", userCargoOwnerPopupDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("根据货主ID集合分页查询")
	@ApiOperation(value = "根据货主ID集合分页查询", notes = "根据货主ID集合分页查询")
	@PostMapping("/byIds")
	public RestMessage<Page<CargoOwnerByIdsDTO>> pageCargoOwnerByIdsExecute(@RequestBody CargoOwnerByIdsVO cargoOwnerByIdsVO) {
		try {
			Page<CargoOwnerByIdsDTO> cargoOwnerByIdsDTOs = baseCargoOwnerService.pageCargoOwnerByIdsData(cargoOwnerByIdsVO);
			return RestMessage.newInstance(true, "查询成功", cargoOwnerByIdsDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料新增")
	@ApiOperation(value = "货主资料新增", notes = "货主资料新增")
	@PostMapping("/add")
	public RestMessage<String> addCargoOwnerExecute(@RequestBody CargoOwnerAddVO cargoOwnerAddVO) {
		try {
			baseCargoOwnerService.addCargoOwnerData(cargoOwnerAddVO);
			return RestMessage.newInstance(true, "新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料复制")
	@ApiOperation(value = "货主资料复制", notes = "货主资料复制")
	@PostMapping("/copy")
	public RestMessage<String> copyCargoOwnerExecute(@RequestBody CargoOwnerCopyVO cargoOwnerCopyVO) {
		try {
			baseCargoOwnerService.copyCargoOwnerData(cargoOwnerCopyVO);
			return RestMessage.newInstance(true, "新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料修改")
	@ApiOperation(value = "货主资料修改", notes = "货主资料修改")
	@PostMapping("/modify")
	public RestMessage<String> modifyCargoOwnerExecute(@RequestBody CargoOwnerModifyVO cargoOwnerModifyVO) {
		try {
			baseCargoOwnerService.modifyCargoOwnerData(cargoOwnerModifyVO);
			return RestMessage.newInstance(true, "修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料批量删除")
	@ApiOperation(value = "货主资料批量删除", notes = "货主资料批量删除")
	@PostMapping("/batch_delete")
	public RestMessage<String> batchDeleteCargoOwnerExecute(@RequestBody List<CargoOwnerBatchDeleteVO> cargoOwnerBatchDeleteVOs) {
		try {
			baseCargoOwnerService.batchDeleteCargoOwnerData(cargoOwnerBatchDeleteVOs);
			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<String> whetherEnableCargoOwnerExecute(@RequestBody CargoOwnerWhetherEnableVO cargoOwnerWhetherEnableVO) {
		try {
			baseCargoOwnerService.whetherEnableCargoOwnerData(cargoOwnerWhetherEnableVO);
			return RestMessage.newInstance(true, "操作成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料地址解析")
	@ApiOperation(value = "货主资料地址解析", notes = "货主资料地址解析")
	@PostMapping("/geocoding")
	public RestMessage<String> geocodingExecute(@RequestBody CargoOwnerGeocodingVO cargoOwnerGeocodingVO) {
		baseCargoOwnerService.geocodingData(cargoOwnerGeocodingVO);
		return RestMessage.newInstance(true, "操作成功", null);
	}

	@UserLog("根据货主编码名称查询货主资料")
	@ApiOperation(value = "根据货主编码名称查询货主资料", notes = "根据货主编码名称查询货主资料")
	@PostMapping("/by_encoding_name")
	public RestMessage<CargoOwnerByEncodingNameDTO> getCargoOwnerByEncodingNameExecute(@RequestBody CargoOwnerByEncodingNameVO cargoOwnerByEncodingNameVO) {
		try {
			CargoOwnerByEncodingNameDTO cargoOwnerByEncodingNameDTO = baseCargoOwnerService.getCargoOwnerByEncodingNameData(cargoOwnerByEncodingNameVO);
			return RestMessage.newInstance(true, "查询成功", cargoOwnerByEncodingNameDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主流程审批 撤回")
	@ApiOperation(value = "货主流程审批 撤回", notes = "货主流程审批 撤回")
	@PostMapping("/approval_retract")
	public RestMessage<String> retractApprovalExecute(@RequestBody CargoOwnerProcessApprovalVO cargoOwnerProcessApprovalVO) {
		try {
			baseCargoOwnerService.retractApproval(cargoOwnerProcessApprovalVO);
			return RestMessage.newInstance(true, "货主流程审批撤回成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主流程审批 作废")
	@ApiOperation(value = "货主流程审批 作废", notes = "货主流程审批 作废")
	@PostMapping("/approval_invalid")
	public RestMessage<String> invalidApprovalExecute(@RequestBody CargoOwnerProcessApprovalVO cargoOwnerProcessApprovalVO) {
		try {
			baseCargoOwnerService.invalidApproval(cargoOwnerProcessApprovalVO);
			return RestMessage.newInstance(true, "货主流程审批作废成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主流程审批 提交")
	@ApiOperation(value = "货主流程审批 提交", notes = "货主流程审批 提交")
	@PostMapping("/approval_summit")
	public RestMessage<String> summitApprovalExecute(@RequestBody CargoOwnerSummitApprovalVO cargoOwnerSummitApprovalVO) {
		try {
			baseCargoOwnerService.summitApproval(cargoOwnerSummitApprovalVO);
			return RestMessage.newInstance(true, "货主流程审批提交成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主流程审批 审核")
	@ApiOperation(value = "货主流程审批 审核", notes = "货主流程审批 审核")
	@PostMapping("/approval")
	public RestMessage<String> approvalExecute(@RequestBody CargoOwnerApprovalVO cargoOwnerApprovalVO) {
		try {
			baseCargoOwnerService.approval(cargoOwnerApprovalVO);
			return RestMessage.newInstance(true, "货主流程审批审核成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主资料和流程审批的查询")
	@ApiOperation(value = "货主资料和流程审批的查询", notes = "货主资料和流程审批的查询")
	@PostMapping("/approval_view")
	public RestMessage<CargoOwnerApprovalQueryDTO> approvalQueryExecute(@RequestBody CargoOwnerApprovalQueryVO cargoOwnerApprovalQueryVO) {
		try {
			CargoOwnerApprovalQueryDTO rs = baseCargoOwnerService.approvalQuery(cargoOwnerApprovalQueryVO);
			return RestMessage.newInstance(true, "货主资料和流程审批的查询成功", rs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("货主接口转TMS")
	@ApiOperation(value = "货主接口转TMS", notes = "货主接口转TMS")
	@PostMapping("/save/interface")
	public RestMessage<List<IntfErrorLogDTO>> saveCargoOwnerInterfaceExecute(@RequestBody List<IntfCargoOwnerSaveVO> intfCargoOwnerSaveVOs) {
		try {
			List<IntfErrorLogDTO> intfErrorLogDTOs = baseCargoOwnerService.saveCargoOwnerInterfaceData(intfCargoOwnerSaveVOs);
			return RestMessage.newInstance(true, "保存成功", intfErrorLogDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("根据货主名称返回货主资料")
	@ApiOperation(value = "根据货主名称返回货主资料", notes = "根据货主名称返回货主资料")
	@PostMapping("/by_name")
	public RestMessage<CargoOwnerCheckDTO> getCargoOwnerByNameExecute(@RequestBody CargoOwnerCheckVO cargoOwnerCheckVO) {
		try {
			CargoOwnerCheckDTO cargoOwnerCheckDTO = baseCargoOwnerService.getCargoOwnerByNameData(cargoOwnerCheckVO);
			return RestMessage.newInstance(true, "查询成功", cargoOwnerCheckDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
