package com.hotent.portal.controller;

import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.controller.BaseController2;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.FieldRelation;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.query.QueryOP;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.CommonResultUtil;
import com.hotent.base.util.StringUtil;
import com.hotent.portal.model.MessageNews;
import com.hotent.portal.persistence.manager.MessageNewsManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Optional;

/**
 * 
 * <pre> 
 * 描述：新闻公告 控制器类
 * 构建组：x7
 * 作者:dengyg
 * 邮箱:dengyg@jee-soft.cn
 * 日期:2018-08-20 16:04:35
 * 版权：广州宏天软件有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/portal/messageNews/v2")
@Api(tags="新闻公告2")
@ApiGroup(group= {ApiGroupConsts.GROUP_PORTAL})
public class MessageNewsController2 extends BaseController2<MessageNewsManager, MessageNews> {
	@Resource
	MessageNewsManager messageNewsManager;

	/**
	 * 新闻公告列表(分页条件查询)数据 （vue发文公告）
	 *
	 * @param isPublic
	 * @return
	 * @throws Exception PageJson
	 * @throws
	 */
	@PostMapping("/listNotice")
	@ApiOperation(value = "新闻公告数据列表", httpMethod = "POST", notes = "获取新闻公告列表")
	public CommonResult<PageList<MessageNews>> list(@ApiParam(name = "queryFilter", value = "查询对象") @RequestBody QueryFilter<MessageNews> queryFilter, @ApiParam(name = "isPublic", value = "是否只查询发布的新闻公告") @RequestParam Optional<Boolean> isPublic) throws Exception {
		boolean isp = isPublic.orElse(false);
		if (isp) {
			queryFilter.addFilter("FStatus", "2", QueryOP.EQUAL, FieldRelation.AND, "2");
		}
		PageList<MessageNews> pageList = messageNewsManager.query(queryFilter);
		return CommonResult.<PageList<MessageNews>>ok().value(pageList);
	}


	@RequestMapping(value = "publicMsgNews", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
	@ApiOperation(value = "发布新闻公告记录", httpMethod = "POST", notes = "发布新闻公告记录")
	public CommonResult<String> publicMsgNews(@ApiParam(name = "idStrs", value = "业务主键（列表）", required = true) @RequestBody String array) throws Exception {
		CommonResult<String> commonResult = messageNewsManager.publicMsgNews(array);
		return CommonResultUtil.<String>getResult(commonResult);
	}
}
