package com.prolog.rdc.tms.app.controller.business;

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.app.model.dto.WaitDeliveredPackageDetailDTO;
import com.prolog.rdc.tms.app.model.dto.business.WaitDeliveredItemDTO;
import com.prolog.rdc.tms.app.model.dto.business.WaitDeliveredPageDTO;
import com.prolog.rdc.tms.app.model.vo.WaitDeliveredDeliveredConfirmVO;
import com.prolog.rdc.tms.app.model.vo.WaitDeliveredPackageDetailVO;
import com.prolog.rdc.tms.app.model.vo.business.WaitDeliveredAbnormalVO;
import com.prolog.rdc.tms.app.model.vo.business.WaitDeliveredItemQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.WaitDeliveredQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.WaitDeliveredSignVO;
import com.prolog.rdc.tms.app.service.business.WaitDeliveredService;

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

/**
 * 业务APP小程序-待送达控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author xiaoyf
 * @since 2022/6/15 9:46
 */
@RestController
@Api(tags = "业务APP——待送达控制层")
@RequestMapping("/waitDelivered")
public class WaitDeliveredController {

	@Autowired
	private WaitDeliveredService service;

	@UserLog("运单分页查询")
	@ApiOperation(value = "运单分页查询", notes = "运单分页查询")
	@PostMapping("/page")
	public RestMessage<Page<WaitDeliveredPageDTO>> queryPage(@RequestBody @Valid WaitDeliveredQueryVO vo) throws Exception {
		Page<WaitDeliveredPageDTO> page = service.queryPage(vo);
		return RestMessage.newInstance(true, "操作成功！", page);
	}

	@UserLog("运单分页查询-收货方模式")
	@ApiOperation(value = "运单分页查询-收货方模式", notes = "运单分页查询-收货方模式")
	@PostMapping("/queryPageGroupByConsignee")
	public RestMessage<Page<WaitDeliveredPageDTO>> queryPageGroupByConsignee(@RequestBody @Valid WaitDeliveredQueryVO vo) {
		Page<WaitDeliveredPageDTO> page = service.queryPageGroupByConsignee(vo);
		return RestMessage.newInstance(true, "操作成功！", page);
	}

	@UserLog("运单商品明细查询")
	@ApiOperation(value = "运单商品明细查询", notes = "运单商品明细查询")
	@PostMapping("/queryItem")
	public RestMessage<List<WaitDeliveredItemDTO>> queryItem(@RequestBody @Valid WaitDeliveredItemQueryVO vo) throws Exception {
		List<WaitDeliveredItemDTO> page = service.queryItem(vo);
		return RestMessage.newInstance(true, "操作成功！", page);
	}

	@UserLog("运单包裹查询")
	@ApiOperation(value = "运单包裹查询", notes = "运单包裹查询")
	@PostMapping("/queryPack")
	public RestMessage<List<WaitDeliveredPackageDetailDTO>> queryPack(@RequestBody @Valid WaitDeliveredPackageDetailVO waitDeliveredPackageDetailVO) {
		List<WaitDeliveredPackageDetailDTO> page = service.queryPack(waitDeliveredPackageDetailVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("签到")
	@ApiOperation(value = "签到", notes = "签到")
	@PostMapping("/sign")
	public RestMessage<Object> sign(@RequestBody @Valid WaitDeliveredSignVO vo) throws Exception {
		service.sign(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("送达确认")
	@ApiOperation(value = "送达确认", notes = "送达确认")
	@PostMapping("/deliveredConfirm")
	public RestMessage<Object> deliveredConfirm(@RequestBody WaitDeliveredDeliveredConfirmVO vo) throws Exception {
		service.deliveredConfirmData(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("异常上报")
	@ApiOperation(value = "异常上报", notes = "异常上报")
	@PostMapping("/abnormalSend")
	public RestMessage<Object> abnormalSend(@RequestBody @Valid WaitDeliveredAbnormalVO vo) {
		try {
			service.abnormalSend(vo);
			return RestMessage.newInstance(true, "操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
