提交 567be7a1 authored 作者: xc's avatar xc

xc

上级 f3fc5312
......@@ -14,5 +14,5 @@ public interface NoticeDao extends JpaRepository<Notice , Integer> {
Notice findById(int id);
Page<Notice> findOutBySenderAndType(String sender, int type, Pageable pageable);
Page<Notice> findOutByAddresseeLikeAndType(String addressee, int type, Pageable pageable);
List<Notice> findOutByStatusAndType(int status, int type);
List<Notice> findOutByStatusAndTypeAndLabel(int status, int type, int label);
}
......@@ -8,6 +8,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
......@@ -22,6 +23,7 @@ import java.util.List;
@Api(tags = "提醒接口")
@RestController
@RequestMapping("/attention")
@Slf4j
public class AttentionController {
@Autowired
AttentionService attentionService;
......@@ -33,6 +35,7 @@ public class AttentionController {
})
@GetMapping("/getAttention")
public ResponseEntity<Paging<Attention>> getAttentionList(@RequestParam String userId, int pageNum, int pageSize){
log.info("获取提醒列表:{}", userId);
return ResponseEntity.ok(attentionService.getAttentionList(userId, pageNum, pageSize));
}
......@@ -43,6 +46,7 @@ public class AttentionController {
})
@PutMapping("/updateStatus")
public ResponseEntity updateStatus(@RequestBody @Valid List<Attention> attentions){
log.info("修改提醒为已读");
return ResponseEntity.ok(attentionService.updateStatus(attentions));
}
......@@ -52,6 +56,7 @@ public class AttentionController {
})
@GetMapping("/redDot")
public ResponseEntity getRedDot(@RequestParam String userId){
log.info("消息提醒小红点");
return ResponseEntity.ok(attentionService.getRedDot(userId));
}
......
......@@ -8,6 +8,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -19,6 +20,7 @@ import java.util.List;
@Api(tags = "通知接口")
@RestController
@RequestMapping("/notice")
@Slf4j
public class NoticeController {
@Autowired
private NoticeService noticeService;
......@@ -33,6 +35,7 @@ public class NoticeController {
@ApiImplicitParam(name = "notice", value = "通知实体", dataType = "Notice", paramType = "body", required = true)
@PostMapping("/addNotice")
public ResponseEntity addNotice(@RequestBody @Valid Notice notice){
log.info("新增通知:{}", notice);
return ResponseEntity.ok(noticeService.addNotice(notice));
}
......@@ -45,7 +48,7 @@ public class NoticeController {
@ApiImplicitParam(name = "notice", value = "通知实体", dataType = "Notice", paramType = "body", required = true)
@PutMapping("/updateNotice")
public ResponseEntity updateNotice(@RequestBody @Valid Notice notice){
log.info("修改通知接口:{}", notice);
return ResponseEntity.ok(noticeService.updateNotice(notice));
}
......@@ -66,6 +69,7 @@ public class NoticeController {
@ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "条数", paramType = "query", required = true, dataType = "int")})
public ResponseEntity<Paging<Notice>> getNoticeList(@RequestParam String user, int type, int pageNum, int pageSize){
log.info("获取通知列表接口:{},{}", user,type);
Paging<Notice> data = noticeService.getReceiveList(user, type, pageNum, pageSize);
return ResponseEntity.ok(data);
}
......@@ -76,6 +80,7 @@ public class NoticeController {
allowMultiple = true, dataType = "Notice"),
@ApiImplicitParam(name = "userId", value = "当前登录用户", paramType = "query", required = true,dataType = "String")})
public ResponseEntity updateStatus(@RequestBody List<Notice> notices, @RequestParam String userId){
log.info("修改通知为已读:{}", userId);
return ResponseEntity.ok(noticeService.updateStatus(notices, userId));
}
......
......@@ -59,7 +59,8 @@ public class Attention {
@ApiModelProperty(value = "updateTime", name = "更新时间", example = "2019-01-01 00:00:00.000")
@Column(name = "update_time")
@JsonFormat(pattern = "yyyy-HH-dd HH:mm:ss", timezone = "GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
......@@ -83,7 +83,7 @@ public class Notice {
*/
@ApiModelProperty(value = "deadline", name = "通知失效时间", example = "2019-01-01 00:00:00.000")
@Column(name = "deadline")
@JsonFormat(pattern = "yyyy-HH-dd HH:mm:ss", timezone = "GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date deadline;
/**
......@@ -92,7 +92,7 @@ public class Notice {
@ApiModelProperty(value = "updateTime", name = "通知更新时间", example = "2019-01-01 00:00:00.000")
@Column(name = "update_time")
@JsonFormat(pattern = "yyyy-HH-dd HH:mm:ss", timezone = "GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
/**
......@@ -121,6 +121,13 @@ public class Notice {
@ApiModelProperty(value = "name", example = "", dataType = "String", name = "发件人名称")
@Column(name = "name")
private String name;
/**
* 是否提醒 没提醒 0,提醒 1
*/
@ApiModelProperty(value = "label", example = "1", dataType = "int", name = "是否提醒")
@Column(name = "label")
private int label;
}
......@@ -54,6 +54,7 @@ public interface NoticeService {
* @return
*/
List<Notice> findBySender(String userId, int status, int type);
void saveNotice(Notice notice);
}
......@@ -11,6 +11,7 @@ import com.zjty.efs.log.subject.entity.EfsLog;
import com.zjty.efs.log.tool.EfsLogUtil;
import com.zjty.efs.user.subject.entity.UserDo;
import com.zjty.efs.user.subject.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Transient;
......@@ -24,6 +25,7 @@ import java.lang.reflect.Array;
import java.util.*;
@Service
@Slf4j
public class NoticeServiceImpl implements NoticeService {
@Autowired
NoticeDao noticeDao;
......@@ -45,6 +47,7 @@ public class NoticeServiceImpl implements NoticeService {
notice.setUnit(userDo.getUnit());
notice.setStatus(0);
notice.setName(userDo.getName());
notice.setLabel(0);
......@@ -65,40 +68,43 @@ public class NoticeServiceImpl implements NoticeService {
}else {
List<Addressee> addresseeList2 = new ArrayList<>(); //接受者显示的接收列表
Notice notice1 = transform(notice); //发送通知
String dataList = "";
for(String addressee:strings){
List<Addressee> addresseeList = new ArrayList<>();
UserDo userDo1 = userService.findById(addressee); //收件人用户
Addressee addressee1 = new Addressee();
addressee1.setId(userDo1.getId());
addressee1.setName(userDo1.getName());
addressee1.setUnit(userDo1.getUnit());
addresseeList.add(addressee1);
addresseeList2.add(addressee1);
Notice notice1 = transform(notice); //发送通知
Notice notice2 = transform(notice); // 接收通知
String add = JSONObject.toJSONString(addresseeList);
String add2 = JSONObject.toJSONString(addresseeList2);
notice1.setAddressee(add);
notice2.setAddressee(add2);
notice2.setUnit(userDo1.getUnit());
notice2.setType(0);
noticeDao.save(notice1);
noticeDao.save(notice2);
String data1 = "[" +userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "]给[" + userDo1.getUnit() + "][" + userDo1.getDepartment() + "]的[" + userDo1.getName()
+ "发送了关于[" + notice.getTitle() + "]的通知";
String data2 = "[" +userDo1.getUnit() + "][" + userDo1.getDepartment() + "]的[" + userDo1.getName()
+ "]收到了来自[" + userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "]关于[" + notice.getTitle() + "的通知";
efsLogUtil.addLog(new EfsLog(null, userDo.getId(), data1, new Date()));
dataList = dataList + "[" + userDo1.getUnit() + "][" + userDo1.getDepartment() + "]的[" + userDo1.getName()
+ "] ";
efsLogUtil.addLog(new EfsLog(null, userDo1.getId(), data2, new Date()));
}
String add2 = JSONObject.toJSONString(addresseeList2);
for (String addressee:strings){
Notice notice2 = transform(notice); // 接收通知
notice2.setAddressee(add2);
notice2.setType(0);
noticeDao.save(notice2);
}
notice1.setAddressee(add2);
noticeDao.save(notice1);
String data1 = "[" +userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "]给" + dataList
+ "发送了关于[" + notice.getTitle() + "]的通知";
efsLogUtil.addLog(new EfsLog(null, userDo.getId(), data1, new Date()));
}
......@@ -123,6 +129,8 @@ public class NoticeServiceImpl implements NoticeService {
notice1.setUpdateTime(notice.getUpdateTime());
notice1.setType(notice.getType());
notice1.setUnit(notice.getUnit());
notice1.setName(notice.getName());
notice1.setLabel(notice.getLabel());
return notice1;
}
......@@ -265,12 +273,17 @@ public class NoticeServiceImpl implements NoticeService {
@Override
public List<Notice> findBySender(String userId, int status, int type) {
try{
return noticeDao.findOutByStatusAndType(status, type);
return noticeDao.findOutByStatusAndTypeAndLabel(status, type, 0);
}catch (Exception e){
e.printStackTrace();
return null;
}
}
@Override
public void saveNotice(Notice notice) {
noticeDao.save(notice);
}
}
......@@ -10,6 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
......@@ -23,33 +26,40 @@ public class Job {
@Scheduled(cron = "0 */1 * * * ?")
public void cronJob() {
Date now = new Date();
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, 7);
Date time = calendar.getTime();
List<Notice> noticeList = noticeService.findBySender("",0,0);
String data = "";
for(Notice notice:noticeList){
Attention attention = new Attention();
Date endTime = notice.getDeadline();
long days = (endTime.getTime()-now.getTime())/(1000*3600*24);
System.out.println(days);
if (days == 3 || days == 1){
data = "您收到来自[" + notice.getName() +"]的[" + notice.getTitle() + "],还有" + days +"天失效。";
attention.setData(data);
attention.setNoticeId(notice.getId());
String str = notice.getAddressee();
List<Addressee> addresseeList = JSONArray.parseArray(str,Addressee.class);
String userId = addresseeList.get(0).getId();
attention.setUserId(userId);
attention.setStatus(0);
attention.setUpdateTime(new Date());
attentionService.addAttention(attention);
}
try {
Date now = new Date();
List<Notice> noticeList = noticeService.findBySender("",0,0);
String data = "";
for(Notice notice:noticeList){
Attention attention = new Attention();
Date endTime = notice.getDeadline();
double days = (endTime.getTime()-now.getTime())/(1000*3600*24.0);
// System.out.println(days);
if (days <= 3.001 || days <= 1.001){
int d = (int)days;
data = "您收到来自[" + notice.getName() +"]的[" + notice.getTitle() + "],还有" + d +"天失效。";
attention.setData(data);
attention.setNoticeId(notice.getId());
String str = notice.getAddressee();
List<Addressee> addresseeList = JSONArray.parseArray(str,Addressee.class);
String userId = addresseeList.get(0).getId();
attention.setUserId(userId);
attention.setStatus(0);
attention.setUpdateTime(new Date());
attentionService.addAttention(attention);
notice.setLabel(1);
noticeService.saveNotice(notice);
}
}
}catch (Exception e){
e.printStackTrace();
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论