提交 84808aca authored 作者: zhangshuang's avatar zhangshuang

Merge branch 'develop' of 192.168.1.249:LJJ/encrypted-file-system into develop

......@@ -39,6 +39,24 @@
<artifactId>swagger-annotations</artifactId>
<version>1.5.18</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>com.zjty</groupId>
<artifactId>efs-log</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zjty</groupId>
<artifactId>efs-user</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
......
......@@ -3,15 +3,19 @@ package com.zjty.efs.bus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@ComponentScan(basePackages = {
"com.zjty.efs.misc",
"com.zjty.efs.bus"
"com.zjty.efs.bus",
"com.zjty.efs.log",
"com.zjty.efs.user"
})
@EnableSwagger2
@EnableScheduling
public class BusApplication {
public static void main(String[] args) {
SpringApplication.run(BusApplication.class, args);
......
......@@ -6,7 +6,10 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface AttentionDao extends JpaRepository<Attention, Integer> {
Page<Attention> findOutByUserId(int sender, Pageable pageable);
Page<Attention> findOutByUserId(String sender, Pageable pageable);
List<Attention> findOutByUserIdAndStatus(String userId, int status);
}
......@@ -12,6 +12,7 @@ import java.util.List;
@Repository
public interface NoticeDao extends JpaRepository<Notice , Integer> {
Notice findById(int id);
Page<Notice> findOutBySenderAndType(int sender, int type, Pageable pageable);
List<Notice> findOutBySenderAndStatusAndType(int sender, int status, int type);
Page<Notice> findOutBySenderAndType(String sender, int type, Pageable pageable);
Page<Notice> findOutByAddresseeAndType(String addressee, int type, Pageable pageable);
List<Notice> findOutByStatusAndType(int status, int type);
}
......@@ -2,35 +2,57 @@ package com.zjty.efs.bus.controller;
import com.zjty.efs.bus.entity.Attention;
import com.zjty.efs.bus.entity.Paging;
import com.zjty.efs.bus.service.AttentionService;
import com.zjty.efs.misc.config.AutoDocument;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
@AutoDocument
@Api(tags = "提醒接口")
@RestController
@RequestMapping("/attention")
public class AttentionController {
@Autowired
AttentionService attentionService;
@ApiOperation(value = "获取提醒列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "当前登录用户", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "条数", dataType = "int", paramType = "query", required = true)
})
@PostMapping("/getAttention")
public ResponseEntity<Paging<Attention>> test(@RequestParam int userId, int pageNum, int pageSize){
return ResponseEntity.ok(new Paging<>());
@GetMapping("/getAttention")
public ResponseEntity<Paging<Attention>> getAttentionList(@RequestParam String userId, int pageNum, int pageSize){
return ResponseEntity.ok(attentionService.getAttentionList(userId, pageNum, pageSize));
}
@ApiOperation(value = "修改提醒为已读")
@ApiImplicitParams({
@ApiImplicitParam(name = "attentions", value = "提醒实体", paramType = "body", dataType = "Attention",
required = true, allowMultiple = true)
})
@PutMapping("/updateStatus")
public ResponseEntity updateStatus(@RequestBody @Valid List<Attention> attentions){
return ResponseEntity.ok(attentionService.updateStatus(attentions));
}
@ApiOperation(value = "消息提醒小红点")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "当前用户", paramType = "query", dataType = "String", required = true)
})
@GetMapping("/redDot")
public ResponseEntity getRedDot(@RequestParam String userId){
return ResponseEntity.ok(attentionService.getRedDot(userId));
}
}
......@@ -50,8 +50,10 @@ public class NoticeController {
}
@ApiOperation(value = "查看通知接口")
@ApiImplicitParam(name = "id", value = "通知id", paramType = "query",
required = true, example = "1", dataType = "int")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "通知id", paramType = "query",
required = true, example = "1", dataType = "int")
})
@GetMapping("/getNotice")
public ResponseEntity<Notice> getNotice(@RequestParam int id){
return ResponseEntity.ok(noticeService.getNotice(id));
......@@ -63,7 +65,7 @@ public class NoticeController {
@ApiImplicitParam(name = "type", value = "通知类型", paramType = "query", required = true, example = "0", dataType = "int"),
@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 int user, int type, int pageNum, int pageSize){
public ResponseEntity<Paging<Notice>> getNoticeList(@RequestParam String user, int type, int pageNum, int pageSize){
Paging<Notice> data = noticeService.getReceiveList(user, type, pageNum, pageSize);
return ResponseEntity.ok(data);
}
......
......@@ -9,9 +9,10 @@ import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.lang.annotation.Documented;
import java.util.Date;
@AutoDocument
@ApiModel(value = "提醒", description = "提醒实体类")
//@ApiModel(value = "提醒", description = "提醒实体类")
@AllArgsConstructor
@NoArgsConstructor
@Data
......@@ -44,8 +45,19 @@ public class Attention {
/**
* 当前用户
*/
@ApiModelProperty(value = "userId", example = "1", dataType = "int", name = "当前用户编号")
@ApiModelProperty(value = "userId", example = "1", dataType = "String", name = "当前用户编号")
@Column(name = "user_id")
private int userId;
private String userId;
/**
* 状态
*/
@ApiModelProperty(value = "status", example = "1", dataType = "int", name = "状态", notes = "未查看 0,已查看 1")
@Column(name = "status")
private int status;
@ApiModelProperty(value = "updateTime", name = "更新时间")
@Column(name = "update_time")
private Date updateTime;
}
......@@ -43,16 +43,16 @@ public class Notice {
/**
* 收件人
*/
@ApiModelProperty(value = "addressee", example = "1", dataType = "int", name = "收件人")
@ApiModelProperty(value = "addressee", example = "1", dataType = "String", name = "收件人")
@Column(name = "addressee")
private int addressee;
private String addressee;
/**
* 发件人
*/
@ApiModelProperty(value = "sender", example = "2", dataType = "String", name = "发件人")
@Column(name = "sender")
private int sender;
private String sender;
/**
* 留言
......@@ -80,14 +80,14 @@ public class Notice {
/**
* 失效时间
*/
@ApiModelProperty(value = "deadline", example = "2020-02-12 10:23:12", name = "通知失效时间")
@ApiModelProperty(value = "deadline", name = "通知失效时间")
@Column(name = "deadline")
private Date deadline;
/**
* 通知更新时间
*/
@ApiModelProperty(value = "updateTime", example = "2020-02-12 10:23:12", name = "通知更新时间")
@ApiModelProperty(value = "updateTime", name = "通知更新时间")
@Column(name = "update_time")
private Date updateTime;
......@@ -105,4 +105,12 @@ public class Notice {
@Column(name = "file_list")
private String fileList;
/**
* 附件列表
*/
@ApiModelProperty(value = "unit", example = "", dataType = "String", name = "单位名称")
@Column(name = "unit")
private String unit;
}
......@@ -2,8 +2,12 @@ package com.zjty.efs.bus.service;
import com.zjty.efs.bus.entity.Attention;
import com.zjty.efs.bus.entity.Paging;
import org.springframework.data.domain.Page;
import java.util.List;
public interface AttentionService {
Paging<Attention> getAttentionList(int userId, int pageNum, int pageSize);
Paging<Attention> getAttentionList(String userId, int pageNum, int pageSize);
boolean addAttention(Attention attention);
boolean updateStatus(List<Attention> attentions);
boolean getRedDot(String userId);
}
......@@ -24,6 +24,7 @@ public interface NoticeService {
/**
* 查看通知
* @param id 通知id
*
* @return
*/
Notice getNotice(int id);
......@@ -36,7 +37,7 @@ public interface NoticeService {
*
* @return 通知json对象
*/
Paging<Notice> getReceiveList(int user, int type, int pageNum, int pageSize);
Paging<Notice> getReceiveList(String user, int type, int pageNum, int pageSize);
/**
* 修改通知为已读
......@@ -52,7 +53,7 @@ public interface NoticeService {
* @param type 0 接收通知
* @return
*/
List<Notice> findBySender(int userId, int status, int type);
List<Notice> findBySender(String userId, int status, int type);
}
......@@ -9,12 +9,17 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class AttentionServiceImpl implements AttentionService {
@Autowired
AttentionDao attentionDao;
@Override
public Paging<Attention> getAttentionList(int userId, int pageNum, int pageSize) {
public Paging<Attention> getAttentionList(String userId, int pageNum, int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNum - 1, pageSize, Sort.Direction.DESC,"updateTime");
Page<Attention> p = attentionDao.findOutByUserId(userId, pageable);
......@@ -32,8 +37,41 @@ public class AttentionServiceImpl implements AttentionService {
}
public boolean addAttention(int noticeId){
@Override
public boolean addAttention(Attention attention) {
try{
attentionDao.save(attention);
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}
}
@Override
@Transactional
public boolean updateStatus(List<Attention> attentions) {
try{
for(Attention attention:attentions){
attention.setStatus(1);
attentionDao.save(attention);
}
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}
}
return true;
@Override
public boolean getRedDot(String userId) {
List<Attention> attentions = attentionDao.findOutByUserIdAndStatus(userId, 0);
if(attentions.size() > 0){
return true;
}else {
return false;
}
}
}
......@@ -4,37 +4,77 @@ import com.zjty.efs.bus.Dao.NoticeDao;
import com.zjty.efs.bus.entity.Notice;
import com.zjty.efs.bus.entity.Paging;
import com.zjty.efs.bus.service.NoticeService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.annotation.Transient;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired
NoticeDao noticeDao;
@Autowired
EfsLogUtil efsLogUtil;
@Autowired
UserService userService;
@Override
@Transactional
public boolean addNotice(Notice notice) {
try{
noticeDao.save(notice);
Notice notice1 = new Notice();
notice1.setType(0);
notice1.setTitle(notice.getTitle());
notice1.setAddressee(notice.getAddressee());
notice1.setDeadline(notice.getDeadline());
notice1.setFileList(notice.getFileList());
notice1.setMessage(notice.getMessage());
notice1.setNote(notice.getNote());
notice1.setSender(notice.getSender());
notice1.setStatus(notice.getStatus());
notice1.setUpdateTime(notice.getUpdateTime());
noticeDao.save(notice1);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, 7);
UserDo userDo = userService.findById(notice.getSender()); // 发送人
UserDo userDo1 = userService.findById(notice.getAddressee()); //接收人
notice.setUpdateTime(new Date());
notice.setDeadline(calendar.getTime());
notice.setUnit(userDo.getUnit());
notice.setStatus(0);
noticeDao.save(notice);
String data = "";
if(notice.getType() == 2){
//如果是草稿
data = "[" +userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "]新增关于[" + notice.getTitle() + "草稿";
}else {
//如果是发送,就新增接收
data = "[" +userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "]给[" + userDo1.getUnit() + "][" + userDo1.getDepartment() + "]的[" + userDo1.getName()
+ "发送了关于[" + notice.getTitle() + "]的通知";
Notice notice1 = new Notice();
notice1.setType(0);
notice1.setTitle(notice.getTitle());
notice1.setAddressee(notice.getAddressee());
notice1.setDeadline(notice.getDeadline());
notice1.setFileList(notice.getFileList());
notice1.setMessage(notice.getMessage());
notice1.setNote(notice.getNote());
notice1.setSender(notice.getSender());
notice1.setStatus(notice.getStatus());
notice1.setUpdateTime(notice.getUpdateTime());
notice1.setUnit(notice.getUnit());
noticeDao.save(notice1);
String data1 = "[" +userDo1.getUnit() + "][" + userDo1.getDepartment() + "]的[" + userDo1.getName()
+ "]收到了来自[" + userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "关于[" + notice.getTitle() + "的通知";
efsLogUtil.addLog(new EfsLog(null, userDo1.getId(), data1, new Date()));
}
efsLogUtil.addLog(new EfsLog(null, userDo.getId(), data, new Date()));
return true;
}catch (Exception e){
......@@ -45,8 +85,10 @@ public class NoticeServiceImpl implements NoticeService {
}
@Override
@Transactional
public boolean updateNotice(Notice notice) {
try{
notice.setStatus(0);
noticeDao.save(notice);
return true;
......@@ -57,11 +99,30 @@ public class NoticeServiceImpl implements NoticeService {
}
@Override
@Transactional
public Notice getNotice(int id) {
try {
Notice notice = noticeDao.findById(id);
notice.setStatus(1);
noticeDao.save(notice);
String userId = "";
if (notice.getType() == 0){
//已接收
userId = notice.getAddressee();
}else {
userId = notice.getSender();
}
if (notice.getType() == 0){
//已接收
userId = notice.getAddressee();
}else {
userId = notice.getSender();
}
UserDo userDo = userService.findById(userId); // 发送人
String data = "[" +userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "查看了关于[" + notice.getTitle() + "的通知";
efsLogUtil.addLog(new EfsLog(null, userDo.getId(), data, new Date()));
return notice;
}catch (Exception e){
e.printStackTrace();
......@@ -71,10 +132,19 @@ public class NoticeServiceImpl implements NoticeService {
}
@Override
public Paging<Notice> getReceiveList(int user, int type, int pageNum, int pageSize) {
public Paging<Notice> getReceiveList(String user, int type, int pageNum, int pageSize) {
Pageable pageable = PageRequest.of(pageNum - 1, pageSize, Sort.Direction.DESC,"updateTime");
Page<Notice> p = noticeDao.findOutBySenderAndType(user, type, pageable);
Page<Notice> p;
if (type == 0){
//已接收
p = noticeDao.findOutByAddresseeAndType(user, type, pageable);
}else {
//已发送,草稿
p = noticeDao.findOutBySenderAndType(user, type, pageable);
}
Paging<Notice> paging = new Paging<>();
paging.setData(p.getContent());
paging.setPageSize(pageSize);
......@@ -84,11 +154,27 @@ public class NoticeServiceImpl implements NoticeService {
}
@Override
@Transactional
public boolean updateStatus(List<Notice> notices) {
try {
String userId = "";
if (notices.get(0).getType() == 0){
userId = notices.get(0).getAddressee();
}else {
userId = notices.get(0).getSender();
}
UserDo userDo = userService.findById(userId); // 发送人
String data = "[" +userDo.getUnit() + "][" + userDo.getDepartment() + "]的[" + userDo.getName()
+ "修改";
for (Notice notice:notices){
notice.setStatus(1);
noticeDao.save(notice);
data = data + "[" + notice.getTitle() + "]";
}
data = data + "为已读";
efsLogUtil.addLog(new EfsLog(null, userDo.getId(), data, new Date()));
return true;
}catch (Exception e){
e.printStackTrace();
......@@ -97,9 +183,9 @@ public class NoticeServiceImpl implements NoticeService {
}
@Override
public List<Notice> findBySender(int userId, int status, int type) {
public List<Notice> findBySender(String userId, int status, int type) {
try{
return noticeDao.findOutBySenderAndStatusAndType(userId, status, type);
return noticeDao.findOutByStatusAndType(status, type);
}catch (Exception e){
e.printStackTrace();
return null;
......
package com.zjty.efs.bus.util;
import com.zjty.efs.bus.entity.Attention;
import com.zjty.efs.bus.entity.Notice;
import com.zjty.efs.bus.service.AttentionService;
import com.zjty.efs.bus.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
public class Job {
@Autowired
NoticeService noticeService;
@Autowired
AttentionService attentionService;
@Scheduled(cron = "0 0 10 * * ? ")
public void cronJob() {
List<Notice> noticeList = noticeService.findBySender("",0,0);
Date now = new Date();
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.getSender() +"]的[" + notice.getTitle() + "],还有" + days +"天失效。";
attention.setData(data);
attention.setNoticeId(notice.getId());
attention.setUserId(notice.getAddressee());
attention.setStatus(0);
attention.setUpdateTime(new Date());
attentionService.addAttention(attention);
}
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论