UserFeedbackErrorService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.qxgmat.service.inline;
  2. import com.github.pagehelper.Page;
  3. import com.nuliji.tools.AbstractService;
  4. import com.nuliji.tools.Tools;
  5. import com.nuliji.tools.Transform;
  6. import com.nuliji.tools.exception.ParameterException;
  7. import com.nuliji.tools.exception.SystemException;
  8. import com.nuliji.tools.mybatis.Example;
  9. import com.qxgmat.data.constants.enums.module.FeedbackModule;
  10. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  11. import com.qxgmat.data.constants.enums.status.FeedbackStatus;
  12. import com.qxgmat.data.constants.enums.user.MoneyRange;
  13. import com.qxgmat.data.dao.UserFeedbackErrorMapper;
  14. import com.qxgmat.data.dao.entity.UserFeedbackError;
  15. import com.qxgmat.data.relation.UserFeedbackErrorRelationMapper;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.stereotype.Service;
  19. import javax.annotation.Resource;
  20. import java.util.Collection;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. @Service
  25. public class UserFeedbackErrorService extends AbstractService {
  26. private static final Logger logger = LoggerFactory.getLogger(UserFeedbackErrorService.class);
  27. @Resource
  28. private UserFeedbackErrorMapper userFeedbackErrorMapper;
  29. @Resource
  30. private UserFeedbackErrorRelationMapper userFeedbackErrorRelationMapper;
  31. private Map<String, String> adminMap = new HashMap<String, String>(){{
  32. put("", "ufe");
  33. }};
  34. public Page<UserFeedbackError> listAdmin(int page, int size, FeedbackModule module, FeedbackStatus status, String questionType, String target, Integer moduleId, String keyword, Integer userId, MoneyRange moneyRange, String order, DirectionStatus direction){
  35. String moduleKey = module == null ? null : module.key;
  36. Integer statusIndex = status == null ? null : status.index;
  37. Integer max = moneyRange != null ? moneyRange.max == Integer.MAX_VALUE ? null : moneyRange.max : null;
  38. Integer min = moneyRange != null ? moneyRange.min : null;
  39. if(order == null || order.isEmpty()){
  40. order = "id";
  41. }
  42. if(adminMap.containsKey(order)){
  43. order = adminMap.get(order)+".`"+Tools.underscoreName(order)+"`";
  44. }else{
  45. order = adminMap.get("")+".`"+Tools.underscoreName(order)+"`";
  46. }
  47. if (direction == null){
  48. direction = DirectionStatus.DESC;
  49. }
  50. String finalOrder = order;
  51. DirectionStatus finalDirection = direction;
  52. Page<UserFeedbackError> p = page(
  53. ()-> userFeedbackErrorRelationMapper.listAdmin(moduleKey, statusIndex, questionType, target, moduleId, userId, keyword, min, max, finalOrder, finalDirection.key)
  54. , page, size);
  55. Collection ids = Transform.getIds(p, UserFeedbackError.class, "id");
  56. Transform.replace(p, select(ids), UserFeedbackError.class, "id");
  57. return p;
  58. }
  59. public UserFeedbackError add(UserFeedbackError feedbackError){
  60. int result = insert(userFeedbackErrorMapper, feedbackError);
  61. feedbackError = one(userFeedbackErrorMapper, feedbackError.getId());
  62. if(feedbackError == null){
  63. throw new SystemException("勘误添加失败");
  64. }
  65. return feedbackError;
  66. }
  67. public UserFeedbackError edit(UserFeedbackError feedbackError){
  68. UserFeedbackError in = one(userFeedbackErrorMapper, feedbackError.getId());
  69. if(in == null){
  70. throw new ParameterException("勘误不存在");
  71. }
  72. int result = update(userFeedbackErrorMapper, feedbackError);
  73. return feedbackError;
  74. }
  75. public boolean delete(Number id){
  76. UserFeedbackError in = one(userFeedbackErrorMapper, id);
  77. if(in == null){
  78. throw new ParameterException("勘误不存在");
  79. }
  80. int result = delete(userFeedbackErrorMapper, id);
  81. return result > 0;
  82. }
  83. public UserFeedbackError get(Number id){
  84. UserFeedbackError in = one(userFeedbackErrorMapper, id);
  85. if(in == null){
  86. throw new ParameterException("勘误不存在");
  87. }
  88. return in;
  89. }
  90. public Page<UserFeedbackError> select(int page, int pageSize){
  91. return select(userFeedbackErrorMapper, page, pageSize);
  92. }
  93. public Page<UserFeedbackError> select(Integer[] ids){
  94. return page(()->select(userFeedbackErrorMapper, ids), 1, ids.length);
  95. }
  96. public List<UserFeedbackError> select(Collection ids){
  97. return select(userFeedbackErrorMapper, ids);
  98. }
  99. }