Commit 6102b18c authored by chenying's avatar chenying

4.8修改线路的app接口,添加报警信息的下载接口

parent 0bd50c68
...@@ -47,6 +47,8 @@ dependencies { ...@@ -47,6 +47,8 @@ dependencies {
compile ('org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0') compile ('org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0')
compile ('org.influxdb:influxdb-java:2.7') compile ('org.influxdb:influxdb-java:2.7')
compile ('com.github.miwurster:spring-data-influxdb:1.6') compile ('com.github.miwurster:spring-data-influxdb:1.6')
compile('com.aliyun.oss:aliyun-sdk-oss:2.5.0')
compile('org.apache.poi:poi:3.9')
} }
jar { jar {
String someString = '' String someString = ''
......
package com.example.tdl.common;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
* 导出工具和备件Excel公共方法
*/
public class CommonExcel {
private String path;
//显示的导出表的标题
private String name;
private String title;
//导出表的列名
private String[] rowName;
//导出的文件名
private String fileName;
private List<Object[]> dataList = new ArrayList<Object[]>();
//构造方法,传入要导出的数据
public CommonExcel(String name, String title, String[] rowName,List<Object[]> dataList, String fileName) {
this.name=name;
this.dataList = dataList;
this.rowName = rowName;
this.title = title;
this.fileName = fileName;
}
/*
* 导出数据
*/
public HSSFWorkbook downloadExcel() {
HSSFWorkbook workbook = new HSSFWorkbook(); // 创建工作簿对象
HSSFSheet sheet = workbook.createSheet(name); // 创建工作表
HSSFCellStyle style = this.getStyle(workbook);
try{
/*
* 创建第一行(表格标题行)
* */
HSSFRow rowm = sheet.createRow((short)0);
HSSFCell cellTitle=null;
//设置单元格格式
HSSFCellStyle titleStyle = this.getTitleStyle(workbook);
//循环创建列
for(int n=0;n<rowName.length;n++){
cellTitle= rowm.createCell(n);
//设置列的格式
cellTitle.setCellStyle(titleStyle);
//将标题添加到列中
cellTitle.setCellValue(new HSSFRichTextString(title));
}
//设置行高
rowm.setHeight((short)(30*20));
//合并单元格(参数1:起始行,参数2:截至行,参数3:起始列,参数4:截至列)
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, (rowName.length-1)));
/*
* 创建第二行(中文列名)
* */
// 定义所需列数
int columnNum = rowName.length;
// 在索引2的位置创建行(最顶端的行开始的第二行)
HSSFRow rowRowName = sheet.createRow(1);
rowRowName.setHeight((short)(25*20));
//获取列头样式对象
HSSFCellStyle columnTopStyle = this.getColumnTopStyle(workbook);
for(int n=0;n<columnNum;n++){
//创建列头对应个数的单元格
HSSFCell cellRowName = rowRowName.createCell(n);
//设置列头单元格的数据类型
cellRowName.setCellType(HSSFCell.CELL_TYPE_STRING);
//设置列头单元格的值
HSSFRichTextString text = new HSSFRichTextString(rowName[n]);
cellRowName.setCellValue(text);
//设置列头单元格样式
cellRowName.setCellStyle(columnTopStyle);
}
sheet.setColumnWidth(0, 35*256);
sheet.setColumnWidth(1, 18*256);
sheet.setColumnWidth(2, 18*256);
sheet.setColumnWidth(3, 13*256);
sheet.setColumnWidth(4, 15*256);
sheet.setColumnWidth(5, 13*256);
sheet.setColumnWidth(6, 13*256);
/*
* 循环将查询出的数据设置到sheet对应的单元格中
* */
for(int i=0;i<dataList.size();i++){
//便利集合传过来的值
Object[] obj = dataList.get(i);
//从第五行开始创建
HSSFRow row = sheet.createRow(i+2);
row.setHeight((short)(30*20));
for(int j=0; j<obj.length; j++){
HSSFCell cell = null;
cell = row.createCell(j,HSSFCell.CELL_TYPE_STRING);
if(!"".equals(obj[j]) && obj[j] != null){
cell.setCellValue(obj[j].toString()); //设置单元格的值
}
cell.setCellStyle(style); //设置单元格样式
}
}
return workbook;
} catch (Exception e) {
e.printStackTrace();
}
// if(workbook !=null){
// try {
// if (response != null){
// response.reset();
// response.setContentType("application/vnd.ms-excel;charset=utf-8");
// response.addHeader("Content-Disposition", "attachment;filename="+ fileName);
//// response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("gb2312"),"ISO8859-1"));
// response.setHeader("Pragma", "no-cache");
// response.setHeader("Cache-Control", "no-cache");
// response.setDateHeader("Expires", 0);
// OutputStream out = response.getOutputStream();
// BufferedOutputStream bufferedOutPut = new BufferedOutputStream(out);
// workbook.write(bufferedOutPut);
// bufferedOutPut.flush();
// bufferedOutPut.close();
// return workbook;
// } else {
// FileOutputStream outputStream = new FileOutputStream(path+fileName);
// workbook.write(outputStream);
// outputStream.close();
// return workbook;
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
return workbook;
}
/*
* 中文标题单元格样式
*/
public HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short) 18);
//字体加粗
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//设置字体名字
font.setFontName("等线");
//设置样式;
HSSFCellStyle style = workbook.createCellStyle();
//设置底边框;
// style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
// //设置底边框颜色;
// style.setBottomBorderColor(HSSFColor.WHITE.index);
// //设置左边框;
// style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
// //设置左边框颜色;
// style.setLeftBorderColor(HSSFColor.WHITE.index);
// //设置右边框;
// style.setBorderRight(HSSFCellStyle.BORDER_THIN);
// //设置右边框颜色;
// style.setRightBorderColor(HSSFColor.WHITE.index);
//设置顶边框;
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
//设置顶边框颜色;
style.setTopBorderColor(HSSFColor.WHITE.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
/*
* 中文列头单元格样式
*/
public HSSFCellStyle getColumnTopStyle(HSSFWorkbook workbook) {
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short) 14);
//字体加粗
// font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//设置字体名字
font.setFontName("微软雅黑");
//设置样式;
HSSFCellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//设置底边框颜色;
style.setBottomBorderColor(HSSFColor.WHITE.index);
//设置左边框;
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//设置左边框颜色;
style.setLeftBorderColor(HSSFColor.BLACK.index);
//设置右边框;
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//设置右边框颜色;
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
//设置顶边框颜色;
style.setTopBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
/*
* 列数据信息单元格样式
*/
public HSSFCellStyle getStyle(HSSFWorkbook workbook) {
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体名字
font.setFontName("微软雅黑");
//设置样式;
HSSFCellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//设置底边框颜色;
style.setBottomBorderColor(HSSFColor.BLACK.index);
//设置左边框;
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//设置左边框颜色;
style.setLeftBorderColor(HSSFColor.BLACK.index);
//设置右边框;
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//设置右边框颜色;
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
//设置顶边框颜色;
style.setTopBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
}
\ No newline at end of file
...@@ -9,6 +9,16 @@ public class UserTermVo { ...@@ -9,6 +9,16 @@ public class UserTermVo {
private String phone; private String phone;
private String companyName;
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getUserName() { public String getUserName() {
return userName; return userName;
} }
......
...@@ -11,17 +11,17 @@ public interface UserMapper { ...@@ -11,17 +11,17 @@ public interface UserMapper {
int login(LoginUserVo loginUserVo); int login(LoginUserVo loginUserVo);
UserVo getByUserName(String userName); UserVo getByUserName(@Param("userName") String userName);
List<ResultUserVo> getAll(); List<ResultUserVo> getAll(String companyName);
List<ResultUserVo> getByTerm(UserTermVo userTermVo); List<ResultUserVo> getByTerm(UserTermVo userTermVo);
ResultUserVo getByPhone(String phone); ResultUserVo getByPhone(@Param("phone") String phone,@Param("companyName") String companyName);
ResultUserVo getByEmail(String email); ResultUserVo getByEmail(@Param("email") String email,@Param("companyName") String companyName);
ResultUserVo getByUserNumber(String userNumber); ResultUserVo getByUserNumber(@Param("userNumber") String userNumber,@Param("companyName") String companyName);
int addUser(AddUserVo addUserVo); int addUser(AddUserVo addUserVo);
......
...@@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit; ...@@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
public class MqttListener implements MqttCallback { public class MqttListener implements MqttCallback {
private static final int INIT_DELAY_DEFAULT = 1000; // unit:ms private static final int INIT_DELAY_DEFAULT = 1000; // unit:ms
private static final int SCH_PERIOD_DEFAULT = 10 * INIT_DELAY_DEFAULT; // unit:ms private static final int SCH_PERIOD_DEFAULT = 10 * INIT_DELAY_DEFAULT; // unit:ms
private static final String CHECKIN_TOPIC = "TDL/+/+/CheckIn"; private static final String CHECKIN_TOPIC = "Witium/+/+/CheckIn";
private MqttTemlateAsync mqttAsyncClient; private MqttTemlateAsync mqttAsyncClient;
...@@ -187,9 +187,12 @@ public class MqttListener implements MqttCallback { ...@@ -187,9 +187,12 @@ public class MqttListener implements MqttCallback {
// 有设备信息 // 有设备信息
ConfigVo configVo = configService.getConfig(SN,Type); ConfigVo configVo = configService.getConfig(SN,Type);
ConfigCMDVo configCMDVo = new Gson().fromJson(configVo.getMessage(),ConfigCMDVo.class); ConfigCMDVo configCMDVo = new Gson().fromJson(configVo.getMessage(),ConfigCMDVo.class);
if(StringUtils.isEmpty(configVo.getMessage())){ if(configVo.getUntie()){
return 2;//解绑 //解绑状态
} else if (configCMDVo.getDevList().containsAll(checkInVo.getDevList()) return 2;//解绑
}
//判断两者的devList是否一致
if (configCMDVo.getDevList().containsAll(checkInVo.getDevList())
&& checkInVo.getDevList().containsAll(configCMDVo.getDevList()) && checkInVo.getDevList().containsAll(configCMDVo.getDevList())
&& checkInVo.getGprsPeriod().equals(configCMDVo.getGprsPeriod()) && checkInVo.getGprsPeriod().equals(configCMDVo.getGprsPeriod())
&& checkInVo.getGpsPeriod().equals(configCMDVo.getGpsPeriod()) && checkInVo.getGpsPeriod().equals(configCMDVo.getGpsPeriod())
......
...@@ -30,24 +30,24 @@ public class UserService { ...@@ -30,24 +30,24 @@ public class UserService {
return userMapper.getByUserName(userName); return userMapper.getByUserName(userName);
} }
public List<ResultUserVo> getAll(){ public List<ResultUserVo> getAll(String companyName){
return userMapper.getAll(); return userMapper.getAll(companyName);
} }
public List<ResultUserVo> getByTerm(UserTermVo userTermVo){ public List<ResultUserVo> getByTerm(UserTermVo userTermVo){
return userMapper.getByTerm(userTermVo); return userMapper.getByTerm(userTermVo);
} }
public ResultUserVo getByPhone(String phone){ public ResultUserVo getByPhone(String phone,String companyName){
return userMapper.getByPhone(phone); return userMapper.getByPhone(phone,companyName);
} }
public ResultUserVo getByEmail(String email){ public ResultUserVo getByEmail(String email,String companyName){
return userMapper.getByEmail(email); return userMapper.getByEmail(email,companyName);
} }
public ResultUserVo getByUserNumber(String userNumber){ public ResultUserVo getByUserNumber(String userNumber,String companyName){
return userMapper.getByUserNumber(userNumber); return userMapper.getByUserNumber(userNumber,companyName);
} }
public int addUser(AddUserVo addUserVo){ public int addUser(AddUserVo addUserVo){
......
package com.example.tdl.util;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.URL;
import java.util.Date;
public class AliyunOSSClientUtil {
private static Logger logger = LoggerFactory.getLogger(AliyunOSSClientUtil.class);
//阿里云API的内或外网域名
private static String ENDPOINT;
//阿里云API的密钥Access Key ID
private static String ACCESS_KEY_ID;
//阿里云API的密钥Access Key Secret
private static String ACCESS_KEY_SECRET;
//阿里云API的bucket名称
private static String BACKET_NAME;
//阿里云API的文件夹名称
private static String FOLDER1;
private static String FOLDER2;
private static String FOLDER3;
private static String FOLDER4;
private static CannedAccessControlList acl_pub_readwrite = CannedAccessControlList.PublicReadWrite;
//初始化属性
static {
ENDPOINT = OSSClientConstants.ENDPOINT;
ACCESS_KEY_ID = OSSClientConstants.ACCESS_KEY_ID;
ACCESS_KEY_SECRET = OSSClientConstants.ACCESS_KEY_SECRET;
BACKET_NAME = OSSClientConstants.BACKET_NAME;
FOLDER1 = OSSClientConstants.FOLDER1;
FOLDER2 = OSSClientConstants.FOLDER2;
FOLDER3 = OSSClientConstants.FOLDER3;
FOLDER4 = OSSClientConstants.FOLDER4;
}
public static String getENDPOINT() {
return ENDPOINT;
}
public static void setENDPOINT(String ENDPOINT) {
AliyunOSSClientUtil.ENDPOINT = ENDPOINT;
}
public static String getAccessKeyId() {
return ACCESS_KEY_ID;
}
public static void setAccessKeyId(String accessKeyId) {
ACCESS_KEY_ID = accessKeyId;
}
public static String getAccessKeySecret() {
return ACCESS_KEY_SECRET;
}
public static void setAccessKeySecret(String accessKeySecret) {
ACCESS_KEY_SECRET = accessKeySecret;
}
public static String getBacketName() {
return BACKET_NAME;
}
public static void setBacketName(String backetName) {
BACKET_NAME = backetName;
}
public static String getFOLDER1() {
return FOLDER1;
}
public static void setFOLDER1(String FOLDER1) {
AliyunOSSClientUtil.FOLDER1 = FOLDER1;
}
public static String getFOLDER2() {
return FOLDER2;
}
public static void setFOLDER2(String FOLDER2) {
AliyunOSSClientUtil.FOLDER2 = FOLDER2;
}
public static String getFOLDER3() {
return FOLDER3;
}
public static void setFOLDER3(String FOLDER3) {
AliyunOSSClientUtil.FOLDER3 = FOLDER3;
}
public static String getFOLDER4() {
return FOLDER4;
}
public static void setFOLDER4(String FOLDER4) {
AliyunOSSClientUtil.FOLDER4 = FOLDER4;
}
/**
* 获取阿里云OSS客户端对象
* @return ossClient
*/
public static OSSClient getOSSClient(){
return new OSSClient(ENDPOINT,ACCESS_KEY_ID, ACCESS_KEY_SECRET);//ossEndpoint, aliyunId, aliyunSecret
}
/**
* 创建存储空间
* @param ossClient OSS连接
* @param bucketName 存储空间
* @return
*/
public static void createBucketName(OSSClient ossClient,String bucketName){
//存储空间
final String bucketNames=bucketName;
if(!ossClient.doesBucketExist(bucketName)){
//创建存储空间
ossClient.setBucketAcl(bucketName,CannedAccessControlList.PublicRead);
logger.info("创建存储空间成功");
}
}
/**
* 删除存储空间buckName
* @param ossClient oss对象
* @param bucketName 存储空间
*/
public static void deleteBucket(OSSClient ossClient, String bucketName){
ossClient.deleteBucket(bucketName);
logger.info("删除" + bucketName + "Bucket成功");
}
/**
* 上传图片
*
* @param url
*/
public static void uploadImg2Oss(OSSClient ossClient,String url) {
File fileOnServer = new File(url);
FileInputStream fin;
try {
fin = new FileInputStream(fileOnServer);
String[] split = url.split("/");
uploadFile2OSS(ossClient,fin, split[split.length - 1]);
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.info("图片上传失败" +e.toString());
}
}
public static String uploadImg2Oss(OSSClient ossClient, MultipartFile file, String workNumber) {
String originalFilename = file.getOriginalFilename();
String name = workNumber + originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
try {
InputStream inputStream = file.getInputStream();
uploadFile2OSS(ossClient,inputStream, name);
return name;
} catch (Exception e) {
logger.info("图片上传失败!");
return null;
//throw new ImgException("图片上传失败");
}
}
/**
* 获得图片路径
*
* @param fileUrl
* @return
*/
public static String getImgUrl(OSSClient ossClient,String fileUrl) {
if (!StringUtils.isEmpty(fileUrl)) {
String[] split = fileUrl.split("/");
return getUrl(ossClient,FOLDER2 + split[split.length - 1]);
}
return null;
}
/**
* 上传到OSS服务器 如果同名文件会覆盖服务器上的
*
* @param instream 文件流
* @param fileName 文件名称 包括后缀名
* @return 出错返回"" ,唯一MD5数字签名
*/
public static String uploadFile2OSS(OSSClient ossClient,InputStream instream, String fileName) {
String ret = "";
try {
//创建上传Object的Metadata
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(instream.available());
objectMetadata.setCacheControl("no-cache");
objectMetadata.setContentType("image/jpeg");
objectMetadata.setContentDisposition("inline;filename=" + fileName);
//上传文件
PutObjectResult putResult = ossClient.putObject(BACKET_NAME, FOLDER2 + fileName, instream, objectMetadata);
ret = putResult.getETag();
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (instream != null) {
instream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return ret;
}
/**
* 创建模拟文件夹
* @param ossClient oss连接
* @param bucketName 存储空间
* @param folder 模拟文件夹名如"qj_nanjing/"
* @return 文件夹名
*/
public static String createFolder(OSSClient ossClient,String bucketName,String folder){
//文件夹名
final String keySuffixWithSlash =folder;
//判断文件夹是否存在,不存在则创建
if(!ossClient.doesObjectExist(bucketName, keySuffixWithSlash)){
//创建文件夹
ossClient.putObject(bucketName, keySuffixWithSlash, new ByteArrayInputStream(new byte[0]));
logger.info("创建文件夹成功");
//得到文件夹名
OSSObject object = ossClient.getObject(bucketName, keySuffixWithSlash);
String fileDir=object.getKey();
return fileDir;
}
return keySuffixWithSlash;
}
/**
* 获得url链接
*
* @param key
* @return
*/
public static String getUrl(OSSClient ossClient,String key) {
// 设置URL过期时间为10年 3600l* 1000*24*365*10
Date expiration = new Date(new Date().getTime() + 3600l * 1000 * 24 * 365 * 10);
// 生成URL
URL url = ossClient.generatePresignedUrl(BACKET_NAME, key, expiration);
if (url != null) {
return url.toString();
}
return null;
}
/**
* 根据key删除OSS服务器上的文件
* @param ossClient oss连接
* @param bucketName 存储空间
* @param folder 模拟文件夹名 如"qj_nanjing/"
* @param key Bucket下的文件的路径名+文件名 如:"upload/cake.jpg"
*/
public static void deleteFile(OSSClient ossClient, String bucketName, String folder, String key){
ossClient.deleteObject(bucketName, folder + key);
logger.info("删除" + bucketName + "下的文件" + folder + key + "成功");
}
/**
* 上传图片/文件至OSS
* @param ossClient oss连接
* @param file 上传文件(文件全路径如:D:\\image\\cake.jpg)
* @return String 返回的唯一MD5数字签名
* */
public static String uploadObject2OSS(OSSClient ossClient, File file) {
String resultStr = null;
try {
//以输入流的形式上传文件
InputStream is = new FileInputStream(file);
//文件名
String fileName = file.getName();
//文件大小
Long fileSize = file.length();
//创建上传Object的Metadata
ObjectMetadata metadata = new ObjectMetadata();
//上传的文件的长度
metadata.setContentLength(is.available());
//指定该Object被下载时的网页的缓存行为
metadata.setCacheControl("no-cache");
metadata.setContentType("application/octet-stream");
//指定该Object下设置Header
metadata.setHeader("Pragma", "no-cache");
//指定该Object被下载时的内容编码格式
metadata.setContentEncoding("utf-8");
//文件的MIME,定义文件的类型及网页编码,决定浏览器将以什么形式、什么编码读取文件。如果用户没有指定则根据Key或文件名的扩展名生成,
//如果没有扩展名则填默认值application/octet-stream
metadata.setContentType(getContentType(fileName));
//指定该Object被下载时的名称(指示MINME用户代理如何显示附加的文件,打开或下载,及文件名称)
metadata.setContentDisposition("attachment;filename=" + fileName );
//上传文件 (上传文件流的形式)
PutObjectResult putResult = null;
if(fileName.contains("时") && fileName.contains("分") && fileName.contains("秒")){
putResult = ossClient.putObject(BACKET_NAME, FOLDER3+ fileName, is, metadata);
} else if(fileName.contains("CHN")){
putResult = ossClient.putObject(BACKET_NAME, FOLDER4+ fileName, is, metadata);
} else {
putResult = ossClient.putObject(BACKET_NAME, FOLDER1+ fileName, is, metadata);
}
//解析结果
resultStr = putResult.getETag();
} catch (Exception e) {
e.printStackTrace();
logger.error("上传阿里云OSS服务器异常." + e.getMessage(), e);
}
return resultStr;
}
/**
* 通过文件名判断并获取OSS服务文件上传时文件的contentType
* @param fileName 文件名
* @return 文件的contentType
*/
public static final String getContentType(String fileName){
//文件后缀
String fileExtension = fileName.substring(fileName.lastIndexOf("."));
if("bmp".equalsIgnoreCase(fileExtension))
return "image/bmp";
if("gif".equalsIgnoreCase(fileExtension))
return "image/gif";
if("jpeg".equalsIgnoreCase(fileExtension) || "jpg".equalsIgnoreCase(fileExtension) || "png".equalsIgnoreCase(fileExtension) )
return "image/jpeg";
if("html".equalsIgnoreCase(fileExtension))
return "text/html";
if("txt".equalsIgnoreCase(fileExtension))
return "text/plain";
if("vsd".equalsIgnoreCase(fileExtension))
return "application/vnd.visio";
if("ppt".equalsIgnoreCase(fileExtension) || "pptx".equalsIgnoreCase(fileExtension))
return "application/vnd.ms-powerpoint";
if("doc".equalsIgnoreCase(fileExtension) || "docx".equalsIgnoreCase(fileExtension))
return "application/msword";
if("xml".equalsIgnoreCase(fileExtension))
return "text/xml";
return "text/html";
}
//测试
public static void main(String[] args) {
//初始化OSSClient
OSSClient ossClient=AliyunOSSClientUtil.getOSSClient();
//上传文件
String files="D://专用工具登记表-761923471.xls";
File filess=new File(files);
String md5key = AliyunOSSClientUtil.uploadObject2OSS(ossClient, filess);
logger.info("上传后的文件MD5数字唯一签名:" + md5key);
}
}
package com.example.tdl.util;
import com.aliyun.oss.model.CannedAccessControlList;
public class OSSClientConstants {
//阿里云API的外网域名
public static final String ENDPOINT = "oss-cn-shanghai.aliyuncs.com";
//阿里云API的密钥Access Key ID
public static final String ACCESS_KEY_ID = "LTAITBRGP5O2x861";
//阿里云API的密钥Access Key Secret
public static final String ACCESS_KEY_SECRET = "JgupdkkFg1Ot1eRsdk6wXU3CJiWdaw";
//阿里云API的bucket名称
public static final String BACKET_NAME = "witcloud-oss";//uploadexcelhltp
//阿里云API的文件夹名称
public static final String FOLDER1="everyData/";//每日设备数据
public static final String FOLDER2="picture/"; //图片上传
public static final String FOLDER3="historyData/probesData/";//探点数据
public static final String FOLDER4="tdlAlarmData/";//探点数据
//公共读写
private static final CannedAccessControlList acl_pub_readwrite = CannedAccessControlList.PublicReadWrite;
}
package com.example.tdl.util;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipCompressUtil {
private String zipFileName; // 目的地Zip文件
private String sourceFileName; //源文件(带压缩的文件或文件夹)
public ZipCompressUtil(String zipFileName, String sourceFileName){
this.zipFileName=zipFileName;
this.sourceFileName=sourceFileName;
}
public void zip() throws Exception {
//创建zip输出流
ZipOutputStream out = new ZipOutputStream( new FileOutputStream(zipFileName));
//创建缓冲输出流
BufferedOutputStream bos = new BufferedOutputStream(out);
File sourceFile = new File(sourceFileName);
//调用函数
compress(out,bos,sourceFile,sourceFile.getName());
bos.close();
out.close();
}
public void compress(ZipOutputStream out,BufferedOutputStream bos,File sourceFile,String base) throws Exception {
//如果路径为目录(文件夹)
if(sourceFile.isDirectory()){
//取出文件夹中的文件(或子文件夹)
File[] flist = sourceFile.listFiles();
//如果文件夹为空,则只需在目的地zip文件中写入一个目录进入点
if(flist.length==0){
out.putNextEntry( new ZipEntry(base+"/") );
} else {
//如果文件夹不为空,则递归调用compress,文件夹中的每一个文件(或文件夹)进行压缩
for(int i=0;i<flist.length;i++) {
compress(out,bos,flist[i],base+"/"+flist[i].getName());
}
}
}else {
//如果不是目录(文件夹),即为文件,则先写入目录进入点,之后将文件写入zip文件中
out.putNextEntry(new ZipEntry(base));
FileInputStream fos = new FileInputStream(sourceFile);
BufferedInputStream bis = new BufferedInputStream(fos);
int tag;
//将源文件写入到zip文件中
while ((tag = bis.read()) != -1) {
bos.write(tag);
}
bis.close();
fos.close();
}
}
}
...@@ -2,16 +2,22 @@ package com.example.tdl.web; ...@@ -2,16 +2,22 @@ package com.example.tdl.web;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.example.tdl.common.CommonExcel;
import com.example.tdl.domain.dto.CommFeedback; import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.*; import com.example.tdl.domain.vo.*;
import com.example.tdl.service.CircuitService; import com.example.tdl.service.CircuitService;
import com.example.tdl.service.TDLDeviceService; import com.example.tdl.service.TDLDeviceService;
import com.example.tdl.service.redis.RealRedisService; import com.example.tdl.service.redis.RealRedisService;
import com.example.tdl.service.redis.TokenRedisService; import com.example.tdl.service.redis.TokenRedisService;
import com.example.tdl.util.AliyunOSSClientUtil;
import com.example.tdl.util.ZipCompressUtil;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.influxdb.dto.Query; import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult; import org.influxdb.dto.QueryResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -19,6 +25,10 @@ import org.springframework.data.influxdb.InfluxDBTemplate; ...@@ -19,6 +25,10 @@ import org.springframework.data.influxdb.InfluxDBTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -45,7 +55,7 @@ public class AlarmDataController { ...@@ -45,7 +55,7 @@ public class AlarmDataController {
private final static String database ="original"; private final static String database ="original";
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
}) })
@RequestMapping(value="/getTrack",method = RequestMethod.GET) @RequestMapping(value="/getTrack",method = RequestMethod.GET)
public Object getTrack(){ public Object getTrack(){
...@@ -59,7 +69,7 @@ public class AlarmDataController { ...@@ -59,7 +69,7 @@ public class AlarmDataController {
return gson.toJson(fb); return gson.toJson(fb);
} }
String device = resultGatewayVo.getType() +"_" +resultGatewayVo.getSN(); String device = resultGatewayVo.getType() +"_" +resultGatewayVo.getSN();
List<String> list=tdlDeviceService.getByGatewaySN(resultGatewayVo.getSN(),resultGatewayVo.getType()); List<String> list=tdlDeviceService.getTdlSN(resultGatewayVo.getSN(),resultGatewayVo.getType());
String tdl=""; String tdl="";
if (list.size()==1){ if (list.size()==1){
tdl="'tdl-"+list.get(0)+"'"; tdl="'tdl-"+list.get(0)+"'";
...@@ -75,12 +85,6 @@ public class AlarmDataController { ...@@ -75,12 +85,6 @@ public class AlarmDataController {
} }
} }
} }
List<TrackVo> trackVos=new ArrayList<>();
String sqls = "SELECT \"tdl\",\"T\", \"b\", \"h\", \"p\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"= "+tdl+" order by time";
QueryResult queryResult = influxDBTemplate.query(new Query(sqls,database));
if (queryResult.getResults().get(0).getSeries()!=null){
trackVos=getTrack(queryResult);
}
List<LocationDataVo> locationDataVos = new ArrayList<>(); List<LocationDataVo> locationDataVos = new ArrayList<>();
String sql ="SELECT \"time\",\"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\" order by time"; String sql ="SELECT \"time\",\"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\" order by time";
QueryResult queryResults = influxDBTemplate.query(new Query(sql,database)); QueryResult queryResults = influxDBTemplate.query(new Query(sql,database));
...@@ -90,48 +94,164 @@ public class AlarmDataController { ...@@ -90,48 +94,164 @@ public class AlarmDataController {
List<TrackVo> trackVos1=new ArrayList<>(); List<TrackVo> trackVos1=new ArrayList<>();
for (int a=0;a<locationDataVos.size();a++){ for (int a=0;a<locationDataVos.size();a++){
TrackVo trackVo=new TrackVo(); TrackVo trackVo=new TrackVo();
trackVo.setTime(locationDataVos.get(a).getTime()); trackVo.setTime(dateToStamp(locationDataVos.get(a).getTime()));
trackVo.setLng(locationDataVos.get(a).getLng().toString()); trackVo.setLng(locationDataVos.get(a).getLng().toString());
trackVo.setLat(locationDataVos.get(a).getLat().toString()); trackVo.setLat(locationDataVos.get(a).getLat().toString());
// for (int b=0;b<trackVos.size();b++){ String sqls ="";
// if () if (a+1<locationDataVos.size()){
// } sqls ="SELECT \"tdl\",\"T\", \"b\", \"h\", \"p\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"= "+tdl+" AND \"time\"<='"+locationDataVos.get(a).getTime()+"' AND \"time\">='"+locationDataVos.get(a+1).getTime()+"' order by time limit 1";
}else{
sqls = "SELECT \"tdl\",\"T\", \"b\", \"h\", \"p\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"= "+tdl+" AND \"time\"<='"+locationDataVos.get(a).getTime()+"' order by time limit 1";
}
QueryResult queryResult = influxDBTemplate.query(new Query(sqls,database));
if (queryResult.getResults().get(0).getSeries()!=null) {
trackVo.setT(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(2) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(2).toString() : "-");
trackVo.setB(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(3) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(3).toString() : "-");
trackVo.setH(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4).toString() : "-");
trackVo.setA0(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(5) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(5).toString() : "-");
}else{
trackVo.setB("-");
trackVo.setT("-");
trackVo.setH("-");
trackVo.setA0("-");
}
trackVos1.add(trackVo);
} }
return gson.toJson(trackVos1);
}
//下载成表格
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@ApiOperation(value = "将数据下载成表格",notes = "将数据下载成表格")
@RequestMapping(value = "/downloadExcel", method = RequestMethod.POST)
public @ResponseBody Object downloadExcel(HttpServletRequest request,HttpServletResponse response)throws Exception{
String transportationNo="CHN20180323G1111";
// JSONObject jsonObject= JSON.parseObject(transportationNo);
// transportationNo=(String)jsonObject.get("transportationNo");
ResultGatewayVo resultGatewayVo=circuitService.getByNo(transportationNo);
if (resultGatewayVo==null){
fb.setCode(0);
fb.setMessage("该线路没有绑定网关");
return gson.toJson(fb);
}
String device = resultGatewayVo.getType() +"_" +resultGatewayVo.getSN();
List<String> list=tdlDeviceService.getTdlSN(resultGatewayVo.getSN(),resultGatewayVo.getType());
String tdl="";
if (list.size()==1){
tdl="'tdl-"+list.get(0)+"'";
}else if(list.size()==0){
fb.setCode(0);
fb.setMessage("该网关下没有tdl设备");
return gson.toJson(fb);
}else{
for (int a=0;a<list.size();a++){
tdl=tdl+"'tdl-"+list.get(a)+"'";
if (a<list.size()-1){
tdl=tdl+"or \"tdl\"=";
}
}
}
List<LocationDataVo> locationDataVos = new ArrayList<>();
String sql ="SELECT \"time\",\"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\" order by time desc";
QueryResult queryResults = influxDBTemplate.query(new Query(sql,database));
if (queryResults.getResults().get(0).getSeries()!=null){
locationDataVos=getAllAddress(queryResults);
}
List<TrackVo> trackVos1=new ArrayList<>();
for (int a=0;a<locationDataVos.size();a++){
TrackVo trackVo=new TrackVo();
trackVo.setTime(locationDataVos.get(a).getTime());
trackVo.setLng(locationDataVos.get(a).getLng().toString());
trackVo.setLat(locationDataVos.get(a).getLat().toString());
String sqls ="";
if (a+1<locationDataVos.size()){
sqls ="SELECT \"tdl\",\"T\", \"b\", \"h\", \"p\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"= "+tdl+" AND \"time\"<='"+locationDataVos.get(a).getTime()+"' AND \"time\">='"+locationDataVos.get(a+1).getTime()+"' order by time limit 1";
}else{
sqls = "SELECT \"tdl\",\"T\", \"b\", \"h\", \"p\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"= "+tdl+" AND \"time\"<='"+locationDataVos.get(a).getTime()+"' order by time limit 1";
}
QueryResult queryResult = influxDBTemplate.query(new Query(sqls,database));
if (queryResult.getResults().get(0).getSeries()!=null) {
trackVo.setT(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(2) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(2).toString() : "-");
trackVo.setB(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(3) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(3).toString() : "-");
trackVo.setH(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(4).toString() : "-");
trackVo.setA0(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(5) != null ? queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(5).toString() : "-");
}else{
trackVo.setB("-");
trackVo.setT("-");
trackVo.setH("-");
trackVo.setA0("-");
}
trackVos1.add(trackVo);
}
if (trackVos1.size()>0){
String name = "设备报警信息表";
String title = "设 备 报 警 信 息 表";
String[] rowsName = new String[]{"报警时间","经度","纬度","温度","电池电压","湿度","压力"};
String fileName = transportationNo;
File file=new File("D:/"+fileName);
List<Object[]> dataList = new ArrayList<Object[]>();
Object[] objs = null;
for(int i = 0; i < trackVos1.size();i++){
objs = new Object[rowsName.length];
objs[0] = trackVos1.get(i).getTime();
objs[1] = trackVos1.get(i).getLng();
objs[2] = trackVos1.get(i).getLat();
objs[3] = trackVos1.get(i).getT();
objs[4] = trackVos1.get(i).getB();
objs[5] = trackVos1.get(i).getH();
objs[6] = trackVos1.get(i).getA0();
dataList.add(objs);
}
try {
CommonExcel ex = new CommonExcel(name,title, rowsName, dataList, fileName);
HSSFWorkbook workbook=ex.downloadExcel();
if (workbook!=null){
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename="+fileName);
OutputStream os = new FileOutputStream(new File(file+".xls"));
workbook.write(os);
os.flush();
os.close();
ZipCompressUtil zipCom = new ZipCompressUtil(file+".zip",file+".xls");
zipCom.zip();
try {
OSSClient ossClient = AliyunOSSClientUtil.getOSSClient();
String resultStr = AliyunOSSClientUtil.uploadObject2OSS(ossClient, new File(file +".zip"));
if (new File(file+".xls").delete()){
fb.setCode(1);
fb.setMessage("https://witcloud-oss.oss-cn-shanghai.aliyuncs.com/tdlAlarmData/"+fileName +".zip");
return gson.toJson(fb);
}else{
fb.setCode(0);
fb.setMessage("下载失败");
}
} catch (Exception e) {
e.printStackTrace();
this.fb.setCode(Integer.valueOf(0));
this.fb.setMessage("上传失败");
}
}else{
fb.setCode(0);
fb.setMessage("下载失败");
}
}catch(Exception e){
e.printStackTrace();
fb.setCode(0);
fb.setMessage("下载失败");
}
}else{
fb.setCode(0);
fb.setMessage("没有数据可以下载");
}
return gson.toJson(fb);
}
// SELECT "tdl","T", "b", "h", "p" FROM "tdl_policy"."WTD93LG_20180314" WHERE ("tdl" = 'tdl-0F0D0C0B0A') or "tdl" = 'tdl-0A0B0C0D0F' AND $timeFilter
// String sqls = "SELECT \"time\",\"b\",\"t\",\"h\",\"p\" FROM \"tdl_policy\".\""+device+"\" where \"tdl\"= "+tdl+" and \"time\"<='"+locationDataVos.get(a).getTime()+"' ORDER BY time desc limit 1;";
return gson.toJson(trackVos);
// List<LocationDataVo> locationDataVos1 = new ArrayList<>();
// for(int a=0;a<locationDataVos.size();a++){
// String sqls="SELECT \"time\",\"T\",\"h\",\"b\",\"p\" FROM \"tdl_policy\".\""+device+"\" where time <='"+locationDataVos.get(a).getTime()+"' ORDER BY time desc limit 1;";
// QueryResult queryResults1 = influxDBTemplate.query(new Query(sqls,database));
// if (queryResults.getResults().get(0).getSeries()!=null){
// locationDataVos1=getAllAddress(queryResults1);
// }
// }
// String sql1="SELECT \"time\",\"lng\",\"lat\" FROM \"tdl_policy\".\""+device+"\" order by time";
// QueryResult queryResult1 = influxDBTemplate.query(new Query(sql1,database));
// List<LocationDataVo> locationDataVos1 = new ArrayList<>();
// if (queryResult1.getResults().get(0).getSeries()!=null){
// locationDataVos1=getAllAddress(queryResult1);
// }
// for (int a=0;a<locationDataVos1.size();a++){
// for (int b=0;b<locationDataVos.size();b++){
// if (locationDataVos1.get(a).getLng().equals(locationDataVos.get(b).getLng())&&locationDataVos1.get(a).getLat().equals(locationDataVos.get(b).getLat())){
// locationDataVos1.get(a).setError(1);
// }
// }
// }
}
...@@ -245,7 +365,7 @@ public class AlarmDataController { ...@@ -245,7 +365,7 @@ public class AlarmDataController {
List<LocationDataVo> locationDataVos=new ArrayList<>(); List<LocationDataVo> locationDataVos=new ArrayList<>();
for (List<Object> value:lists){ for (List<Object> value:lists){
LocationDataVo locationDataVo=new LocationDataVo(); LocationDataVo locationDataVo=new LocationDataVo();
locationDataVo.setTime(dateToStamp(value.get(0).toString())); locationDataVo.setTime(value.get(0).toString());
locationDataVo.setLng((Double)value.get(1)); locationDataVo.setLng((Double)value.get(1));
locationDataVo.setLat((Double)value.get(2)); locationDataVo.setLat((Double)value.get(2));
// locationDataVo.setError(0); // locationDataVo.setError(0);
......
...@@ -132,7 +132,9 @@ public class CircuitController { ...@@ -132,7 +132,9 @@ public class CircuitController {
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class); UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
JSONObject jsonObject=JSON.parseObject(transportationNo); JSONObject jsonObject=JSON.parseObject(transportationNo);
transportationNo=(String) jsonObject.get("transportationNo"); transportationNo=(String) jsonObject.get("transportationNo");
return circuitService.getByTransportationNoForApp(transportationNo,user.getCompanyName()); ResultCircuitForAppVo resultCircuitForAppVo=circuitService.getByTransportationNoForApp(transportationNo,user.getCompanyName());
resultCircuitForAppVo.setStartTime(System.currentTimeMillis());
return resultCircuitForAppVo;
} }
//根据条件查询 //根据条件查询
......
...@@ -45,18 +45,42 @@ public class UserController { ...@@ -45,18 +45,42 @@ public class UserController {
private RoleService roleService; private RoleService roleService;
//获取所有用户信息 //获取所有用户信息
@ApiOperation(value = "获取所有用户信息",notes = "获取所有用户信息") @ApiOperation(value = "获取所有用户信息",notes = "获取所有用户信息:" +
" userNumber:用户编号," +
" userName:用户名," +
" nickName:昵称," +
" phone:电话," +
" email:邮箱," +
" roleName:角色名," +
" companyName:公司名.")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
}) })
@RequestMapping(value="/getAll",method = RequestMethod.GET) @RequestMapping(value="/getAll",method = RequestMethod.GET)
public Object getAll(){ public Object getAll(HttpServletRequest request){
return userService.getAll(); String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
return userService.getAll(user.getCompanyName());
} }
//根据条件查询 //根据条件查询
@ApiOperation(value = "根据条件查询",notes = "根据条件查询") @ApiOperation(value = "根据条件查询",notes = "根据条件查询:需要传的值:" +
" email:邮件," +
" phone:电话," +
" roleName:角色名," +
" userName:用户名." +
"返回值说明:" +
" userNumber:," +
" userName:," +
" nickName:," +
" phone:," +
" email:," +
" roleName:," +
" companyName:.")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
}) })
...@@ -119,7 +143,7 @@ public class UserController { ...@@ -119,7 +143,7 @@ public class UserController {
fb.setMessage("手机号不规范"); fb.setMessage("手机号不规范");
return gson.toJson(fb); return gson.toJson(fb);
} }
if ((userService.getByPhone(userVo.getPhone()))!=null){ if ((userService.getByPhone(userVo.getPhone(),userVo.getCompanyName()))!=null){
fb.setCode(0); fb.setCode(0);
fb.setMessage("该手机号已被注册"); fb.setMessage("该手机号已被注册");
return gson.toJson(fb); return gson.toJson(fb);
...@@ -134,7 +158,7 @@ public class UserController { ...@@ -134,7 +158,7 @@ public class UserController {
fb.setMessage("邮箱格式不规范"); fb.setMessage("邮箱格式不规范");
return gson.toJson(fb); return gson.toJson(fb);
} }
if ((userService.getByEmail(userVo.getEmail()))!=null){ if ((userService.getByEmail(userVo.getEmail(),userVo.getCompanyName()))!=null){
fb.setCode(0); fb.setCode(0);
fb.setMessage("该邮箱已被注册"); fb.setMessage("该邮箱已被注册");
return gson.toJson(fb); return gson.toJson(fb);
...@@ -176,8 +200,11 @@ public class UserController { ...@@ -176,8 +200,11 @@ public class UserController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
}) })
@RequestMapping(value="/updateUser",method = RequestMethod.POST) @RequestMapping(value="/updateUser",method = RequestMethod.POST)
public Object updateUser(@RequestBody UpdateUserVo userVo){ public Object updateUser(@RequestBody UpdateUserVo userVo,HttpServletRequest request){
ResultUserVo userInfo=userService.getByUserNumber(userVo.getUserNumber()); String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
ResultUserVo userInfo=userService.getByUserNumber(userVo.getUserNumber(),user.getCompanyName());
if (StringUtils.isEmpty(userVo.getNickName())){ if (StringUtils.isEmpty(userVo.getNickName())){
fb.setCode(0); fb.setCode(0);
fb.setMessage("昵称不能为空"); fb.setMessage("昵称不能为空");
......
...@@ -11,23 +11,27 @@ ...@@ -11,23 +11,27 @@
<!--通过用户名查询用户信息--> <!--通过用户名查询用户信息-->
<select id="getByUserName" parameterType="String" resultType="com.example.tdl.domain.vo.UserVo"> <select id="getByUserName" parameterType="String" resultType="com.example.tdl.domain.vo.UserVo">
select userNumber, userName,password,nickName,phone,email,roleName,(SELECT companyName from company WHERE id=u.company_id) companyName select userNumber, userName,password,nickName,phone,email,roleName,c.companyName
from `user` u INNER JOIN role r ON u.role_id=r.id from company c,`user` u INNER JOIN role r ON u.role_id=r.id
WHERE userName=#{userName,jdbcType=VARCHAR} WHERE u.company_id=c.id
AND state=1 AND userName=#{userName,jdbcType=VARCHAR}
AND u.state=1
</select> </select>
<!--获取所有用户信息--> <!--获取该公司所有用户信息-->
<select id="getAll" resultType="com.example.tdl.domain.vo.ResultUserVo"> <select id="getAll" resultType="com.example.tdl.domain.vo.ResultUserVo">
select userNumber, userName,nickName,phone,email,roleName,(SELECT companyName from company WHERE id=u.company_id) companyName select userNumber, userName,password,nickName,phone,email,roleName,c.companyName
from `user` u INNER JOIN role r ON u.role_id=r.id from company c,`user` u INNER JOIN role r ON u.role_id=r.id
WHERE state=1 WHERE u.company_id=c.id
AND c.companyName=#{companyName,jdbcType=VARCHAR}
AND u.state=1
</select> </select>
<!--根据条件查询--> <!--根据条件查询-->
<select id="getByTerm" resultType="com.example.tdl.domain.vo.ResultUserVo" parameterType="com.example.tdl.domain.vo.UserTermVo"> <select id="getByTerm" resultType="com.example.tdl.domain.vo.ResultUserVo" parameterType="com.example.tdl.domain.vo.UserTermVo">
select userNumber, userName,nickName,phone,email,roleName,(SELECT companyName from company WHERE id=u.company_id) companyName select userNumber, userName,password,nickName,phone,email,roleName,c.companyName
from `user` u INNER JOIN role r ON u.role_id=r.id WHERE 1=1 from company c,`user` u INNER JOIN role r ON u.role_id=r.id
WHERE u.company_id=c.id
<if test="userName!=null"> <if test="userName!=null">
AND userName like CONCAT(CONCAT('%',#{userName,jdbcType=VARCHAR}), '%') AND userName like CONCAT(CONCAT('%',#{userName,jdbcType=VARCHAR}), '%')
</if> </if>
...@@ -40,31 +44,38 @@ ...@@ -40,31 +44,38 @@
<if test="phone!=null"> <if test="phone!=null">
AND phone like CONCAT(CONCAT('%',#{phone,jdbcType=VARCHAR}), '%') AND phone like CONCAT(CONCAT('%',#{phone,jdbcType=VARCHAR}), '%')
</if> </if>
AND state=1 AND c.companyName=#{companyName,jdbcType=VARCHAR}
AND u.state=1
</select> </select>
<!--通过手机号查询用户信息--> <!--通过手机号查询用户信息-->
<select id="getByPhone" parameterType="String" resultType="com.example.tdl.domain.vo.ResultUserVo"> <select id="getByPhone" parameterType="String" resultType="com.example.tdl.domain.vo.ResultUserVo">
select userNumber, userName,nickName,phone,email,roleName,(SELECT companyName from company WHERE id=u.company_id) companyName select userNumber, userName,password,nickName,phone,email,roleName,c.companyName
from `user` u INNER JOIN role r ON u.role_id=r.id from company c,`user` u INNER JOIN role r ON u.role_id=r.id
WHERE phone=#{phone,jdbcType=VARCHAR} WHERE u.company_id=c.id
AND state=1 AND c.companyName=#{companyName,jdbcType=VARCHAR}
AND phone=#{phone,jdbcType=VARCHAR}
AND u.state=1
</select> </select>
<!--通过邮箱查询用户信息--> <!--通过邮箱查询用户信息-->
<select id="getByEmail" parameterType="String" resultType="com.example.tdl.domain.vo.ResultUserVo"> <select id="getByEmail" parameterType="String" resultType="com.example.tdl.domain.vo.ResultUserVo">
select userNumber, userName,nickName,phone,email,roleName,(SELECT companyName from company WHERE id=u.company_id) companyName select userNumber, userName,password,nickName,phone,email,roleName,c.companyName
from `user` u INNER JOIN role r ON u.role_id=r.id from company c,`user` u INNER JOIN role r ON u.role_id=r.id
WHERE email=#{email,jdbcType=VARCHAR} WHERE u.company_id=c.id
AND state=1 AND c.companyName=#{companyName,jdbcType=VARCHAR}
AND email=#{email,jdbcType=VARCHAR}
AND u.state=1
</select> </select>
<!--通过用户编号查询用户信息--> <!--通过用户编号查询用户信息-->
<select id="getByUserNumber" parameterType="String" resultType="com.example.tdl.domain.vo.ResultUserVo"> <select id="getByUserNumber" parameterType="String" resultType="com.example.tdl.domain.vo.ResultUserVo">
select userNumber, userName,nickName,phone,email,roleName,(SELECT companyName from company WHERE id=u.company_id) companyName select userNumber, userName,password,nickName,phone,email,roleName,c.companyName
from `user` u INNER JOIN role r ON u.role_id=r.id from company c,`user` u INNER JOIN role r ON u.role_id=r.id
WHERE userNumber=#{userNumber,jdbcType=VARCHAR} WHERE u.company_id=c.id
AND state=1 AND c.companyName=#{companyName,jdbcType=VARCHAR}
AND userNumber=#{userNumber,jdbcType=VARCHAR}
AND u.state=1
</select> </select>
<!--添加用户--> <!--添加用户-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment