package com.ym.mec.web.controller;

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

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
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.ym.mec.biz.dal.entity.TenantEntryActivities;
import com.ym.mec.biz.dal.page.TenantEntryActivitiesQueryInfo;
import com.ym.mec.biz.service.TenantEntryActivitiesService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("tenantEntryActivities")
@Api(tags = "租客入驻活动")
@RestController
public class TenantEntryActivitiesController extends BaseController {

	@Autowired
	private TenantEntryActivitiesService tenantEntryActivitiesService;

	@ApiOperation(value = "分页查询活动列表")
	@GetMapping("/queryPage")
	@PreAuthorize("@pcs.hasPermissions('tenantEntryActivities/queryPage')")
	public Object queryPage(TenantEntryActivitiesQueryInfo queryInfo) {
		return succeed(tenantEntryActivitiesService.queryPage(queryInfo));
	}

	@ApiOperation(value = "查询活动信息")
	@GetMapping("/query")
	@PreAuthorize("@pcs.hasPermissions('tenantEntryActivities/query')")
	public Object query(Integer id) {
		return succeed(tenantEntryActivitiesService.get(id));
	}

	@ApiOperation(value = "新增、修改活动")
	@PostMapping("/merge")
	@PreAuthorize("@pcs.hasPermissions('tenantEntryActivities/merge')")
	public Object merge(@RequestBody TenantEntryActivities tenantEntryActivites) {
		tenantEntryActivitiesService.merge(tenantEntryActivites);
		return succeed();
	}

	@ApiOperation(value = "停用、启用")
	@PostMapping("/updateDelFlag")
	@PreAuthorize("@pcs.hasPermissions('tenantEntryActivities/updateDelFlag')")
	public Object updateDelFlag(int id, boolean delFlag) {
		TenantEntryActivities tenantEntryActivities = tenantEntryActivitiesService.get(id);
		if (tenantEntryActivities == null) {
			return failed("活动不存在");
		}
		tenantEntryActivities.setDelFlag(delFlag);
		tenantEntryActivities.setUpdateTime(new Date());
		tenantEntryActivitiesService.merge(tenantEntryActivities);
		return succeed();
	}

}
