Jelajahi Sumber

添加建议留言板功能。

lighter 4 tahun lalu
induk
melakukan
ac70e15a5c

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>web-server</artifactId>
-    <version>7.1</version>
+    <version>7.3</version>
     <name>web-server</name>
     <description>server for yibao-web</description>
 

+ 26 - 0
src/main/java/thyyxxk/webserver/controller/settings/SettingsController.java

@@ -7,6 +7,7 @@ import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.settings.deptphones.DeptPhones;
 import thyyxxk.webserver.entity.settings.permissions.*;
 import thyyxxk.webserver.entity.settings.users.ChangePwdParam;
+import thyyxxk.webserver.entity.settings.users.WorkIntegrationPlatformAdvice;
 import thyyxxk.webserver.service.settings.SettingsService;
 
 import java.util.List;
@@ -85,4 +86,29 @@ public class SettingsController {
     public ResultVo<String> saveDeptPhone(@RequestBody DeptPhones param) {
         return service.saveDeptPhone(param);
     }
+
+    @GetMapping("/getMyAdvices")
+    public ResultVo<List<WorkIntegrationPlatformAdvice>> getMyAdvices() {
+        return service.getMyAdvices();
+    }
+
+    @PostMapping("/submitNewAdvice")
+    public ResultVo<String> submitNewAdvice(@RequestBody WorkIntegrationPlatformAdvice advice) {
+        return service.submitNewAdvice(advice);
+    }
+
+    @GetMapping("/checkAdvice")
+    public ResultVo<String> checkAdvice(@RequestParam("id") Integer id) {
+        return service.checkAdvice(id);
+    }
+
+    @GetMapping("/dismissUserBadge")
+    public ResultVo<String> dismissUserBadge(@RequestParam("id") Integer id) {
+        return service.dismissUserBadge(id);
+    }
+
+    @PostMapping("/replyAdvice")
+    public ResultVo<String> replyAdvice(@RequestBody WorkIntegrationPlatformAdvice advice) {
+        return service.replyAdvice(advice);
+    }
 }

+ 24 - 0
src/main/java/thyyxxk/webserver/dao/his/settings/SettingsDao.java

@@ -6,6 +6,7 @@ import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.settings.deptphones.DeptPhones;
 import thyyxxk.webserver.entity.settings.permissions.MenuItem;
 import thyyxxk.webserver.entity.settings.permissions.Role;
+import thyyxxk.webserver.entity.settings.users.WorkIntegrationPlatformAdvice;
 
 import java.util.List;
 
@@ -103,4 +104,27 @@ public interface SettingsDao {
 
     @Update("update dj_dict_dept_phones set in_phone=#{inPhone}, out_phone=#{outPhone} where id=#{id}")
     void saveDeptPhone(DeptPhones param);
+
+    @Select("select * from t_work_integration_platform_advice order by status_flag")
+    List<WorkIntegrationPlatformAdvice> selectAllAdvices();
+
+    @Select("select * from t_work_integration_platform_advice where submit_staff=#{code} order by user_badge desc")
+    List<WorkIntegrationPlatformAdvice> selectMyAdvices(@Param("code") String code);
+
+    @Insert("insert into t_work_integration_platform_advice (submit_staff, submit_datetime, submit_content, status_flag) " +
+            "values (#{staff},getdate(),#{content},0)")
+    void insertNewAdvice(@Param("staff") String staff, @Param("content") String content);
+
+    @Select("select user_code from dj_user_role where role_id=1")
+    List<String> selectAdmins();
+
+    @Update("update t_work_integration_platform_advice set status_flag=1 where id=#{id}")
+    void checkAdvice(@Param("id") Integer id);
+
+    @Update("update t_work_integration_platform_advice set user_badge=0 where id=#{id}")
+    void dismissUserBadge(@Param("id") Integer id);
+
+    @Update("update t_work_integration_platform_advice set reply=#{reply},reply_staff=#{staff}, " +
+            "reply_datetime=getdate(), status_flag=2, user_badge=1 where id=#{id}")
+    void updateReply(@Param("id") Integer id, @Param("reply") String reply, @Param("staff") String staff);
 }

+ 60 - 0
src/main/java/thyyxxk/webserver/entity/settings/users/WorkIntegrationPlatformAdvice.java

