Browse Source

重构关注

master
陈裕财 4 years ago
parent
commit
97d688c993
  1. 65
      xm-core/src/main/java/com/xm/core/ctrl/XmMyFocusController.java
  2. 120
      xm-core/src/main/java/com/xm/core/service/XmMyFocusService.java

65
xm-core/src/main/java/com/xm/core/ctrl/XmMyFocusController.java

@ -1,8 +1,11 @@
package com.xm.core.ctrl; package com.xm.core.ctrl;
import com.mdp.core.entity.Tips; import com.mdp.core.entity.Tips;
import com.mdp.core.err.BizException;
import com.mdp.core.utils.RequestUtils; import com.mdp.core.utils.RequestUtils;
import com.mdp.mybatis.PageUtils; import com.mdp.mybatis.PageUtils;
import com.mdp.safe.client.entity.User;
import com.mdp.safe.client.utils.LoginUtils;
import com.mdp.swagger.ApiEntityParams; import com.mdp.swagger.ApiEntityParams;
import com.xm.core.entity.XmMyFocus; import com.xm.core.entity.XmMyFocus;
import com.xm.core.service.XmMyFocusService; import com.xm.core.service.XmMyFocusService;
@ -10,17 +13,19 @@ import io.swagger.annotations.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import static com.mdp.core.utils.BaseUtils.map;
import static com.mdp.core.utils.BaseUtils.toMap; import static com.mdp.core.utils.BaseUtils.toMap;
import static com.mdp.core.utils.ResponseHelper.failed;
/** /**
* url编制采用rest风格,如对xm_my_focus 我关注的项目或者任务的操作有增删改查,对应的url分别为:<br> * url编制采用rest风格,如对xm_my_focus 我关注的项目或者任务的操作有增删改查,对应的url分别为:<br>
@ -68,8 +73,7 @@ public class XmMyFocusController {
} }
/**
@ApiOperation( value = "新增一条我关注的项目或者任务信息",notes=" ") @ApiOperation( value = "新增一条我关注的项目或者任务信息",notes=" ")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200,response=XmMyFocus.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") @ApiResponse(code = 200,response=XmMyFocus.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}")
@ -77,29 +81,26 @@ public class XmMyFocusController {
@RequestMapping(value="/add",method=RequestMethod.POST) @RequestMapping(value="/add",method=RequestMethod.POST)
public Map<String,Object> addXmMyFocus(@RequestBody XmMyFocus xmMyFocus) { public Map<String,Object> addXmMyFocus(@RequestBody XmMyFocus xmMyFocus) {
Map<String,Object> m = new HashMap<>(); Map<String,Object> m = new HashMap<>();
Tips tips=new Tips("成功新增一条数据");
Tips tips=new Tips("关注成功");
try{ try{
boolean createPk=false;
if(!StringUtils.hasText(xmMyFocus.getUserid())) {
createPk=true;
xmMyFocus.setUserid(xmMyFocusService.createKey("userid"));
}
User user = LoginUtils.getCurrentUserInfo();
if(!StringUtils.hasText(xmMyFocus.getBizId())) { if(!StringUtils.hasText(xmMyFocus.getBizId())) {
createPk=true;
xmMyFocus.setBizId(xmMyFocusService.createKey("bizId"));
return failed("bizId","业务编号不能为空");
} }
if(!StringUtils.hasText(xmMyFocus.getPbizId())) { if(!StringUtils.hasText(xmMyFocus.getPbizId())) {
createPk=true;
xmMyFocus.setPbizId(xmMyFocusService.createKey("pbizId"));
return failed("pbizId","上级编号不能为空");
} }
if(createPk==false){
if(xmMyFocusService.selectOneObject(xmMyFocus) !=null ){
return failed("pk-exists","编号重复,请修改编号再提交");
}
}
xmMyFocusService.insert(xmMyFocus);
if(!StringUtils.hasText(xmMyFocus.getFocusType())) {
return failed("focusType","关注类型不能为空");
}
xmMyFocus.setUserid(user.getUserid());
xmMyFocus.setUsername(user.getUsername());
if(xmMyFocusService.selectOneObject(xmMyFocus) !=null ){
return failed("pk-exists","编号重复,请修改编号再提交");
}
xmMyFocusService.focus(xmMyFocus);
m.put("data",xmMyFocus); m.put("data",xmMyFocus);
}catch (BizException e) {
}catch (BizException e) {
tips=e.getTips(); tips=e.getTips();
logger.error("",e); logger.error("",e);
}catch (Exception e) { }catch (Exception e) {
@ -109,9 +110,7 @@ public class XmMyFocusController {
m.put("tips", tips); m.put("tips", tips);
return m; return m;
} }
*/
/**
@ApiOperation( value = "删除一条我关注的项目或者任务信息",notes=" ") @ApiOperation( value = "删除一条我关注的项目或者任务信息",notes=" ")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}") @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}")
@ -119,22 +118,21 @@ public class XmMyFocusController {
@RequestMapping(value="/del",method=RequestMethod.POST) @RequestMapping(value="/del",method=RequestMethod.POST)
public Map<String,Object> delXmMyFocus(@RequestBody XmMyFocus xmMyFocus){ public Map<String,Object> delXmMyFocus(@RequestBody XmMyFocus xmMyFocus){
Map<String,Object> m = new HashMap<>(); Map<String,Object> m = new HashMap<>();
Tips tips=new Tips("成功删除一条数据");
Tips tips=new Tips("成功取消关注");
try{ try{
if(!StringUtils.hasText(xmMyFocus.getUserid())) {
return failed("pk-not-exists","请上送主键参数userid");
}
User user = LoginUtils.getCurrentUserInfo();
if(!StringUtils.hasText(xmMyFocus.getBizId())) { if(!StringUtils.hasText(xmMyFocus.getBizId())) {
return failed("pk-not-exists","请上送主键参数bizId"); return failed("pk-not-exists","请上送主键参数bizId");
} }
if(!StringUtils.hasText(xmMyFocus.getPbizId())) { if(!StringUtils.hasText(xmMyFocus.getPbizId())) {
return failed("pk-not-exists","请上送主键参数pbizId"); return failed("pk-not-exists","请上送主键参数pbizId");
} }
xmMyFocus.setUserid(user.getUserid());
XmMyFocus xmMyFocusDb = xmMyFocusService.selectOneObject(xmMyFocus); XmMyFocus xmMyFocusDb = xmMyFocusService.selectOneObject(xmMyFocus);
if( xmMyFocusDb == null ){ if( xmMyFocusDb == null ){
return failed("data-not-exists","数据不存在,无法删除"); return failed("data-not-exists","数据不存在,无法删除");
} }
xmMyFocusService.deleteByPk(xmMyFocus);
xmMyFocusService.unfocus(xmMyFocusDb);
}catch (BizException e) { }catch (BizException e) {
tips=e.getTips(); tips=e.getTips();
logger.error("",e); logger.error("",e);
@ -145,7 +143,6 @@ public class XmMyFocusController {
m.put("tips", tips); m.put("tips", tips);
return m; return m;
} }
*/
/** /**
@ApiOperation( value = "根据主键修改一条我关注的项目或者任务信息",notes=" ") @ApiOperation( value = "根据主键修改一条我关注的项目或者任务信息",notes=" ")
@ -260,7 +257,6 @@ public class XmMyFocusController {
} }
*/ */
/**
@ApiOperation( value = "根据主键列表批量删除我关注的项目或者任务信息",notes=" ") @ApiOperation( value = "根据主键列表批量删除我关注的项目或者任务信息",notes=" ")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}") @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}")
@ -307,6 +303,5 @@ public class XmMyFocusController {
} }
m.put("tips", tips); m.put("tips", tips);
return m; return m;
}
*/
}
} }

