From 71b3d6851d12a0d0e7637b0cfac269e48f8f0b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Sun, 11 Dec 2022 23:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AF=84=E8=AE=BA=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xm/core/ctrl/XmMenuCommentController.java | 234 ++++++++++++++++-- .../xm/core/service/XmMenuCalcService.java | 76 ++++++ .../xm/core/service/XmMenuCommentService.java | 25 +- .../com/xm/core/service/XmMenuService.java | 11 + .../xm/core/dao/XmMenuCommentMapper.xml | 37 ++- .../mapper/xm/core/dao/XmMenuMapper.xml | 38 +++ 6 files changed, 392 insertions(+), 29 deletions(-) create mode 100644 xm-core/src/main/java/com/xm/core/service/XmMenuCalcService.java diff --git a/xm-core/src/main/java/com/xm/core/ctrl/XmMenuCommentController.java b/xm-core/src/main/java/com/xm/core/ctrl/XmMenuCommentController.java index a3c7c67e..b5364801 100644 --- a/xm-core/src/main/java/com/xm/core/ctrl/XmMenuCommentController.java +++ b/xm-core/src/main/java/com/xm/core/ctrl/XmMenuCommentController.java @@ -1,32 +1,32 @@ package com.xm.core.ctrl; -import java.util.*; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import io.swagger.annotations.*; - -import static com.mdp.core.utils.ResponseHelper.*; -import static com.mdp.core.utils.BaseUtils.*; import com.mdp.core.entity.Tips; import com.mdp.core.err.BizException; -import com.mdp.mybatis.PageUtils; import com.mdp.core.utils.RequestUtils; -import com.mdp.core.utils.NumberUtil; +import com.mdp.core.utils.ResponseHelper; +import com.mdp.msg.client.PushNotifyMsgService; +import com.mdp.mybatis.PageUtils; +import com.mdp.qx.HasRole; import com.mdp.safe.client.entity.User; import com.mdp.safe.client.utils.LoginUtils; -import ApiEntityParams; +import com.mdp.swagger.ApiEntityParams; +import com.xm.core.entity.XmMenu; +import com.xm.core.entity.XmMenuComment; +import com.xm.core.service.XmMenuCalcService; +import com.xm.core.service.XmMenuCommentService; +import com.xm.core.service.XmMenuService; +import io.swagger.annotations.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; -import com.xm.core.service.XmMenuCommentService; -import com.xm.core.entity.XmMenuComment; +import java.util.*; +import java.util.stream.Collectors; + +import static com.mdp.core.utils.BaseUtils.toMap; /** * url编制采用rest风格,如对xm_menu_comment 档案评论表的操作有增删改查,对应的url分别为:
@@ -42,6 +42,12 @@ public class XmMenuCommentController { @Autowired private XmMenuCommentService xmMenuCommentService; + + @Autowired + XmMenuService xmMenuService; + + @Autowired + PushNotifyMsgService notifyMsgService; Map fieldsMap = toMap(new XmMenuComment()); @@ -65,15 +71,199 @@ public class XmMenuCommentController { Tips tips=new Tips("查询成功"); RequestUtils.transformArray(xmMenuComment, "ids"); PageUtils.startPage(xmMenuComment); + String pid= (String) xmMenuComment.get("pid"); + if(!StringUtils.hasText(pid)){ + xmMenuComment.put("pidIsNull","1"); + } + List> xmMenuCommentList = xmMenuCommentService.selectListMapByWhere(xmMenuComment); //列出XmMenuComment列表 + + if(xmMenuCommentList.size()>0) { + List> children=xmMenuCommentService.selectListByPids(xmMenuCommentList.stream().map(k->(String)k.get("id")).collect(Collectors.toList())); + m.put("children", children); + } + PageUtils.responePage(m, xmMenuCommentList); m.put("data",xmMenuCommentList); m.put("tips", tips); return m; } - - + + + @ApiOperation( value = "新增一条档案评论表信息",notes="addXmMenuComment,主键如果为空,后台自动生成") + @ApiResponses({ + @ApiResponse(code = 200,response=XmMenuComment.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @HasRole + @RequestMapping(value="/add",method=RequestMethod.POST) + public Map addXmMenuComment(@RequestBody XmMenuComment xmMenuComment) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功评论"); + try{ + User user=LoginUtils.getCurrentUserInfo(); + XmMenu xmMenuDb=this.xmMenuService.selectOneById(xmMenuComment.getMenuId()); + if(xmMenuDb==null){ + return ResponseHelper.failed("xmMenu-0","需求已不存在"); + } + xmMenuComment.setId(xmMenuCommentService.createKey("id")); + xmMenuComment.setBranchId(user.getBranchId()); + xmMenuComment.setUserid(user.getUserid()); + xmMenuComment.setUsername(user.getUsername()); + xmMenuComment.setCdate(new Date()); + xmMenuComment.setIp(RequestUtils.getIpAddr(RequestUtils.getRequest())); + xmMenuCommentService.insert(xmMenuComment); + if(StringUtils.hasText(xmMenuComment.getPid())){ + xmMenuCommentService.updateChildrenSum(xmMenuComment.getPid(),Integer.valueOf(1)); + } + XmMenuCalcService.commentsSet.add(xmMenuComment.getMenuId()); + if(!user.getUserid().equals(xmMenuDb.getMmUserid())){ + notifyMsgService.pushMsg(user, xmMenuDb.getMmUserid(), xmMenuDb.getMmUsername(),"10",xmMenuDb.getMenuId(),xmMenuComment.getId(),user.getUsername()+"发表评论:"+xmMenuComment.getContext()); + } + m.put("data",xmMenuComment); + }catch (BizException e) { + tips=e.getTips(); + logger.error("执行异常",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("执行异常",e); + } + m.put("tips", tips); + return m; + } + + + @ApiOperation( value = "删除一条档案评论表信息",notes="delXmMenuComment,仅需要上传主键字段") + @ApiResponses({ + @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}") + }) + @RequestMapping(value="/del",method=RequestMethod.POST) + public Map delXmMenuComment(@RequestBody XmMenuComment xmMenuComment){ + Map m = new HashMap<>(); + Tips tips=new Tips("成功删除一条数据"); + try{ + XmMenuComment commentDb=this.xmMenuCommentService.selectOneById(xmMenuComment.getId()); + if(commentDb==null){ + return ResponseHelper.failed("data-0","评论已不存在"); + } + User user=LoginUtils.getCurrentUserInfo(); + if(!LoginUtils.isSuperAdmin()){ + if(!LoginUtils.isBranchAdmin(commentDb.getBranchId())){ + if(!user.getUserid().equals(commentDb.getUserid())){ + return ResponseHelper.failed("no-qx-0","无权限删除评论"); + } + } + } + xmMenuCommentService.deleteByPk(xmMenuComment); + if(StringUtils.hasText(commentDb.getPid())){ + xmMenuCommentService.updateChildrenSum(commentDb.getPid(),Integer.valueOf(-1)); + } + }catch (BizException e) { + tips=e.getTips(); + logger.error("执行异常",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("执行异常",e); + } + m.put("tips", tips); + return m; + } + + + @ApiOperation( value = "点赞评论",notes="praiseComment") + @ApiResponses({ + @ApiResponse(code = 200,response=XmMenuComment.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @RequestMapping(value="/praise",method=RequestMethod.POST) + public Map praiseComment(@RequestBody XmMenuComment xmMenuComment) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功更新一条数据"); + try{ + xmMenuCommentService.update("praiseComment", xmMenuComment); + + m.put("data",xmMenuComment); + }catch (BizException e) { + tips=e.getTips(); + logger.error("执行异常",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("执行异常",e); + } + m.put("tips", tips); + return m; + } + + @ApiOperation( value = "屏蔽评论",notes="unShowComment") + @ApiResponses({ + @ApiResponse(code = 200,response=XmMenuComment.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @RequestMapping(value="/unshow",method=RequestMethod.POST) + public Map unShowComment(@RequestBody String[] ids) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功屏蔽评论"); + try{ + User user=LoginUtils.getCurrentUserInfo(); + List comments=this.xmMenuCommentService.selectListByIds(Arrays.asList(ids)); + if(comments==null || comments.size()==0){ + return ResponseHelper.failed("data-0","评论已不存在"); + } + boolean isSuperAdmin=LoginUtils.isSuperAdmin(); + for (XmMenuComment comment : comments) { + if(!isSuperAdmin){ + if(!LoginUtils.isBranchAdmin(comment.getBranchId())){ + if(!user.getUserid().equals(comment.getUserid())){ + return ResponseHelper.failed("无权限修改","无权限屏蔽评论【"+comment.getContext()+"】"); + } + } + } + } + xmMenuCommentService.unShowComment(ids); + }catch (BizException e) { + tips=e.getTips(); + logger.error("执行异常",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("执行异常",e); + } + m.put("tips", tips); + return m; + } + + @ApiOperation( value = "打开评论",notes="showComment") + @ApiResponses({ + @ApiResponse(code = 200,response=XmMenuComment.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @RequestMapping(value="/show",method=RequestMethod.POST) + public Map showComment(@RequestBody String[] ids) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功打开评论"); + try{ + User user= LoginUtils.getCurrentUserInfo(); + List comments=this.xmMenuCommentService.selectListByIds(Arrays.asList(ids)); + if(comments==null || comments.size()==0){ + return ResponseHelper.failed("data-0","评论已不存在"); + } + boolean isSuperAdmin=LoginUtils.isSuperAdmin(); + for (XmMenuComment comment : comments) { + if(!isSuperAdmin){ + if(!LoginUtils.isBranchAdmin(comment.getBranchId())){ + if(!user.getUserid().equals(comment.getUserid())){ + return ResponseHelper.failed("无权限修改","无权限打开此评论【"+comment.getContext()+"】"); + } + } + } + } + xmMenuCommentService.showComment(ids); + }catch (BizException e) { + tips=e.getTips(); + logger.error("执行异常",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("执行异常",e); + } + m.put("tips", tips); + return m; + } /** @ApiOperation( value = "新增一条档案评论表信息",notes=" ") diff --git a/xm-core/src/main/java/com/xm/core/service/XmMenuCalcService.java b/xm-core/src/main/java/com/xm/core/service/XmMenuCalcService.java new file mode 100644 index 00000000..bceccab8 --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/service/XmMenuCalcService.java @@ -0,0 +1,76 @@ +package com.xm.core.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.
+ * 组织 com.mdp 顶级模块 arc 大模块 archive 小模块
+ * 实体 ArchiveUp 表 arc_archive_up 当前主键(包括多主键): archive_id,userid; + ***/ +@Service("xm.xmMenu.xmMenuCalcService") +public class XmMenuCalcService { + static Logger logger =LoggerFactory.getLogger(XmMenuCalcService.class); + + public static Set upSet =new HashSet<>(); + public static Set commentsSet =new HashSet<>(); + + private static Map readMap=new HashMap<>(); + + @Autowired + XmMenuService xmMenuService; + + + public static void putReads(String menuId,int nums){ + Integer c=readMap.get(menuId); + if(c==null){ + readMap.put(menuId,new Integer(nums)); + }else{ + readMap.put(menuId,new Integer(c+nums)); + } + } + + @Scheduled(cron = "* */4 * * * ?") + private void calcUp(){ + if(upSet.isEmpty()){ + return; + } + List menuIds= upSet.stream().collect(Collectors.toList()); + upSet.clear(); + + xmMenuService.updateUps(menuIds); + + } + + @Scheduled(cron = "* */5 * * * ?") + private void calcComments(){ + if(commentsSet.isEmpty()){ + return; + } + List menuIds= commentsSet.stream().collect(Collectors.toList()); + commentsSet.clear(); + + xmMenuService.updateComments(menuIds); + + } + + @Scheduled(cron = "* */2 * * * ?") + private void calcRead(){ + Map map=new HashMap<>(); + map.putAll(readMap); + readMap.clear(); + if(map.isEmpty()){ + return; + } + for (Map.Entry entry : map.entrySet()) { + xmMenuService.upReads(entry.getKey(),entry.getValue()); + } + } +} + diff --git a/xm-core/src/main/java/com/xm/core/service/XmMenuCommentService.java b/xm-core/src/main/java/com/xm/core/service/XmMenuCommentService.java index 686ac94a..238e2f0c 100644 --- a/xm-core/src/main/java/com/xm/core/service/XmMenuCommentService.java +++ b/xm-core/src/main/java/com/xm/core/service/XmMenuCommentService.java @@ -1,16 +1,13 @@ package com.xm.core.service; +import com.mdp.core.service.BaseService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + import java.util.List; import java.util.Map; -import org.springframework.stereotype.Service; -import com.mdp.core.service.BaseService; -import static com.mdp.core.utils.BaseUtils.*; -import com.mdp.core.entity.Tips; -import com.mdp.core.err.BizException; -import com.xm.core.entity.XmMenuComment; /** * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.
* 组织 com 顶级模块 xm 大模块 core 小模块
@@ -20,5 +17,21 @@ import com.xm.core.entity.XmMenuComment; public class XmMenuCommentService extends BaseService { static Logger logger =LoggerFactory.getLogger(XmMenuCommentService.class); + + public void showComment(String[] ids) { + this.update("showComment", ids); + + } + public void unShowComment(String[] ids) { + this.update("unShowComment", ids); + } + + public void updateChildrenSum(String pid,Integer addCount) { + super.update("updateChildrenSum",map("pid",pid,"addCount",addCount)); + } + + public List> selectListByPids(List pids) { + return super.selectList("selectListByPids",pids); + } } diff --git a/xm-core/src/main/java/com/xm/core/service/XmMenuService.java b/xm-core/src/main/java/com/xm/core/service/XmMenuService.java index 43d35dfc..ea1f072d 100644 --- a/xm-core/src/main/java/com/xm/core/service/XmMenuService.java +++ b/xm-core/src/main/java/com/xm/core/service/XmMenuService.java @@ -404,5 +404,16 @@ public class XmMenuService extends BaseService { public String createKey(String keyName) { return "M"+sequenceService.getCommonNo("{date62:yyyyMMddHHmmss}{rands:4}"); } + + public void updateUps(List menuIds) { + super.update("updateUps",menuIds); + } + + public void updateComments(List menuIds) { + super.update("updateComments",menuIds); + } + public void upReads(String menuId,Integer reads) { + super.update("upReads",map("menuId",menuId,"reads",reads)); + } } diff --git a/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuCommentMapper.xml b/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuCommentMapper.xml index c640208d..ad92dab7 100644 --- a/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuCommentMapper.xml +++ b/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuCommentMapper.xml @@ -12,8 +12,43 @@ - + and pid is null + + + update xm_menu_comment + set is_show='1' + where id in + + #{item } + + + + + update xm_menu_comment + set is_show='0' + where id in + + #{item } + + + + + update xm_menu_comment + set ups=ifnull(ups,0)+1 + where id = #{id} + + + + update xm_menu_comment res set res.child_nums=ifnull(res.child_nums,0) + #{addCount} + where id=#{pid} + diff --git a/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuMapper.xml b/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuMapper.xml index d442d9e3..5a48ddac 100644 --- a/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuMapper.xml +++ b/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuMapper.xml @@ -238,6 +238,44 @@ or exists( select 1 from xm_menu m where m.mm_userid=#{mmUserid} and res.pid_paths like concat(m.pid_paths,'%') ) ) + + + + + + update xm_menu res set reads=ifnull(reads,0)+#{reads} + where menu_id=#{menuId} + + + + update xm_menu res left join + (select count(*) ups,up.menu_id from xm_menu_up up + where up.menu_id in + + #{item } + + group by up.menu_id + ) as up_sum on res.menu_id=up_sum.menu_id set res.ups=up_sum.ups + where res.menu_id in + + #{item } + + + + + update xm_menu res left join + (select count(*) ups,up.menu_id from xm_menu_comment up + where up.menu_id in + + #{item } + + group by up.menu_id + ) as up_sum on res.menu_id=up_sum.menu_id set res.comments=up_sum.ups + where res.menu_id in + + #{item } + +