2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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<MainInfoJoinEvaluation> list = resEvaluationService.selectResEvaluation(resEvaluation);
        int countNums = (int) ((Page) list).getTotal();
        PageBean<MainInfoJoinEvaluation> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(list);
 
        List<Map<String, Object>> 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<String, Object> 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<Res_Evaluation> selectByResourceid(Integer resourceid) {
        Res_Evaluation evaluation = new Res_Evaluation();
        evaluation.setResourceid(resourceid);
        evaluation.setEvaluserid(Integer.parseInt(getUser().getUserid().toString()));
        List<Res_Evaluation> evaluationList = resEvaluationService.selectOtherByResourceid(evaluation);
        for(int i = 0;i<evaluationList.size();i++) {
            String chinesename = orgUserService.getChinesename(evaluationList.get(i).getEvaluserid());
            OrgUnit orgUnit = orgUserService.getDefaultUnit(evaluationList.get(i).getEvaluserid().longValue());
            String unitname = orgUnit.getUnitname();
            evaluationList.get(i).setUsername(chinesename);
            evaluationList.get(i).setUnitname(unitname);
        }
        return evaluationList;
    }
}