|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package edu.ncst.ioreport.service.impl; |
|
|
|
package edu.ncst.ioreport.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import afu.org.checkerframework.checker.oigj.qual.O; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
@ -8,7 +9,6 @@ import edu.ncst.ioreport.exception.BusinessException; |
|
|
|
import edu.ncst.ioreport.exception.CodeMsg; |
|
|
|
import edu.ncst.ioreport.exception.CodeMsg; |
|
|
|
import edu.ncst.ioreport.mapper.IORecordsMapper; |
|
|
|
import edu.ncst.ioreport.mapper.IORecordsMapper; |
|
|
|
import edu.ncst.ioreport.model.IORecords; |
|
|
|
import edu.ncst.ioreport.model.IORecords; |
|
|
|
import edu.ncst.ioreport.model.User; |
|
|
|
|
|
|
|
import edu.ncst.ioreport.service.IIORecordService; |
|
|
|
import edu.ncst.ioreport.service.IIORecordService; |
|
|
|
import edu.ncst.ioreport.utils.SessionUtils; |
|
|
|
import edu.ncst.ioreport.utils.SessionUtils; |
|
|
|
import edu.ncst.ioreport.vo.QRToken; |
|
|
|
import edu.ncst.ioreport.vo.QRToken; |
|
|
|
@ -18,9 +18,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class IORecordServiceImpl implements IIORecordService { |
|
|
|
public class IORecordServiceImpl implements IIORecordService { |
|
|
|
@ -28,6 +29,7 @@ public class IORecordServiceImpl implements IIORecordService { |
|
|
|
private IORecordsMapper recordsMapper; |
|
|
|
private IORecordsMapper recordsMapper; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private RedisTemplate<String, String> stringRedisTemplate; |
|
|
|
private RedisTemplate<String, String> stringRedisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<IORecords> getIORecordsList(QRecord query) { |
|
|
|
public List<IORecords> getIORecordsList(QRecord query) { |
|
|
|
IORecords ioRecords = new IORecords(); |
|
|
|
IORecords ioRecords = new IORecords(); |
|
|
|
@ -78,7 +80,7 @@ public class IORecordServiceImpl implements IIORecordService { |
|
|
|
} |
|
|
|
} |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public IORecords getIORecordsDetail(Integer ID) { |
|
|
|
public IORecords getIORecordsDetail(Integer ID) { |
|
|
|
if(null==ID){ |
|
|
|
if (null == ID) { |
|
|
|
throw new BusinessException(CodeMsg.PARAM_ERROR.fillArgs("记录单ID为空")); |
|
|
|
throw new BusinessException(CodeMsg.PARAM_ERROR.fillArgs("记录单ID为空")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -86,22 +88,22 @@ public class IORecordServiceImpl implements IIORecordService { |
|
|
|
queryWrapper.eq("id",ID); |
|
|
|
queryWrapper.eq("id",ID); |
|
|
|
IORecords records = recordsMapper.selectDetail(queryWrapper); |
|
|
|
IORecords records = recordsMapper.selectDetail(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if(records.getStatus().compareTo("SCHOOL_PASS")==0){ |
|
|
|
if (records.getStatus().compareTo("SCHOOL_PASS") == 0) { |
|
|
|
if(!stringRedisTemplate.hasKey("qrToken_"+ID)){ |
|
|
|
if (!stringRedisTemplate.hasKey("qrToken_" + ID)) { |
|
|
|
QRToken qrToken = new QRToken(); |
|
|
|
QRToken qrToken = new QRToken(); |
|
|
|
qrToken.setRecordID(ID); |
|
|
|
qrToken.setRecordID(ID); |
|
|
|
stringRedisTemplate.opsForValue().set("qrToken_"+ID,JSON.toJSONString(qrToken),1, TimeUnit.MINUTES); |
|
|
|
stringRedisTemplate.opsForValue().set("qrToken_" + ID, JSON.toJSONString(qrToken), 1, TimeUnit.MINUTES); |
|
|
|
} |
|
|
|
} |
|
|
|
String qrTokenStr = stringRedisTemplate.opsForValue().get("qrToken_"+ID); |
|
|
|
String qrTokenStr = stringRedisTemplate.opsForValue().get("qrToken_" + ID); |
|
|
|
QRToken qrToken = JSON.parseObject(qrTokenStr,QRToken.class); |
|
|
|
QRToken qrToken = JSON.parseObject(qrTokenStr, QRToken.class); |
|
|
|
if(qrToken!=null){ |
|
|
|
if (qrToken != null) { |
|
|
|
Long seconds = stringRedisTemplate.getExpire("qrToken_"+ID); |
|
|
|
Long seconds = stringRedisTemplate.getExpire("qrToken_" + ID); |
|
|
|
qrToken.setExpireTime(seconds); |
|
|
|
qrToken.setExpireTime(seconds); |
|
|
|
records.setQrToken(qrToken); |
|
|
|
records.setQrToken(qrToken); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(null==records){ |
|
|
|
if (null == records) { |
|
|
|
throw new BusinessException("记录不存在"); |
|
|
|
throw new BusinessException("记录不存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
return records; |
|
|
|
return records; |
|
|
|
@ -111,18 +113,88 @@ public class IORecordServiceImpl implements IIORecordService { |
|
|
|
public int addIORecord(IORecords record) { |
|
|
|
public int addIORecord(IORecords record) { |
|
|
|
UserInfoVO user = SessionUtils.getCurrentUser(); |
|
|
|
UserInfoVO user = SessionUtils.getCurrentUser(); |
|
|
|
List<String> roles = user.getRoles(); |
|
|
|
List<String> roles = user.getRoles(); |
|
|
|
if(roles==null||(roles.size()==1&&user.getRoles().get(0).compareTo("DOORMEN")==0)){ |
|
|
|
if(roles==null||(roles.size()==1&&user.getRoles().get(0).compareTo("DOOR_GUARD")==0)){ |
|
|
|
throw new BusinessException(CodeMsg.CAN_NOT_DATA_ACCESS); |
|
|
|
throw new BusinessException(CodeMsg.CAN_NOT_DATA_ACCESS); |
|
|
|
} |
|
|
|
} |
|
|
|
if(user.getTeacherID().compareTo(record.getTeacherID())!=0){ |
|
|
|
if (user.getTeacherID().compareTo(record.getTeacherID()) != 0) { |
|
|
|
throw new BusinessException(CodeMsg.BUSINESS_ERROR.fillArgs("当前用户为"+user.getTeacherID()+",与单据中提交人不一致")); |
|
|
|
throw new BusinessException(CodeMsg.BUSINESS_ERROR.fillArgs("当前用户为" + user.getTeacherID() + ",与单据中提交人不一致")); |
|
|
|
} |
|
|
|
} |
|
|
|
record.setStatus("SUBMIT"); |
|
|
|
record.setStatus("SUBMIT"); |
|
|
|
int id = recordsMapper.insertAndGetId(record); |
|
|
|
int id = recordsMapper.insertAndGetId(record); |
|
|
|
if(id==1){ |
|
|
|
if (id == 1) { |
|
|
|
return record.getId(); |
|
|
|
return record.getId(); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
throw new BusinessException(CodeMsg.ADD_ERROR); |
|
|
|
throw new BusinessException(CodeMsg.ADD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 审核通过接口
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void passIORecord(Integer recordId) { |
|
|
|
|
|
|
|
if (null == recordId) { |
|
|
|
|
|
|
|
throw new BusinessException(CodeMsg.PARAM_ERROR.fillArgs("记录单ID为空")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// user 是审核人信息
|
|
|
|
|
|
|
|
IORecords ioRecords = recordsMapper.selectById(recordId); |
|
|
|
|
|
|
|
if (ioRecords == null) { |
|
|
|
|
|
|
|
throw new BusinessException("记录不存在"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// if (!ioRecords.getStatus().equals("SUBMIT")) {
|
|
|
|
|
|
|
|
// throw new BusinessException("记录不存在");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
UserInfoVO user = SessionUtils.getCurrentUser(); |
|
|
|
|
|
|
|
List<String> roles = user.getRoles(); |
|
|
|
|
|
|
|
List<String> res_1 = roles.stream().filter(role -> role.equals("SCHOOL_AUDITOR") || role.equals("DEPART_AUDITOR")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (res_1.size() == 0) { |
|
|
|
|
|
|
|
throw new BusinessException(CodeMsg.CAN_NOT_DATA_ACCESS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> res_2 = res_1.stream().filter(role -> role.equals("DEPT_AUDITOR")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (res_2.size() != 0) { |
|
|
|
|
|
|
|
ioRecords.setStatus("DEPT_PASS"); |
|
|
|
|
|
|
|
ioRecords.setDeptAuditorID(user.getUserID()); |
|
|
|
|
|
|
|
ioRecords.setDeptAuditTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> res_3 = res_1.stream().filter(role -> role.equals("SCHOOL_AUDITOR")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (res_3.size() != 0) { |
|
|
|
|
|
|
|
ioRecords.setStatus("SCHOOL_PASS"); |
|
|
|
|
|
|
|
ioRecords.setSchoolAuditorID(user.getUserID()); |
|
|
|
|
|
|
|
ioRecords.setSchoolAuditTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 更新数据库
|
|
|
|
|
|
|
|
recordsMapper.auditIORecord(ioRecords); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 审核通过接口
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void denyIORecord(Integer recordId) { |
|
|
|
|
|
|
|
if (null == recordId) { |
|
|
|
|
|
|
|
throw new BusinessException(CodeMsg.PARAM_ERROR.fillArgs("记录单ID为空")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// user 是审核人信息
|
|
|
|
|
|
|
|
IORecords ioRecords = recordsMapper.selectById(recordId); |
|
|
|
|
|
|
|
if (ioRecords == null) { |
|
|
|
|
|
|
|
throw new BusinessException("记录不存在"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
UserInfoVO user = SessionUtils.getCurrentUser(); |
|
|
|
|
|
|
|
List<String> roles = user.getRoles(); |
|
|
|
|
|
|
|
List<String> res_1 = roles.stream().filter(role -> role.equals("SCHOOL_AUDITOR") || role.equals("DEPART_AUDITOR")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (res_1.size() == 0) { |
|
|
|
|
|
|
|
throw new BusinessException(CodeMsg.CAN_NOT_DATA_ACCESS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> res_2 = res_1.stream().filter(role -> role.equals("DEPT_AUDITOR")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (res_2.size() != 0) { |
|
|
|
|
|
|
|
ioRecords.setStatus("DEPT_DENY"); |
|
|
|
|
|
|
|
ioRecords.setDeptAuditorID(user.getUserID()); |
|
|
|
|
|
|
|
ioRecords.setDeptAuditTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> res_3 = res_1.stream().filter(role -> role.equals("SCHOOL_AUDITOR")).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if (res_3.size() != 0) { |
|
|
|
|
|
|
|
ioRecords.setStatus("SCHOOL_DENY"); |
|
|
|
|
|
|
|
ioRecords.setSchoolAuditorID(user.getUserID()); |
|
|
|
|
|
|
|
ioRecords.setSchoolAuditTime(new Date()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 更新数据库
|
|
|
|
|
|
|
|
recordsMapper.auditIORecord(ioRecords); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|