@@ -0,0 +1,60 @@
+package thyyxxk.webserver.entity.settings.users;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @description: 工作集成平台建议留言
+ * @author: DingJie
+ * @create: 2021-04-13 16:13:40
+ **/
+@Data
+public class WorkIntegrationPlatformAdvice {
+    private static final long serialVersionUID =  7775714639656441287L;
+
+    /**
+     * 主键,自增id
+     */
+    private Integer id;
+
+    /**
+     * 提交人id
+     */
+    private String submitStaff;
+
+    /**
+     * 提交时间
+     */
+    private Date submitDatetime;
+
+    /**
+     * 建议内容,长度不超过300个汉字
+     */
+    private String submitContent;
+
+    /**
+     * 状态标志:0-未查看,1-已查看,2-已回复
+     */
+    private Integer statusFlag;
+
+    /**
+     * 对本条建议的回复,不超过150个汉字
+     */
+    private String reply;
+
+    /**
+     * 回复人id
+     */
+    private String replyStaff;
+
+    /**
+     * 回复时间
+     */
+    private Date replyDatetime;
+
+    /**
+     * 是否为用户显示小红点,1:是,0:否
+     * */
+    private Integer userBadge;
+}

+ 56 - 0
src/main/java/thyyxxk/webserver/service/settings/SettingsService.java

@@ -13,8 +13,11 @@ import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.settings.deptphones.DeptPhones;
 import thyyxxk.webserver.entity.settings.users.ChangePwdParam;
 import thyyxxk.webserver.entity.settings.permissions.*;
+import thyyxxk.webserver.entity.settings.users.WorkIntegrationPlatformAdvice;
 import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
 import thyyxxk.webserver.utils.TokenUtil;
+import thyyxxk.webserver.websocket.WebSocketServer;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -35,6 +38,9 @@ public class SettingsService {
     public ResultVo<UserInfo> getUserInfo() {
         final String code = TokenUtil.getTokenUserId();
         final UserInfo user = dao.getUserInfo(code);
+        if (null == user) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此用户的在职信息,请重新登录!");
+        }
         final String token = TokenUtil.getCorpWechatToken();
         final String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + token +
                 "&userid=" + user.getCodeRs();
@@ -42,6 +48,7 @@ public class SettingsService {
         final String result = restTemplate.getForObject(url, String.class);
         JSONObject json = JSONObject.parseObject(result);
         user.setAvatar(json.getString("avatar"));
+        user.setRoles(dao.getUserRoles(code));
         return ResultVoUtil.success(user);
     }
 
@@ -172,4 +179,53 @@ public class SettingsService {
         dao.saveDeptPhone(param);
         return ResultVoUtil.success();
     }
+
+    public ResultVo<List<WorkIntegrationPlatformAdvice>> getMyAdvices() {
+        String userId = TokenUtil.getTokenUserId();
+        List<Integer> userRoles = dao.getUserRoles(userId);
+        List<WorkIntegrationPlatformAdvice> list;
+        if (null != userRoles && userRoles.contains(1)) {
+            list = dao.selectAllAdvices();
+        } else {
+            list = dao.selectMyAdvices(userId);
+        }
+        return ResultVoUtil.success(list);
+    }
+
+    public ResultVo<String> submitNewAdvice(WorkIntegrationPlatformAdvice advice) {
+        if (StringUtil.isBlank(advice.getSubmitContent())) {
+            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请填写建议内容!");
+        }
+        String userId = TokenUtil.getTokenUserId();
+        dao.insertNewAdvice(userId, advice.getSubmitContent());
+        List<String> admins = dao.selectAdmins();
+        JSONObject obj = new JSONObject();
+        obj.put("name", "systemNotification");
+        obj.put("message", String.format("用户【%s】提交了新的建议,请前往个人中心查看。", userId));
+        String message = obj.toJSONString();
+        admins.forEach(code -> WebSocketServer.sendMessageByUserCode(code, message));
+        return ResultVoUtil.success();
+    }
+
+    public ResultVo<String> checkAdvice(Integer id) {
+        dao.checkAdvice(id);
+        return ResultVoUtil.success();
+    }
+
+    public ResultVo<String> dismissUserBadge(Integer id) {
+        dao.dismissUserBadge(id);
+        return ResultVoUtil.success();
+    }
+
+    public ResultVo<String> replyAdvice(WorkIntegrationPlatformAdvice advice) {
+        if (StringUtil.isBlank(advice.getReply())) {
+            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请填写回复内容!");
+        }
+        dao.updateReply(advice.getId(), advice.getReply(), TokenUtil.getTokenUserId());
+        JSONObject obj = new JSONObject();
+        obj.put("name", "systemNotification");
+        obj.put("message", "您提交的建议已有新的回复,请前往个人中心查看。");
+        WebSocketServer.sendMessageByUserCode(advice.getSubmitStaff(), obj.toJSONString());
+        return ResultVoUtil.success();
+    }
 }

