package com.muchinfo.mtp3century.controller;

import com.muchinfo.mtp3century.service.INoticeService;
import com.muchinfo.mtp3century.utils.AjaxResult;
import com.muchinfo.mtp3century.utils.CenturyDecryptUtil;
import com.muchinfo.mtp3common.enumtype.Constants;
import com.muchinfo.mtp3common.enumtype.MessageType;
import com.muchinfo.mtp3common.utils.JsonUtils;
import com.muchinfo.mtp3common.vo.PageResult;
import com.muchinfo.mtp3pojos.entity.GzMemberinfo;
import com.muchinfo.mtp3pojos.entity.Noticemsg;
import com.muchinfo.mtp3pojos.entity.SiteColumnconfig;
import com.muchinfo.mtp3pojos.entity.SiteColumndetail;
import com.muchinfo.mtp3pojos.vo.notice.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/notice")
@Api(value = "通知公告API", description = "通知公告管理")
public class NoticeController {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    private INoticeService iNoticeService;

    @ApiOperation("通知公告-->发布通知公告-->新增")
    @RequestMapping(method = RequestMethod.POST, value = "/noticemsgadd")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult noticemsgadd(@RequestBody String param, HttpServletRequest request) {
        try {
            NoticeMsgAddParam addParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), NoticeMsgAddParam.class);
            return iNoticeService.noticemsgadd(addParam, request);
        } catch (Exception e) {
            log.error("发布通知公告新增，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("通知公告-->发布通知公告-->修改")
    @RequestMapping(method = RequestMethod.POST, value = "/noticemsgedit")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult noticemsgedit(@RequestBody String param, HttpServletRequest request) {
        try {
            NoticeMsgAddParam addParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), NoticeMsgAddParam.class);
            return iNoticeService.noticemsgedit(addParam, request);
        } catch (Exception e) {
            log.error("发布通知公告修改，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("通知公告-->公告通知管理-->提前失效")
    @RequestMapping(method = RequestMethod.GET, value = "/invalid")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult invalid(Long auditid, HttpServletRequest request) {
        return iNoticeService.invalid(auditid, request);
    }

    @ApiOperation("通知公告-->公告通知管理-->获取列表")
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<NoticeMsgQueryResult> query(NoticeMsgQueryParam param, HttpServletRequest request) {
        return iNoticeService.query(param, request);
    }

    @ApiOperation("通知公告-->公告通知管理-->详情")
    @RequestMapping(method = RequestMethod.GET, value = "/noticeMsgDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<Noticemsg> noticeMsgDetail(Long auditid, HttpServletRequest request) {
        return iNoticeService.noticeMsgDetail(auditid, request);
    }

    @ApiOperation("通知公告-->公告通知管理-->删除")
    @RequestMapping(method = RequestMethod.GET, value = "/delete")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult delete(Long auditid, HttpServletRequest request) {
        return iNoticeService.delete(auditid, request);
    }

    @ApiOperation("通知公告-->公告通知管理-->强制弹出/取消强制弹出")
    @RequestMapping(method = RequestMethod.GET, value = "/updateforcedisplay")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult updateforcedisplay(Long auditid, Integer isforcedisplay, HttpServletRequest request) {
        return iNoticeService.updateforcedisplay(auditid, isforcedisplay, request);
    }

    @ApiOperation("通知公告-->公告通知管理-->审核")
    @RequestMapping(method = RequestMethod.GET, value = "/auditMsg")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult auditMsg(Long auditid, Integer auditflag, String msg, HttpServletRequest request) {
        return iNoticeService.auditMsg(auditid, auditflag, msg, request);
    }

    @ApiOperation("通知公告-->短信查询-->获取列表")
    @RequestMapping(method = RequestMethod.GET, value = "/smsquery")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<SmsQueryResult> smsquery(SmsQueryParam param, HttpServletRequest request) {
        return iNoticeService.smsquery(param, request);
    }

    @ApiOperation("通知公告-->短信查询-->重新发送")
    @RequestMapping(method = RequestMethod.GET, value = "/resend")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult resend(Long msgid, HttpServletRequest request) {
        return iNoticeService.resend(msgid, request);
    }

    @ApiOperation("通知公告-->资讯栏目-->获取列表")
    @RequestMapping(method = RequestMethod.GET, value = "/columnquery")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<ColumnQueryResult> columnquery(ColumnQueryParam param, HttpServletRequest request) {
        return iNoticeService.columnquery(param, request);
    }

    @ApiOperation("通知公告-->资讯栏目-->新增/修改")
    @RequestMapping(method = RequestMethod.POST, value = "/dealcolumn")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult dealcolumn(@RequestBody String param, HttpServletRequest request) {
        try {
            ColumnAddParam addParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), ColumnAddParam.class);
            return iNoticeService.dealcolumn(addParam, request);
        } catch (Exception e) {
            log.error("资讯栏目新增/修改，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("通知公告-->资讯栏目-->详情")
    @RequestMapping(method = RequestMethod.GET, value = "/columnDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<SiteColumnconfig> columnDetail(Long id, HttpServletRequest request) {
        return iNoticeService.columnDetail(id, request);
    }

    @ApiOperation("通知公告-->资讯栏目-->删除")
    @RequestMapping(method = RequestMethod.GET, value = "/columndelete")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult columndelete(Long id, HttpServletRequest request) {
        return iNoticeService.columndelete(id, request);
    }

    @ApiOperation("通知公告-->资讯来源-->获取列表")
    @RequestMapping(method = RequestMethod.GET, value = "/columnsourcequery")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<ColumnSourceQueryResult> columnsourcequery(String smembername, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        return iNoticeService.columnsourcequery(smembername, pageNum, pageSize, request);
    }

    @ApiOperation("通知公告-->资讯来源-->新增/修改")
    @RequestMapping(method = RequestMethod.POST, value = "/dealcolumnsource")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult dealcolumnsource(@RequestBody String param, HttpServletRequest request) {
        try {
            ColumnSourceAddParam addParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), ColumnSourceAddParam.class);
            return iNoticeService.dealcolumnsource(addParam, request);
        } catch (Exception e) {
            log.error("资讯来源新增/修改，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("通知公告-->资讯来源-->删除")
    @RequestMapping(method = RequestMethod.GET, value = "/columnsourcedelete")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult columnsourcedelete(Long memberid, HttpServletRequest request) {
        return iNoticeService.columnsourcedelete(memberid, request);
    }

    @ApiOperation("通知公告-->资讯来源-->详情")
    @RequestMapping(method = RequestMethod.GET, value = "/columnsourceDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<GzMemberinfo> columnsourceDetail(Long memberid, HttpServletRequest request) {
        return iNoticeService.columnsourceDetail(memberid, request);
    }

    @ApiOperation("通知公告-->资讯管理-->初始化类型列表")
    @RequestMapping(method = RequestMethod.GET, value = "/informManinit")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<InformManinitMessage> informManinit(HttpServletRequest request) {
        return iNoticeService.informManinit(request);
    }

    @ApiOperation("通知公告-->资讯管理-->获取列表")
    @RequestMapping(method = RequestMethod.GET, value = "/informManquery")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<InforManQueryResult> informManquery(InforManQueryParam param, HttpServletRequest request) {
        return iNoticeService.informManquery(param, request);
    }

    @ApiOperation("通知公告-->资讯管理-->详情")
    @RequestMapping(method = RequestMethod.GET, value = "/informDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<SiteColumndetail> informDetail(Long id, HttpServletRequest request) {
        return iNoticeService.informDetail(id, request);
    }

    @ApiOperation("通知公告-->资讯管理-->展示/不展示")
    @RequestMapping(method = RequestMethod.GET, value = "/isshow")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult isshow(Long id, HttpServletRequest request) {
        return iNoticeService.isshow(id, request);
    }

    @ApiOperation("通知公告-->资讯管理-->新增/修改")
    @RequestMapping(method = RequestMethod.POST, value = "/dealinform")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult dealinform(@RequestBody String param, HttpServletRequest request) {
        try {
            SiteColumndetail addParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), SiteColumndetail.class);
            return iNoticeService.dealinform(addParam, request);
        } catch (Exception e) {
            log.error("资讯管理新增/修改，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("通知公告-->资讯管理-->审核")
    @RequestMapping(method = RequestMethod.GET, value = "/auditinform")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult auditinform(Long id, Integer flag, HttpServletRequest request) {
        return iNoticeService.auditinform(id, flag, request);
    }

    @ApiOperation("通知公告-->资讯管理-->删除")
    @RequestMapping(method = RequestMethod.GET, value = "/deleteinform")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult deleteinform(Long id, HttpServletRequest request) {
        return iNoticeService.deleteinform(id, request);
    }
}
