package com.pj.project.tb_message;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.current.satoken.StpAPPUserUtil;
import com.pj.project4sp.SP;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: tb_message -- 通知消息
 *
 * @author lsw
 */
@RestController
@RequestMapping("/app/TbMessage/")
public class TbMessageAppController {

    /**
     * 底层 Service 对象
     */
    @Autowired
    TbMessageService tbMessageService;

    /**
     * app端: 删除消息 (可批量,可单条)
     * @param ids
     * @return
     */
    @DeleteMapping("deleteByIdList")
    public AjaxJson deleteByIdList(List<Long> ids){
        tbMessageService.removeByIds(ids);
        return AjaxJson.getSuccess();
    }

    /**
     * 消息中心
     */
    @GetMapping("getList")
    public AjaxJson getList() {
        SoMap so = SoMap.getRequestSoMap();
        so.put("enable", 1);
        if (so.get("types").toString().equals("2")) {
            so.put("userId", StpAPPUserUtil.getAPPLoginInfo().getFk());
            tbMessageService.clearRead(StpAPPUserUtil.getAPPLoginInfo().getFk());
        }
        List<TbMessage> list = tbMessageService.getList(so.startPage());
        return AjaxJson.getPageData(so.getDataCount(), list);
    }

    @GetMapping("getRead")
    public AjaxJson getRead() {
        return AjaxJson.getSuccessData(tbMessageService.getRead(StpAPPUserUtil.getAPPLoginInfo().getFk()));
    }
}
