package com.landtool.lanbase.modules.res.controller; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.common.utils.Result; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.org.entity.OrgUnit; import com.landtool.lanbase.modules.org.service.OrgUserService; import com.landtool.lanbase.modules.res.entity.Res_Evaluation; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinEvaluation; import com.landtool.lanbase.modules.res.service.ResEvaluationService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.sys.controller.AbstractController; /** * 资源评价 */ @Controller public class ResEvaluationController extends AbstractController { @Autowired private ResEvaluationService resEvaluationService; @Autowired private SysTemPropertyConfig sysConfig; @Autowired private OrgUserService orgUserService; @Autowired private ResMainInfoService resMainInfoService; // ============================================================================ // 后台管理 // ============================================================================ /** * 后台管理 - 列表页面 */ @RequestMapping("/res/manage/evaluation/index") public String indexX(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "manage/evaluation/index"; } /** * 后台管理 - 获取列表数据 */ @ResponseBody @RequestMapping("/res/manage/evaluation/getlist") @LogAction("资源管理,资源评价,资源评价列表查询,查询") public Result getlist(Res_Evaluation resEvaluation, PageBean pageBean) { PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String timeBeg = resEvaluation.getEvaltimeBeg(); String timeEnd = resEvaluation.getEvaltimeEnd(); // 查询当前登陆用户是否是超级管理员 是:查所有 不是:查自己的 if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) { // 如果是超级管理员,不添加用户id,查询所有。如果不是 添加id 查询单个 resEvaluation.setExistpermission(getUserId().toString()); } List list = resEvaluationService.selectResEvaluation(resEvaluation); int countNums = (int) ((Page) list).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(list); List> maps = new LinkedList<>(); for (Integer i = 0; i < list.size(); i++) { // 查询id对应的name String evalname = ""; String auditname = ""; if (list.get(i).getEvaluserid() != null) { evalname = orgUserService.getChinesename(list.get(i).getEvaluserid()); } if (list.get(i).getAudituserid() != null) { auditname = orgUserService.getChinesename(list.get(i).getAudituserid()); } Map map = new HashMap<>(); map.put("resourceid", list.get(i).getResourceid()); map.put("evalid", list.get(i).getEvalid()); map.put("title", list.get(i).getTitle()); map.put("starrating", list.get(i).getStarrating()); map.put("evaluserid", evalname); map.put("evaltime", sdf.format(list.get(i).getEvaltime())); map.put("auditresult", list.get(i).getAuditresult()); map.put("audituserid", auditname); maps.add(map); } return Result.ok().put("totalCount", countNums).put("topics", maps); } /** * 后台管理 - 保存评价 */ @ResponseBody @RequestMapping("/res/manage/evaluation/save") @LogAction("资源管理,资源评价,资源评价信息新增,新增") public String save(Res_Evaluation resEvaluation) { int result = 0; if (resEvaluation.getEvalid() != null && resEvaluation.getEvalid() != 0) {// 后台评价审核 resEvaluation.setAudituserid(getUserId().intValue()); int updateresult = resEvaluationService.updateResEvaluationResult(resEvaluation); if (updateresult == 1) { result = 1; } } else {// 前台新增评价 Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resEvaluation.getResourceid()); Timestamp time = new Timestamp(new Date().getTime()); resEvaluation.setEvaluserid(getUserId().intValue()); //判断当前用户是否是发布人,是发布人则不需要要审核评价 if(getUserId().intValue() == resMainInfo.getCreateuserid()) { resEvaluation.setAuditresult(1); } else { resEvaluation.setAuditresult(0); } resEvaluation.setEvalid(0); resEvaluation.setEvaltime(time); int saveresult = resEvaluationService.insertSelective(resEvaluation); if (saveresult == 1) { result = 1; } } return "{'result':'" + result + "'}"; } /** * 后台管理 - 查看评价内容 */ @RequestMapping("/res/manage/evaluation/content") public String content(int evalid, Model model) { Res_Evaluation res_evaluation = resEvaluationService.selectByPrimaryKey(evalid); model.addAttribute("res_evaluation", res_evaluation); return "manage/evaluation/content"; } /** * 资源查看 - 获取资源评价审核过的列表(自己的评价不用判断) * * @param resourceid * 资源ID * @return */ @ResponseBody @RequestMapping("/res/manage/evaluation/selectByResourceid") public List selectByResourceid(Integer resourceid) { Res_Evaluation evaluation = new Res_Evaluation(); evaluation.setResourceid(resourceid); evaluation.setEvaluserid(Integer.parseInt(getUser().getUserid().toString())); List evaluationList = resEvaluationService.selectOtherByResourceid(evaluation); for(int i = 0;i