package com.zhiqiyun.open.router.apis;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dliyun.oap.framework.annotation.ServiceMethod;
import com.dliyun.oap.framework.annotation.ServiceMethodBean;
import com.dliyun.oap.framework.response.OapResponse;
import com.zhiqiyun.open.core.models.statistics.TravelHotelAudit;
import com.zhiqiyun.open.core.service.SequenceService;
import com.zhiqiyun.open.core.service.TravelHotelAuditService;
import com.zhiqiyun.open.router.request.sentiment.IdsRequest;
import com.zhiqiyun.open.router.request.statistics.QueryTravelHotelAuditRequest;
import com.zhiqiyun.open.router.request.statistics.SaveTravelHotelAuditRequest;
import com.zhiqiyun.open.router.request.statistics.UpdateTravelHotelAuditRequest;
import com.zhiqiyun.open.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@ServiceMethodBean
public class TravelHotelAuditApi {

	@Autowired
	private TravelHotelAuditService travelHotelAuditService;

	@Autowired
	private SequenceService sequenceService;

	@ServiceMethod(method = "travel.hotel.audit.findPage", title = "查询酒店申报记录")
	public OapResponse findPage(QueryTravelHotelAuditRequest request) {
		QueryWrapper<TravelHotelAudit> wrapper = new QueryWrapper<>();

		Page<TravelHotelAudit> page = new Page<>(request.getCurrent(), request.getPageSize());
		page.addOrder(OrderItem.desc("id"));

		Page<TravelHotelAudit> resultData = this.travelHotelAuditService.page(page, wrapper);

		return OapResponse.success().setBody(resultData);
	}

	@ServiceMethod(method = "travel.hotel.audit.add", title = "新建酒店申报")
	public OapResponse save(SaveTravelHotelAuditRequest request) {

		TravelHotelAudit entity = new TravelHotelAudit();
		BeanUtils.copyProperties(request, entity);

		entity.setCreateDate(DateUtil.current());
		entity.setId(this.sequenceService.nextId());

		this.travelHotelAuditService.save(entity);

		return OapResponse.success().setBody(entity);
	}

	@ServiceMethod(method = "travel.hotel.audit.updateById", title = "更新酒店申报")
	public OapResponse updateById(UpdateTravelHotelAuditRequest request) {
		TravelHotelAudit entity = new TravelHotelAudit();
		BeanUtils.copyProperties(request, entity);

		this.travelHotelAuditService.updateById(entity);

		return OapResponse.success().setBody(entity);
	}

	@ServiceMethod(method = "travel.hotel.audit.deleteByIds", title = "删除酒店申报")
	public OapResponse deleteByIds(IdsRequest request) {
		this.travelHotelAuditService.removeByIds(request.getIds());
		return OapResponse.success();
	}
}
