Commit 33c65107 authored by 王淑君's avatar 王淑君

修改通知

parent a1cc9a29
package org.rcisoft.business.bdiscuss.service.impl; package org.rcisoft.business.bdiscuss.service.impl;
import com.netflix.discovery.converters.Auto;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.bdiscuss.dto.BDiscussDto; import org.rcisoft.business.bdiscuss.dto.BDiscussDto;
import org.rcisoft.business.blesson.dao.BLessonRepository; import org.rcisoft.business.blesson.dao.BLessonRepository;
import org.rcisoft.business.blesson.entity.BLesson;
import org.rcisoft.business.blesson.service.BLessonService;
import org.rcisoft.business.bnotice.entity.BNotice;
import org.rcisoft.business.bnotice.service.BNoticeService;
import org.rcisoft.common.model.InfoTypeEnum;
import org.rcisoft.common.util.feignDto.MTUserGetsReqDTO; import org.rcisoft.common.util.feignDto.MTUserGetsReqDTO;
import org.rcisoft.common.util.feignDto.MTUserInfoRspDTO; import org.rcisoft.common.util.feignDto.MTUserInfoRspDTO;
import org.rcisoft.common.util.outClient.MTCotactApiRequestClient; import org.rcisoft.common.util.outClient.MTCotactApiRequestClient;
import org.rcisoft.common.util.outClient.MTNotificationApiRequestClient;
import org.rcisoft.core.util.IdGen;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
...@@ -14,6 +22,7 @@ import org.rcisoft.business.bdiscuss.entity.BDiscuss; ...@@ -14,6 +22,7 @@ import org.rcisoft.business.bdiscuss.entity.BDiscuss;
import org.rcisoft.business.bdiscuss.service.BDiscussService; import org.rcisoft.business.bdiscuss.service.BDiscussService;
import org.rcisoft.sys.user.service.SysUserService;
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.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Isolation;
...@@ -42,6 +51,21 @@ public class BDiscussServiceImpl implements BDiscussService { ...@@ -42,6 +51,21 @@ public class BDiscussServiceImpl implements BDiscussService {
@Autowired @Autowired
BLessonRepository bLessonRepository; BLessonRepository bLessonRepository;
@Autowired
MTNotificationApiRequestClient notificationApiRequestClient;
@Autowired
SysUserService sysUserServiceImpl;
@Autowired
BNoticeService bNoticeServiceImpl;
@Autowired
BLessonRepository lessonRepository;
@Autowired
MTNotificationApiRequestClient client;
/** /**
* 保存 bDiscuss * 保存 bDiscuss
* @param bDiscuss * @param bDiscuss
...@@ -50,11 +74,22 @@ public class BDiscussServiceImpl implements BDiscussService { ...@@ -50,11 +74,22 @@ public class BDiscussServiceImpl implements BDiscussService {
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override @Override
public PersistModel save(BDiscuss bDiscuss){ public PersistModel save(BDiscuss bDiscuss){
if (StringUtils.isNotBlank(bDiscuss.getReplyId())){
BNotice bNotice = new BNotice();
// UserUtil.setCurrentPersistOperation(bNotice);
bNotice.setRecipientId(bDiscuss.getReplyId());
bNotice.setInfoType(InfoTypeEnum.REPLY_DISCUSS.getValue());
// 获取课程信息
BLesson bLesson = lessonRepository.selectByPrimaryKey(bDiscuss.getLessonId());
String lessonType = "0".equals(bLesson.getLessonType()) ? "线上课程" : "线下培训";
bNotice.setInfoText(sysUserServiceImpl.getNameById(bDiscuss.getStudentId()).getName() + "回复了您在" + lessonType +"[" + bLesson.getLessonName() +"]的评论" );
bNoticeServiceImpl.save(bNotice);
// 往智信平台发啊消息
client.send(bNotice,InfoTypeEnum.REPLY_DISCUSS.getLable());
}
//增加操作 //增加操作
UserUtil.setCurrentPersistOperation(bDiscuss); UserUtil.setCurrentPersistOperation(bDiscuss);
int line = bDiscussRepository.insertSelective(bDiscuss); int line = bDiscussRepository.insertSelective(bDiscuss);
// log.info(UserUtil.getUserInfoProp(bDiscuss.getToken(),UserUtil.USER_USERNAME)+"新增了ID为"+
// bDiscuss.getBusinessId()+"的信息");
bLessonRepository.discussNumberReCount(bDiscuss.getLessonId()); bLessonRepository.discussNumberReCount(bDiscuss.getLessonId());
return new PersistModel(line); return new PersistModel(line);
} }
......
package org.rcisoft.business.bnotice.controller;
/*固定导入*/
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.common.model.GridModel;
import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.util.UserUtil;
import org.rcisoft.core.exception.ServiceException;
import javax.validation.Valid;
import org.rcisoft.business.bnotice.entity.BNotice;
import org.rcisoft.business.bnotice.service.BNoticeService;
import java.util.List;
/**
* Created by on 2019-11-28 11:18:34.
*/
@RestController
@RequestMapping("bnotice")
public class BNoticeController extends PaginationController<BNotice> {
@Autowired
private BNoticeService bNoticeServiceImpl;
@ApiOperation(value="添加", notes="添加")
//@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar")})
@PostMapping(value = "/add")
public Result add(@Valid BNotice bNotice, BindingResult bindingResult) {
PersistModel data = bNoticeServiceImpl.save(bNotice);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bNotice);
}
@ApiOperation(value="逻辑删除", notes="逻辑删除")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "id", required = false, dataType = "varchar")})
@DeleteMapping("/delete/{id:\\w+}")
public Result delete(@PathVariable String id) {
BNotice bNotice = new BNotice();
bNotice.setBusinessId(id);
PersistModel data = bNoticeServiceImpl.remove(bNotice);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
id);
}
@ApiOperation(value="查看单 ", notes="查看单 ")
@GetMapping("/detail/{id:\\w+}")
public Result detail(@PathVariable String id) {
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bNoticeServiceImpl.findById(id));
}
@ApiOperation(value="查看 集合", notes="查看 集合")
@GetMapping(value = "/queryBNoticeByPagination")
public GridModel listByPagination(BNotice bNotice) {
bNoticeServiceImpl.findAllByPagination(getPaginationUtility(), bNotice);
return getGridModelResponse();
}
}
package org.rcisoft.business.bnotice.dao;
import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.business.bnotice.entity.BNotice;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created with on 2019-11-28 11:18:34.
*/
@Repository
public interface BNoticeRepository extends BaseMapper<BNotice> {
/**
* 分页查询 bNotice
*
*/
@Select("<script>select * from b_notice where 1=1 "
+ "<if test=\"delFlag !=null and delFlag != '' \">and del_flag = #{delFlag} </if> "
+ "<if test=\"flag !=null and flag != '' \">and flag = #{flag} </if> "
+ "</script>")
@ResultMap(value = "BaseResultMap" )
List<BNotice> queryBNotices(BNotice bNotice);
}
package org.rcisoft.business.bnotice.entity;
import lombok.*;
import org.rcisoft.core.entity.IdEntity;
import javax.persistence.*;
import java.util.Date;
/**
* Created with on 2019-11-28 11:18:34.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "b_notice")
public class BNotice extends IdEntity<BNotice> {
private String infoType;
private String infoText;
private String recipientId;
private String readFlag;
}
package org.rcisoft.business.bnotice.service;
import org.rcisoft.business.bnotice.entity.BNotice;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil;
import java.util.List;
/**
* Created by on 2019-11-28 11:18:34.
*/
public interface BNoticeService {
/**
* 保存
* @param bNotice
* @return
*/
PersistModel save(BNotice bNotice);
/**
* 逻辑删除
* @param bNotice
* @return
*/
PersistModel remove(BNotice bNotice);
/**
* 修改
* @param bNotice
* @return
*/
PersistModel merge(BNotice bNotice);
/**
* 根据id查询
* @param id
* @return
*/
BNotice findById(String id);
/**
* 分页查询
* @param bNotice
* @return
*/
List<BNotice> findAllByPagination(PageUtil<BNotice> paginationUtility,
BNotice bNotice);
}
package org.rcisoft.business.bnotice.service.impl;
import org.rcisoft.core.util.UserUtil;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.business.bnotice.dao.BNoticeRepository;
import org.rcisoft.business.bnotice.entity.BNotice;
import org.rcisoft.business.bnotice.service.BNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
/**
* Created by on 2019-11-28 11:18:34.
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.NOT_SUPPORTED)
@Slf4j
public class BNoticeServiceImpl implements BNoticeService {
@Autowired
private BNoticeRepository bNoticeRepository;
/**
* 保存 bNotice
* @param bNotice
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel save(BNotice bNotice){
//增加操作
UserUtil.setCurrentPersistOperation(bNotice);
int line = bNoticeRepository.insertSelective(bNotice);
return new PersistModel(line);
}
/**
* 逻辑删除
* @param bNotice
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel remove(BNotice bNotice){
UserUtil.setCurrentMergeOperation(bNotice);
bNotice.setDeleted();
int line = bNoticeRepository.logicalDelete(bNotice);
return new PersistModel(line);
}
/**
* 修改 bNotice
* @param bNotice
* @return
*/
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
public PersistModel merge(BNotice bNotice){
UserUtil.setCurrentMergeOperation(bNotice);
int line = bNoticeRepository.updateByPrimaryKeySelective(bNotice);
return new PersistModel(line);
}
/**
* 根据id查询 bNotice
* @param id
* @return
*/
public BNotice findById(String id){
return bNoticeRepository.selectByPrimaryKey(id);
}
/**
* 分页查询 bNotice
* @param bNotice
* @return
*/
public List<BNotice> findAllByPagination(PageUtil<BNotice> paginationUtility,
BNotice bNotice){
bNotice.setStart();
bNotice.setNotDeleted();
return bNoticeRepository.queryBNotices(bNotice);
}
}
...@@ -2,19 +2,30 @@ package org.rcisoft.common.util.outClient; ...@@ -2,19 +2,30 @@ package org.rcisoft.common.util.outClient;
//import com.zgiot.zx.schedule.service.INotificationService; //import com.zgiot.zx.schedule.service.INotificationService;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.bnotice.entity.BNotice;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultCode; import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.result.Ret; import org.rcisoft.core.result.Ret;
import org.rcisoft.common.util.feignClient.NotificationFeignClient; import org.rcisoft.common.util.feignClient.NotificationFeignClient;
import org.rcisoft.common.util.feignDto.MTNotificationSendReqDTO; import org.rcisoft.common.util.feignDto.MTNotificationSendReqDTO;
import org.rcisoft.common.util.feignDto.MTUserGetsReqDTO; import org.rcisoft.common.util.feignDto.MTUserGetsReqDTO;
import org.rcisoft.common.util.feignDto.MTUserInfoRspDTO; import org.rcisoft.common.util.feignDto.MTUserInfoRspDTO;
import org.rcisoft.core.util.UrlUtil;
import org.rcisoft.sys.dept.dao.SysDeptRepository;
import org.rcisoft.sys.user.dao.SysUserMapper;
import org.rcisoft.sys.user.entity.SysUser;
import org.rcisoft.sys.user.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
...@@ -25,6 +36,9 @@ import java.util.List; ...@@ -25,6 +36,9 @@ import java.util.List;
@Slf4j @Slf4j
public class MTNotificationApiRequestClient { public class MTNotificationApiRequestClient {
@Value("${notice.properties.url}")
public String noticePropertiesUrl;
@Value("${server.type}") @Value("${server.type}")
private String serverType; private String serverType;
...@@ -32,38 +46,104 @@ public class MTNotificationApiRequestClient { ...@@ -32,38 +46,104 @@ public class MTNotificationApiRequestClient {
private NotificationFeignClient notificationFeignClient; private NotificationFeignClient notificationFeignClient;
@Autowired @Autowired
private MTCotactApiRequestClient mtCotactApiRequestClient; private MTCotactApiRequestClient mtCotactApiRequestClient;
@Autowired
private SysUserMapper sysUserMapper;
// @Autowired // @Autowired
// private INotificationService notificationService; // private INotificationService notificationService;
/** /**
* 发送通知 * 发送通知
* @param mtNotificationSendReqDTO * @param
* @return * @return
*/ */
public boolean send(MTNotificationSendReqDTO mtNotificationSendReqDTO, String type) { public boolean send(BNotice message, String noticeTitle) {
if("dev".equalsIgnoreCase(serverType)) { if("dev".equalsIgnoreCase(serverType)) {
return true; return true;
} }
List<String> userIds = mtNotificationSendReqDTO.getReceiverIds(); List<String> receiIdListtake = new ArrayList<>();
List<String> accountIds = new ArrayList<>(); String receive = "";
MTUserGetsReqDTO mtUserGetsReqDTO = new MTUserGetsReqDTO(); String corpId = "";
mtUserGetsReqDTO.setCorpId(mtNotificationSendReqDTO.getCorpId()); List<SysUser> personnelsList = sysUserMapper.selectByIds(Arrays.asList(new String[]{message.getRecipientId()}));
mtUserGetsReqDTO.setIds(userIds); if (null !=personnelsList && personnelsList.size() >0) {
List<MTUserInfoRspDTO> allUserList = mtCotactApiRequestClient.userGets(mtUserGetsReqDTO); SysUser personnels = personnelsList.get(0);
if(allUserList != null && allUserList.size() > 0){ if (null != personnels && null != personnels.getAccountId()) {
for(MTUserInfoRspDTO mtUserInfoRspDTO : allUserList){ receiIdListtake.add(personnels.getAccountId());
accountIds.add(mtUserInfoRspDTO.getAccountId()); receive = personnels.getAccountId();
corpId = personnels.getCorpId();
} }
} }
log.info("消息发送人accountId:" + accountIds); MTNotificationSendReqDTO mtNotificationSendReqDTO = MTNotificationSendReqDTO.builder().title(noticeTitle).content(message.getInfoText())
mtNotificationSendReqDTO.setReceiverIds(accountIds); .channels("ALL").targetId(message.getBusinessId()).receiverIds(receiIdListtake).build();
mtNotificationSendReqDTO.setSenderName("排班");
mtNotificationSendReqDTO.setChannels("ALL"); mtNotificationSendReqDTO.setChannels("ALL");
mtNotificationSendReqDTO.setCategoryCodes(Arrays.asList(new String[]{type})); mtNotificationSendReqDTO.setCategoryCodes(Arrays.asList(new String[]{"SHIFTS"}));
Ret ret = notificationFeignClient.sendMessage(mtNotificationSendReqDTO,"app",(long)1); if (StrUtil.isNotEmpty(corpId))
if(ret != null && ResultCode.SUCCESS.getCode().toString().equals(ret.getCode())){ mtNotificationSendReqDTO.setCorpId(corpId);
else
throw new ServiceException("未获取到corpId");
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String url = this.noticePropertiesUrl + "noticeType="+dealWithTitle(noticeTitle)+"&id="+receive + "&infoText="+UrlUtil.Utf8URLencode(message.getInfoText())
+"&messageId="+message.getBusinessId() +"&createDate="+ UrlUtil.Utf8URLencodeTime(df.format(message.getCreateDate()))+"&from=zx";
mtNotificationSendReqDTO.setProperties(new HashMap<String, String>(){{
put("url", url);
}});
Ret ret = new Ret();
try {
ret = notificationFeignClient.sendMessage(mtNotificationSendReqDTO, "app", (long) 1);
}catch (Exception ex){
log.error("----------------------------------------------------调用智信通知失败!----------------------------------------------------------");
// throw new BizCommonException("调用智信通知失败");
}
if(ret != null && "M0000".equals(ret.getCode())){
return true; return true;
} }
return false; return false;
} }
private String dealWithTitle(String title){
// (GO_WORK_INFO:上班提醒";HAND_WORK_INFO:交班提醒;TAKE_WORK_INFO:接班提醒;FEEDBACK_WORK_INFO:反馈提醒;CHANGE_WORK_INFO","调班通知)
String result = "";
switch(title){
case "回复提醒" :
result = "REPLY_DISCUSS";
break;
default : //可选
}
return result;
}
// public boolean send(MTNotificationSendReqDTO mtNotificationSendReqDTO, String type) {
// if("dev".equalsIgnoreCase(serverType)) {
// return true;
// }
// List<String> userIds = mtNotificationSendReqDTO.getReceiverIds();
// List<String> accountIds = new ArrayList<>();
// MTUserGetsReqDTO mtUserGetsReqDTO = new MTUserGetsReqDTO();
// mtUserGetsReqDTO.setCorpId(mtNotificationSendReqDTO.getCorpId());
// mtUserGetsReqDTO.setIds(userIds);
// List<MTUserInfoRspDTO> allUserList = mtCotactApiRequestClient.userGets(mtUserGetsReqDTO);
// if(allUserList != null && allUserList.size() > 0){
// for(MTUserInfoRspDTO mtUserInfoRspDTO : allUserList){
// accountIds.add(mtUserInfoRspDTO.getAccountId());
// }
// }
// log.info("消息发送人accountId:" + accountIds);
// mtNotificationSendReqDTO.setReceiverIds(accountIds);
// mtNotificationSendReqDTO.setChannels("ALL");
// mtNotificationSendReqDTO.setCategoryCodes(Arrays.asList(new String[]{type}));
//// DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
//// String url = this.noticePropertiesUrl + "noticeType="+dealWithTitle(noticeTitle)+"&id="+receive + "&infoText="+UrlUtil.Utf8URLencode(message.getInfoText())
//// +"&messageId="+message.getId() +"&createDate="+UrlUtil.Utf8URLencodeTime(df.format(message.getCreateDt()))+"&from=zx";
////
//// mtNotificationSendReqDTO.setProperties(new HashMap<String, String>(){{
//// put("url", url);
//// }});
// Ret ret = notificationFeignClient.sendMessage(mtNotificationSendReqDTO,"app",(long)1);
// if(ret != null && ResultCode.SUCCESS.getCode().toString().equals(ret.getCode())){
// return true;
// }
// return false;
// }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment