package platform.modules.sys.service; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import platform.common.base.service.BaseService; import platform.common.util.ShiroUtils; import platform.modules.government.dto.FeedbackQuery; import platform.modules.government.entity.User; import platform.modules.sys.dao.ActivityFeedbackDao; import platform.modules.sys.entity.ActivityFeedback; import java.math.BigDecimal; import java.util.*; @Service @Transactional public class ActivityFeedbackService extends BaseService { @Autowired private ActivityFeedbackDao activityFeedbackDao; public Integer saveActivityFeedback(ActivityFeedback activityFeedback) { User currUser = ShiroUtils.getUserEntity(); activityFeedback.setUser_id(currUser.getId() + ""); activityFeedback.setUser_type(currUser.getUser_type().toString()); return this.saveSelective(activityFeedback); } @Transactional(readOnly = true) public PageInfo findAvtivityPage(Integer pageNum, Integer pageSize, Integer id) throws Exception { PageHelper.startPage(pageNum, pageSize); List list = activityFeedbackDao.findPage(id); return new PageInfo(list); } @Transactional(readOnly = true) public List findAvtivityList(Integer id) throws Exception { List list = activityFeedbackDao.findPage(id); return list; } /** * 获取反馈列表 * * @param query * @return */ public PageInfo findFeedbackList(FeedbackQuery query) { PageHelper.startPage(query.getPageNum(), query.getPageSzie()); List commentList = activityFeedbackDao.findFeedbackList(query); return new PageInfo<>(commentList); } /** * 获取各反馈类型数 * * @param query * @return */ public List findFeedbackTypelist(FeedbackQuery query) { List feedbacks = activityFeedbackDao.findFeedbackTypelist(query); return feedbacks; } /** * 获取反馈类型数 * * @param query * @return */ public ActivityFeedback findCountByFeedbackType(FeedbackQuery query) { ActivityFeedback feedback = activityFeedbackDao.findCountByFeedbackType(query); return feedback; } /** * 获取综合星级 * * @param activity_id * @return */ public Double findAvgStar(Integer activity_id) { Double avgStar = activityFeedbackDao.findAvgStar(activity_id); return new BigDecimal(avgStar).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); } /** * 获取用户反馈 * * @param id * @param userId * @return */ public ActivityFeedback findUserFeedback(Integer id, int userId) { List feedbacks = activityFeedbackDao.findUserFeedback(id, userId); if (feedbacks.size() > 0) { return feedbacks.get(0); } return new ActivityFeedback(); } /** * @Author: huZhiHao * @Description: 获取列表 * @Date: 2020/1/7 * @Params: [activityId, userId, isPublic, isView] * @Return: java.util.List **/ @Transactional(readOnly = true) public List feedbackList(String activityId, String isPublic, String isView, String minScore, String maxScore) { List feedbacks = activityFeedbackDao.feedbackList(activityId, isPublic, isView, minScore, maxScore); return feedbacks; } /** * @Author: huZhiHao * @Description: 保存 * @Date: 2020/1/7 * @Params: [activityFeedback] * @Return: java.lang.Integer **/ public Integer feedbackSave(ActivityFeedback activityFeedback) { Integer score_1 = activityFeedback.getScore_1(); Integer score_2 = activityFeedback.getScore_2(); Integer score_3 = activityFeedback.getScore_3(); Integer score = 0; if (score_1 != null) score += score_1 * 4; if (score_2 != null) score += score_2 * 4; if (score_3 != null) score += score_3 * 12; activityFeedback.setScore(score); activityFeedback.setFeedback_time(new Date()); return this.saveSelective(activityFeedback); } /** * @Author: huZhiHao * @Description: 更新 * @Date: 2020/1/7 * @Params: [activityFeedback] * @Return: java.lang.Integer **/ public Integer feedbackUpdate(ActivityFeedback activityFeedback) { if (activityFeedback.getIs_top() != null && activityFeedback.getIs_top()) { activityFeedback.setIs_view(true); ActivityFeedback temp1 = this.findById(activityFeedback.getId()); ActivityFeedback query = new ActivityFeedback(); query.setActivity_id(temp1.getActivity_id()); query.setIs_top(true); ActivityFeedback temp2 = this.findOne(query); if(temp2!=null){ temp2.setIs_top(false); this.updateSelective(temp2); } } if (activityFeedback.getIs_view() != null && !activityFeedback.getIs_view()) { activityFeedback.setIs_top(false); } return this.updateSelective(activityFeedback); } /** * @Author: huZhiHao * @Description: 获取详情 * @Date: 2020/1/7 * @Params: [activityId, userId] * @Return: platform.modules.sys.entity.ActivityFeedback * * @return*/ @Transactional(readOnly = true) public List feedbackGet(String activityId, String userId) { ActivityFeedback activityFeedback = new ActivityFeedback(); activityFeedback.setActivity_id(activityId); activityFeedback.setUser_id(userId); return this.findListByWhere(activityFeedback); } /** * @Author: huZhiHao * @Description: 获取分页 * @Date: 2020/1/7 * @Params: [activityId, pageNum, pageSize] * @Return: com.github.pagehelper.PageInfo **/ @Transactional(readOnly = true) public PageInfo feedbackPage(String activityId, String minScore, String maxScore, Integer pageNum, Integer pageSize) { PageHelper.startPage(pageNum, pageSize); List page = activityFeedbackDao.feedbackPage(activityId, minScore, maxScore); return new PageInfo(page); } @Transactional(readOnly = true) public Map getScoreCount(String activityId, String isPublic, String isView, String minScore, String maxScore) { int score100_80 = 0, score80_60 = 0, score60_40 = 0, score40_20 = 0, score20_0 = 0; List feedbacks = activityFeedbackDao.feedbackList(activityId, isPublic, isView, minScore, maxScore); for (ActivityFeedback feedback : feedbacks) { Integer score = feedback.getScore(); if (score != null) { if (score > 80) { score100_80++; } else if (score > 60) { score80_60++; } else if (score > 40) { score60_40++; } else if (score > 20) { score40_20++; } else if (score >= 0) { score20_0++; } } } Map map = new HashMap(); map.put("score100_80", score100_80); map.put("score80_60", score80_60); map.put("score60_40", score60_40); map.put("score40_20", score40_20); map.put("score20_0", score20_0); map.put("score_all", feedbacks.size()); return map; } }