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 adminMap = new HashMap(){{ put("", "utf"); }}; public Page 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 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 select(int page, int pageSize){ return select(userTextbookFeedbackMapper, page, pageSize); } public Page select(Integer[] ids){ return page(()->select(userTextbookFeedbackMapper, ids), 1, ids.length); } public List select(Collection ids){ return select(userTextbookFeedbackMapper, ids); } }