package com.iformall.controller.invest;

import com.iformall.annotation.SystemServiceLog;
import com.iformall.common.InvestResultData;
import com.iformall.domain.po.invest.InvestMessageEntity;
import com.iformall.domain.vo.invest.InvestMessageQuery;
import com.iformall.domain.vo.invest.InvestPageResult;
import com.iformall.service.invest.InvestBizService;
import com.iformall.service.invest.InvestMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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/message")
@Api(tags = "招商模块-消息提醒")
public class InvestMessageController extends InvestBaseController {
	@Autowired
	private InvestMessageService investRemindService;
	@Autowired
	private InvestBizService bizService;

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


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

	/**
	 * 保存
	 */
	//@RequiresPermissions("investFollowRecordEdit")
	@SystemServiceLog
	//@PostMapping("/save")
	public InvestResultData save(@RequestBody InvestMessageEntity messageEntity) {
		return execute(messageEntity, p -> investRemindService.save(p));
	}

	/**
	 * 修改
	 */
	@SystemServiceLog
	//@PostMapping("/update")
	public InvestResultData update(@RequestBody InvestMessageEntity messageEntity) {
		return execute(messageEntity, p -> investRemindService.updateById(p));
	}

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

	/**
	 * 删除登录用户全部提醒
	 */
	@SystemServiceLog
	@PostMapping("/deleteAll")
	public InvestResultData deleteAll() {
		return execute(null, p -> investRemindService.removeAll());
	}

}
