UserSearchHistoryService.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.qxgmat.service.inline;
  2. import com.github.pagehelper.Page;
  3. import com.nuliji.tools.AbstractService;
  4. import com.nuliji.tools.exception.ParameterException;
  5. import com.nuliji.tools.exception.SystemException;
  6. import com.nuliji.tools.mybatis.Example;
  7. import com.qxgmat.data.constants.enums.user.ExportType;
  8. import com.qxgmat.data.dao.UserExportMapper;
  9. import com.qxgmat.data.dao.UserSearchHistoryMapper;
  10. import com.qxgmat.data.dao.entity.UserExport;
  11. import com.qxgmat.data.dao.entity.UserSearchHistory;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.util.Collection;
  17. import java.util.List;
  18. @Service
  19. public class UserSearchHistoryService extends AbstractService {
  20. private static final Logger logger = LoggerFactory.getLogger(UserSearchHistoryService.class);
  21. @Resource
  22. private UserSearchHistoryMapper userSearchHistoryMapper;
  23. public List<UserSearchHistory> listByUser(Integer userId, String startTime, String endTime){
  24. Example example = new Example(UserExport.class);
  25. example.and(
  26. example.createCriteria()
  27. .andEqualTo("userId", userId)
  28. .andGreaterThanOrEqualTo("createTime", startTime)
  29. .andLessThan("createTime", endTime)
  30. );
  31. return select(userSearchHistoryMapper, example);
  32. }
  33. public UserSearchHistory add(UserSearchHistory entity){
  34. int result = insert(userSearchHistoryMapper, entity);
  35. entity = one(userSearchHistoryMapper, entity.getId());
  36. if(entity == null){
  37. throw new SystemException("记录添加失败");
  38. }
  39. return entity;
  40. }
  41. public UserSearchHistory edit(UserSearchHistory entity){
  42. UserSearchHistory in = one(userSearchHistoryMapper, entity.getId());
  43. if(in == null){
  44. throw new ParameterException("记录不存在");
  45. }
  46. int result = update(userSearchHistoryMapper, entity);
  47. return entity;
  48. }
  49. public boolean delete(Number id){
  50. UserSearchHistory in = one(userSearchHistoryMapper, id);
  51. if(in == null){
  52. throw new ParameterException("记录不存在");
  53. }
  54. int result = delete(userSearchHistoryMapper, id);
  55. return result > 0;
  56. }
  57. public UserSearchHistory get(Number id){
  58. UserSearchHistory in = one(userSearchHistoryMapper, id);
  59. if(in == null){
  60. throw new ParameterException("记录不存在");
  61. }
  62. return in;
  63. }
  64. public Page<UserSearchHistory> select(int page, int pageSize){
  65. return select(userSearchHistoryMapper, page, pageSize);
  66. }
  67. public Page<UserSearchHistory> select(Integer[] ids){
  68. return page(()->select(userSearchHistoryMapper, ids), 1, ids.length);
  69. }
  70. public List<UserSearchHistory> select(Collection ids){
  71. return select(userSearchHistoryMapper, ids);
  72. }
  73. }