120
xm-core/src/main/java/com/xm/core/service/XmMyFocusService.java

@ -5,9 +5,6 @@ import com.mdp.core.service.BaseService;
import com.xm.core.entity.XmMyFocus; import com.xm.core.entity.XmMyFocus;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/** /**
* 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br> * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br>
* 组织 com.qqkj 顶级模块 oa 大模块 xm 小模块 <br> * 组织 com.qqkj 顶级模块 oa 大模块 xm 小模块 <br>
@ -25,96 +22,49 @@ public class XmMyFocusService extends BaseService {
* @param xmMyFocus * @param xmMyFocus
*/ */
public void unfocus(XmMyFocus xmMyFocus) { public void unfocus(XmMyFocus xmMyFocus) {
if(StringUtils.isEmpty(xmMyFocus.getId())) {
if("project".equals(xmMyFocus.getFocusType())) {
if(StringUtils.isEmpty(xmMyFocus.getProjectId())) {
throw new BizException("projectId参数必须上传");
}
if(StringUtils.isEmpty(xmMyFocus.getUserid())) {
throw new BizException("userid参数必须上传");
}
this.deleteByWhere(xmMyFocus);
xmRecordService.addXmProjectRecord(xmMyFocus.getProjectId(), "项目-取消关注项目", xmMyFocus.getUsername()+"取消关注项目"+xmMyFocus.getProjectName());
this.deleteByPk(xmMyFocus);
if("1".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmProjectRecord(xmMyFocus.getBizId(), "项目-取消关注项目", xmMyFocus.getUsername()+"取消关注了项目"+xmMyFocus.getBizName());
}else if("2".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmTaskRecord(xmMyFocus.getPbizId(), xmMyFocus.getBizId(), "项目-任务-取消关注任务", xmMyFocus.getUsername()+"取消关注了任务"+xmMyFocus.getBizName());
}else if("3".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmProductRecord(xmMyFocus.getBizId(), "产品-取消关注", xmMyFocus.getUsername()+"取消关注了产品"+xmMyFocus.getBizName());
}else if("4".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmMenuRecord(xmMyFocus.getPbizId(), xmMyFocus.getBizId(), "产品-需求-取消关注需求", xmMyFocus.getUsername()+"取消关注了需求"+xmMyFocus.getBizName());
}else if("5".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmTaskRecord(xmMyFocus.getPbizId(), xmMyFocus.getBizId(), "项目-缺陷-取消关注缺陷", xmMyFocus.getUsername()+"取消关注了缺陷"+xmMyFocus.getBizName());
}else {
throw new BizException("focusType参数必须上传,取值project/task");
}
}else if("task".equals(xmMyFocus.getFocusType())) {
if(StringUtils.isEmpty(xmMyFocus.getProjectId())) {
throw new BizException("taskId参数必须上传");
}
if(StringUtils.isEmpty(xmMyFocus.getUserid())) {
throw new BizException("userid参数必须上传");
}
this.deleteByWhere(xmMyFocus);
xmRecordService.addXmTaskRecord(xmMyFocus.getProjectId(), xmMyFocus.getTaskId(), "项目-任务-取消关注", xmMyFocus.getUsername()+"取消关注任务"+xmMyFocus.getTaskName());
}else {
throw new BizException("focusType参数必须上传,取值project/task");
}
}else {
this.deleteByPk(xmMyFocus);
if("project".equals(xmMyFocus.getFocusType())) {
if(StringUtils.isEmpty(xmMyFocus.getProjectId())) {
} else if(StringUtils.isEmpty(xmMyFocus.getUserid())) {
}else {
xmRecordService.addXmProjectRecord(xmMyFocus.getProjectId(), "项目-取消关注项目", xmMyFocus.getUsername()+"取消关注项目"+xmMyFocus.getProjectName());
}
}else if("task".equals(xmMyFocus.getFocusType())) {
if(StringUtils.isEmpty(xmMyFocus.getProjectId())) {
} else if(StringUtils.isEmpty(xmMyFocus.getUserid())) {
}else {
xmRecordService.addXmTaskRecord(xmMyFocus.getProjectId(), xmMyFocus.getTaskId(), "项目-任务-取消关注", xmMyFocus.getUsername()+"取消关注任务"+xmMyFocus.getTaskName());
}
}
}
} }
/** /**
* 关注项目或者任务 * 关注项目或者任务
* @param xmMyFocus * @param xmMyFocus
*/ */
public void focus(XmMyFocus xmMyFocus) {
if("project".equals(xmMyFocus.getFocusType())) {
if(StringUtils.isEmpty(xmMyFocus.getProjectId())) {
throw new BizException("projectId参数必须上传");
}
if(StringUtils.isEmpty(xmMyFocus.getUserid())) {
throw new BizException("userid参数必须上传");
}
XmMyFocus query=new XmMyFocus();
query.setFocusType(xmMyFocus.getFocusType());
query.setUserid(xmMyFocus.getUserid());
query.setProjectId(xmMyFocus.getProjectId());
List<XmMyFocus> dblist=this.selectListByWhere(query);
if(dblist !=null && dblist.size()>0) {
return;
}else {
this.insert(xmMyFocus);
xmRecordService.addXmProjectRecord(xmMyFocus.getProjectId(), "项目-关注项目", xmMyFocus.getUsername()+"关注了项目"+xmMyFocus.getProjectName());
}
}else if("task".equals(xmMyFocus.getFocusType())) {
if(StringUtils.isEmpty(xmMyFocus.getProjectId())) {
throw new BizException("taskId参数必须上传");
}
if(StringUtils.isEmpty(xmMyFocus.getUserid())) {
throw new BizException("userid参数必须上传");
}
public void focus(XmMyFocus xmMyFocus) {
this.insert(xmMyFocus);
if("1".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmProjectRecord(xmMyFocus.getBizId(), "项目-关注项目", xmMyFocus.getUsername()+"关注了项目"+xmMyFocus.getBizName());
}else if("2".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmTaskRecord(xmMyFocus.getPbizId(), xmMyFocus.getBizId(), "项目-任务-关注任务", xmMyFocus.getUsername()+"关注了任务"+xmMyFocus.getBizName());
}else if("3".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmProductRecord(xmMyFocus.getBizId(), "产品-关注", xmMyFocus.getUsername()+"关注了产品"+xmMyFocus.getBizName());
}else if("4".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmMenuRecord(xmMyFocus.getPbizId(), xmMyFocus.getBizId(), "产品-需求-关注需求", xmMyFocus.getUsername()+"关注了需求"+xmMyFocus.getBizName());
}else if("5".equals(xmMyFocus.getFocusType())) {
xmRecordService.addXmTaskRecord(xmMyFocus.getPbizId(), xmMyFocus.getBizId(), "项目-缺陷-关注缺陷", xmMyFocus.getUsername()+"关注了缺陷"+xmMyFocus.getBizName());
XmMyFocus query=new XmMyFocus();
query.setFocusType(xmMyFocus.getFocusType());
query.setUserid(xmMyFocus.getUserid());
query.setTaskId(xmMyFocus.getTaskId());
List<XmMyFocus> dblist=this.selectListByWhere(query);
if(dblist !=null && dblist.size()>0) {
return;
}else {
this.insert(xmMyFocus);
xmRecordService.addXmTaskRecord(xmMyFocus.getProjectId(), xmMyFocus.getTaskId(), "项目-任务-关注任务", xmMyFocus.getUsername()+"关注了任务"+xmMyFocus.getTaskName());
}
}else {
}else {
throw new BizException("focusType参数必须上传,取值project/task"); throw new BizException("focusType参数必须上传,取值project/task");
} }

Loading…
Cancel
Save