package com.lantone.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.security.dto.GetHospitalUserPageDTO;
import com.lantone.security.dto.GetMyNoticeListDTO;
import com.lantone.security.dto.GetNoticeInfoByIdDTO;
import com.lantone.security.dto.ListManagePageDTO;
import com.lantone.security.vo.AddNoticeVO;
import com.lantone.security.vo.GetHospitalUserVO;
import com.lantone.security.vo.GetMyNoticeListVO;
import com.lantone.security.vo.ListManagePageVO;
import com.lantone.security.facade.NoticeManagementFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * @Description: 站内通知管理API
 * @author: songxl
 * @time: 2021/9/10 13:39
 */
@RestController
@Api(value = "站内通知管理API", tags = {"站内通知管理API"})
@RequestMapping("/noticeManage")
public class NoticeManagementController {

    @Autowired
    private NoticeManagementFacade noticeManagementFacade;

    @ApiOperation(value = "我的通知列表页")
    @PostMapping(value = "/listPage")
    public CommonResult<IPage<GetMyNoticeListDTO>> listPage(@Valid @RequestBody GetMyNoticeListVO getMyNoticeListVO) {
        return CommonResult.success(noticeManagementFacade.listPage(getMyNoticeListVO));
    }

    @ApiOperation(value = "知管理列表页")
    @PostMapping(value = "/listManagePage")
    public CommonResult<IPage<ListManagePageDTO>> listManagePage(@Valid @RequestBody ListManagePageVO listManagePageVO) {
        return CommonResult.success(noticeManagementFacade.listManagePage(listManagePageVO));
    }

    @ApiOperation(value = "获取指定组织的用户")
    @PostMapping(value = "/getHospitalUser")
    public CommonResult<IPage<GetHospitalUserPageDTO>> getHospitalUser(@Valid @RequestBody GetHospitalUserVO getHospitalUserVO) {
        return CommonResult.success(noticeManagementFacade.getHospitalUser(getHospitalUserVO));
    }

    @ApiOperation(value = "获取未读信息数量")
    @PostMapping(value = "/getNotNoticeCount")
    public CommonResult<Map<String, Integer>> getNotNoticeCount() {
        return CommonResult.success(noticeManagementFacade.getNotNoticeCount());
    }


    @ApiOperation(value = "添加")
    @PostMapping(value = "/add")
    @Transactional
    public CommonResult<Boolean> add(@Valid @RequestBody AddNoticeVO addNoticeVO) {
        return CommonResult.success(noticeManagementFacade.add(addNoticeVO));
    }

    @ApiOperation(value = "查看",
            notes = "type:管理列表查看通知内容还是我的通知列表查看通知功能（0:管理页面查看，1:我的通知列表查看），必填<br>")
    @PostMapping(value = "/getNoticeInfoById")
    public CommonResult<GetNoticeInfoByIdDTO> getNoticeInfoById(@RequestParam @Valid @NotNull(message = "通知编号为空") Long id
            , @RequestParam @Valid @NotBlank(message = "查看类型为空") String type) {
        return CommonResult.success(noticeManagementFacade.getNoticeInfoById(id, type));
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/deleteNoticeInfo")
    @Transactional
    public CommonResult<Boolean> deleteNoticeInfo(@RequestParam @Valid @NotNull(message = "通知编号为空") Long id) {
        return CommonResult.success(noticeManagementFacade.deleteNoticeInfo(id));
    }

}