package com.qxgmat.service.inline; import com.github.pagehelper.Page; import com.nuliji.tools.AbstractService; import com.nuliji.tools.exception.ParameterException; import com.nuliji.tools.exception.SystemException; import com.nuliji.tools.mybatis.Example; import com.qxgmat.data.constants.enums.status.DirectionStatus; import com.qxgmat.data.dao.MessageMapper; import com.qxgmat.data.dao.entity.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; import java.util.Date; import java.util.List; @Service public class MessageService extends AbstractService { private static final Logger logger = LoggerFactory.getLogger(MessageService.class); @Resource private MessageMapper messageMapper; public Page listAdmin(int page, int pageSize, String order, DirectionStatus direction){ Example example = new Example(Message.class); if(order == null || order.isEmpty()) order = "id"; switch(direction){ case ASC: example.orderBy(order).asc(); break; case DESC: default: example.orderBy(order).desc(); } return select(messageMapper, example, page, pageSize); } /** * 获取到期还未发送消息列表 * @return */ public List listExpire(){ Example example = new Example(Message.class); example.and( example.createCriteria() .andEqualTo("sendNumber", 0) .andEqualTo("sendStatus", 0) .andLessThan("sendTime", new Date()) ); return select(messageMapper, example); } public Message add(Message message){ int result = insert(messageMapper, message); message = one(messageMapper, message.getId()); if(message == null){ throw new SystemException("消息添加失败"); } return message; } public Message edit(Message message){ Message in = one(messageMapper, message.getId()); if(in == null){ throw new ParameterException("消息不存在"); } int result = update(messageMapper, message); return message; } public boolean delete(Number id){ Message in = one(messageMapper, id); if(in == null){ throw new ParameterException("消息不存在"); } int result = delete(messageMapper, id); return result > 0; } public Message get(Number id){ Message in = one(messageMapper, id); if(in == null){ throw new ParameterException("消息不存在"); } return in; } public Page select(int page, int pageSize){ return select(messageMapper, page, pageSize); } public Page select(Integer[] ids){ return page(()->select(messageMapper, ids), 1, ids.length); } public List select(Collection ids){ return select(messageMapper, ids); } }