Browse Source

需求评论模块

master
陈裕财 3 years ago
parent
commit
71b3d6851d
  1. 234
      xm-core/src/main/java/com/xm/core/ctrl/XmMenuCommentController.java
  2. 76
      xm-core/src/main/java/com/xm/core/service/XmMenuCalcService.java
  3. 25
      xm-core/src/main/java/com/xm/core/service/XmMenuCommentService.java
  4. 11
      xm-core/src/main/java/com/xm/core/service/XmMenuService.java
  5. 37
      xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuCommentMapper.xml
  6. 38
      xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuMapper.xml

234
xm-core/src/main/java/com/xm/core/ctrl/XmMenuCommentController.java

@ -1,32 +1,32 @@
package com.xm.core.ctrl; 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.entity.Tips;
import com.mdp.core.err.BizException; import com.mdp.core.err.BizException;
import com.mdp.mybatis.PageUtils;
import com.mdp.core.utils.RequestUtils; 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.entity.User;
import com.mdp.safe.client.utils.LoginUtils; 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 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分别为:<br> * url编制采用rest风格,如对xm_menu_comment 档案评论表的操作有增删改查,对应的url分别为:<br>
@ -42,6 +42,12 @@ public class XmMenuCommentController {
@Autowired @Autowired
private XmMenuCommentService xmMenuCommentService; private XmMenuCommentService xmMenuCommentService;
@Autowired
XmMenuService xmMenuService;
@Autowired
PushNotifyMsgService notifyMsgService;
Map<String,Object> fieldsMap = toMap(new XmMenuComment()); Map<String,Object> fieldsMap = toMap(new XmMenuComment());
@ -65,15 +71,199 @@ public class XmMenuCommentController {
Tips tips=new Tips("查询成功"); Tips tips=new Tips("查询成功");
RequestUtils.transformArray(xmMenuComment, "ids"); RequestUtils.transformArray(xmMenuComment, "ids");
PageUtils.startPage(xmMenuComment); PageUtils.startPage(xmMenuComment);
String pid= (String) xmMenuComment.get("pid");
if(!StringUtils.hasText(pid)){
xmMenuComment.put("pidIsNull","1");
}
List<Map<String,Object>> xmMenuCommentList = xmMenuCommentService.selectListMapByWhere(xmMenuComment); //列出XmMenuComment列表 List<Map<String,Object>> xmMenuCommentList = xmMenuCommentService.selectListMapByWhere(xmMenuComment); //列出XmMenuComment列表
if(xmMenuCommentList.size()>0) {
List<Map<String, Object>> children=xmMenuCommentService.selectListByPids(xmMenuCommentList.stream().map(k->(String)k.get("id")).collect(Collectors.toList()));
m.put("children", children);
}
PageUtils.responePage(m, xmMenuCommentList); PageUtils.responePage(m, xmMenuCommentList);
m.put("data",xmMenuCommentList); m.put("data",xmMenuCommentList);
m.put("tips", tips); m.put("tips", tips);
return m; 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<String,Object> addXmMenuComment(@RequestBody XmMenuComment xmMenuComment) {
Map<String,Object> 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<String,Object> delXmMenuComment(@RequestBody XmMenuComment xmMenuComment){
Map<String,Object> 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<String,Object> praiseComment(@RequestBody XmMenuComment xmMenuComment) {
Map<String,Object> 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<String,Object> unShowComment(@RequestBody String[] ids) {
Map<String,Object> m = new HashMap<>();
Tips tips=new Tips("成功屏蔽评论");
try{
User user=LoginUtils.getCurrentUserInfo();
List<XmMenuComment> 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<String,Object> showComment(@RequestBody String[] ids) {
Map<String,Object> m = new HashMap<>();
Tips tips=new Tips("成功打开评论");
try{
User user= LoginUtils.getCurrentUserInfo();
List<XmMenuComment> 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=" ") @ApiOperation( value = "新增一条档案评论表信息",notes=" ")

76
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;
/**
* 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br>
* 组织 com.mdp 顶级模块 arc 大模块 archive 小模块 <br>
* 实体 ArchiveUp arc_archive_up 当前主键(包括多主键): archive_id,userid;
***/
@Service("xm.xmMenu.xmMenuCalcService")
public class XmMenuCalcService {
static Logger logger =LoggerFactory.getLogger(XmMenuCalcService.class);
public static Set<String> upSet =new HashSet<>();
public static Set<String> commentsSet =new HashSet<>();
private static Map<String,Integer> 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<String> menuIds= upSet.stream().collect(Collectors.toList());
upSet.clear();
xmMenuService.updateUps(menuIds);
}
@Scheduled(cron = "* */5 * * * ?")
private void calcComments(){
if(commentsSet.isEmpty()){
return;
}
List<String> menuIds= commentsSet.stream().collect(Collectors.toList());
commentsSet.clear();
xmMenuService.updateComments(menuIds);
}
@Scheduled(cron = "* */2 * * * ?")
private void calcRead(){
Map<String,Integer> map=new HashMap<>();
map.putAll(readMap);
readMap.clear();
if(map.isEmpty()){
return;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
xmMenuService.upReads(entry.getKey(),entry.getValue());
}
}
}

25
xm-core/src/main/java/com/xm/core/service/XmMenuCommentService.java

@ -1,16 +1,13 @@
package com.xm.core.service; package com.xm.core.service;
import com.mdp.core.service.BaseService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map; 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;
/** /**
* 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br> * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br>
* 组织 com 顶级模块 xm 大模块 core 小模块 <br> * 组织 com 顶级模块 xm 大模块 core 小模块 <br>
@ -20,5 +17,21 @@ import com.xm.core.entity.XmMenuComment;
public class XmMenuCommentService extends BaseService { public class XmMenuCommentService extends BaseService {
static Logger logger =LoggerFactory.getLogger(XmMenuCommentService.class); 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<Map<String, Object>> selectListByPids(List<String> pids) {
return super.selectList("selectListByPids",pids);
}
} }

11
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) { public String createKey(String keyName) {
return "M"+sequenceService.getCommonNo("{date62:yyyyMMddHHmmss}{rands:4}"); return "M"+sequenceService.getCommonNo("{date62:yyyyMMddHHmmss}{rands:4}");
} }
public void updateUps(List<String> menuIds) {
super.update("updateUps",menuIds);
}
public void updateComments(List<String> menuIds) {
super.update("updateComments",menuIds);
}
public void upReads(String menuId,Integer reads) {
super.update("upReads",map("menuId",menuId,"reads",reads));
}
} }

37
xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmMenuCommentMapper.xml

@ -12,8 +12,43 @@
</foreach> </foreach>
</if> </if>
<if test="key != null and key !='' "> </if> <if test="key != null and key !='' "> </if>
</sql>
<if test="pidIsNull!=null and pidIsNull!=''"> and pid is null</if>
</sql>
<update id="showComment">
update xm_menu_comment
set is_show='1'
where id in
<foreach collection="array" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
</update>
<!-- 批量关闭评论 -->
<update id="unShowComment">
update xm_menu_comment
set is_show='0'
where id in
<foreach collection="array" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
</update>
<!-- 批量关闭评论 -->
<update id="praiseComment">
update xm_menu_comment
set ups=ifnull(ups,0)+1
where id = #{id}
</update>
<select id="selectListByPids" parameterType="List" resultType="com.mdp.arc.archive.entity.ArchiveComment">
select * from xm_menu_comment res
where res.pid in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
</select>
<update id="updateChildrenSum" parameterType="HashMap">
update xm_menu_comment res set res.child_nums=ifnull(res.child_nums,0) + #{addCount}
where id=#{pid}
</update>
<!--结束 自定义sql函数区域--> <!--结束 自定义sql函数区域-->

38
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,'%') ) or exists( select 1 from xm_menu m where m.mm_userid=#{mmUserid} and res.pid_paths like concat(m.pid_paths,'%') )
) )
</select> </select>
<update id="upReads" parameterType="HashMap">
update xm_menu res set reads=ifnull(reads,0)+#{reads}
where menu_id=#{menuId}
</update>
<update id="updateUps" parameterType="List">
update xm_menu res left join
(select count(*) ups,up.menu_id from xm_menu_up up
where up.menu_id in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
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
<foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
</update>
<update id="updateComments" parameterType="List">
update xm_menu res left join
(select count(*) ups,up.menu_id from xm_menu_comment up
where up.menu_id in
<foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
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
<foreach collection="list" item="item" index="index" open="(" separator="," close=")" >
#{item }
</foreach>
</update>
<!--结束 自定义sql函数区域--> <!--结束 自定义sql函数区域-->

Loading…
Cancel
Save