123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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.dao.UserTextbookEnrollMapper;
- import com.qxgmat.data.dao.entity.UserTextbookEnroll;
- import com.qxgmat.data.relation.UserTextbookEnrollRelationMapper;
- import com.qxgmat.data.relation.entity.MonthNumberRelation;
- 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 UserTextbookEnrollService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(UserTextbookEnrollService.class);
- @Resource
- private UserTextbookEnrollMapper userTextbookEnrollMapper;
- @Resource
- private UserTextbookEnrollRelationMapper userTextbookEnrollRelationMapper;
- public List<UserTextbookEnroll> allByUser(Integer userId, String startTime, String endTime){
- Example example = new Example(UserTextbookEnroll.class);
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- .andGreaterThanOrEqualTo("date", startTime)
- .andLessThan("date", endTime)
- );
- example.orderBy("date").asc();
- return select(userTextbookEnrollMapper, example);
- }
- public List<MonthNumberRelation> groupByMonth(String startTime, String endTime){
- return userTextbookEnrollRelationMapper.groupByMonth(startTime, endTime);
- }
- public UserTextbookEnroll getByUser(Integer userId){
- Example example = new Example(UserTextbookEnroll.class);
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- );
- return one(userTextbookEnrollMapper, example);
- }
- public UserTextbookEnroll add(UserTextbookEnroll ad){
- int result = insert(userTextbookEnrollMapper, ad);
- ad = one(userTextbookEnrollMapper, ad.getId());
- if(ad == null){
- throw new SystemException("记录添加失败");
- }
- return ad;
- }
- public UserTextbookEnroll edit(UserTextbookEnroll ad){
- UserTextbookEnroll in = one(userTextbookEnrollMapper, ad.getId());
- if(in == null){
- throw new ParameterException("记录不存在");
- }
- int result = update(userTextbookEnrollMapper, ad);
- return ad;
- }
- public boolean delete(Number id){
- UserTextbookEnroll in = one(userTextbookEnrollMapper, id);
- if(in == null){
- throw new ParameterException("记录不存在");
- }
- int result = delete(userTextbookEnrollMapper, id);
- return result > 0;
- }
- public UserTextbookEnroll get(Number id){
- UserTextbookEnroll in = one(userTextbookEnrollMapper, id);
- if(in == null){
- throw new ParameterException("记录不存在");
- }
- return in;
- }
- public Page<UserTextbookEnroll> select(int page, int pageSize){
- return select(userTextbookEnrollMapper, page, pageSize);
- }
- public Page<UserTextbookEnroll> select(Integer[] ids){
- return page(()->select(userTextbookEnrollMapper, ids), 1, ids.length);
- }
- public List<UserTextbookEnroll> select(Collection ids){
- return select(userTextbookEnrollMapper, ids);
- }
- }
|