提交 69e59422 authored 作者: 133's avatar 133

提交user、file、misc、train

上级 99f3b55e
...@@ -15,7 +15,16 @@ ...@@ -15,7 +15,16 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
package com.tykj.dev.blockcha.conf;
/**
* 区块链提供的url
*
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
public interface BcUrl {
/**
* 区块链状态查询
*/
String GET_STATUS = "/blockchain/state";
/**
* 业务类型码注册
*/
String SUB_CODE_REGISTER = "/blockchain/subcode/register";
/**
* 文本上链
*/
String SEND_TEXT = "/blockchain/send/text";
/**
* 哈希上链
*/
String SEND_HASH = "/blockchain/send/hash";
/**
* 记录查询
*/
String FETCH_RECORD = "/blockchain/fetch/record";
/**
* 记录批量查询
*/
String FETCH_HISTORY = "/blockchain/fetch/history";
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcHash {
/**
* 结果状态码,成功为0
*/
private Integer code;
/**
* 结果状态文字描述
*/
private String info;
/**
* 接口返回结果
*/
private BcHashData data;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcHashData {
private String recordID;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcHistory {
/**
* 结果状态码,成功为0
*/
private Integer code;
/**
* 结果状态文字描述
*/
private String info;
/**
* 接口返回结果
*/
private BcHistoryData data;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcHistoryData {
/**
* 记录列表,数据项与“记录查询”一致
*/
private List<BcRecordData> records;
/**
* 游标,用于分页查询
*/
private String cursor;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcRecord {
/**
* 结果状态码,成功为0
*/
private Integer code;
/**
* 结果状态文字描述
*/
private String info;
/**
* 接口返回结果
*/
private BcRecordData data;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcRecordData {
/**
* 记录id
*/
private String recordID;
/**
* 记录类型,text/hash(文本或哈希)
*/
private String type;
/**
* 业务类型码,用于区分不同业务
*/
private String subCode;
/**
* 记录内容
*/
private String content;
/**
* 上链时间戳,精确到秒
*/
private String timestamp;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcRegister {
/**
* 结果状态码,成功为0
*/
private Integer code;
/**
* 结果状态文字描述
*/
private String info;
/**
* 接口返回结果
*/
private BcRegisterData data;
}
package com.tykj.dev.blockcha.subject.entity;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
public class BcRegisterData {
/**
* 业务名称
*/
private String subName;
/**
* 业务类型码
*/
private Integer subCode;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BcStatus {
/**
* 结果状态码,成功为0
*/
private Integer code;
/**
* 结果状态文字描述
*/
private String info;
/**
* 接口返回结果
*/
private BcStatusData data;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcStatusData {
/**
* 当前区块高度
*/
private String height;
/**
* 共识节点数量
*/
private Integer consensusNodeCount;
/**
* 业务节点数量
*/
private Integer serviceNodeCount;
}
package com.tykj.dev.blockcha.subject.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcText {
/**
* 结果状态码,成功为0
*/
private Integer code;
/**
* 结果状态文字描述
*/
private String info;
/**
* 接口返回结果
*/
private BcTextData data;
}
package com.tykj.dev.blockcha.subject.entity;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BcTextData {
@JSONField(name = "recordID")
private String recordID;
}
package com.tykj.dev.blockcha.subject.service;
import com.tykj.dev.blockcha.subject.entity.*;
import java.util.Map;
/**
* 对接白鸟区块链接口实现
*
* @author LJJ cnljj1995@gmail.com
* on 2020-08-13
*/
public interface BlockChainUtil {
/**
* 获取区块链状态
*
* @return BS
*/
BcStatus getStatus();
/**
* 业务类型码注册
*
* @param subName 业务名称,可以是中英文
* @return br
*/
BcRegister subRegister(String subName);
/**
* 文本上链
*
* @param subCode 业务代码编号
* @param content 文本 200k以内
* @return bt
*/
BcText sendText(Integer subCode, String content);
/**
* hash 上链
*
* @param subCode 业务代码编号
* @param content 内容哈希,256bits hex编码。 方法可参考本模块HexUtil
* @return bh
*/
BcHash sendHash(Integer subCode, String content);
/**
* 记录查询
*
* @param recordId 记录id
* @return fr
*/
BcRecord fetchRecord(String recordId);
/**
* 记录批量查询
*
* @param map k: "type", v: String,
* required:false, remark: 记录类型,text/hash(文本或哈希), 省略包含两者
*
* k: "subCode", v: Integer,
* required:false, remark: 业务类型码,用于区分不同业务,默认全部
*
* k: "fromEarliest", v: Integer,
* required:false, remark: 是否从最早的数据开始查询,默认从最新数据开始
*
* k: "limit", v: Integer,
* required:false, remark: 获取记录数,默认20,上限200
*
* k: "cursor", v: String,
* required:false, remark: 游标,用于标识数据读取位置,首次留空, 查询下一页数据传上一次返回的值
* @return bc
*/
BcHistory fetchHistory(Map<String, Object> map);
}
package com.tykj.dev.blockcha.subject.service.impl;
import lombok.extern.slf4j.Slf4j;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.util.SortedMap;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-18
*/
@Slf4j
class ApiSignatureUtil {
/**
* @param map you can use SortedMap<Object, Object> map = new TreeMap<Object, Object>();
* need to add nonce,secretID,timestamp(s) columns;
* @param key SECRET_KEY
*/
static String getApiSignature(SortedMap<Object, Object> map, String key) {
StringBuilder sb = new StringBuilder();
map.forEach((k,v) -> sb.append(k).append("=").append(v).append("&"));
String str = sb.toString();
String message = str.substring(0, str.length() - 1);
return sha256_HMAC(message, key);
}
/**
* 将加密后的字节数组转换成字符串
*
* @param b 字节数组
* @return 字符串
*/
private static String byteArrayToHexString(byte[] b) {
StringBuilder hs = new StringBuilder();
String stmp;
for (int n = 0; b != null && n < b.length; n++) {
stmp = Integer.toHexString(b[n] & 0XFF);
if (stmp.length() == 1) {
hs.append('0');
}
hs.append(stmp);
}
return hs.toString().toLowerCase();
}
/**
* sha256_HMAC加密
*
* @param message 消息
* @param secret 秘钥
* @return 加密后字符串
*/
private static String sha256_HMAC(String message, String secret) {
String hash = "";
try {
Mac sha256 = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
sha256.init(secretKey);
byte[] bytes = sha256.doFinal(message.getBytes());
hash = byteArrayToHexString(bytes);
} catch (Exception e) {
log.error("[BlockChain] sha256_HMAC加密出错:{}", e.toString());
}
return hash.toUpperCase();
}
}
package com.tykj.dev.blockcha.subject.service.impl;
import com.tykj.dev.blockcha.conf.BcUrl;
import com.tykj.dev.blockcha.subject.entity.*;
import com.tykj.dev.blockcha.subject.service.BlockChainUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;
/**
* 步骤:
* 1.构建请求参数
* 2.通过rest_template获取数据
*
* @author LJJ cnljj1995@gmail.com
* on 2020-08-13
*/
@Slf4j
@Component
public class BlockChainUtilImpl implements BlockChainUtil {
private final static String SECRET_KEY = "aLTEmMyIfAWzVCIy8EKI0uGFThrR20dR12C62ENZ16RAX5TNTLUC4CCP";
private final static String SECRET_ID = "tLNj025SOWTWv56ORlRdGA";
private final static String BLOCK_CHAIN_URL = "http://120.55.94.123";
@Override
public BcStatus getStatus() {
SortedMap<Object, Object> request = getRequest();
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.GET_STATUS,
request,
BcStatus.class);
}
@Override
public BcRegister subRegister(String subName) {
SortedMap<Object, Object> request = getRequest();
request.put("subName", subName);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.SUB_CODE_REGISTER,
request,
BcRegister.class
);
}
@Override
public BcText sendText(Integer subCode, String content) {
SortedMap<Object, Object> request = getRequest();
request.put("content", content);
request.put("subCode", subCode);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.SEND_TEXT,
request,
BcText.class
);
}
@Override
public BcHash sendHash(Integer subCode, String content) {
SortedMap<Object, Object> request = getRequest();
request.put("content", content);
request.put("subCode", subCode);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.SEND_HASH,
request,
BcHash.class
);
}
@Override
public BcRecord fetchRecord(String recordId) {
SortedMap<Object, Object> request = getRequest();
request.put("recordID", recordId);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.FETCH_RECORD,
request,
BcRecord.class
);
}
@Override
public BcHistory fetchHistory(Map<String, Object> map) {
SortedMap<Object, Object> request = getRequest();
map.forEach(request::put);
request.put("apiSignature", ApiSignatureUtil.getApiSignature(request, SECRET_KEY));
log.info("{}", request);
return new RestTemplate().postForObject(
BLOCK_CHAIN_URL + BcUrl.FETCH_HISTORY,
request,
BcHistory.class
);
}
/**
* 存储通用参数
*
* @return request
*/
private SortedMap<Object, Object> getRequest() {
long timestamp = System.currentTimeMillis() / 1000;
String nonce = UUID.randomUUID().toString().trim().replaceAll("-", "");
SortedMap<Object, Object> request = new TreeMap<Object, Object>();
request.put("timestamp", timestamp);
request.put("nonce", nonce);
request.put("secretID", SECRET_ID);
return request;
}
}
package com.tykj.dev.blockcha.subject.service.impl;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-08-19
*/
public class HexUtil {
/**
* @param b 字节数组
* @return 16进制字符串
* @throws
* @Title:bytes2HexString
* @Description:字节数组转16进制字符串
*/
public static String bytes2HexString(byte[] b) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < b.length; i++) {
result.append(String.format("%02X", b[i]));
}
return result.toString();
}
/**
* @param src 16进制字符串
* @return 字节数组
* @throws
* @Title:hexString2Bytes
* @Description:16进制字符串转字节数组
*/
public static byte[] hexString2Bytes(String src) {
int l = src.length() / 2;
byte[] ret = new byte[l];
for (int i = 0; i < l; i++) {
ret[i] = Integer.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
}
return ret;
}
/**
* @param strPart 字符串
* @return 16进制字符串
* @throws
* @Title:string2HexUTF8
* @Description:字符UTF8串转16进制字符串
*/
public static String string2HexUTF8(String strPart) {
return string2HexString(strPart, "UTF-8");
}
/**
* @param strPart 字符串
* @return 16进制字符串
* @throws
* @Title:string2HexUTF8
* @Description:字符UTF-16LE串转16进制字符串,此UTF-16LE等同于C#中的Unicode
*/
public static String string2HexUTF16LE(String strPart) {
return string2HexString(strPart, "UTF-16LE");
}
/**
* @param strPart 字符串
* @return 16进制字符串
* @throws
* @Title:string2HexUnicode
* @Description:字符Unicode串转16进制字符串
*/
public static String string2HexUnicode(String strPart) {
return string2HexString(strPart, "Unicode");
}
/**
* @param strPart 字符串
* @return 16进制字符串
* @throws
* @Title:string2HexGBK
* @Description:字符GBK串转16进制字符串
*/
public static String string2HexGBK(String strPart) {
return string2HexString(strPart, "GBK");
}
/**
* @param strPart 字符串
* @param tochartype hex目标编码
* @return 16进制字符串
* @throws
* @Title:string2HexString
* @Description:字符串转16进制字符串
*/
public static String string2HexString(String strPart, String tochartype) {
try {
return bytes2HexString(strPart.getBytes(tochartype));
} catch (Exception e) {
return "";
}
}
/**
* @param src 16进制字符串
* @return 字节数组
* @throws
* @Title:hexUTF82String
* @Description:16进制UTF-8字符串转字符串
*/
public static String hexUTF82String(String src) {
return hexString2String(src, "UTF-8", "UTF-8");
}
/**
* @param src 16进制字符串
* @return 字节数组
* @throws
* @Title:hexUTF16LE2String
* @Description:16进制UTF-8字符串转字符串,,此UTF-16LE等同于C#中的Unicode
*/
public static String hexUTF16LE2String(String src) {
return hexString2String(src, "UTF-16LE", "UTF-8");
}
/**
* @param src 16进制字符串
* @return 字节数组
* @throws
* @Title:hexGBK2String
* @Description:16进制GBK字符串转字符串
*/
public static String hexGBK2String(String src) {
return hexString2String(src, "GBK", "UTF-8");
}
/**
* @param src 16进制字符串
* @return 字节数组
* @throws
* @Title:hexUnicode2String
* @Description:16进制Unicode字符串转字符串
*/
public static String hexUnicode2String(String src) {
return hexString2String(src, "Unicode", "UTF-8");
}
/**
* @param src 16进制字符串
* @return 字节数组
* @throws
* @Title:hexString2String
* @Description:16进制字符串转字符串
*/
public static String hexString2String(String src, String oldchartype, String chartype) {
byte[] bts = hexString2Bytes(src);
try {
if (oldchartype.equals(chartype)) {
return new String(bts, oldchartype);
} else {
return new String(new String(bts, oldchartype).getBytes(), chartype);
}
} catch (Exception e) {
return "";
}
}
}
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>device</artifactId>
<groupId>com.tykj.dev</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>device-file</artifactId>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.tykj.dev.device.file.Controller;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfWriter;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.file.entity.FileRet;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartRequest;
import com.itextpdf.text.Rectangle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;
import java.util.UUID;
/**
* @author zjm
* @version 1.0.0
* @ClassName FileController.java
* @Description TODO
* @createTime 2020年08月03日 18:05:00
*/
@RestController
@AutoDocument
@Api(tags = "文件模块", description = "提供文件相关的接口")
@Slf4j
public class FileController {
@Value("${file.path}")
public String url;
@Value("${preview.path}")
public String preview;
/**
* 文件上传
*/
@PostMapping("/upload")
public ResponseEntity<FileRet> upload(HttpServletRequest request){
MultipartRequest multiRequest = (MultipartRequest)request;
MultipartFile file = multiRequest.getFile("file");
String originalFilename = file.getOriginalFilename();
System.out.println(originalFilename);
File file1= new File(url);
if (!file1.exists()){
file1.mkdirs();
}
FileOutputStream fos = null;
InputStream inputStream = null;
OutputStream os = null;
String[] split = originalFilename.split("\\.");
String newName=UUID.randomUUID().toString()+"."+split[split.length-1];
byte[] typeByte = new byte[1024*1024*10];
try {
inputStream = file.getInputStream();
fos = new FileOutputStream(url+newName);
int i = 0;
while((i=inputStream.read(typeByte))!=-1){
fos.write(typeByte,0,i);
}
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
inputStream = null;
}
}
if(fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
fos = null;
}
}
if(os!=null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
os = null;
}
}
return ResponseEntity.ok(new FileRet(originalFilename,url+newName,preview+newName));
}
/**
* 文件下载
*/
@PostMapping("/download")
public void download(@RequestParam(value = "url") String url, @RequestParam(value = "name") String name, HttpServletResponse response, HttpServletRequest httpServletRequest){
String fileName = name;
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
try {
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
setFileDownloadHeader(httpServletRequest, response, fileName);
OutputStream os = null;
InputStream is = null;
BufferedInputStream bs = null;
byte[] buffer = new byte[1024];
try {
is = new FileInputStream(new File(url));
bs = new BufferedInputStream(is);
os = response.getOutputStream();
int i = bs.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bs.read(buffer);
}
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bs.close();
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@PostMapping("/print/pdf")
public ResponseEntity<FileRet> fileUpload(HttpServletRequest request) throws IOException, DocumentException {
List<MultipartFile> multipartFiles = ((MultipartHttpServletRequest)request).getFiles("file");
System.out.println("数据条数"+multipartFiles.size());
String fileName = UUID.randomUUID().toString()+".pdf";
File file = new File(url+"print/"+fileName);
if (file.exists()){
file.mkdirs();
}
// 第一步:创建一个document对象。
Document document = new Document();
document.setMargins(0, 0, 0, 0);
// 第二步:
// 创建一个PdfWriter实例,
PdfWriter.getInstance(document, new FileOutputStream(file));
// 第三步:打开文档。
document.open();
for(MultipartFile multipartFile:multipartFiles){
Image img = Image.getInstance(multipartFile.getBytes());
//转成
// Image.byte()
//多文件上传 图片专程byte 2进制
img.setAlignment(Image.ALIGN_CENTER);
// 根据图片大小设置页面,一定要先设置页面,再newPage(),否则无效
document.setPageSize(new Rectangle(img.getWidth(), img.getHeight()));
document.newPage();
document.add(img);
}
document.close();
return ResponseEntity.ok(new FileRet("",url+"print/"+fileName+fileName,preview+"print/"+fileName));
}
/**
* 解决中文名称
*/
private void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) {
try {
//中文文件名支持
String encodedfileName;
String agent = request.getHeader("USER-AGENT");
if (null != agent && agent.contains("MSIE")) {//IE
encodedfileName = java.net.URLEncoder.encode(fileName, "UTF-8");
} else if (null != agent && agent.contains("Mozilla")) {
encodedfileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
} else {
encodedfileName = java.net.URLEncoder.encode(fileName, "UTF-8");
}
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedfileName + "\"");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
package com.tykj.dev.device.file;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author zjm
* @version 1.0.0
* @ClassName userApp.java
* @Description TODO
* @createTime 2020年09月01日 14:32:00
*/
@SpringBootApplication(scanBasePackages={
"com.tykj.dev.*",
}
)
public class FileApp {
public static void main(String[] args) {
SpringApplication.run(FileApp.class, args);
}
}
package com.tykj.dev.device.file.entity;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author zjm
* @version 1.0.0
* @ClassName FileRet.java
* @Description TODO
* @createTime 2020年08月03日 18:03:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "文件上传返回对象", description = "文件上传返回对象信息")
public class FileRet {
/**
* 上传文件名称
*/
private String name;
/**
* 文件路径
*/
private String filePath;
/**
* 预览地址
*/
private String previewPath;
}
...@@ -17,4 +17,20 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE ...@@ -17,4 +17,20 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE
* 根据账单Id和业务类型查询task * 根据账单Id和业务类型查询task
*/ */
Task findByBillIdAndBusinessType(Integer billId, Integer businessType); Task findByBillIdAndBusinessType(Integer billId, Integer businessType);
/**
* 根据账单id、业务类型、任务状态查询task
* @param billId 账单id
* @param businessType 业务类型
* @param billStatus 任务状态
*/
List<Task> findAllByBillIdAndBusinessTypeAndBillStatus(Integer billId,Integer businessType,Integer billStatus);
/**
* 根据账单id、业务类型、以及父id为null
* @param billId 账单ID
* @param businessType 业务类型
*/
Task findAllByParentTaskIdIsNullAndBillIdAndBusinessType(Integer billId,Integer businessType);
} }
...@@ -42,6 +42,34 @@ public enum StatusEnum { ...@@ -42,6 +42,34 @@ public enum StatusEnum {
*/ */
END(9999,"业务完结"), END(9999,"业务完结"),
TRAIN1000(1000,"报名中"),
TRAIN1001(1001,"报名确认"),
TRAIN1002(1002,"待报名"),
TRAIN1003(1003,"等待培训"),
TRAIN1004(1004,"培训中"),
TRAIN1005(1005,"申请发证"),
TRAIN1006(1006,"市培训申请发证审核"),
TRAIN1007(1007,"省培训发证审核"),
TRAIN1008(1008,"成绩录入"),
TRAIN1009(1009,"成绩确认"),
//
TRAIN1010(1010,"待培训"),
//
// TRAIN1011(1011,""),
//
// TRAIN1012(1012,""),
//
// TRAIN1013(1013,""),
/** /**
* 业务封存 * 业务封存
*/ */
......
...@@ -10,5 +10,28 @@ ...@@ -10,5 +10,28 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>device-train</artifactId> <artifactId>device-train</artifactId>
<dependencies>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>device-user</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.tykj.dev</groupId>
<artifactId>device-train</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>device-task</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.tykj.dev</groupId>
<artifactId>device-train</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
package com.tykj.dev.device.train;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author zjm
* @version 1.0.0
* @ClassName userApp.java
* @Description TODO
* @createTime 2020年09月01日 14:32:00
*/
@SpringBootApplication(scanBasePackages={
"com.tykj.dev.*",
}
)
public class TrainApp {
public static void main(String[] args) {
SpringApplication.run(TrainApp.class, args);
}
}
package com.tykj.dev.device.train.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.train.entity.vo.HandoverVo;
import com.tykj.dev.device.train.service.TrainThemeService;
import com.tykj.dev.device.user.base.ret.HandoverUser;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.SecurityUser;
import com.tykj.dev.device.user.subject.service.MgrcertService;
import com.tykj.dev.device.user.subject.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
/**
* @author zjm
* @version 1.0.0
* @ClassName HandoverController.java
* @Description 工作交接服务层
* @createTime 2020年08月19日 09:36:00
*/
@RestController
@RequestMapping(value = "/user/handover/")
@AutoDocument
@Api(tags = "工作交接",description = "工作交接")
public class HandoverController {
@Autowired
TrainThemeService trainThemeService;
@Autowired
MgrcertService mgrcertService;
@Autowired
UnitsDao unitsDao;
@Autowired
UserService userService;
@GetMapping(value = "/{userId}")
@ApiOperation(value = "根据用户id查询交接用户详情", notes = "成功返回handoverUser对象集合")
public ResponseEntity<HandoverUser> getHandoverUser(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser, @PathVariable Integer userId){
return ResponseEntity.ok(userService.findByIdHandoverUser(userId));
}
@PostMapping(value = "/job")
@ApiOperation(value = "用户工作交接")
public ResponseEntity<String> getHandoverUser(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser, @RequestBody HandoverVo handoverVo){
// jobService.findByIdsList(handoverVo.getCommissionJobIds()).forEach(
// jobEntity -> {
// if (jobEntity.getBelongUserId()==handoverVo.getHandoverUserId()) {
// jobEntity.setBelongUserId(handoverVo.getBeHandoverUserId());
// jobEntity.setInvoleUserId(jobEntity.getInvoleUserId().replace(handoverVo.getHandoverUserId().toString(),handoverVo.getBeHandoverUserId().toString()));
// jobService.update(jobEntity);
// }
// }
// );
// jobService.findByIdsList(handoverVo.getTrackingJobIds()).forEach(
// jobEntity -> {
// jobEntity.setInvoleUserId(jobEntity.getInvoleUserId().replace(handoverVo.getHandoverUserId().toString(),handoverVo.getBeHandoverUserId().toString()));
// jobService.update(jobEntity);
// }
// );
return ResponseEntity.ok("成功");
}
}
package com.tykj.dev.device.train.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.train.entity.TrainTheme;
import com.tykj.dev.device.train.entity.vo.ConditionsTrainVo;
import com.tykj.dev.device.train.entity.vo.TrainThemePage;
import com.tykj.dev.device.train.service.TrainThemeService;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.service.MgrcertService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.web.bind.annotation.*;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainController.java
* @Description TODO
* @createTime 2020年08月11日 21:42:00
*/
@RestController
@RequestMapping(value = "/user/train")
@AutoDocument
@Api(tags = "专管员培训",description = "培训接口")
public class TrainController {
@Autowired
TrainThemeService trainThemeService;
// @Autowired
// JobService jobService;
@Autowired
MgrcertService mgrcertService;
@Autowired
UnitsDao unitsDao;
/**
* 培训列表查询接口(分页)
* @return
*/
@PostMapping("/summary/page")
public ResponseEntity<TrainThemePage> trainThemeVoResponseEntity(@RequestBody ConditionsTrainVo conditionsTrainVo){
return ResponseEntity.ok(trainThemeService.findTrainPageVo(conditionsTrainVo));
}
/**
* 培训详情接口
* @param trainThemeId 培训id
*/
@GetMapping("/detail/{trainThemeId}")
public ResponseEntity<TrainTheme> trainThemeVoResponseEntity(@PathVariable Integer trainThemeId){
return ResponseEntity.ok(trainThemeService.findById(trainThemeId));
}
}
package com.tykj.dev.device.train.dao;
import com.tykj.dev.device.train.entity.TrainTheme;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainDao.java
* @Description TODO
* @createTime 2020年08月13日 15:19:00
*/
public interface TrainThemeDao extends JpaRepository<TrainTheme, Integer>, JpaSpecificationExecutor<TrainTheme> {
List<TrainTheme> findAllByTrainStatus(Integer status);
}
package com.tykj.dev.device.train.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.train.entity.vo.*;
import com.tykj.dev.misc.base.BeanHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainTheme.java
* @Description 新增培训对象
* @createTime 2020年08月11日 21:35:00
*/
@ApiModel("新增培训对象")
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class TrainTheme {
/**
* 培训id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人id")
private Integer originatorId;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
/**
* 参会人员(必须参会)
*/
@ApiModelProperty(value = "参会人员id 多个使用人员id+x+id+x")
private String joinUserId;
/**
* 不必须参会人员
*/
@ApiModelProperty(value = "参会人员id 多个使用人员id+x+id+x")
private String noJoinUserId;
/**
* 报名人员
*/
@ApiModelProperty(value = "参会人员id 多个使用人员id+x+id+x")
private String signUp;
/**
* 培训结果
*/
private String trainingResults;
/**
* 培训状态 1报名中 2待培训 3培训中
*/
@ApiModelProperty(value = "培训状态")
private Integer trainStatus;
/**
* 发证状态
*/
@ApiModelProperty(value = "发证状态")
private Integer isCertificate;
/**
* 及格
*/
@ApiModelProperty(value = "发证状态")
private Integer pass;
/**
* 优秀
*/
@ApiModelProperty(value = "发证状态")
private Integer good;
public ByTrainingPeople toByTrainingPeople(){
ModelMapper mapper= BeanHelper.getUserMapper();
return mapper.map(this, ByTrainingPeople.class);
}
public TrainThemeVo toTrainThemeVo(){
ModelMapper mapper= BeanHelper.getUserMapper();
return mapper.map(this,TrainThemeVo.class);
}
public TrainRegistrationVo toTrainRegistrationVo(){
ModelMapper mapper= BeanHelper.getUserMapper();
return mapper.map(this,TrainRegistrationVo.class);
}
public TrainTrainingVo toTrainTrainingVo(){
ModelMapper mapper= BeanHelper.getUserMapper();
return mapper.map(this, TrainTrainingVo.class);
}
public TrainAuditVo toTrainAuditVo(){
ModelMapper mapper= BeanHelper.getUserMapper();
return mapper.map(this,TrainAuditVo.class);
}
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.user.subject.entity.Mgrcert;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName ByTrainingPeople.java
* @Description 被培训人vo类
* @createTime 2020年08月18日 15:06:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ByTrainingPeople {
/**
* 培训id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人id")
private Integer originatorId;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis",name = "trainSynopsis")
private String trainSynopsis;
/**
* 培训状态 1报名中 2待培训 3培训中
*/
@ApiModelProperty(value = "培训状态",name = "trainStatus")
private Integer trainStatus;
/**
* 发证状态
*/
@ApiModelProperty(value = "发证状态",name = "isCertificate")
private Integer isCertificate;
@ApiModelProperty(value = "分数",name = "score")
private String score;
@ApiModelProperty(value = "评价",name = "evaluation")
private String evaluation;
/**
* 证书
*/
@ApiModelProperty(value = "证书",name = "mgrcert")
private Mgrcert mgrcert;
/**
* 及格
*/
@ApiModelProperty(value = "发证状态")
private Integer pass;
/**
* 优秀
*/
@ApiModelProperty(value = "发证状态")
private Integer good;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName ConditionsTrain.java
* @Description 培训查询类
* @createTime 2020年08月19日 21:50:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "培训条件查询类", description = "培训条件查询类")
public class ConditionsTrainVo {
@ApiModelProperty(value = "开始时间",example = "bmxx",name = "statusTime")
private Integer page;
@ApiModelProperty(value = "开始时间",example = "bmxx",name = "statusTime")
private Integer size;
@ApiModelProperty(value = "开始时间",example = "bmxx",name = "statusTime")
private String dimName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@ApiModelProperty(value = "开始时间",example = "bmxx",name = "statusTime")
private Date statusTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@ApiModelProperty(value = "结束时间",example = "bmxx",name = "endTime")
private Date endTime;
}
package com.tykj.dev.device.train.entity.vo;
import com.tykj.dev.device.user.subject.entity.Mgrcert;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName GradeEntry.java
* @Description 成绩录入类
* @createTime 2020年08月15日 16:11:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "录入成绩对象", description = "录入成绩对象")
public class GradeEntry {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id" ,name ="userId" )
private Integer userId;
/**
* 用户名称
*/
@ApiModelProperty(value = "用户名称" ,name ="name" )
private String name;
/**
* 用户单位
*/
@ApiModelProperty(value = "用户单位", name = "unitsId", example = "12321L")
private String unitsName;
/**
* 移动电话
*/
@ApiModelProperty(value = "移动电话", name = "mobile", example = "12321L")
private String mobile;
/**
* 考勤
*/
@ApiModelProperty(value = "考勤" ,name ="attendance" )
private String attendance;
/**
* 分数
*/
@ApiModelProperty(value = "分数" ,name ="score" )
private String score;
/**
* 评价
*/
@ApiModelProperty(value = "评价" ,name ="evaluation" )
private String evaluation;
/**
* 是否发证
*/
@ApiModelProperty(value = "是否发证" ,name ="certificate" )
private Integer certificate;
public Mgrcert toDo(){
// LocalDateTime now = LocalDateTime.now().plusYears(2).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(formatStr);
// String twoYearsFormat = now.format(dateTimeFormatter)
Date time=new Date();
Date date=new Date(new Date().getTime()+1000000000);
return new Mgrcert(null,name,userId,null,time,date,0,"培训证书");
}
}
package com.tykj.dev.device.train.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName GradeEntryVo.java
* @Description 成绩录入vo类
* @createTime 2020年08月15日 16:27:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "录入成绩对象提交", description = "录入成绩对象")
public class GradeEntryVo {
@ApiModelProperty(value = "业务id" ,name ="trainThemeId" )
private Integer trainThemeId;
@ApiModelProperty(value = "成绩对象集合" ,name ="gradeEntryList" )
List<GradeEntry> gradeEntryList;
@ApiModelProperty(value = "审核id" ,name ="auditId" )
private Integer auditId;
/**
* 0 发证 1 不发证
*/
@ApiModelProperty(value = "0 发证 1 不发证" ,name ="isCertificate" )
private Integer isCertificate;
/**
* 是否通过
* 0 是通过 1 是不通过
*/
@ApiModelProperty(value = "是否通过 0 是通过 1 是不通过" ,name ="through" )
private Integer through;
/**
* 及格
*/
@ApiModelProperty(value = "发证状态")
private Integer pass;
/**
* 优秀
*/
@ApiModelProperty(value = "发证状态")
private Integer good;
}
package com.tykj.dev.device.train.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName HandoverVo.java
* @Description TODO
* @createTime 2020年08月19日 09:42:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "工作交接对象vo", description = "工作交接对象")
public class HandoverVo {
@ApiModelProperty(value = "交接人id" ,name ="handoverUserId" )
private Integer handoverUserId;
@ApiModelProperty(value = "被交接人id" ,name ="beHandoverUserId" )
private Integer beHandoverUserId;
@ApiModelProperty(value = "代办jobid集合" ,name ="commissionJobIds" )
private List<Integer> commissionJobIds;
@ApiModelProperty(value = "跟踪jobId集合" ,name ="trackingJobIds" )
private List<Integer> trackingJobIds;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.user.subject.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName InTrainVo.java
* @Description TODO
* @createTime 2020年08月17日 23:45:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "培训返回的对象", description = "培训的对象")
public class InTrainVo {
/**
* 培训id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private Integer speakerUserId;
/**
* 培训资料
*/
@ApiModelProperty(value = "培训资料")
private String trainData;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
// /**
// * 参会人员(必须参会)
// */
// @ApiModelProperty(value = "参会人员id 多个使用人员id+x+id+x")
// private String joinUserId;
/**
* 报名人员 暂时user代替
*/
@ApiModelProperty(value = "参会人员id 多个使用人员id+x+id+x")
private List<User> signUp;
/**
* 培训结果
*/
private List<GradeEntry> trainingResults;
/**
* 培训状态 1报名中 2待培训 3培训中
*/
@ApiModelProperty(value = "培训状态")
private Integer trainStatus;
/**
* 发证状态
*/
@ApiModelProperty(value = "发证状态")
private Integer isCertificate;
}
package com.tykj.dev.device.train.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author zjm
* @version 1.0.0
* @ClassName SignUpUser.java
* @Description TODO 报名用户对象
* @createTime 2020年08月17日 23:49:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "报名用户对象", description = "报名用户")
public class SignUpUser {
@ApiModelProperty(value = "用户id" ,name ="userId" )
private Integer userId;
@ApiModelProperty(value = "用户名称",name ="name")
private String name;
@ApiModelProperty(value = "是否为必须参与人 0 是 1否",name ="isMust")
private Integer isMust;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName InTrainVo.java
* @Description 报名中
* @createTime 2020年08月17日 23:45:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "培训中返回的对象", description = "培训中返回的对象")
public class TrainAuditVo {
/**
* 培训id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人id")
private Integer originatorId;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
/**
* 及格
*/
@ApiModelProperty(value = "发证状态")
private Integer pass;
/**
* 优秀
*/
@ApiModelProperty(value = "发证状态")
private Integer good;
/**
* 成绩
*/
@ApiModelProperty(value = "gradeEntry")
private List<GradeEntry> gradeEntry;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.user.base.ret.UserTrainVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName InTrainVo.java
* @Description 报名中
* @createTime 2020年08月17日 23:45:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "报名中培训返回的对象", description = "报名中培训的对象")
public class TrainRegistrationVo {
/**
* 培训id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人id")
private Integer originatorId;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
/**
* 以报名人员
*/
@ApiModelProperty(value = "trainSynopsis")
private List<UserTrainVo> signUpUser;
/**
* 没报名人员
*/
@ApiModelProperty(value = "trainSynopsis")
private List<UserTrainVo> noSignUpUser;
}
package com.tykj.dev.device.train.entity.vo;
import com.tykj.dev.device.train.entity.TrainTheme;
import com.tykj.dev.misc.base.BeanHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import java.util.Date;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainThemeAddVo.java
* @Description TODO
* @createTime 2020年08月13日 14:46:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel(value = "新建培训对象", description = "新建培训对象")
public class TrainThemeAddVo {
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人id")
private Integer originatorId;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
/**
* 必须参加
*/
@ApiModelProperty(value = "参会人员id 集合")
private List<Integer> joinUserIds;
/**
* 不必须参会人员
*/
@ApiModelProperty(value = "参会人员id 集合")
private List<Integer> noJoinUserIds;
/**
* 培训状态 1报名中 2待培训 3培训中
*/
@ApiModelProperty(value = "培训状态")
private Integer trainStatus;
public TrainTheme toDo(){
ModelMapper mapper= BeanHelper.getUserMapper();
return mapper.map(this,TrainTheme.class);
}
}
package com.tykj.dev.device.train.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainThemePage.java
* @Description TODO
* @createTime 2020年08月11日 21:49:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "培训分页对象", description = "培训分页记录")
@Builder
public class TrainThemePage {
@ApiModelProperty(value = "总数",example = "10")
private Integer total;
@ApiModelProperty(value = "页数,0开始",example = "0")
private Integer page;
@ApiModelProperty(value = "大小",example = "10")
private Integer size;
@ApiModelProperty(value = "数据内容",example = "略")
private List<TrainThemeVo> data;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainTheme.java
* @Description TODO
* @createTime 2020年08月11日 21:35:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "培训分页对象", description = "培训分页记录")
public class TrainThemeVo {
//培训主题
//时间
//主机讲人
//状态
@ApiModelProperty(value = "培训主题",example = "10")
private String name;
@ApiModelProperty(value = "时间",example = "10")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
@ApiModelProperty(value = "状态",example = "10")
private String trainStatus;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.dev.device.user.base.ret.UserTrainVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName InTrainVo.java
* @Description 报名中
* @createTime 2020年08月17日 23:45:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "培训中返回的对象", description = "培训中返回的对象")
public class TrainTrainingVo {
/**
* 培训id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训主题
*/
@ApiModelProperty(value = "培训主题")
private String name;
/**
* 报名截止时间
*/
@ApiModelProperty(value = "报名截止时间")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date trainTime;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人")
private String originatorName;
/**
* 发起人 originator
*/
@ApiModelProperty(value = "发起人id")
private Integer originatorId;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位名称")
private String unitsName;
/**
* 主办单位
*/
@ApiModelProperty(value = "主办单位")
private Integer unitsId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
/**
* 以报名人员
*/
@ApiModelProperty(value = "trainSynopsis")
private List<UserTrainVo> signUpUser;
}
package com.tykj.dev.device.train.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainUpdateVo.java
* @Description TODO
* @createTime 2020年08月18日 23:09:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "培训更新对象", description = "培训更新对象")
public class TrainUpdateVo {
/**
* 培训id
*/
@ApiModelProperty(value = "培训id")
private Integer trainId;
/**
* 培训开始时间
*/
@ApiModelProperty(value = "培训开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/**
* 培训结束时间
*/
@ApiModelProperty(value = "培训结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
/**
* 培训地点
*/
@ApiModelProperty(value = "培训地点")
private String trainLocation;
/**
* 主讲人
*/
@ApiModelProperty(value = "主讲人")
private String speakerUserId;
/**
* 培训资料名称
*/
@ApiModelProperty(value = "培训资料")
private String trainDataName;
/**
* 培训url
*/
@ApiModelProperty(value = "培训资料")
private String trainDataUrl;
/**
* 培训简介
*/
@ApiModelProperty(value = "trainSynopsis")
private String trainSynopsis;
}
package com.tykj.dev.device.train.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author zjm
* @version 1.0.0
* @ClassName signUpReturn.java
* @Description TODO 报名结果类
* @createTime 2020年08月16日 10:19:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "报名对象vo", description = "报名对象vo")
public class signUpReturn {
@ApiModelProperty(value = "是否报名 0 报名 1否" ,name ="returns" )
private Integer returns;
@ApiModelProperty(value = "job——id" ,name ="jobId" )
private Integer taskId;
@ApiModelProperty(value = "培训id" ,name ="trainThemeId" )
private Integer trainThemeId;
}
package com.tykj.dev.device.train.service;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import java.util.List;
public interface TrainTaskService {
List<TaskBto> selectBillidAndBillType(Integer billId,Integer billType,Integer billStatus);
TaskBto selectFatherIsNullAndBillidAndBillType(Integer billId,Integer billType);
}
package com.tykj.dev.device.train.service;
import com.tykj.dev.device.train.entity.TrainTheme;
import com.tykj.dev.device.train.entity.vo.*;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainService.java
* @Description TODO
* @createTime 2020年08月13日 15:21:00
*/
public interface TrainThemeService {
TrainTheme save(TrainTheme trainTheme);
TrainTheme findById(Integer trainThemeId);
List<TrainTheme> findAllStatus(Integer status);
ByTrainingPeople findByTrainingPeople(Integer trainThemeId, Integer userId);
TrainRegistrationVo findRegistrationVo(Integer trainThemeId);
TrainTrainingVo findTrainTrainingVo(Integer trainThemeId);
TrainAuditVo findTrainAuditVo(Integer trainThemeId);
TrainTheme updateTrain(TrainUpdateVo trainUpdateVo);
TrainThemePage findTrainPageVo(ConditionsTrainVo conditionsTrainVo);
}
package com.tykj.dev.device.train.service.impl;
import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.train.service.TrainTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainTaskServiceImpl.java
* @Description TODO
* @createTime 2020年09月03日 11:16:00
*/
@Service
public class TrainTaskServiceImpl implements TrainTaskService {
@Autowired
TaskDao taskDao;
@Override
public List<TaskBto> selectBillidAndBillType(Integer billId, Integer billType,Integer billStatus) {
return taskDao.findAllByBillIdAndBusinessTypeAndBillStatus(billId, billType, billStatus)
.stream()
.map(Task::parse2Bto)
.collect(Collectors.toList());
}
@Override
public TaskBto selectFatherIsNullAndBillidAndBillType(Integer billId, Integer billType) {
return taskDao.findAllByParentTaskIdIsNullAndBillIdAndBusinessType(billId, billType).parse2Bto();
}
}
package com.tykj.dev.device.train.service.impl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.github.wenhao.jpa.PredicateBuilder;
import com.tykj.dev.device.train.dao.TrainThemeDao;
import com.tykj.dev.device.train.entity.TrainTheme;
import com.tykj.dev.device.train.entity.vo.*;
import com.tykj.dev.device.train.service.TrainThemeService;
import com.tykj.dev.device.user.subject.service.MgrcertService;
import com.tykj.dev.device.user.subject.service.UserService;
import com.tykj.dev.misc.utils.JacksonUtil;
import com.tykj.dev.misc.utils.StringSplitUtil;
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.domain.Sort;
import com.github.wenhao.jpa.Specifications;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainServiceImpl.java
* @Description 培训逻辑层
* @createTime 2020年08月13日 15:25:00
*/
@Service
public class TrainThemeServiceImpl implements TrainThemeService {
@Autowired
TrainThemeDao trainThemeDao;
@Autowired
MgrcertService mgrcertService;
@Autowired
UserService userService;
@Override
public TrainTheme save(TrainTheme trainTheme) {
return trainThemeDao.save(trainTheme);
}
@Override
public TrainTheme findById(Integer trainThemeId) {
return trainThemeDao.findById(trainThemeId).get();
}
@Override
public List<TrainTheme> findAllStatus(Integer status) {
return trainThemeDao.findAllByTrainStatus(status);
}
@Override
public ByTrainingPeople findByTrainingPeople(Integer trainThemeId, Integer userId) {
TrainTheme trainTheme= trainThemeDao.findById(trainThemeId).get();
ByTrainingPeople byTrainingPeople= trainTheme.toByTrainingPeople();
List<GradeEntry> gradeEntries =new ArrayList<>();
if (trainTheme.getTrainingResults()!=null) {
gradeEntries = JacksonUtil.readValue(trainTheme.getTrainingResults(), new TypeReference<List<GradeEntry>>() {
});
}
if (gradeEntries!=null && gradeEntries.size()!=0){
gradeEntries.forEach(gradeEntry -> {
if (gradeEntry.getUserId()==userId){
byTrainingPeople.setScore(gradeEntry.getScore());
byTrainingPeople.setEvaluation(gradeEntry.getEvaluation());
byTrainingPeople.setMgrcert(mgrcertService.findByUserId(userId));
}
});
}
return byTrainingPeople;
}
@Override
public TrainRegistrationVo findRegistrationVo(Integer trainThemeId) {
TrainTheme trainTheme = trainThemeDao.findById(trainThemeId).get();
TrainRegistrationVo trainRegistrationVo= trainTheme.toTrainRegistrationVo();
List<Integer> signUp = StringSplitUtil.userIdSplit(trainTheme.getSignUp());
trainRegistrationVo.setSignUpUser(userService.findByIdListUserTarinVo(signUp));
List<Integer> integerList1=JacksonUtil.readValue(trainTheme.getNoJoinUserId(), new TypeReference<List<Integer>>() {
});
List<Integer> integerList2=JacksonUtil.readValue(trainTheme.getJoinUserId(), new TypeReference<List<Integer>>() {
});
integerList1.addAll(integerList2);
integerList1.removeAll(signUp);
trainRegistrationVo.setNoSignUpUser(userService.findByIdListUserTarinVo(integerList1));
return trainRegistrationVo;
}
@Override
public TrainTrainingVo findTrainTrainingVo(Integer trainThemeId) {
TrainTheme trainTheme = trainThemeDao.findById(trainThemeId).get();
TrainTrainingVo trainTrainingVo= trainTheme.toTrainTrainingVo();
List<Integer> signUp = StringSplitUtil.userIdSplit(trainTheme.getSignUp());
trainTrainingVo.setSignUpUser(userService.findByIdListUserTarinVo(signUp));
return trainTrainingVo;
}
@Override
public TrainAuditVo findTrainAuditVo(Integer trainThemeId) {
TrainTheme trainTheme = trainThemeDao.findById(trainThemeId).get();
TrainAuditVo trainAuditVo= trainTheme.toTrainAuditVo();
trainAuditVo.setGradeEntry(JacksonUtil.readValue(trainTheme.getTrainingResults(), new TypeReference<List<GradeEntry>>() {
}));
return trainAuditVo;
}
@Override
public TrainTheme updateTrain(TrainUpdateVo trainUpdateVo) {
TrainTheme trainTheme= trainThemeDao.findById(trainUpdateVo.getTrainId()).get();
if (trainUpdateVo.getEndTime()!=null){
trainTheme.setEndTime(trainUpdateVo.getEndTime());
}
if (trainUpdateVo.getSpeakerUserId()!=null){
trainTheme.setSpeakerUserId(trainUpdateVo.getSpeakerUserId());
}
if (trainUpdateVo.getStartTime()!=null){
trainTheme.setStartTime(trainUpdateVo.getStartTime());
}
if (trainUpdateVo.getTrainDataName()!=null){
trainTheme.setTrainDataName(trainUpdateVo.getTrainDataName());
}
if (trainUpdateVo.getTrainDataUrl()!=null){
trainTheme.setTrainDataUrl(trainUpdateVo.getTrainDataUrl());
}
if (trainUpdateVo.getTrainLocation()!=null){
trainTheme.setTrainLocation(trainUpdateVo.getTrainLocation());
}
if (trainUpdateVo.getTrainSynopsis()!=null){
trainTheme.setTrainSynopsis(trainUpdateVo.getTrainSynopsis());
}
return trainThemeDao.save(trainTheme);
}
@Override
public TrainThemePage findTrainPageVo(ConditionsTrainVo conditionsTrainVo) {
Pageable pageable = PageRequest.of(conditionsTrainVo.getPage(), conditionsTrainVo.getSize(), Sort.Direction.ASC, "trainTime");
Page<TrainTheme> all = getContacts(conditionsTrainVo, pageable);
List<TrainThemeVo> list=new ArrayList<>();
all.get().forEach(
trainTheme -> {
list.add(trainTheme.toTrainThemeVo());
}
);
return TrainThemePage.builder()
.data(list)
.page(conditionsTrainVo.getPage())
.size(conditionsTrainVo.getSize())
.total((int) all.getTotalElements()).build();
}
private Page<TrainTheme> getContacts(ConditionsTrainVo conditionsTrainVo, Pageable pageable) {
PredicateBuilder<TrainTheme> predicateBuilder = Specifications.and();
if (conditionsTrainVo.getEndTime()!=null && conditionsTrainVo.getStatusTime()!=null){
predicateBuilder.gt("startTime",conditionsTrainVo.getStatusTime());
predicateBuilder.lt("endTime",conditionsTrainVo.getEndTime());
}
if (conditionsTrainVo.getDimName() != null) {
Class<TrainTheme> trainThemeClass = TrainTheme.class;
Field[] declaredFields = trainThemeClass.getDeclaredFields();
PredicateBuilder<TrainTheme> p = Specifications.or();
for (Field field : declaredFields) {
if (field.getType().equals(String.class)) {
p.like(field.getName(), "%" + conditionsTrainVo.getDimName() + "%");
}
}
predicateBuilder.predicate(p.build());
}
return trainThemeDao.findAll(predicateBuilder.build(), pageable);
}
}
package com.tykj.dev.device.train.task;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.common.StatusEnum;
import com.tykj.dev.device.train.service.TrainTaskService;
import com.tykj.dev.device.train.service.TrainThemeService;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.service.MgrcertService;
import com.tykj.dev.device.user.subject.service.UserService;
import com.tykj.dev.socket.MyWebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainTask.java
* @Description 培训定时任务 主要是 判断报名截止以及培训开始、培训结束
* @createTime 2020年08月17日 23:20:00
*/
@Service
public class TrainTask {
@Autowired
TrainThemeService trainThemeService;
@Autowired
TaskService taskService;
@Autowired
MgrcertService mgrcertService;
@Autowired
TrainTaskService trainTaskService;
@Autowired
UnitsDao unitsDao;
@Autowired
UserService userService;
@Autowired
MyWebSocket myWebSocket;
@Scheduled(cron ="0 0/1 * * * ?")
private void signUpDeadline(){
trainThemeService.findAllStatus(1).forEach(
trainTheme -> {
long time=new Date().getTime();
if (trainTheme.getTrainTime().getTime()>time){
//查询所有必须报名而没有报名的task 状态直接转为待培训
trainTaskService.selectBillidAndBillType(trainTheme.getTrainId(),13,StatusEnum.TRAIN1001.id).forEach(
taskBto -> taskService.moveToSpecial(taskBto,StatusEnum.TRAIN1003,-1)
);
trainTaskService.selectBillidAndBillType(trainTheme.getTrainId(),13,StatusEnum.TRAIN1002.id).forEach(
taskBto -> taskService.moveToEnd(taskBto)
);
trainTaskService.selectBillidAndBillType(trainTheme.getTrainId(),13, StatusEnum.TRAIN1000.id).forEach(
taskBto -> taskService.moveToSpecial(taskBto,StatusEnum.TRAIN1010)
);
trainTheme.setTrainStatus(StatusEnum.TRAIN1010.id);
trainThemeService.save(trainTheme);
myWebSocket.sendMessage1();
}
}
);
}
@Scheduled(cron ="0 0/1 * * * ?")
private void trainingStarted(){
trainThemeService.findAllStatus(2).forEach(
trainTheme -> {
//5 培训中
trainTaskService.selectBillidAndBillType(trainTheme.getTrainId(),13,StatusEnum.TRAIN1010.id).forEach(
taskBto -> taskService.moveToSpecial(taskBto,StatusEnum.TRAIN1004)
);
trainTheme.setTrainStatus(8);
trainThemeService.save(trainTheme);
});
}
@Scheduled(cron ="0 0/1 * * * ?")
private void trainingEnd(){
trainThemeService.findAllStatus(3).forEach(
trainTheme -> {
trainTaskService.selectBillidAndBillType(trainTheme.getTrainId(),13,StatusEnum.TRAIN1004.id).forEach(
taskBto -> taskService.moveToSpecial(taskBto,StatusEnum.TRAIN1008)
);
//5 录入成绩
trainTheme.setTrainStatus(30);
trainThemeService.save(trainTheme);
});
}
@Scheduled(cron ="10 * * * * ?")
private void trainingEnd1(){ System.out.println("启动websocket--");
myWebSocket.sendMessage1();
}
}
package com.tykj.dev.device.user.base.ret;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaInstitutions.java
* @Description 通用组织
* @createTime 2020年09月04日 13:48:00
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class AreaInstitutions {
/**
* 区域id
*/
private Integer AreaId;
/**
* 区域名称
*/
private String name;
/**
* 下级区域对象
*/
// @JsonIgnore
private List<AreaInstitutions> areaInstitutionList;
/**
* 本区域单位集合
*/
private List<UnitsVo> unitsVos;
}
package com.tykj.dev.device.user.subject.controller;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaController.java
* @Description TODO
* @createTime 2020年09月04日 13:34:00
*/
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.user.base.ret.AreaInstitutions;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.PermissionsType;
import com.tykj.dev.device.user.subject.entity.SecurityUser;
import com.tykj.dev.device.user.subject.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
* 区域视图层
*/
@RestController
@AutoDocument
@Api(tags = "区域模块", description = "提供区域模块的接口")
@RequestMapping("/area")
public class AreaController {
@Autowired
AreaService areaService;
@GetMapping(value = "/area/units")
@ApiOperation(value = "查询权限接口,按照类型划分,具体字段查看model" ,notes = "成功返回分类的权限对象")
public ResponseEntity<List<AreaVo>> addPermissions(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser){
return ResponseEntity.ok(areaService.findAll(securityUser.getCurrentUserInfo().getUnits().getAreaId()));
}
}
...@@ -49,11 +49,12 @@ public class Area { ...@@ -49,11 +49,12 @@ public class Area {
private Integer fatherId; private Integer fatherId;
@Transient // @Transient
private List<Units> units; // private List<Units> units;
public AreaVo toVo() { public AreaVo toVo() {
ModelMapper mapper = BeanHelper.getUserMapper(); ModelMapper mapper = BeanHelper.getUserMapper();
return mapper.map(this, AreaVo.class); return mapper.map(this, AreaVo.class);
} }
} }
package com.tykj.dev.device.user.subject.service; package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.ret.AreaInstitutions;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Permissions; import com.tykj.dev.device.user.subject.entity.Permissions;
import java.util.List;
/** /**
* @author zjm * @author zjm
* @version 1.0.0 * @version 1.0.0
...@@ -10,6 +15,10 @@ import com.tykj.dev.device.user.subject.entity.Permissions; ...@@ -10,6 +15,10 @@ import com.tykj.dev.device.user.subject.entity.Permissions;
* @Description 区域逻辑层 * @Description 区域逻辑层
* @createTime 2020年07月27日 14:52:00 * @createTime 2020年07月27日 14:52:00
*/ */
public interface AreaService extends PublicService<Permissions>{ public interface AreaService extends PublicService<Area>{
List<AreaInstitutions> findAllUserUnitsIdAreaList(Integer areaId);
List<AreaVo> findAll(Integer areaId);
} }
...@@ -2,6 +2,7 @@ package com.tykj.dev.device.user.subject.service; ...@@ -2,6 +2,7 @@ package com.tykj.dev.device.user.subject.service;
import com.tykj.dev.device.user.base.ret.AreaVo; import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.UnitsTrainVo; import com.tykj.dev.device.user.base.ret.UnitsTrainVo;
import com.tykj.dev.device.user.base.ret.UnitsVo;
import com.tykj.dev.device.user.subject.entity.Units; import com.tykj.dev.device.user.subject.entity.Units;
import java.util.List; import java.util.List;
...@@ -30,6 +31,22 @@ public interface UnitsService extends PublicService<Units>{ ...@@ -30,6 +31,22 @@ public interface UnitsService extends PublicService<Units>{
*/ */
List<Integer> findListSubordinateId(Integer unitsId); List<Integer> findListSubordinateId(Integer unitsId);
/**
* 查询下属单位id集合
* @param areaId 单位id
* @return 下属单位id集合
*/
List<UnitsVo> findListVoSubordinateAreaId(Integer areaId);
/**
* 根据区域id查看区域对象
* @param areaId 单位id
* @return 单位id集合
*/
List<UnitsVo> findListVoAreaId(Integer areaId);
List<UnitsTrainVo> findListUnitsTrainVo(Integer unitsId); List<UnitsTrainVo> findListUnitsTrainVo(Integer unitsId);
/** /**
......
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.base.ret.AreaInstitutions;
import com.tykj.dev.device.user.base.ret.AreaVo;
import com.tykj.dev.device.user.base.ret.UnitsVo;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.service.AreaService;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author zjm
* @version 1.0.0
* @ClassName AreaServiceImpl.java
* @Description TODO
* @createTime 2020年09月04日 14:39:00
*/
@Service
@Slf4j
public class AreaServiceImpl implements AreaService {
@Autowired
AreaDao areaDao;
@Autowired
UnitsService unitsService;
@Override
public List<AreaInstitutions> findAllUserUnitsIdAreaList(Integer areaId) {
Optional<Area> areaOptional = areaDao.findById(areaId);
log.info("区域id:{}",areaId);
List<AreaInstitutions> areaInstitutions=new ArrayList<>();
if (areaOptional.isPresent()){
// return subordinateArea(areaInstitutions,areaOptional.get());
return null;
} else {
throw new ApiException(ResultUtil.failed("区域id不能为空"));
}
}
@Override
public List<AreaVo> findAll(Integer areaId) {
List<AreaVo> areaVos=new ArrayList<>();
Optional<Area> areaOptional = areaDao.findById(areaId);
if (areaOptional.isPresent()){
Area area = areaOptional.get();
List<Area> list= areaDao.findAllByFatherId(area.getId());
if (list.size()!=0){
if (area.getType() <= 2){
AreaVo areaVo= area.toVo();
areaVo.setName(area.getName()+"本级");
areaVo.setUnits(unitsService.findListVoAreaId(areaId));
areaVos.add(areaVo);
}
for (Area area1:list){
AreaVo areaVo= area1.toVo();
// areaVo.setFrontEnd(i++);
List<UnitsVo> unitsList = new ArrayList<>(unitsService.findListVoAreaId(area1.getId()));
subordinateAllUnits(unitsList,area1);
// for (UnitsVo unitsVo:unitsList){
// unitsVo.setFrontEnd(i++);
// }
areaVo.setUnits(unitsList);
areaVos.add(areaVo);
}
}else {
AreaVo areaVo= area.toVo();
areaVo.setUnits(unitsService.findListVoAreaId(areaId));
areaVos.add(areaVo);
}
return areaVos;
} else {
throw new ApiException(ResultUtil.failed("区域id不能为空"));
}
}
private List<UnitsVo> subordinateAllUnits(List<UnitsVo> units,Area area){
List<Area> list= areaDao.findAllByFatherId(area.getId());
if (list.size()==0){
return units;
}
list.forEach(
area1 -> {
List<UnitsVo> unitsVos;
unitsVos=unitsService.findListVoAreaId(area1.getId());
units.addAll(unitsVos);
subordinateAllUnits(units,area1);
}
);
return units;
}
// private List<AreaInstitutions> subordinateArea(List<AreaInstitutions> areaInstitutions ,Area area){
// List<Area> list= areaDao.findAllByFatherId(area.getId());
// if (list==null || list.size()==0){
// areaInstitutions.add(new AreaInstitutions(area.getId(), area.getName(), areaInstitutions, unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// return areaInstitutions;
// }
// if (area.getType() < 2) {
// areaInstitutions.add(new AreaInstitutions(area.getId(), area.getName(), areaInstitutions, unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// }
//
// list.forEach(
// area1 -> {
// List<AreaInstitutions> areaInstitutions1=new ArrayList<>();
// subordinateArea(areaInstitutions1,area1);
// if (area.getType()==2) {
// areaInstitutions1.add(new AreaInstitutions(area.getId(), area.getName(), areaInstitutions, unitsDao.findAllByAreaId(area.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// }
// areaInstitutions.add(new AreaInstitutions(area1.getId(),area1.getName(),areaInstitutions1,unitsDao.findAllByAreaId(area1.getId()).stream().map(Units::toVo).collect(Collectors.toList())));
// }
// );
// return areaInstitutions;
// }
@Override
public Area save(Area area) {
return areaDao.save(area);
}
@Override
public boolean delete(Integer id) {
return false;
}
@Override
public List<Area> findAll() {
return areaDao.findAll();
}
@Override
public Area update(Area area) {
return areaDao.save(area);
}
}
...@@ -44,9 +44,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -44,9 +44,7 @@ public class UnitsServiceImpl implements UnitsService {
public List<AreaVo> findListAreaUnitsVo() { public List<AreaVo> findListAreaUnitsVo() {
List<AreaVo> areaVos=new ArrayList<>(); List<AreaVo> areaVos=new ArrayList<>();
List<Area> list = areaDao.findAll();
List<Area> list=areaDao.findAll();
int i=0; int i=0;
for (Area area:list){ for (Area area:list){
...@@ -76,6 +74,21 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -76,6 +74,21 @@ public class UnitsServiceImpl implements UnitsService {
return unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::getUnitId).collect(Collectors.toList()); return unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::getUnitId).collect(Collectors.toList());
} }
@Override
public List<UnitsVo> findListVoSubordinateAreaId(Integer areaId) {
List<UnitsVo> unitsVos=new ArrayList<>();
List<Integer> areaIds=areaDao.findAllByFatherId(areaId).stream().map(Area::getId).collect(Collectors.toList());
if (areaIds.size() != 0) {
unitsVos= unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::toVo).collect(Collectors.toList());
}
return unitsVos;
}
@Override
public List<UnitsVo> findListVoAreaId(Integer areaId) {
return unitsDao.findAllByAreaId(areaId).stream().map(Units::toVo).collect(Collectors.toList());
}
@Override @Override
public List<UnitsTrainVo> findListUnitsTrainVo(Integer unitsId) { public List<UnitsTrainVo> findListUnitsTrainVo(Integer unitsId) {
Integer areaId = unitsDao.findById(unitsId).get().getAreaId(); Integer areaId = unitsDao.findById(unitsId).get().getAreaId();
......
...@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service; ...@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
/** /**
* @author mcj * @author zjm
*/ */
@Service @Service
public class LogoutUtil { public class LogoutUtil {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<module>device-train</module> <module>device-train</module>
<module>device-user</module> <module>device-user</module>
<module>device-storage</module> <module>device-storage</module>
<module>device-file</module>
</modules> </modules>
<name>device</name> <name>device</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
...@@ -35,6 +36,11 @@ ...@@ -35,6 +36,11 @@
</parent> </parent>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>device-file</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.tykj.dev</groupId> <groupId>com.tykj.dev</groupId>
<artifactId>device-user</artifactId> <artifactId>device-user</artifactId>
......
...@@ -15,7 +15,21 @@ ...@@ -15,7 +15,21 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
package com.tykj.dev.socket;
/**
* @author zjm
* @version 1.0.0
* @ClassName Message.java
* @Description TODO
* @createTime 2020年08月23日 12:30:00
*/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Message {
private Integer isRequest;
}
package com.tykj.dev.socket;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author zjm
* @version 1.0.0
* @ClassName MyWebSocket.java
* @Description TODO
* @createTime 2020年08月19日 23:53:00
*/
@Slf4j
@ServerEndpoint(value = "/websocket/{userId}") //接受websocket请求路径
@Component //注册到spring容器中
public class MyWebSocket {
private static int onlineCount = 0;
/**concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。*/
private static ConcurrentHashMap<String, MyWebSocket> webSocketMap = new ConcurrentHashMap<>();
/**与某个客户端的连接会话,需要通过它来给客户端发送数据*/
private Session session;
/**接收userId*/
private String userId;
/**
* 连接建立成功调用的方法*/
@OnOpen
public void onOpen(Session session,@PathParam("userId") String userId) {
this.session = session;
this.userId=userId;
if(webSocketMap.containsKey(userId)){
webSocketMap.remove(userId);
webSocketMap.put(userId,this);
//加入set中
}else{
webSocketMap.put(userId,this);
//加入set中
addOnlineCount();
//在线数加1
}
log.info("用户连接:"+userId+",当前在线人数为:" + getOnlineCount());
sendMessage("连接成功");
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose() {
if(webSocketMap.containsKey(userId)){
webSocketMap.remove(userId);
//从set中删除
subOnlineCount();
}
log.info("用户退出:"+userId+",当前在线人数为:" + getOnlineCount());
}
/**
* 收到客户端消息后调用的方法
*
* @param message 客户端发送过来的消息*/
@OnMessage
public void onMessage(String message, Session session) {
log.info("用户消息:"+userId+",报文:"+message);
//可以群发消息
//消息保存到数据库、redis
if(StringUtils.isNotBlank(message)){
try {
//解析发送的报文
JSONObject jsonObject = JSON.parseObject(message);
//追加发送人(防止串改)
jsonObject.put("fromUserId",this.userId);
String toUserId=jsonObject.getString("toUserId");
//传送给对应toUserId用户的websocket
if(StringUtils.isNotBlank(toUserId)&&webSocketMap.containsKey(toUserId)){
webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
}else{
log.error("请求的userId:"+toUserId+"不在该服务器上");
//否则不在这个服务器上,发送到mysql或者redis
}
}catch (Exception e){
e.printStackTrace();
}
}
}
/**
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.error("用户错误:"+this.userId+",原因:"+error.getMessage());
error.printStackTrace();
}
/**
* 实现服务器主动推送
*/
public void sendMessage(String message){
try {
this.session.getBasicRemote().sendText(JSONObject.toJSONString(new Message(1)));
} catch (IOException e) {
e.printStackTrace();
}
}
public void sendMessage1(){
for (String i:webSocketMap.keySet()){
webSocketMap.get(i).sendMessage("1");
}
}
/**
* 发送自定义消息
* */
public static void sendInfo(String message,String userId) throws IOException {
log.info("发送消息到:"+userId+",报文:"+message);
if(StringUtils.isNotBlank(userId)&&webSocketMap.containsKey(userId)){
webSocketMap.get(userId).sendMessage(message);
}else{
log.error("用户"+userId+",不在线!");
}
}
public static synchronized int getOnlineCount() {
return onlineCount;
}
public static synchronized void addOnlineCount() {
MyWebSocket.onlineCount++;
}
public static synchronized void subOnlineCount() {
MyWebSocket.onlineCount--;
}
}
package com.tykj.dev.socket;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @author zjm
* @version 1.0.0
* @ClassName WebSocketConfig.java
* @Description TODO
* @createTime 2020年08月19日 23:52:00
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter(){
return new ServerEndpointExporter();
}
}
...@@ -267,7 +267,6 @@ ...@@ -267,7 +267,6 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tykj.dev</groupId> <groupId>com.tykj.dev</groupId>
<artifactId>socket</artifactId> <artifactId>socket</artifactId>
...@@ -282,7 +281,7 @@ ...@@ -282,7 +281,7 @@
<dependency> <dependency>
<groupId>com.tykj.dev</groupId> <groupId>com.tykj.dev</groupId>
<artifactId>config</artifactId> <artifactId>device-file</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
<module>dev-misc</module> <module>dev-misc</module>
<module>dev-rfid</module> <module>dev-rfid</module>
<module>dev-union</module> <module>dev-union</module>
<module>dev-device/device-storage</module>
</modules> </modules>
<properties> <properties>
...@@ -124,6 +123,7 @@ ...@@ -124,6 +123,7 @@
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论