123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package com.qxgmat.service.inline;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.AbstractService;
- import com.nuliji.tools.Tools;
- import com.nuliji.tools.Transform;
- import com.nuliji.tools.exception.ParameterException;
- import com.nuliji.tools.exception.SystemException;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.constants.enums.status.FeedbackStatus;
- import com.qxgmat.data.dao.UserTextbookFeedbackMapper;
- import com.qxgmat.data.dao.entity.UserTextbookFeedback;
- import com.qxgmat.data.relation.UserTextbookFeedbackRelationMapper;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Service
- public class UserTextbookFeedbackService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(UserTextbookFeedbackService.class);
- @Resource
- private UserTextbookFeedbackMapper userTextbookFeedbackMapper;
- @Resource
- private UserTextbookFeedbackRelationMapper userTextbookFeedbackRelationMapper;
- private Map<String, String> adminMap = new HashMap<String, String>(){{
- put("", "utf");
- }};
- public Page<UserTextbookFeedback> listAdmin(int page, int size, String target, String questionSubject, FeedbackStatus status, Integer no, String order, DirectionStatus direction){
- Integer statusIndex = status == null ? null : status.index;
- if(order == null || order.isEmpty()){
- order = "id";
- }
- if(adminMap.containsKey(order)){
- order = adminMap.get(order)+".`"+Tools.underscoreName(order)+"`";
- }else{
- order = adminMap.get("")+".`"+Tools.underscoreName(order)+"`";
- }
- if (direction == null){
- direction = DirectionStatus.DESC;
- }
- String finalOrder = order;
- DirectionStatus finalDirection = direction;
- Page<UserTextbookFeedback> p = page(
- ()-> userTextbookFeedbackRelationMapper.listAdmin(target, questionSubject, statusIndex, no, finalOrder, finalDirection.key)
- , page, size);
- Collection ids = Transform.getIds(p, UserTextbookFeedback.class, "id");
- Transform.replace(p, select(ids), UserTextbookFeedback.class, "id");
- return p;
- }
- public UserTextbookFeedback add(UserTextbookFeedback ad){
- int result = insert(userTextbookFeedbackMapper, ad);
- ad = one(userTextbookFeedbackMapper, ad.getId());
- if(ad == null){
- throw new SystemException("记录添加失败");
- }
- return ad;
- }
- public UserTextbookFeedback edit(UserTextbookFeedback ad){
- UserTextbookFeedback in = one(userTextbookFeedbackMapper, ad.getId());
- if(in == null){
- throw new ParameterException("记录不存在");
- }
- int result = update(userTextbookFeedbackMapper, ad);
- return ad;
- }
- public boolean delete(Number id){
- UserTextbookFeedback in = one(userTextbookFeedbackMapper, id);
- if(in == null){
- throw new ParameterException("记录不存在");
- }
- int result = delete(userTextbookFeedbackMapper, id);
- return result > 0;
- }
- public UserTextbookFeedback get(Number id){
- UserTextbookFeedback in = one(userTextbookFeedbackMapper, id);
- if(in == null){
- throw new ParameterException("记录不存在");
- }
- return in;
- }
- public Page<UserTextbookFeedback> select(int page, int pageSize){
- return select(userTextbookFeedbackMapper, page, pageSize);
- }
- public Page<UserTextbookFeedback> select(Integer[] ids){
- return page(()->select(userTextbookFeedbackMapper, ids), 1, ids.length);
- }
- public List<UserTextbookFeedback> select(Collection ids){
- return select(userTextbookFeedbackMapper, ids);
- }
- }
|