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.TravelScenicAudit;
import com.zhiqiyun.open.core.service.SequenceService;
import com.zhiqiyun.open.core.service.TravelScenicAuditService;
import com.zhiqiyun.open.router.request.sentiment.IdsRequest;
import com.zhiqiyun.open.router.request.statistics.QueryTravelScenicAuditRequest;
import com.zhiqiyun.open.router.request.statistics.SaveTravelScenicAuditRequest;
import com.zhiqiyun.open.router.request.statistics.UpdateTravelScenicAuditRequest;
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 TravelScenicAuditApi {

	@Autowired
	private TravelScenicAuditService travelScenicAuditService;

	@Autowired
	private SequenceService sequenceService;

	@ServiceMethod(method = "travel.scenic.audit.findPage", title = "查询景区申报")
	public OapResponse findPage(QueryTravelScenicAuditRequest request) {
		QueryWrapper<TravelScenicAudit> wrapper = new QueryWrapper<>();

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

		Page<TravelScenicAudit> resultData = this.travelScenicAuditService.page(page, wrapper);

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

	@ServiceMethod(method = "travel.scenic.audit.add", title = "新建景区申报")
	public OapResponse save(SaveTravelScenicAuditRequest request) {

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

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

		this.travelScenicAuditService.save(entity);

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

	@ServiceMethod(method = "travel.scenic.audit.updateById", title = "更新景区申报")
	public OapResponse updateById(UpdateTravelScenicAuditRequest request) {
		TravelScenicAudit entity = new TravelScenicAudit();
		BeanUtils.copyProperties(request, entity);

		this.travelScenicAuditService.updateById(entity);

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

	@ServiceMethod(method = "travel.scenic.audit.deleteByIds", title = "删除景区申报")
	public OapResponse deleteByIds(IdsRequest request) {
		this.travelScenicAuditService.removeByIds(request.getIds());
		return OapResponse.success();
	}
}
