UserTextbookFeedbackService.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.qxgmat.data.constants.enums.status.DirectionStatus;
  9. import com.qxgmat.data.constants.enums.status.FeedbackStatus;
  10. import com.qxgmat.data.dao.UserTextbookFeedbackMapper;
  11. import com.qxgmat.data.dao.entity.UserTextbookFeedback;
  12. import com.qxgmat.data.relation.UserTextbookFeedbackRelationMapper;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.util.Collection;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. @Service
  22. public class UserTextbookFeedbackService extends AbstractService {
  23. private static final Logger logger = LoggerFactory.getLogger(UserTextbookFeedbackService.class);
  24. @Resource
  25. private UserTextbookFeedbackMapper userTextbookFeedbackMapper;
  26. @Resource
  27. private UserTextbookFeedbackRelationMapper userTextbookFeedbackRelationMapper;
  28. private Map<String, String> adminMap = new HashMap<String, String>(){{
  29. put("", "utf");
  30. }};
  31. public Page<UserTextbookFeedback> listAdmin(int page, int size, String target, String questionSubject, FeedbackStatus status, Integer no, String order, DirectionStatus direction){
  32. Integer statusIndex = status == null ? null : status.index;
  33. if(order == null || order.isEmpty()){
  34. order = "id";
  35. }
  36. if(adminMap.containsKey(order)){
  37. order = adminMap.get(order)+".`"+Tools.underscoreName(order)+"`";
  38. }else{
  39. order = adminMap.get("")+".`"+Tools.underscoreName(order)+"`";
  40. }
  41. if (direction == null){
  42. direction = DirectionStatus.DESC;
  43. }
  44. String finalOrder = order;
  45. DirectionStatus finalDirection = direction;
  46. Page<UserTextbookFeedback> p = page(
  47. ()-> userTextbookFeedbackRelationMapper.listAdmin(target, questionSubject, statusIndex, no, finalOrder, finalDirection.key)
  48. , page, size);
  49. Collection ids = Transform.getIds(p, UserTextbookFeedback.class, "id");
  50. Transform.replace(p, select(ids), UserTextbookFeedback.class, "id");
  51. return p;
  52. }
  53. public UserTextbookFeedback add(UserTextbookFeedback ad){
  54. int result = insert(userTextbookFeedbackMapper, ad);
  55. ad = one(userTextbookFeedbackMapper, ad.getId());
  56. if(ad == null){
  57. throw new SystemException("记录添加失败");
  58. }
  59. return ad;
  60. }
  61. public UserTextbookFeedback edit(UserTextbookFeedback ad){
  62. UserTextbookFeedback in = one(userTextbookFeedbackMapper, ad.getId());
  63. if(in == null){
  64. throw new ParameterException("记录不存在");
  65. }
  66. int result = update(userTextbookFeedbackMapper, ad);
  67. return ad;
  68. }
  69. public boolean delete(Number id){
  70. UserTextbookFeedback in = one(userTextbookFeedbackMapper, id);
  71. if(in == null){
  72. throw new ParameterException("记录不存在");
  73. }
  74. int result = delete(userTextbookFeedbackMapper, id);
  75. return result > 0;
  76. }
  77. public UserTextbookFeedback get(Number id){
  78. UserTextbookFeedback in = one(userTextbookFeedbackMapper, id);
  79. if(in == null){
  80. throw new ParameterException("记录不存在");
  81. }
  82. return in;
  83. }
  84. public Page<UserTextbookFeedback> select(int page, int pageSize){
  85. return select(userTextbookFeedbackMapper, page, pageSize);
  86. }
  87. public Page<UserTextbookFeedback> select(Integer[] ids){
  88. return page(()->select(userTextbookFeedbackMapper, ids), 1, ids.length);
  89. }
  90. public List<UserTextbookFeedback> select(Collection ids){
  91. return select(userTextbookFeedbackMapper, ids);
  92. }
  93. }