+ 17 - 14
src/main/java/thyyxxk/webserver/websocket/WebSocketServer.java

@@ -12,25 +12,28 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
+/**
+ * @author dj
+ */
 @Slf4j
 @ServerEndpoint("/websocket/{sid}")
 @Component
 public class WebSocketServer {
-    private static final AtomicInteger onlineCount = new AtomicInteger();
-    private static final ConcurrentHashMap<String, Session> sessionMap = new ConcurrentHashMap<>();
+    private static final AtomicInteger ONLINE_COUNT = new AtomicInteger();
+    private static final ConcurrentHashMap<String, Session> SESSION_MAP = new ConcurrentHashMap<>();
 
     @OnOpen
     public void onOpen(Session session, @PathParam("sid") String sid) {
-        sessionMap.put(sid, session);
-        onlineCount.incrementAndGet();
-        log.info("有新连接加入:{},当前在线人数为:{}", sid, onlineCount.get());
+        SESSION_MAP.put(sid, session);
+        ONLINE_COUNT.incrementAndGet();
+        log.info("有新连接加入:{},当前在线人数为:{}", sid, ONLINE_COUNT.get());
     }
 
     @OnClose
     public void onClose(@PathParam("sid") String sid) {
-        sessionMap.remove(sid);
-        onlineCount.decrementAndGet();
-        log.info("有一连接关闭:{},当前在线人数为:{}", sid, onlineCount.get());
+        SESSION_MAP.remove(sid);
+        ONLINE_COUNT.decrementAndGet();
+        log.info("有一连接关闭:{},当前在线人数为:{}", sid, ONLINE_COUNT.get());
     }
 
     @OnMessage
@@ -45,7 +48,7 @@ public class WebSocketServer {
     }
 
     public static int sendMessage(String sid, String message) {
-        Session session = sessionMap.get(sid);
+        Session session = SESSION_MAP.get(sid);
         if (null == session) {
             return ExceptionEnum.NULL_POINTER.getCode();
         }
@@ -60,7 +63,7 @@ public class WebSocketServer {
     }
 
     public static int sendFloorTriageMessage(String userCode, String message) {
-        for (Map.Entry<String, Session> entry : sessionMap.entrySet()) {
+        for (Map.Entry<String, Session> entry : SESSION_MAP.entrySet()) {
             if (entry.getKey().startsWith(userCode) && entry.getKey().endsWith("triageFloorScreen")) {
                 try {
                     entry.getValue().getBasicRemote().sendText(message);
@@ -76,7 +79,7 @@ public class WebSocketServer {
     }
 
     public static int sendRoomTriageMessage(String roomCode, String message) {
-        Session session = sessionMap.get(roomCode + "-triageRoomScreen");
+        Session session = SESSION_MAP.get(roomCode + "-triageRoomScreen");
         if (null == session) {
             return ExceptionEnum.NULL_POINTER.getCode();
         }
@@ -91,7 +94,7 @@ public class WebSocketServer {
     }
 
     public static void sendMessageByUserCode(String code, String message) {
-        for (Map.Entry<String, Session> entry : sessionMap.entrySet()) {
+        for (Map.Entry<String, Session> entry : SESSION_MAP.entrySet()) {
             if (entry.getKey().startsWith(code)) {
                 try {
                     entry.getValue().getBasicRemote().sendText(message);
@@ -105,7 +108,7 @@ public class WebSocketServer {
     }
 
     public static void sendMessageToAll(String message) {
-        for (Session session : sessionMap.values()) {
+        for (Session session : SESSION_MAP.values()) {
             try {
                 session.getBasicRemote().sendText(message);
             } catch (IOException e) {
@@ -116,6 +119,6 @@ public class WebSocketServer {
     }
 
     public static int getOnlineCount() {
-        return onlineCount.get();
+        return ONLINE_COUNT.get();
     }
 }