package com.iformall.controller.invest;

import com.iformall.annotation.SystemServiceLog;
import com.iformall.common.InvestResultData;
import com.iformall.domain.po.invest.InvestTaskEntity;
import com.iformall.domain.vo.invest.*;
import com.iformall.service.invest.InvestBizService;
import com.iformall.service.invest.InvestTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 招商模块-招商任务
 *
 * @author
 * @email
 * @date 2019-09-23 18:40:43
 */
@Slf4j
@RestController
@RequestMapping("invest/task")
@Api(tags = "招商模块-招商任务")
public class InvestTaskController extends InvestBaseController {
	@Autowired
	private InvestTaskService investTaskService;
	@Autowired
	private InvestBizService bizService;

	/**
	 * 分页列表
	 */
	//@RequiresPermissions("InvestTaskQuery")
	@SystemServiceLog
	@ApiOperation("分页列表接口")
	@GetMapping("/list")
	public InvestResultData<InvestPageResult<InvestTaskVo>> list(InvestTaskQuery params) {
		return execute(params, p -> bizService.queryPageTask(p));
	}

	/**
	 * 信息
	 */
	@SystemServiceLog
	@GetMapping("/info/{id}")
	public InvestResultData<InvestTaskVo> info(@PathVariable("id") Long id) {
		return execute(id, p -> bizService.findTaskById(id));
	}

	/**
	 * 保存
	 */
	//@RequiresPermissions("investTaskEdit")
	@SystemServiceLog
	@PostMapping("/save")
	public InvestResultData save(@RequestBody InvestTaskEntity investTask) {
		return execute(investTask, p -> bizService.saveTask(p));
	}

	/**
	 * 修改
	 */
	@SystemServiceLog
	@PostMapping("/update")
	public InvestResultData update(@RequestBody InvestTaskEntity investTask) {
		return execute(investTask, p -> bizService.updateTask(p));
	}

	/**
	 * 删除
	 */
	@SystemServiceLog
	@PostMapping("/delete")
	public InvestResultData delete(@RequestBody Long[] ids) {
		return execute(ids, p -> investTaskService.removeByIds(Arrays.asList(p)));
	}

}
