123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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.ReadyDataMapper;
- import com.qxgmat.data.dao.ReadyRoomMapper;
- import com.qxgmat.data.dao.entity.ReadyData;
- 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 ReadyDataService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(ReadyDataService.class);
- @Resource
- private ReadyDataMapper readyDataMapper;
- public Page<ReadyData> listAdmin(int page, int size, Boolean isOfficial, String order, DirectionStatus direction){
- Example example = new Example(ReadyData.class);
- if (isOfficial != null)
- example.and(
- example.createCriteria()
- .andEqualTo("isOfficial", isOfficial)
- );
- 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(readyDataMapper, example, page, size);
- }
- public List<ReadyData> all(Boolean isOfficial){
- Example example = new Example(ReadyData.class);
- if (isOfficial != null)
- example.and(
- example.createCriteria()
- .andEqualTo("isOfficial", isOfficial)
- );
- return select(readyDataMapper, example);
- }
- public ReadyData add(ReadyData entity){
- int result = insert(readyDataMapper, entity);
- entity = one(readyDataMapper, entity.getId());
- if(entity == null){
- throw new SystemException("考场添加失败");
- }
- return entity;
- }
- public ReadyData edit(ReadyData entity){
- ReadyData in = one(readyDataMapper, entity.getId());
- if(in == null){
- throw new ParameterException("考场不存在");
- }
- int result = update(readyDataMapper, entity);
- return entity;
- }
- public boolean delete(Number id){
- ReadyData in = one(readyDataMapper, id);
- if(in == null){
- throw new ParameterException("考场不存在");
- }
- int result = delete(readyDataMapper, id);
- return result > 0;
- }
- public ReadyData get(Number id){
- ReadyData in = one(readyDataMapper, id);
- if(in == null){
- throw new ParameterException("考场不存在");
- }
- return in;
- }
- public Page<ReadyData> select(int page, int pageSize){
- return select(readyDataMapper, page, pageSize);
- }
- public Page<ReadyData> select(Integer[] ids){
- return page(()->select(readyDataMapper, ids), 1, ids.length);
- }
- public List<ReadyData> select(Collection ids){
- return select(readyDataMapper, ids);
- }
- }
|