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.ReadyArticleMapper; import com.qxgmat.data.dao.ReadyRoomMapper; import com.qxgmat.data.dao.entity.ReadyArticle; import com.qxgmat.data.dao.entity.ReadyRoom; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; import java.util.List; @Service public class ReadyRoomService extends AbstractService { private static final Logger logger = LoggerFactory.getLogger(ReadyRoomService.class); @Resource private ReadyRoomMapper readyRoomMapper; public Page list(int page, int size, String keyword, Integer areaId, String order, DirectionStatus direction){ Example example = new Example(ReadyRoom.class); if (keyword != null) example.and( example.createCriteria() .orLike("address", "%"+keyword+"%") .orLike("title", "%"+keyword+"%") .orLike("description", "%"+keyword+"%") ); if (areaId != null) example.and( example.createCriteria() .andEqualTo("areaId", areaId) ); 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(readyRoomMapper, example, page, size); } public Page listAdmin(int page, int size, String position, Integer areaId, String order, DirectionStatus direction){ Example example = new Example(ReadyRoom.class); if (position != null) example.and( example.createCriteria() .andEqualTo("position", position) ); if (areaId != null) example.and( example.createCriteria() .andEqualTo("areaId", areaId) ); 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(readyRoomMapper, example, page, size); } public ReadyRoom add(ReadyRoom entity){ int result = insert(readyRoomMapper, entity); entity = one(readyRoomMapper, entity.getId()); if(entity == null){ throw new SystemException("考场添加失败"); } return entity; } public ReadyRoom edit(ReadyRoom entity){ ReadyRoom in = one(readyRoomMapper, entity.getId()); if(in == null){ throw new ParameterException("考场不存在"); } int result = update(readyRoomMapper, entity); return entity; } public boolean delete(Number id){ ReadyRoom in = one(readyRoomMapper, id); if(in == null){ throw new ParameterException("考场不存在"); } int result = delete(readyRoomMapper, id); return result > 0; } public ReadyRoom get(Number id){ ReadyRoom in = one(readyRoomMapper, id); if(in == null){ throw new ParameterException("考场不存在"); } return in; } public Page select(int page, int pageSize){ return select(readyRoomMapper, page, pageSize); } public Page select(Integer[] ids){ return page(()->select(readyRoomMapper, ids), 1, ids.length); } public List select(Collection ids){ return select(readyRoomMapper, ids); } }