初次提交
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
package com.ho.filecenter;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 文件中心启动类
|
||||
* @date 2022/11/7
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"com.ho.common.tools" ,"com.ho.filecenter"})
|
||||
@EnableDiscoveryClient
|
||||
@MapperScan(basePackages = "com.ho.filecenter.mapper")
|
||||
@EnableFeignClients(basePackages = {"com.ho.filecenter.feignclient"})
|
||||
public class FileCenterApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FileCenterApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,186 @@
|
||||
package com.ho.filecenter.config;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.ho.filecenter.util.MqttConfigUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: Mqtt配置类 文件的先注释掉
|
||||
* @date 2022/11/7
|
||||
*/
|
||||
@Configuration
|
||||
@Data
|
||||
@ConfigurationProperties("mqtt")
|
||||
@Slf4j
|
||||
public class MqttConfig {
|
||||
|
||||
//服务器url
|
||||
String url;
|
||||
//用户名
|
||||
String userName;
|
||||
//密码
|
||||
String passWord;
|
||||
//超时时间
|
||||
Integer timeout;
|
||||
//会话保持时间
|
||||
Integer keepAlive;
|
||||
|
||||
@Value("${topic.edgeFileRequest}")
|
||||
String edgeFileRequest;
|
||||
|
||||
@Value("${topic.edgeFileResponse}")
|
||||
String edgeFileResponse;
|
||||
|
||||
@Value("${topic.cloudFileRequest}")
|
||||
String cloudFileRequest;
|
||||
|
||||
@Value("${topic.cloudFileResponse}")
|
||||
String cloudFileResponse;
|
||||
|
||||
@Value("${topic.edgeCurveResponse}")
|
||||
String edgeCurveResponse;
|
||||
|
||||
@Value("${topic.edgeDispatchResponse}")
|
||||
String edgeDispatchResponse;
|
||||
|
||||
@Autowired
|
||||
FileEdgeRequestConsumer fileEdgeRequestConsumer;
|
||||
|
||||
@Autowired
|
||||
FileEdgeResponseConsumer fileEdgeResponseConsumer;
|
||||
|
||||
@Autowired
|
||||
CurveResponseConsumer curveResponseConsumer;
|
||||
|
||||
@Autowired
|
||||
DispatchResponseConsumer dispatchResponseConsumer;
|
||||
|
||||
//todo 超时时间注释掉
|
||||
//文件请求
|
||||
@Bean(name = "FileEdgeRequest")
|
||||
public MqttClient initFileRequestClient() {
|
||||
String clientId = IdUtil.simpleUUID();
|
||||
log.info("clientId:" + clientId);
|
||||
MqttClient client = null;
|
||||
try {
|
||||
client = new MqttClient(url, clientId,null);
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(userName);
|
||||
options.setPassword(passWord.toCharArray());
|
||||
options.setCleanSession(true);
|
||||
options.setConnectionTimeout(timeout);
|
||||
options.setKeepAliveInterval(keepAlive);
|
||||
client.setCallback(fileEdgeRequestConsumer);
|
||||
IMqttToken iMqttToken = client.connectWithResult(options);
|
||||
boolean complete = iMqttToken.isComplete();
|
||||
log.info("FileRequestClient建立连接:{}", complete);
|
||||
|
||||
//这里监听的是
|
||||
String[] topic = MqttConfigUtil.getFileRequestTopic();
|
||||
int[] qos = new int[topic.length];
|
||||
client.subscribe(topic,qos);
|
||||
log.info("已订阅topic:{}", topic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
//文件响应
|
||||
@Bean(name = "FileEdgeResponse")
|
||||
public MqttClient initFileResponseClient() {
|
||||
String clientId = IdUtil.simpleUUID();
|
||||
log.info("clientId:" + clientId);
|
||||
MqttClient client =null;
|
||||
try {
|
||||
client = new MqttClient(url, clientId,null);
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(userName);
|
||||
options.setPassword(passWord.toCharArray());
|
||||
options.setCleanSession(true);
|
||||
options.setConnectionTimeout(timeout);
|
||||
options.setKeepAliveInterval(keepAlive);
|
||||
client.setCallback(fileEdgeResponseConsumer);
|
||||
IMqttToken iMqttToken = client.connectWithResult(options);
|
||||
boolean complete = iMqttToken.isComplete();
|
||||
log.info("FileResponseClient建立连接:{}", complete);
|
||||
|
||||
//这里监听的是
|
||||
String[] topic = MqttConfigUtil.getFileResponseTopic();
|
||||
int[] qos = new int[topic.length];
|
||||
client.subscribe(topic,qos);
|
||||
log.info("已订阅topic:{}", topic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
@Bean(name = "curveResponse")
|
||||
public MqttClient initCurveResponseClient() {
|
||||
String clientId = IdUtil.simpleUUID();
|
||||
log.info("clientId:" + clientId);
|
||||
MqttClient client =null;
|
||||
try {
|
||||
client = new MqttClient(url, clientId,null);
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(userName);
|
||||
options.setPassword(passWord.toCharArray());
|
||||
options.setCleanSession(true);
|
||||
options.setConnectionTimeout(timeout);
|
||||
options.setKeepAliveInterval(keepAlive);
|
||||
client.setCallback(curveResponseConsumer);
|
||||
IMqttToken iMqttToken = client.connectWithResult(options);
|
||||
boolean complete = iMqttToken.isComplete();
|
||||
log.info("FileRequestClient建立连接:{}", complete);
|
||||
|
||||
//这里监听的是
|
||||
String[] topic = MqttConfigUtil.getCurveResponseTopic();
|
||||
int[] qos = new int[topic.length];
|
||||
client.subscribe(topic,qos);
|
||||
log.info("已订阅topic:{}", topic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
@Bean(name = "dispatchResponse")
|
||||
public MqttClient initDispatchResponseClient() {
|
||||
String clientId = IdUtil.simpleUUID();
|
||||
log.info("clientId:" + clientId);
|
||||
MqttClient client =null;
|
||||
try {
|
||||
client = new MqttClient(url, clientId,null);
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setUserName(userName);
|
||||
options.setPassword(passWord.toCharArray());
|
||||
options.setCleanSession(true);
|
||||
options.setConnectionTimeout(timeout);
|
||||
options.setKeepAliveInterval(keepAlive);
|
||||
client.setCallback(dispatchResponseConsumer);
|
||||
IMqttToken iMqttToken = client.connectWithResult(options);
|
||||
boolean complete = iMqttToken.isComplete();
|
||||
log.info("FileRequestClient建立连接:{}", complete);
|
||||
|
||||
//这里监听的是
|
||||
String[] topic = MqttConfigUtil.getDispatchResponseTopic();
|
||||
int[] qos = new int[topic.length];
|
||||
client.subscribe(topic,qos);
|
||||
log.info("已订阅topic:{}", topic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return client;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,264 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.entity.Picture;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.entity.WorkOrderPicture;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.CommonBytesUtil;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.feignclient.FileCenterFlowFeignClient;
|
||||
import com.ho.filecenter.vo.currencyfile.CurrencyFileReqVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description 文件的上传, 下载以及预览
|
||||
* Author yule
|
||||
* Date 2022/12/30 16:12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "currencyFile")
|
||||
@Api(tags = "多媒体-通用文件模块")
|
||||
@Slf4j
|
||||
public class CurrencyFileController {
|
||||
|
||||
@Value("${files.upload.path}")
|
||||
String fileUploadPath;
|
||||
|
||||
@Value("${files.format}")
|
||||
String fileFormat;
|
||||
|
||||
@Value("${files.maxByte}")
|
||||
Long fileSize;
|
||||
|
||||
@Autowired
|
||||
CommonBytesUtil bytesUtil;
|
||||
|
||||
@Autowired
|
||||
BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Autowired
|
||||
FileCenterFlowFeignClient flowFeignClient;
|
||||
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation(value = "文件上传")
|
||||
@LogAnnotation(title = "通用文件模块", action = "文件上传")
|
||||
public DataResult<Picture> upload(@RequestPart MultipartFile file, @RequestParam String type) {
|
||||
Picture picture = new Picture();
|
||||
//验证文件是否为空
|
||||
if (file.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.FILE_IS_EMPTY);
|
||||
}
|
||||
//验证文件不能超过10M
|
||||
if (file.getSize() >= fileSize) {
|
||||
throw new BusinessException(BaseResponseCode.FILE_IS_TO_MORE);
|
||||
}
|
||||
|
||||
//获取文件名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
//获取文件后缀名
|
||||
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
|
||||
|
||||
//符合要求的文件类型后缀名数组
|
||||
String[] splits = fileFormat.split(",");
|
||||
|
||||
|
||||
//判断文件格式是否符合要求
|
||||
boolean flag = false;
|
||||
for (String split : splits) {
|
||||
if (split.equals(suffix)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
String timeFileName = DateUtil.format(new Date(), CommonConstant.DATE_PATH);
|
||||
String fileName = timeFileName + "/" + originalFilename; //设置新文件名
|
||||
File uploadFile =
|
||||
new File(fileUploadPath + "/" + fileName);
|
||||
if (!uploadFile.exists()) { //判断是否存在该路径
|
||||
uploadFile.mkdirs(); //如果不存在直接创建
|
||||
}
|
||||
try {
|
||||
file.transferTo(uploadFile); //将上传文件读取到服务器路径,参数为绝对路径
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (CommonConstant.WORK_ORDER.equals(type)) {
|
||||
WorkOrderPicture workOrderPicture = flowFeignClient.addPicture(fileUploadPath + fileName);
|
||||
BeanUtils.copyProperties(workOrderPicture, picture);
|
||||
} else {
|
||||
picture = businessFeignClient.addPicture(fileUploadPath + fileName);
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.FILE_FORMAT_ONLY);
|
||||
}
|
||||
return DataResult.success(picture);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件预览
|
||||
*/
|
||||
@PostMapping("/preview")
|
||||
@ApiOperation(value = "文件预览")
|
||||
public String preview(@RequestBody CurrencyFileReqVO currencyFileReqVO) {
|
||||
//根据id查询通用文件对象
|
||||
Picture picture = businessFeignClient.selectPicture(currencyFileReqVO.getId());
|
||||
|
||||
String base64 = null;
|
||||
try {
|
||||
//读取文件
|
||||
byte[] bytes = bytesUtil.readBlock(picture.getUrl(), 0);
|
||||
//文件后缀名
|
||||
String type = FilenameUtils.getExtension(new File(picture.getUrl()).getName());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
base64 = sb.append("data:image/").append(type).append(";base64,").append(Base64.encode(bytes)).toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return base64;
|
||||
}
|
||||
|
||||
@PostMapping("/previewData")
|
||||
@ApiOperation(value = "文件返回二进制流")
|
||||
public DataResult previewData(@RequestBody CurrencyFileReqVO currencyFileReqVO) {
|
||||
return DataResult.success(preview(currencyFileReqVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
*/
|
||||
@PostMapping("/download")
|
||||
@ApiOperation(value = "文件下载")
|
||||
public void download(@RequestBody CurrencyFileReqVO currencyFileReqVO, HttpServletResponse response) {
|
||||
Picture picture = new Picture();
|
||||
//根据id查询通用文件对象
|
||||
if (CommonConstant.WORK_ORDER.equals(currencyFileReqVO.getFileType())){
|
||||
WorkOrderPicture workOrderPicture = flowFeignClient.selectPictureById(currencyFileReqVO.getId());
|
||||
BeanUtils.copyProperties(workOrderPicture,picture);
|
||||
}else {
|
||||
picture = businessFeignClient.selectPicture(currencyFileReqVO.getId());
|
||||
}
|
||||
OutputStream os = null;
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
//获取文件后缀名
|
||||
String suffix = picture.getFileName().substring(picture.getFileName().lastIndexOf("."));
|
||||
// 响应图片
|
||||
response.setContentType("file/" + suffix);
|
||||
os = response.getOutputStream();
|
||||
fis = new FileInputStream(picture.getUrl());
|
||||
byte[] buffer = new byte[(int) bytesUtil.getFileSize(picture.getUrl())];
|
||||
int b = 0;
|
||||
while ((b = fis.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, b);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败");
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* app文件下载
|
||||
*/
|
||||
@GetMapping("/appDownload/{type}/{id}")
|
||||
@ApiOperation(value = "app文件下载")
|
||||
@TokenIgnore
|
||||
public void appDownload(@PathVariable("type") String type,@PathVariable("id") Integer id, HttpServletResponse response) {
|
||||
Picture picture = new Picture();
|
||||
//根据id查询通用文件对象
|
||||
if (CommonConstant.WORK_ORDER.equals(type)){
|
||||
WorkOrderPicture workOrderPicture = flowFeignClient.selectPictureById(id);
|
||||
BeanUtils.copyProperties(workOrderPicture,picture);
|
||||
}else {
|
||||
picture = businessFeignClient.selectPicture(id);
|
||||
}
|
||||
OutputStream os = null;
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
//获取文件后缀名
|
||||
String suffix = picture.getFileName().substring(picture.getFileName().lastIndexOf("."));
|
||||
|
||||
String fileName = URLEncoder. encode(picture.getFileName(), "UTF-8");
|
||||
// 响应图片
|
||||
response.setContentType("application/octet-stream");
|
||||
response.addHeader("Content-disposition", "attachment;filename=" + fileName);
|
||||
os = response.getOutputStream();
|
||||
fis = new FileInputStream(picture.getUrl());
|
||||
byte[] buffer = new byte[(int) bytesUtil.getFileSize(picture.getUrl())];
|
||||
int b = 0;
|
||||
while ((b = fis.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, b);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败");
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "文件删除")
|
||||
@LogAnnotation(title = "通用文件模块", action = "文件删除")
|
||||
public DataResult delete(@RequestBody CurrencyFileReqVO currencyFileReqVO) {
|
||||
|
||||
|
||||
businessFeignClient.deletePicture(currencyFileReqVO.getId());
|
||||
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,393 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import com.ho.business.entity.Picture;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.CommonBytesUtil;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.filecenter.entity.MediaFile;
|
||||
import com.ho.filecenter.service.FileService;
|
||||
import com.ho.filecenter.vo.mqtt.*;
|
||||
import com.ho.filecenter.vo.resp.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 文件Controller
|
||||
* @date 2022/11/7
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "file")
|
||||
@Api(tags = "多媒体-文件模块")
|
||||
@Slf4j
|
||||
public class FileController {
|
||||
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
FileService fileService;
|
||||
|
||||
@Autowired
|
||||
CommonBytesUtil bytesUtil;
|
||||
|
||||
@PostMapping("filePage")
|
||||
@ApiOperation(value = "分页查询文件")
|
||||
public DataResult<PageResult<MediaFile>> filePage(@RequestBody FilePageVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO userDetailRespVO = redisService.getUserDetailByToken(token);
|
||||
String userName = userDetailRespVO.getUsername();
|
||||
String userNameKey = redisService.getUserNameKey(userDetailRespVO, userName);
|
||||
SimpleUser user = (SimpleUser) redisService.get(userNameKey);
|
||||
PageResult<MediaFile> pageResult = fileService.page(vo, user);
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
|
||||
@PostMapping("fileUpload")
|
||||
@ApiOperation(value = "文件上传")
|
||||
public DataResult fileUpload(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
|
||||
//判断文件是否为空
|
||||
if (file.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.FILE_IS_EMPTY);
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO userDetailRespVO = redisService.getUserDetailByToken(token);
|
||||
String userName = userDetailRespVO.getUsername();
|
||||
String userNameKey = redisService.getUserNameKey(userDetailRespVO, userName);
|
||||
SimpleUser user = (SimpleUser) redisService.get(userNameKey);
|
||||
fileService.fileUpload(file, user);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("fileIssued")
|
||||
@ApiOperation(value = "文件下发")
|
||||
public DataResult<HeartbeatResp> fileIssued(@RequestBody FileIssuedVO vo, HttpServletRequest request) {
|
||||
HeartbeatResp heartbeatResp = new HeartbeatResp();
|
||||
String msg = CommonConstant.Heartbeat.MSG + vo.getSerialNo();
|
||||
if (fileService.checkHeartbeat(vo.getSerialNo())) {
|
||||
log.info("文件下发超过5分钟没有检测到心跳");
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
return DataResult.success(heartbeatResp);
|
||||
} else {
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.SUCCESS);
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
if (null == vo.getDestinationAddress()) {
|
||||
DataResult<HeartbeatResp> dataResult = new DataResult<>();
|
||||
dataResult.setMsg(BaseResponseCode.PARAM_CHECK_FAIL.getMsg());
|
||||
dataResult.setData(heartbeatResp);
|
||||
return dataResult;
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO userDetailRespVO = redisService.getUserDetailByToken(token);
|
||||
String userName = userDetailRespVO.getUsername();
|
||||
String userNameKey = redisService.getUserNameKey(userDetailRespVO, userName);
|
||||
SimpleUser user = (SimpleUser) redisService.get(userNameKey);
|
||||
log.info("文件准备开始下发");
|
||||
fileService.fileIssued(vo, user);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("progressBar")
|
||||
@ApiOperation(value = "文件下发进度")
|
||||
public DataResult<FileProcessRespVO> progressBar(@RequestBody FileProcessReqVO vo, HttpServletRequest request) {
|
||||
String fileSendAllKey = vo.getStationId() + ":" + RedisKeyConstant.FILE_SEND_ALL;
|
||||
FileProcessRespVO fileProcessRespVO = fileService.getFileProcess(vo.getStationId(), fileSendAllKey);
|
||||
return DataResult.success(fileProcessRespVO);
|
||||
}
|
||||
|
||||
@PostMapping("deleteFiles")
|
||||
@ApiOperation(value = "删除文件")
|
||||
@LogAnnotation(title = "文件服务", action = "删除文件")
|
||||
public DataResult fileIssued(@RequestBody List<Long> ids) {
|
||||
fileService.deleteFiles(ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("readFile")
|
||||
@ApiOperation(value = "读取文件")
|
||||
public DataResult readFile(@RequestBody FileIssuedVO vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
UserDetailRespVO userDetailRespVO = redisService.getUserDetailByToken(token);
|
||||
String userName = userDetailRespVO.getUsername();
|
||||
String userNameKey = redisService.getUserNameKey(userDetailRespVO, userName);
|
||||
SimpleUser user = (SimpleUser) redisService.get(userNameKey);
|
||||
fileService.readFile(vo, user);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("readFileAttribute")
|
||||
@ApiOperation(value = "读取文件属性")
|
||||
public DataResult<FileAttributeResp> readFileAttribute(@RequestBody FileAttributeReqVO vo, HttpServletRequest request) {
|
||||
FileAttributeResp fileAttributeResp = null;
|
||||
String msg = CommonConstant.Heartbeat.MSG + vo.getSerialNo();
|
||||
if (fileService.checkHeartbeat(vo.getSerialNo())) {
|
||||
fileAttributeResp = new FileAttributeResp();
|
||||
fileAttributeResp.setIsEnd(CommonConstant.TWO);
|
||||
fileAttributeResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
fileAttributeResp.setResponse(CommonConstant.NEGATIV_ONE);
|
||||
fileAttributeResp.setList(new ArrayList<>());
|
||||
return DataResult.success(fileAttributeResp);
|
||||
}
|
||||
fileAttributeResp = fileService.getFileAttribute(vo);
|
||||
return DataResult.success(fileAttributeResp);
|
||||
}
|
||||
|
||||
@PostMapping("deleteDeviceFiles")
|
||||
@ApiOperation(value = "删除文件(删除边端文件)")
|
||||
@LogAnnotation(title = "文件服务", action = "删除文件(删除边端文件)")
|
||||
public DataResult<FileDeleteResp> deleteDeviceFiles(@RequestBody FileForDeviceReqVO fileDeleteReqVO) {
|
||||
FileDeleteResp fileDeleteResp = null;
|
||||
String msg = CommonConstant.Heartbeat.MSG + fileDeleteReqVO.getSerialNo();
|
||||
if (fileService.checkHeartbeat(fileDeleteReqVO.getSerialNo())) {
|
||||
fileDeleteResp = new FileDeleteResp();
|
||||
fileDeleteResp.setDeleteStatus(CommonConstant.TWO);
|
||||
fileDeleteResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
return DataResult.success(fileDeleteResp);
|
||||
}
|
||||
fileDeleteResp = fileService.deleteDeviceFiles(fileDeleteReqVO);
|
||||
return DataResult.success(fileDeleteResp);
|
||||
}
|
||||
|
||||
@PostMapping("fileUploadForDevice")
|
||||
@ApiOperation(value = "文件上传(向边端上传)")
|
||||
//@HzPermission(value = PermissionConstant.REMOTECONTROL_FILE_UPLOAD)
|
||||
@LogAnnotation(title = "文件服务", action = "文件上传(向边端上传)")
|
||||
public DataResult<HeartbeatResp> fileUploadForDevice(@RequestPart("file") MultipartFile file, @RequestParam("stationId") Integer stationId, @RequestParam("serialNo") String serialNo, @RequestParam("filePath") String filePath) {
|
||||
HeartbeatResp resp = fileService.checkHeartAndFileUsing(stationId, serialNo);
|
||||
if (null == resp) {
|
||||
resp = new HeartbeatResp();
|
||||
//文件为空,不给上传
|
||||
if (file.isEmpty()) {
|
||||
resp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
resp.setMsg(BaseResponseCode.FILE_IS_EMPTY.getMsg());
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
// long fileSize = file.getSize();
|
||||
// if (5 * 1024 * 1024 < fileSize) {
|
||||
// throw new BusinessException(BaseResponseCode.FILE_IS_EXCEED_5M);
|
||||
// }
|
||||
resp.setMsg(CommonConstant.Heartbeat.MSG + serialNo + CommonConstant.Heartbeat.SUCCESS);
|
||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
log.info("文件上传(向边端上传)开始上传");
|
||||
fileService.fileUploadForDevice(file, stationId, serialNo, filePath);
|
||||
}
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("downloadFromDevice")
|
||||
@ApiOperation(value = "文件下载(从边端下载到浏览器)")
|
||||
@LogAnnotation(title = "文件服务", action = "文件下载")
|
||||
public DataResult<HeartbeatResp> downloadFromDevice(@RequestBody FileForDeviceReqVO fileForDeviceReqVO) {
|
||||
//todo 测试模拟返回成功
|
||||
/*if(true){
|
||||
HeartbeatResp heart = new HeartbeatResp();
|
||||
heart.setHeartbeatStatus(1);
|
||||
|
||||
return DataResult.success(heart);
|
||||
}*/
|
||||
HeartbeatResp resp = fileService.checkHeartAndFileUsing(fileForDeviceReqVO.getStationId(), fileForDeviceReqVO.getSerialNo());
|
||||
if (null == resp) {
|
||||
resp = new HeartbeatResp();
|
||||
resp.setMsg(CommonConstant.Heartbeat.MSG + fileForDeviceReqVO.getSerialNo() + CommonConstant.Heartbeat.SUCCESS);
|
||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
log.info("文件下载(从边端下载到云端)开始下载");
|
||||
fileService.downloadFromDevice(fileForDeviceReqVO);
|
||||
}
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
|
||||
@PostMapping("downloadProgressBar")
|
||||
@ApiOperation(value = "文件下载进度(从边端下载到浏览器)")
|
||||
public DataResult<FileProcessRespVO> downloadProgressBar(@RequestBody FileProcessReqVO vo, HttpServletResponse response) {
|
||||
//todo 测试模拟返回成功
|
||||
/*if(true){
|
||||
FileProcessRespVO file =new FileProcessRespVO();
|
||||
file.setFileProcess(100);
|
||||
file.setFileStatus(1);
|
||||
return DataResult.success(file);
|
||||
}*/
|
||||
FileProcessRespVO fileProcessRespVO = fileService.getDownloadProgress(vo);
|
||||
return DataResult.success(fileProcessRespVO);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("downloadFromDeviceForWeb")
|
||||
@ApiOperation(value = "文件下载(从边端下载到浏览器准备完成,浏览器已经可以下载)")
|
||||
public void downloadFromDeviceForWeb(@RequestBody FileProcessReqVO vo, HttpServletResponse response) {
|
||||
fileService.downloadFile(vo, response);
|
||||
}
|
||||
|
||||
@PostMapping("downloadFile")
|
||||
@ApiOperation(value = "文件下载(前端分片,从边端下载到浏览器准备完成,浏览器已经可以下载)")
|
||||
public void downloadFile(@RequestBody FileProcessReqVO vo,HttpServletRequest request, HttpServletResponse response) {
|
||||
fileService.downloadFile(vo,request, response);
|
||||
}
|
||||
|
||||
@PostMapping("cancelDownload")
|
||||
@ApiOperation("取消下载")
|
||||
public DataResult cancelDownload(@RequestBody FileProcessReqVO vo) {
|
||||
vo.setCancelStatus(CommonConstant.ZERO);
|
||||
vo.setFileStatus(CommonConstant.ONE);
|
||||
fileService.cancelDownloadFromDevice(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("stopDownload")
|
||||
@ApiOperation("暂停下载")
|
||||
public DataResult stopDownload(@RequestBody FileProcessReqVO vo) {
|
||||
vo.setCancelStatus(CommonConstant.ONE);
|
||||
vo.setFileStatus(CommonConstant.ONE);
|
||||
fileService.cancelDownloadFromDevice(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("cancelUpLoad")
|
||||
@ApiOperation("取消上传")
|
||||
public DataResult cancelUpLoad(@RequestBody FileProcessReqVO vo) {
|
||||
vo.setCancelStatus(CommonConstant.ZERO);
|
||||
vo.setFileStatus(CommonConstant.ZERO);
|
||||
fileService.cancelDownloadFromDevice(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("stopUpLoad")
|
||||
@ApiOperation("暂停上传")
|
||||
public DataResult stopUpLoad(@RequestBody FileProcessReqVO vo) {
|
||||
vo.setCancelStatus(CommonConstant.ONE);
|
||||
vo.setFileStatus(CommonConstant.ZERO);
|
||||
fileService.cancelDownloadFromDevice(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("fileUploadForDeviceList")
|
||||
@ApiOperation(value = "文件批量下发")
|
||||
public DataResult<HeartbeatResp> fileUploadForDeviceList(@RequestBody FileBatchSendReq vo) {
|
||||
List<FileBatchSendDetailReq> list = vo.getList();
|
||||
StringBuffer str = new StringBuffer();
|
||||
//判断设备有没有sn
|
||||
for (FileBatchSendDetailReq f : list) {
|
||||
if (null == f.getSerialNo()) {
|
||||
str.append(f.getDeviceName()).append(",");
|
||||
}
|
||||
}
|
||||
HeartbeatResp heartbeatResp = new HeartbeatResp();
|
||||
if (str.length() > 0) {//若有设备没有配置sn,则不能下发
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(str.toString() + CommonConstant.NOT_SN);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
Map<String, List<FileBatchSendDetailReq>> mapList = list.stream().collect(Collectors.groupingBy(s -> s.getSerialNo()));
|
||||
for (Map.Entry<String, List<FileBatchSendDetailReq>> m : mapList.entrySet()) {
|
||||
HeartbeatResp resp = fileService.checkHeartAndFileUsing(m.getValue().get(0).getStationId(), m.getKey());
|
||||
if (resp != null) {
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
}
|
||||
heartbeatResp.setMsg(CommonConstant.Heartbeat.MSG + CommonConstant.Heartbeat.SUCCESS);
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
log.info("准备文件批量下发");
|
||||
fileService.fileUploadForDeviceList(vo);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
|
||||
@PostMapping("batchProgressBar")
|
||||
@ApiOperation(value = "文件批量下发进度")
|
||||
public DataResult<FileBatchProcessResp> batchProgressBar(@RequestBody FileBatchProcessReqVO vo) {
|
||||
FileBatchProcessResp fileBatchProcessResp = fileService.getFileBatchProcessResp(vo);
|
||||
return DataResult.success(fileBatchProcessResp);
|
||||
}
|
||||
|
||||
@PostMapping("modifyDeviceFiles")
|
||||
@ApiOperation(value = "修改文件(文件夹)属性")
|
||||
public DataResult<FileModifyResp> modifyDeviceFiles(@RequestBody FileForDeviceReqVO fileDeleteReqVO) {
|
||||
FileModifyResp fileModifyResp = null;
|
||||
String msg = CommonConstant.Heartbeat.MSG + fileDeleteReqVO.getSerialNo();
|
||||
if (fileService.checkHeartbeat(fileDeleteReqVO.getSerialNo())) {
|
||||
fileModifyResp = new FileModifyResp();
|
||||
fileModifyResp.setModifyStatus(CommonConstant.TWO);
|
||||
fileModifyResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
return DataResult.success(fileModifyResp);
|
||||
}
|
||||
fileModifyResp = fileService.modifyDeviceFiles(fileDeleteReqVO);
|
||||
return DataResult.success(fileModifyResp);
|
||||
}
|
||||
|
||||
@PostMapping("splitDownloadFromDeviceForWeb")
|
||||
@ApiOperation(value = "文件下载(分片下载)")
|
||||
public void splitDownloadFromDeviceForWeb(@RequestBody FileSplitDownloadReq vo, HttpServletResponse response) {
|
||||
fileService.splitDownloadFromDeviceForWeb(vo, response);
|
||||
}
|
||||
|
||||
@PostMapping("fileUploadForStation")
|
||||
@ApiOperation(value = "文件上传")
|
||||
//@HzPermission(value = PermissionConstant.REMOTECONTROL_FILE_UPLOAD)
|
||||
@TokenIgnore
|
||||
public DataResult<HeartbeatResp> fileUploadForStation(@RequestPart("file") MultipartFile file, @RequestParam("stationId") Integer stationId, @RequestParam("serialNo") String serialNo, @RequestParam("filePath") String filePath) {
|
||||
HeartbeatResp resp = fileService.checkHeartAndFileUsing(stationId, serialNo);
|
||||
if (null == resp) {
|
||||
resp = new HeartbeatResp();
|
||||
//文件为空,不给上传
|
||||
if (file.isEmpty()) {
|
||||
resp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
resp.setMsg(BaseResponseCode.FILE_IS_EMPTY.getMsg());
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
// long fileSize = file.getSize();
|
||||
// if (5 * 1024 * 1024 < fileSize) {
|
||||
// throw new BusinessException(BaseResponseCode.FILE_IS_EXCEED_5M);
|
||||
// }
|
||||
resp.setMsg(CommonConstant.Heartbeat.MSG + serialNo + CommonConstant.Heartbeat.SUCCESS);
|
||||
resp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
log.info("文件上传(向边端上传)开始上传");
|
||||
fileService.fileUploadForDevice(file, stationId, serialNo, filePath);
|
||||
}
|
||||
return DataResult.success(resp);
|
||||
}
|
||||
|
||||
@PostMapping("chargeFilePermission")
|
||||
@ApiOperation(value = "修改文件权限")
|
||||
public DataResult<HeartbeatResp> chargeFilePermission(@RequestBody FilePermissionReq vo) {
|
||||
HeartbeatResp heartbeatResp = fileService.chargeFilePermission(vo);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("chargeFilePermissionProgressBar")
|
||||
@ApiOperation(value = "修改文件权限下发进度")
|
||||
public DataResult<FilePermissionResp> chargeFilePermissionProgressBar(@RequestBody FilePermissionReq vo) {
|
||||
FilePermissionResp filePermissionResp = fileService.chargeFilePermissionProgressBar(vo);
|
||||
return DataResult.success(filePermissionResp);
|
||||
}
|
||||
|
||||
@PostMapping("uploadFileToMinIo")
|
||||
@ApiOperation(value = "将文件传入MinIo")
|
||||
public DataResult<Picture> uploadFileToMinIo(@RequestBody FileForDeviceReqVO vo, HttpServletRequest request) {
|
||||
Picture picture = fileService.uploadFileToMinIo(vo, request);
|
||||
return DataResult.success(picture);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,228 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.constant.FileTypeConstant;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import com.ho.common.tools.vo.req.CardInfoReqVo;
|
||||
import com.ho.filecenter.entity.CardInfo;
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.service.CardInfoService;
|
||||
import com.ho.filecenter.service.FlowMonitorService;
|
||||
import com.ho.filecenter.service.MobileApiService;
|
||||
import com.ho.filecenter.service.TelecomApiService;
|
||||
import com.ho.filecenter.vo.flowMonitor.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2024/1/16 11:13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "flowMonitor")
|
||||
@Api(tags = "多媒体-流量监控")
|
||||
@Slf4j
|
||||
public class FlowMonitorController {
|
||||
@Autowired
|
||||
FlowMonitorService flowMonitorService;
|
||||
|
||||
@Autowired
|
||||
MobileApiService mobileApiService;
|
||||
|
||||
@Autowired
|
||||
TelecomApiService telecomApiService;
|
||||
|
||||
@Autowired
|
||||
CardInfoService cardInfoService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
//套餐的增删改查
|
||||
//新增
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "新增套餐")
|
||||
// @LogAnnotation(title = "业务模块-流量监控", action = "新增")
|
||||
public DataResult add(@RequestBody @Valid FlowMonitorAddVo vo) {
|
||||
flowMonitorService.insertSelective(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("deleteByIds")
|
||||
//@LogAnnotation(title = "业务模块-流量监控", action = "删除套餐")
|
||||
@ApiOperation(value = "删除套餐接口")
|
||||
public DataResult deleteByIds(@RequestBody List<Integer> ids) {
|
||||
flowMonitorService.deletedByIds(ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
// @LogAnnotation(title = "业务模块-流量监控", action = "更新套餐")
|
||||
@ApiOperation(value = "更新套餐接口")
|
||||
public DataResult update(@RequestBody @Valid FlowMonitorPutVo vo) {
|
||||
flowMonitorService.updateByPrimaryKeySelective(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
//根据运营商查询各种套餐 //根据运营商查询各种套餐
|
||||
@PostMapping("select")
|
||||
@ApiOperation(value = "查询套餐")
|
||||
public DataResult<List<FlowMonitorAllData>> select(@RequestBody @Valid FlowMonitor vo) {
|
||||
List<FlowMonitorAllData> list = flowMonitorService.selectAllPack(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
//根据套餐id查询卡列表
|
||||
@PostMapping("selectByCardInfo")
|
||||
@ApiOperation(value = "根据套餐id查询卡列表")
|
||||
public DataResult<PageResult<CardInfoDate>> selectByCardInfo(@RequestBody @Valid CardSelectVO vo) {
|
||||
List<CardInfoDate> pointList = flowMonitorService.selectByCardInfo(vo);
|
||||
for (CardInfoDate cardInfoDate : pointList) {
|
||||
if (null == cardInfoDate.getStatus()) {
|
||||
cardInfoDate.setStatus(CommonConstant.ZERO);
|
||||
}
|
||||
}
|
||||
//java内存分页
|
||||
PageResult pageResult = new PageResult<>();
|
||||
if (!pointList.isEmpty()) {
|
||||
List list = PageUtils.dealList(pointList, vo.getPageNum(), vo.getPageSize());
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(pointList.size());
|
||||
pageResult.setTotalPages(pointList.size() / vo.getPageSize() + 1);
|
||||
} else {
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
|
||||
//卡信息的录入 增删改查
|
||||
//新增
|
||||
@PostMapping("addCardInfo")
|
||||
@ApiOperation(value = "新增移动卡信息")
|
||||
// @LogAnnotation(title = "业务模块-新增移动卡信息", action = "新增")
|
||||
public DataResult addCardInfo(@RequestBody @Valid CardAddVo vo) {
|
||||
flowMonitorService.addCardInfo(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("deleteByCardIds")
|
||||
// @LogAnnotation(title = "业务模块-删除卡信息", action = "删除卡信息")
|
||||
@ApiOperation(value = "删除卡信息接口")
|
||||
public DataResult deleteByCardIds(@RequestBody List<Integer> ids) {
|
||||
cardInfoService.deletedByIds(ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PutMapping("updateCard")
|
||||
// @LogAnnotation(title = "业务模块-更新卡信息", action = "更新卡信息")
|
||||
@ApiOperation(value = "更新卡信息接口")
|
||||
public DataResult updateCard(@RequestBody @Valid CardInfo vo) {
|
||||
cardInfoService.updateByPrimaryKeySelective(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//查询所以未绑定未绑定电站的卡号
|
||||
@PostMapping("selectNotStation")
|
||||
@ApiOperation(value = "查询所以未绑定未绑定电站的卡号")
|
||||
// @LogAnnotation(title = "业务模块-新增移动卡信息", action = "新增")
|
||||
public DataResult<List<CardInfo>> selectNotStation(@RequestBody @Valid CardInfo vo) {
|
||||
List<CardInfo> list = cardInfoService.selectNotStation(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移动卡号excel表导入
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
@PostMapping("/importExcel")
|
||||
@ApiOperation(value = "移动卡号excel表导入")
|
||||
public DataResult importExcel(@RequestBody MultipartFile file, @RequestParam("flowMonitorId") Integer flowMonitorId) {
|
||||
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = "";
|
||||
if (originalFilename != null && originalFilename.lastIndexOf(".") != -1) {
|
||||
extension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
|
||||
extension = extension.toLowerCase();
|
||||
}
|
||||
if (!FileTypeConstant.XLS.equals(extension)) {
|
||||
throw new BusinessException(BaseResponseCode.FILE_FORMAT_ONLY);
|
||||
}
|
||||
List<MobileImportVO> list = new ArrayList<>();
|
||||
try {
|
||||
list = EasyExcel.read(file.getInputStream()).head(MobileImportVO.class).sheet().doReadSync();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
int count = cardInfoService.mobileInsertList(list, flowMonitorId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增电信套餐刷新接口
|
||||
*/
|
||||
@PostMapping("telecomRefresh")
|
||||
@ApiOperation(value = "新增电信套餐刷新接口")
|
||||
public DataResult getTelecomRefresh() {
|
||||
String telecomRefresh = telecomApiService.getTelecomRefresh();
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 电信卡号excel表导入
|
||||
*
|
||||
* @param file
|
||||
|
||||
@PostMapping("/importTeleExcel")
|
||||
@ApiOperation(value = "电信卡号excel表导入") */
|
||||
public DataResult importTeleExcel(@RequestBody MultipartFile file, @RequestParam("flowMonitorId") Integer flowMonitorId) {
|
||||
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String extension = "";
|
||||
if (originalFilename != null && originalFilename.lastIndexOf(".") != -1) {
|
||||
extension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
|
||||
extension = extension.toLowerCase();
|
||||
}
|
||||
if (!FileTypeConstant.XLS.equals(extension)) {
|
||||
throw new BusinessException(BaseResponseCode.FILE_FORMAT_ONLY);
|
||||
}
|
||||
List<TeleReqVo> list = new ArrayList<>();
|
||||
try {
|
||||
list = EasyExcel.read(file.getInputStream()).head(TeleReqVo.class).sheet().doReadSync();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
int count = cardInfoService.List(list, flowMonitorId);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.vo.mqtt.HeartbeatReq;
|
||||
import com.ho.filecenter.vo.resp.HeartbeatResp;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description 心跳检测
|
||||
* Author xueweizhi
|
||||
* Date 2023/3/24 16:09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "heartbeatCheck")
|
||||
@Api(tags = "心跳检测")
|
||||
@Slf4j
|
||||
public class HeartbeatCheckController {
|
||||
|
||||
@Autowired
|
||||
BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
public static final Long TIME_LIMIT = 100L;
|
||||
|
||||
@PostMapping("getHeartbeat")
|
||||
@ApiOperation(value = "心跳检测")
|
||||
public DataResult<HeartbeatResp> getHeartbeat(@RequestBody HeartbeatReq vo) {
|
||||
HeartbeatResp heartbeatResp = new HeartbeatResp();
|
||||
//检测心跳
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(vo.getStationId());
|
||||
deviceReqVO.setSrcId(vo.getSrcId());
|
||||
List<DeviceRespVO> deviceList = businessFeignClient.getDeviceSN(deviceReqVO);
|
||||
if (deviceList.size() == 0 || null == deviceList.get(0).getSerialNo()) {
|
||||
log.info("getHeartbeat 当前设备没有配置SN");
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(CommonConstant.DEVICE_NO_SN);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
String sn = deviceList.get(0).getSerialNo();
|
||||
String heartbeatKey = RedisKeyConstant.HEARTBEAT + sn;
|
||||
String msg = CommonConstant.Heartbeat.MSG + sn;
|
||||
if (redisService.hasKey(heartbeatKey)) {
|
||||
Map<Object, Object> hgetall = redisService.hgetall(heartbeatKey);
|
||||
Date updateTime = (Date) hgetall.get(CommonConstant.UPDATE_TIME);
|
||||
Date date = new Date();
|
||||
long between = DateUtil.between(updateTime, date, DateUnit.MINUTE);
|
||||
if (between >= 5) {
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
log.info("getHeartbeat 超过5分钟没有检测到心跳:{}", between);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.SUCCESS);
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
return DataResult.success(heartbeatResp);
|
||||
} else {
|
||||
log.info("getHeartbeat 没有检测到心跳{}", heartbeatKey);
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(msg + sn + CommonConstant.Heartbeat.FAIL);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,344 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.entity.PlanCurveOperationRecordReq;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.point.PointReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.business.vo.resp.point.PointRespVO;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.feignclient.UserFeignClient;
|
||||
import com.ho.filecenter.service.OrderSendService;
|
||||
import com.ho.filecenter.vo.mqtt.*;
|
||||
import com.ho.filecenter.vo.resp.HeartbeatResp;
|
||||
import com.ho.filecenter.vo.resp.OrderProcessDetailResp;
|
||||
import com.ho.filecenter.vo.resp.OrderProcessResp;
|
||||
import com.ho.user.api.vo.req.SysSubDictVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Description 指令下发
|
||||
* Author xueweizhi
|
||||
* Date 2023/3/15 12:10
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "orderSend")
|
||||
@Api(tags = "指令下发")
|
||||
@Slf4j
|
||||
public class OrderSendController {
|
||||
|
||||
@Autowired
|
||||
BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
OrderSendService orderSendService;
|
||||
|
||||
@Autowired
|
||||
UserFeignClient userFeignClient;
|
||||
|
||||
public static final Long TIME_LIMIT = 90L;
|
||||
|
||||
@PostMapping("orderIssued")
|
||||
@ApiOperation(value = "指令下发")
|
||||
//@HzPermission(value = {PermissionConstant.REMOTECONTROL_COMMAND_BATCHDISTRIBUTION,PermissionConstant.STRATEGY_PLANCURVEDIS_COMMANDISSUANCE,PermissionConstant.REMOTECONTROL_COMMAND_SINGLEREFRESH})
|
||||
// @LogAnnotation(title = "命令下发", action = "指令下发")
|
||||
public DataResult<HeartbeatResp> orderIssued(@RequestBody OrderIssuedReqVO vo) {
|
||||
// String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
// UserDetailRespVO userDetailRespVO = redisService.getUserDetailByToken(token);
|
||||
// String userName = userDetailRespVO.getUsername();
|
||||
// String userNameKey = redisService.getUserNameKey(userDetailRespVO, userName);
|
||||
// SimpleUser user = (SimpleUser) redisService.get(userNameKey);
|
||||
return getDataResult(vo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DataResult getDataResult(OrderIssuedReqVO vo) {
|
||||
HeartbeatResp heartbeatResp = new HeartbeatResp();
|
||||
if (vo.getList() == null || vo.getList().isEmpty() ) {
|
||||
throw new BusinessException(BaseResponseCode.DATA_NOT_EXISTS);
|
||||
}
|
||||
|
||||
//组装计划曲线下发记录参数
|
||||
PlanCurveOperationRecordReq planCurveOperationRecordReq = new PlanCurveOperationRecordReq();
|
||||
planCurveOperationRecordReq.setUserId(vo.getUserId());
|
||||
if(vo.getPlanTemId() != null){
|
||||
planCurveOperationRecordReq.setLatestPlanningCurve(String.valueOf(vo.getPlanTemId()));
|
||||
}
|
||||
planCurveOperationRecordReq.setOperateTime(DateUtil.format(new Date(),CommonConstant.DATE));
|
||||
Integer stationId = vo.getList().get(0).getStationId();
|
||||
planCurveOperationRecordReq.setStationId(stationId);
|
||||
|
||||
String orderUsingKey = stationId + ":" + RedisKeyConstant.ORDER_USING;
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setStationId(stationId);
|
||||
deviceReqVO.setSrcId(vo.getList().get(0).getSrcId());
|
||||
List<DeviceRespVO> deviceList = businessFeignClient.getDeviceSN(deviceReqVO);
|
||||
if (deviceList.size() == 0) {
|
||||
log.info("当前设备没有配置SN");
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(CommonConstant.DEVICE_NO_SN);
|
||||
planCurveOperationRecordReq.setOperateResult(CommonConstant.DEVICE_NO_SN);
|
||||
planCurveOperationRecordReq.setStatus(0);
|
||||
//保存操作记录信息
|
||||
DataResult result = businessFeignClient.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
String sn = deviceList.get(0).getSerialNo();
|
||||
vo.setSn(sn);
|
||||
//检测心跳
|
||||
String heartbeatKey = RedisKeyConstant.HEARTBEAT + sn;
|
||||
String msg = CommonConstant.Heartbeat.MSG + sn;
|
||||
//校验修改值范围
|
||||
Boolean checkValueFlag = false;
|
||||
List<OrderIssuedVO> list = vo.getList();
|
||||
for (OrderIssuedVO orderIssuedVO : list) {
|
||||
if (orderIssuedVO.getMaxValue().compareTo(orderIssuedVO.getModifyValue()) < 0 || orderIssuedVO.getMinValue().compareTo(orderIssuedVO.getModifyValue()) > 0) {
|
||||
log.info("修改值不符合要求");
|
||||
checkValueFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (checkValueFlag) {
|
||||
//将值校验放在心跳检测中一起返回,如果校验不符合要求,则返回心跳为0,便于前端停止循环调用
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(CommonConstant.CHECK_MODIFY_VALUE);
|
||||
planCurveOperationRecordReq.setOperateResult(CommonConstant.CHECK_MODIFY_VALUE);
|
||||
planCurveOperationRecordReq.setStatus(0);
|
||||
//保存操作记录信息
|
||||
DataResult result = businessFeignClient.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
if (redisService.hasKey(heartbeatKey)) {
|
||||
Map<Object, Object> hgetall = redisService.hgetall(heartbeatKey);
|
||||
Date updateTime = (Date) hgetall.get(CommonConstant.UPDATE_TIME);
|
||||
Date date = new Date();
|
||||
long between = DateUtil.between(updateTime, date, DateUnit.MINUTE);
|
||||
if (between >= 5) {
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
log.info("orderIssued 命令下发超过5分钟没有检测到心跳:{}", between);
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
planCurveOperationRecordReq.setStatus(0);
|
||||
planCurveOperationRecordReq.setOperateResult(msg + CommonConstant.Heartbeat.FAIL);
|
||||
//保存操作记录信息
|
||||
DataResult result = businessFeignClient.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.SUCCESS);
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ONE);
|
||||
if (redisService.hasKey(orderUsingKey)) {
|
||||
heartbeatResp.setMsg(BaseResponseCode.ORDER_IS_USING.getMsg());
|
||||
planCurveOperationRecordReq.setStatus(0);
|
||||
planCurveOperationRecordReq.setOperateResult(BaseResponseCode.ORDER_IS_USING.getMsg());
|
||||
//保存操作记录信息
|
||||
DataResult result = businessFeignClient.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
log.info("指令下发正常开始下发");
|
||||
orderSendService.orderIssued(vo);
|
||||
if(vo.getPlanTemId() != null){
|
||||
String hourValue ="";
|
||||
String minuteValue ="";
|
||||
String hourCol ="";
|
||||
String minuteCol ="";
|
||||
//获取计划曲线执行测点数据
|
||||
PointReq pointReq = new PointReq();
|
||||
pointReq.setName("计划曲线每日刷新时间");
|
||||
pointReq.setStationId(stationId);
|
||||
pointReq.setSrcId(vo.getList().get(0).getSrcId());
|
||||
DataResult<PageResult<PointRespVO>> timeList = new DataResult<>();
|
||||
timeList = businessFeignClient.page(pointReq);
|
||||
for(PointRespVO pointRespVO:timeList.getData().getList()){
|
||||
if(pointRespVO.getColName().contains("(时0-23)")){
|
||||
hourValue = String.valueOf(pointRespVO.getValue());
|
||||
hourValue = hourValue.substring(0,hourValue.indexOf("."));
|
||||
hourCol = pointRespVO.getCol();
|
||||
}else{
|
||||
minuteValue = String.valueOf(pointRespVO.getValue());
|
||||
minuteValue = minuteValue.substring(0,minuteValue.indexOf("."));
|
||||
minuteCol = pointRespVO.getCol();
|
||||
}
|
||||
}
|
||||
if(vo.getList().size()<62){
|
||||
for(OrderIssuedVO orderIssuedVO:vo.getList()){
|
||||
if(orderIssuedVO.getCol().equals(hourCol)){
|
||||
hourValue = orderIssuedVO.getModifyValue().toString();
|
||||
}else if(orderIssuedVO.getCol().equals(minuteCol)){
|
||||
minuteValue = orderIssuedVO.getModifyValue().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
minuteValue = "".equals(minuteValue)?"00":minuteValue;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY,"".equals(hourValue)?CommonConstant.ZERO:Integer.valueOf(hourValue));
|
||||
calendar.set(Calendar.MINUTE,Integer.valueOf(minuteValue));
|
||||
calendar.set(Calendar.SECOND,CommonConstant.ZERO);
|
||||
int a = DateUtil.compare(new Date(),DateUtil.parse(hourValue+":"+minuteValue),CommonConstant.DATE_Hm);
|
||||
if(a== 1){
|
||||
calendar.add(Calendar.DATE,1);
|
||||
}
|
||||
planCurveOperationRecordReq.setEffectiveTime(DateUtil.format(calendar.getTime(),CommonConstant.DATE));
|
||||
planCurveOperationRecordReq.setStatus(1);
|
||||
planCurveOperationRecordReq.setOperateResult("成功下发");
|
||||
//保存操作记录信息
|
||||
DataResult result = businessFeignClient.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
}
|
||||
return DataResult.success(heartbeatResp);
|
||||
} else {
|
||||
log.info("orderIssued 命令下发没有检测到心跳{}", heartbeatKey);
|
||||
heartbeatResp.setHeartbeatStatus(CommonConstant.ZERO);
|
||||
heartbeatResp.setMsg(msg + CommonConstant.Heartbeat.FAIL);
|
||||
planCurveOperationRecordReq.setStatus(0);
|
||||
planCurveOperationRecordReq.setOperateResult(msg + CommonConstant.Heartbeat.FAIL);
|
||||
//保存操作记录信息
|
||||
DataResult result = businessFeignClient.planCurveOperationRecord(planCurveOperationRecordReq);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("progressBar")
|
||||
@ApiOperation(value = "指令下发进度")
|
||||
@TokenIgnore
|
||||
public DataResult<OrderProcessResp> progressBar(@RequestBody OrderProgressReqVO vo) {
|
||||
String key = vo.getStationId() + ":" + vo.getSrcId();
|
||||
log.info("指令下发进度 key:{}", key);
|
||||
OrderProcessResp orderProcessResp = new OrderProcessResp();
|
||||
List<OrderProcessDetailResp> processDetailRespList = new ArrayList<>();
|
||||
if (!redisService.hasKey(key)) {
|
||||
orderProcessResp.setIsEnd(CommonConstant.TWO);
|
||||
orderProcessResp.setMsg(BaseResponseCode.COMMAND_IS_EMPTY.getMsg());
|
||||
orderProcessResp.setProcessList(processDetailRespList);
|
||||
return DataResult.success(orderProcessResp);
|
||||
}
|
||||
Long expireTime = redisService.getExpire(key, TimeUnit.SECONDS);
|
||||
Map<Object, Object> dataMap = redisService.hgetall(key);
|
||||
log.info("redis dataMap {}", dataMap);
|
||||
if (CommonConstant.ZERO.equals(dataMap.get(RedisKeyConstant.IS_END))) {
|
||||
if (expireTime <= TIME_LIMIT) {
|
||||
redisService.delete(vo.getStationId() + ":" + RedisKeyConstant.ORDER_USING);
|
||||
orderProcessResp.setIsEnd(CommonConstant.TWO);
|
||||
orderProcessResp.setMsg(CommonConstant.IssuedFlag.TIMEOUT_FAIL);
|
||||
} else {
|
||||
orderProcessResp.setIsEnd(CommonConstant.ZERO);
|
||||
orderProcessResp.setMsg(CommonConstant.IssuedFlag.ORDER_PROCESS);
|
||||
orderProcessResp.setProcessList(processDetailRespList);
|
||||
return DataResult.success(orderProcessResp);
|
||||
}
|
||||
} else {
|
||||
StringBuffer strSuccess = new StringBuffer();
|
||||
StringBuffer strFail = new StringBuffer();
|
||||
OrderProcessDetailResp orderProcessDetailResp = null;
|
||||
for (Map.Entry<Object, Object> s : dataMap.entrySet()) {
|
||||
if (!RedisKeyConstant.IS_END.equals(s.getKey())) {
|
||||
//只给前端返回下发失败的列表
|
||||
if (CommonConstant.IssuedFlag.UPDATE_FAIL.equals(String.valueOf(s.getValue()))) {
|
||||
orderProcessDetailResp = new OrderProcessDetailResp();
|
||||
orderProcessDetailResp.setCol(String.valueOf(s.getKey()));
|
||||
orderProcessDetailResp.setMsg(String.valueOf(s.getValue()));
|
||||
processDetailRespList.add(orderProcessDetailResp);
|
||||
strFail.append(s.getKey() + ",");
|
||||
} else {
|
||||
strSuccess.append(s.getKey() + ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
//缩短提示,只要有一个失败,那么isEnd就给2,否则给1
|
||||
if (strFail.length() > 0) {
|
||||
orderProcessResp.setIsEnd(CommonConstant.TWO);
|
||||
orderProcessResp.setMsg(strFail.toString() + CommonConstant.IssuedFlag.UPDATE_FAIL);
|
||||
} else {
|
||||
orderProcessResp.setIsEnd(CommonConstant.ONE);
|
||||
orderProcessResp.setMsg(strSuccess.toString() + CommonConstant.IssuedFlag.SUCCESS);
|
||||
}
|
||||
}
|
||||
orderProcessResp.setProcessList(processDetailRespList);
|
||||
return DataResult.success(orderProcessResp);
|
||||
}
|
||||
|
||||
@PostMapping("apiOrderIssued")
|
||||
@ApiOperation(value = "指令下发(对外提供)")
|
||||
@TokenIgnore
|
||||
public DataResult<HeartbeatResp> apiOrderIssued(@RequestBody ApiOrderIssuedReqVO vo) {
|
||||
SysSubDictVO sysSubDictVO = new SysSubDictVO();
|
||||
sysSubDictVO.setType(CommonConstant.PUSH_DATA);
|
||||
Map<String, String> sysSubDict = userFeignClient.getSysSubDict(sysSubDictVO);
|
||||
String stationId = sysSubDict.get(vo.getApiSecret());
|
||||
HeartbeatResp heartbeatResp = new HeartbeatResp();
|
||||
if (stationId != null) {
|
||||
List<OrderIssuedVO> list = vo.getList();
|
||||
for (OrderIssuedVO orderIssuedVO : list) {
|
||||
orderIssuedVO.setStationId(Integer.valueOf(stationId));
|
||||
}
|
||||
DataResult<HeartbeatResp> heartbeatRespDataResult = orderIssued(vo);
|
||||
heartbeatResp = heartbeatRespDataResult.getData();
|
||||
}
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
|
||||
@PostMapping("apiProgressBar")
|
||||
@ApiOperation(value = "指令下发进度(对外提供)")
|
||||
@TokenIgnore
|
||||
public DataResult<OrderProcessResp> apiProgressBar(@RequestBody ApiOrderProgressReqVO apiVo) {
|
||||
SysSubDictVO sysSubDictVO = new SysSubDictVO();
|
||||
sysSubDictVO.setType(CommonConstant.PUSH_DATA);
|
||||
Map<String, String> sysSubDict = userFeignClient.getSysSubDict(sysSubDictVO);
|
||||
String stationId = sysSubDict.get(apiVo.getApiSecret());
|
||||
OrderProcessResp orderProcessResp = new OrderProcessResp();
|
||||
if (stationId != null) {
|
||||
OrderProgressReqVO vo = new OrderProgressReqVO();
|
||||
vo.setStationId(Integer.valueOf(stationId));
|
||||
vo.setSrcId(apiVo.getSrcId());
|
||||
DataResult<OrderProcessResp> orderProcessRespDataResult = progressBar(vo);
|
||||
orderProcessResp = orderProcessRespDataResult.getData();
|
||||
}
|
||||
return DataResult.success(orderProcessResp);
|
||||
}
|
||||
|
||||
@PostMapping("sendPlanPowerOrder")
|
||||
@ApiOperation(value = "命令下发曲线")
|
||||
// @LogAnnotation(title = "命令下发曲线", action = "命令下发曲线")
|
||||
@TokenIgnore
|
||||
public DataResult<HeartbeatResp> sendPlanPowerOrder(@RequestBody OrderPlanPowerReq vo) {
|
||||
HeartbeatResp heartbeatResp = orderSendService.sendPlanPowerOrder(vo);
|
||||
return DataResult.success(heartbeatResp);
|
||||
}
|
||||
|
||||
@PostMapping("planPowerProgressBar")
|
||||
@ApiOperation(value = "指令下发进度")
|
||||
@TokenIgnore
|
||||
public DataResult<OrderProcessResp> planPowerProgressBar(@RequestBody OrderPlanPowerReq vo) {
|
||||
OrderProcessResp orderProcessResp = orderSendService.planPowerProgressBar(vo);
|
||||
return DataResult.success(orderProcessResp);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("orderIssued4plan")
|
||||
@ApiOperation(value = "指令下发")
|
||||
@TokenIgnore
|
||||
public DataResult<HeartbeatResp> orderIssued4plan(@RequestBody OrderIssuedReqVO vo) {
|
||||
return this.getDataResult(vo);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: OTA升级
|
||||
* @DateTime: 2023/8/2 10:29
|
||||
*/
|
||||
|
||||
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.entity.UserDetailRespVO;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.filecenter.entity.Otaupgrad;
|
||||
import com.ho.filecenter.service.OtaupgradService;
|
||||
import com.ho.filecenter.vo.OtaFileVO;
|
||||
import com.ho.filecenter.vo.ScheduleReqVo;
|
||||
import com.ho.filecenter.vo.UpdateRecords;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "otaupgrad")
|
||||
@Api(tags = "OTA升级")
|
||||
@Slf4j
|
||||
public class OtaupgradController {
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
@Autowired
|
||||
OtaupgradService otaupgradService;
|
||||
|
||||
@PostMapping("page")
|
||||
@ApiOperation(value = "分页查询")
|
||||
public DataResult<PageResult<Otaupgrad>> page(@RequestBody OtaFileVO vo) {
|
||||
PageResult<Otaupgrad> pageResult = otaupgradService.page(vo);
|
||||
return DataResult.success(pageResult);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("hisFile")
|
||||
@ApiOperation(value = "查询更新记录")
|
||||
public DataResult<List<UpdateRecords>> SelectHisFile(@RequestBody OtaFileVO vo) {
|
||||
List<UpdateRecords> list = otaupgradService.selectHisFile(vo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("upgradation")
|
||||
@ApiOperation(value = "设备升级")
|
||||
public DataResult upgradation(@RequestPart("file") MultipartFile file ,
|
||||
@RequestParam("stationIdAndDeviceList") List<String> stationIdAndDeviceList,
|
||||
@RequestParam("deviceName") String deviceName,
|
||||
@RequestParam("version") String version,
|
||||
@RequestParam("updateCause") String updateCause,
|
||||
@RequestParam("updateTime") String updateTime,HttpServletRequest request) throws Exception {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
if(stationIdAndDeviceList.isEmpty()){
|
||||
throw new BusinessException(BaseResponseCode.NOT_CHECK_STATION_DEVICE);
|
||||
}
|
||||
UserDetailRespVO userDetailRespVO = redisService.getUserDetailByToken(token);
|
||||
String userName = userDetailRespVO.getUsername();
|
||||
String userNameKey = redisService.getUserNameKey(userDetailRespVO, userName);
|
||||
SimpleUser user = (SimpleUser) redisService.get(userNameKey);
|
||||
OtaFileVO vo =new OtaFileVO();
|
||||
vo.setDeviceName(deviceName);
|
||||
vo.setStationIdAndDeviceList(stationIdAndDeviceList);
|
||||
vo.setUpdateCause(updateCause);
|
||||
vo.setVersion(version);
|
||||
//对时间进行比对
|
||||
vo.setUpdateTime(updateTime);
|
||||
otaupgradService.tage(file,vo);
|
||||
otaupgradService.upgradation(file, vo, user);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("getUpgradeProgress")
|
||||
@ApiOperation(value = "升级进度")
|
||||
public DataResult<List<ScheduleReqVo>> getUpgradeProgress(@RequestBody OtaFileVO vo) {
|
||||
List<ScheduleReqVo> scheduleReqVo = otaupgradService.getUpgradeProgress(vo);
|
||||
return DataResult.success(scheduleReqVo);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,140 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.vo.req.CardInfoReqVo;
|
||||
import com.ho.filecenter.entity.CardInfo;
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.service.CardInfoService;
|
||||
import com.ho.filecenter.service.FileService;
|
||||
import com.ho.filecenter.service.FlowMonitorService;
|
||||
import com.ho.filecenter.service.MobileApiService;
|
||||
import com.ho.filecenter.vo.flowMonitor.CardAddVo;
|
||||
import com.ho.filecenter.vo.flowMonitor.CardInfoDate;
|
||||
import com.ho.filecenter.vo.flowMonitor.PackageDetailRespVo;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 提供给外部调用,不校验token
|
||||
* Author yule
|
||||
* Date 2023/2/6 10:08
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.FILE_CENTER + "outerApi")
|
||||
@ApiIgnore
|
||||
@Slf4j
|
||||
public class OuterApiController {
|
||||
|
||||
@Autowired
|
||||
FileService fileService;
|
||||
|
||||
@Autowired
|
||||
CardInfoService cardInfoService;
|
||||
|
||||
@Autowired
|
||||
FlowMonitorService flowMonitorService;
|
||||
|
||||
@Autowired
|
||||
MobileApiService mobileApiService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@PostMapping("/getBySnIsOnline")
|
||||
@TokenIgnore
|
||||
public Boolean getBySnIsOnline(@RequestBody String sn) {
|
||||
return fileService.checkHeartbeat(sn);
|
||||
}
|
||||
|
||||
//电站接口新增移动卡信息
|
||||
@PostMapping("insertValue")
|
||||
@TokenIgnore
|
||||
public DataResult insertValue(@RequestBody @Valid CardInfoReqVo vo) {
|
||||
//判断增加的卡号是否重复
|
||||
CardInfo cardValue = cardInfoService.selectByCard(vo.getCard());
|
||||
if (cardValue != null) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_ICCID_EXISTS);
|
||||
}
|
||||
//判断初始状态是否存在不存在则赋值未激活状态
|
||||
if (vo.getCardStatus() == null) {
|
||||
vo.setCardStatus(CommonConstant.ZERO);
|
||||
}
|
||||
CardInfo cardInfo = new CardInfo();
|
||||
BeanUtils.copyProperties(vo, cardInfo);
|
||||
//根据套餐id查询类型
|
||||
FlowMonitor flowMonitor = flowMonitorService.selectById(vo.getFlowMonitorId());
|
||||
if (CommonConstant.ONE.equals(flowMonitor.getPackageType())) {
|
||||
cardInfo.setPackageType(flowMonitor.getPackageType());
|
||||
cardInfoService.insertValue(cardInfo);
|
||||
String singleCard = mobileApiService.getSingleCard(vo.getCard());
|
||||
if (singleCard != null) {
|
||||
PackageDetailRespVo packageDetailRespVo = new PackageDetailRespVo();
|
||||
List<CardInfoDate> cardInfoList = new ArrayList<>();
|
||||
CardInfoDate cardInfoDate = new CardInfoDate();
|
||||
cardInfoDate.setCardNo(vo.getCard());
|
||||
cardInfoDate.setStationId(vo.getStationId());
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
cardInfoDate.setUpdateTime(format);
|
||||
cardInfoDate.setUserAmount(singleCard);
|
||||
cardInfoList.add(cardInfoDate);
|
||||
packageDetailRespVo.setCardInfoList(cardInfoList);
|
||||
String key = "flowMonitor:mobile:" + vo.getFlowMonitorId();
|
||||
log.info("flowMonitorKey:" + key);
|
||||
log.info("packageDetailRespVo:" + packageDetailRespVo);
|
||||
redisService.set(key, packageDetailRespVo);
|
||||
}
|
||||
} else if (CommonConstant.THREE.equals(flowMonitor.getPackageType())) {
|
||||
CardAddVo addVo = new CardAddVo();
|
||||
BeanUtils.copyProperties(vo, addVo);
|
||||
flowMonitorService.addCardInfo(addVo);
|
||||
}
|
||||
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//电站接口更新移动卡信息
|
||||
@PostMapping("updateValue")
|
||||
@TokenIgnore
|
||||
public DataResult updateValue(@RequestBody @Valid CardInfoReqVo vo) {
|
||||
CardInfo cardInfo = new CardInfo();
|
||||
BeanUtils.copyProperties(vo, cardInfo);
|
||||
cardInfoService.updateByPrimaryKeySelective(cardInfo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("selectByCondition")
|
||||
@ApiOperation(value = "根据条件查询")
|
||||
@TokenIgnore
|
||||
public DataResult<List<CardInfoReqVo>> selectByCondition(@RequestBody @Valid CardInfoReqVo cardInfo) {
|
||||
List<CardInfoReqVo> list = cardInfoService.selectByCondition(cardInfo);
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
@DeleteMapping("deleteByCardIds")
|
||||
@ApiOperation(value = "删除卡信息接口")
|
||||
@TokenIgnore
|
||||
public DataResult deleteByCardIds(@RequestBody List<Integer> ids) {
|
||||
cardInfoService.deletedByIds(ids);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,157 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.filecenter.entity.Power;
|
||||
|
||||
import com.ho.filecenter.service.PowerDetailService;
|
||||
import com.ho.filecenter.service.PowerService;
|
||||
import com.ho.filecenter.vo.PowerDetailVo;
|
||||
import com.ho.filecenter.vo.PowerImport;
|
||||
import com.ho.filecenter.vo.QueryPower;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 发电量和收益功能
|
||||
* @DateTime: 2023/3/16 10:45
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "power")
|
||||
@Api(tags = "发电量和收益功能-excel基本信息")
|
||||
@Slf4j
|
||||
public class PowerController {
|
||||
@Autowired
|
||||
PowerService powerService;
|
||||
|
||||
@Autowired
|
||||
PowerDetailService powerDetailService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
//查(无入参)
|
||||
@PostMapping("/queryList")
|
||||
@ApiOperation(value = "发电量和收益功能列表")
|
||||
|
||||
public DataResult<List<Power>> queryList(HttpServletRequest request, @RequestBody QueryPower power) {
|
||||
DataResult<List<Power>> result = DataResult.success();
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
List<Power> powerList = powerService.queryList(user.getGroupId(), power);
|
||||
List<Power> list =new ArrayList<>();
|
||||
//根据项目名称进行过滤
|
||||
list = powerList.stream().collect(Collectors.collectingAndThen(
|
||||
Collectors.toCollection(() -> new TreeSet<>(
|
||||
Comparator.comparing(p -> p.getProjectName()))), ArrayList::new));
|
||||
//过滤排序
|
||||
if(!list.isEmpty()){
|
||||
list = list.stream().sorted(Comparator.comparing(Power::getCreateTime).reversed()).collect(Collectors.toList());
|
||||
log.info("list" + list);
|
||||
}
|
||||
|
||||
result.setData(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
//改(先根据id将明细表中的数据重新入库,后将将基本信息进行更新)
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "列表修改")
|
||||
@LogAnnotation(title = "发电量和收益", action = "更新发电量和收益")
|
||||
public DataResult update(@RequestBody @Valid PowerDetailVo vo) {
|
||||
powerService.update(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/importExcel")
|
||||
@ApiOperation("导入发电量和收益功能")
|
||||
@LogAnnotation(title = "发电量和收益", action = "导入发电量和收益")
|
||||
public void importExcel(@RequestBody MultipartFile file, HttpServletRequest request) {
|
||||
List<PowerImport> list = null;
|
||||
|
||||
try {
|
||||
//默认是从第二行开始读取,也就是去掉表头
|
||||
// 直接使用EasyExcel.read(file.getInputStream()).head(TestComplexDao.class).sheet().doReadSync();
|
||||
//设置headRowNumber(0)就是从excel第一行读取
|
||||
list = EasyExcel.read(file.getInputStream()).headRowNumber(0).head(PowerImport.class).sheet().doReadSync();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
//请核对excel格式
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CHECK_THE_EXCEL_FORMAT);
|
||||
}
|
||||
//增加判断list是否为空
|
||||
if (list.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_DATA_TABLE_EMPTY);
|
||||
}
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
if (user.getPlatSuper()) {
|
||||
throw new BusinessException(BaseResponseCode.PLATFORM_ADMIN_CANNOT_DIRECTLY_USE);
|
||||
}
|
||||
powerService.importExcel(user, list);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("exportTemplate")
|
||||
@ApiOperation(value = "导出电费结算单模板")
|
||||
public void exportTemplate(HttpServletResponse response) {
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
String fileName = URLEncoder.encode("template.xls", "utf-8");
|
||||
InputStream fis = getResourcesFileInputStream("template/template.xls");
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
response.setHeader("Content-disposition", "attachment;fileName=" + fileName);
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
out = response.getOutputStream();
|
||||
out.write(buffer);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("下载失败");
|
||||
} finally {
|
||||
try {
|
||||
assert out != null;
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出模板
|
||||
private static InputStream getResourcesFileInputStream(String fileName) {
|
||||
return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.filecenter.service.PowerDetailService;
|
||||
import com.ho.filecenter.vo.DetailVo;
|
||||
import com.ho.filecenter.vo.PowerDetailVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 发电量和收益功能
|
||||
* @DateTime: 2023/3/16 10:46
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "powerDetail")
|
||||
@Api(tags = "发电量和收益功能-发电量明细")
|
||||
public class PowerDetailController {
|
||||
@Autowired
|
||||
PowerDetailService powerDetailService;
|
||||
|
||||
//查(主表id进行查找)
|
||||
//查(无入参)
|
||||
@PostMapping("/selectDetails")
|
||||
@ApiOperation(value = "明细列表")
|
||||
|
||||
public DataResult<PowerDetailVo> selectDetails(@RequestBody @Valid DetailVo vo) {
|
||||
DataResult<PowerDetailVo> result = DataResult.success();
|
||||
PowerDetailVo powerDetail = powerDetailService.selectDetails(vo);
|
||||
result.setData(powerDetail);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import com.ho.common.tools.annotation.LogAnnotation;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.filecenter.entity.PvEleAnalysis;
|
||||
import com.ho.filecenter.service.PvEleAnalysisService;
|
||||
import com.ho.filecenter.vo.req.PvEleAnalysisAddReq;
|
||||
import com.ho.filecenter.vo.req.PvEleAnalysisQueryReq;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 光伏发电分析
|
||||
* @Author xueweizhi
|
||||
* @Date 2023/4/07
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "pvEleAnalysis")
|
||||
@Api(tags = "光伏发电分析")
|
||||
@Slf4j
|
||||
public class PvEleAnalysisController {
|
||||
|
||||
@Autowired
|
||||
PvEleAnalysisService pvEleAnalysisService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@PostMapping("pvEleAnalysisList")
|
||||
@ApiOperation(value = "光伏发电分析列表查询")
|
||||
public DataResult<List<PvEleAnalysis>> pvEleAnalysisList(@RequestBody PvEleAnalysisQueryReq vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
PvEleAnalysis pvEleAnalysis = new PvEleAnalysis();
|
||||
pvEleAnalysis.setYear(vo.getYear());
|
||||
pvEleAnalysis.setGroupId(user.getGroupId());
|
||||
List<PvEleAnalysis> pvEleAnalysisList = pvEleAnalysisService.getPvEleAnalysisList(pvEleAnalysis);
|
||||
return DataResult.success(pvEleAnalysisList);
|
||||
}
|
||||
|
||||
@PostMapping("pvEleAnalysisAdd")
|
||||
@ApiOperation(value = "光伏发电分析数据新增")
|
||||
@LogAnnotation(title = "光伏发电分析", action = "光伏发电分析数据新增")
|
||||
public DataResult pvEleAnalysisAdd(@RequestBody PvEleAnalysisAddReq vo, HttpServletRequest request) {
|
||||
String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
|
||||
SimpleUser user = redisService.getSimpleUserByToken(token);
|
||||
pvEleAnalysisService.savePvEleAnalysisList(vo.getList(),user);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,130 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.vo.req.point.PointReq;
|
||||
import com.ho.business.vo.resp.point.PointRespVO;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.common.tools.util.EasyExcelUtil;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import com.ho.filecenter.constant.FileConstant;
|
||||
import com.ho.filecenter.entity.StandingBook;
|
||||
import com.ho.filecenter.service.StandingBookService;
|
||||
import com.ho.filecenter.vo.StandingBookVo;
|
||||
import com.ho.filecenter.vo.standingbook.StandingBookImport;
|
||||
import com.ho.filecenter.vo.standingbook.StandingBookOut;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @DateTime: 2023/3/15 14:19
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "file")
|
||||
@Api(tags = "多媒体-资产管理")
|
||||
@Slf4j
|
||||
public class StandingBookController {
|
||||
|
||||
@Autowired
|
||||
StandingBookService standingBookService;
|
||||
|
||||
|
||||
// 查
|
||||
@PostMapping("/queryList")
|
||||
@ApiOperation(value = "查询资产管理列表")
|
||||
|
||||
public DataResult<PageResult<List<StandingBook>>> queryList(@RequestBody @Valid StandingBookVo vo) {
|
||||
List<StandingBook> standingBookList = standingBookService.queryList(vo);
|
||||
|
||||
//java内存分页
|
||||
PageResult pageResult = new PageResult<>();
|
||||
if (!standingBookList.isEmpty()) {
|
||||
List list = PageUtils.dealList(standingBookList, vo.getPageNum(), vo.getPageSize());
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
pageResult.setTotalRows(standingBookList.size());
|
||||
pageResult.setTotalPages(standingBookList.size() / vo.getPageSize() + 1);
|
||||
} else {
|
||||
pageResult = PageUtils.getPageResult(new PageInfo<>(new ArrayList<>()));
|
||||
}
|
||||
return DataResult.success(pageResult);
|
||||
}
|
||||
|
||||
// 改(都可以修改)
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "资产管理列表修改")
|
||||
public DataResult update(@RequestBody @Valid StandingBook vo) {
|
||||
standingBookService.update(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
// 删(根据id删除)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "根据id删除")
|
||||
public DataResult deleteById(@RequestBody @Valid StandingBookVo vo) {
|
||||
standingBookService.deleteById(vo);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/import")
|
||||
@ApiOperation("导入资产台账")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "stationId", value = "站id", dataType = "Integer", required = true),
|
||||
@ApiImplicitParam(name = "file", value = "导入的Excel文件", dataType = "File", paramType = "form", required = true)
|
||||
})
|
||||
|
||||
public DataResult importCustomer(@RequestParam(value = "stationId") Integer stationId,
|
||||
@RequestParam(value = "file") MultipartFile file) {
|
||||
List<StandingBookImport> list = null;
|
||||
try {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
list = EasyExcel.read(inputStream)
|
||||
.headRowNumber(0).head(StandingBookImport.class).sheet().doReadSync();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
//请核对excel格式
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CHECK_THE_EXCEL_FORMAT);
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_DATA_TABLE_EMPTY);
|
||||
}
|
||||
standingBookService.importCustomer(stationId, list);
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/exportExcel")
|
||||
@ApiOperation("导出资产台账")
|
||||
public void exportExcel(HttpServletResponse response) {
|
||||
|
||||
String fileName = "资产台账模板";
|
||||
String sheetName = "资产台账模板";
|
||||
try {
|
||||
EasyExcelUtil.writeExcel(response, new ArrayList<>(), fileName, sheetName, StandingBookOut.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,288 @@
|
||||
package com.ho.filecenter.controller;
|
||||
|
||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.vo.req.StationReq;
|
||||
import com.ho.common.tools.annotation.TokenIgnore;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.constant.ContextConstant;
|
||||
import com.ho.common.tools.constant.EnvConstant;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.MyAddress;
|
||||
import com.ho.common.tools.entity.WeatherRespVo;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.AddressUntils;
|
||||
import com.ho.common.tools.util.IPUtils;
|
||||
import com.ho.common.tools.util.WeatherUntils;
|
||||
import com.ho.common.tools.vo.req.WeatherReq;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.service.WeatherService;
|
||||
import com.ho.filecenter.service.WeatherStationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 天气Controller
|
||||
* @date 2022/11/11
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ContextConstant.MEDIA_CONTEXT + "weather")
|
||||
@Api(tags = "多媒体-天气模块")
|
||||
@Slf4j
|
||||
public class WeatherController {
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
String env;
|
||||
|
||||
@Value("${openRedis.host}")
|
||||
String host;
|
||||
|
||||
@Value("${openRedis.port}")
|
||||
String port;
|
||||
|
||||
@Value("${openRedis.pass}")
|
||||
String pass;
|
||||
|
||||
@Value("${openTestRedis.host}")
|
||||
String testHost;
|
||||
|
||||
@Value("${openTestRedis.port}")
|
||||
String testPort;
|
||||
|
||||
@Value("${openTestRedis.pass}")
|
||||
String testPass;
|
||||
|
||||
|
||||
@Autowired
|
||||
WeatherService weatherService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Autowired
|
||||
WeatherStationService weatherStationService;
|
||||
|
||||
|
||||
@GetMapping("info")
|
||||
@ApiOperation(value = "查询天气")
|
||||
public DataResult<WeatherRespVo> getWeather(HttpServletRequest request) {
|
||||
//先获取到IP,这个ip一定要是公网IP ,否则没有实际意义
|
||||
//URL resource = HttpUtil.class.getClassLoader().getResource("ip2region.db");;
|
||||
String ipAddr = IPUtils.getIpAddr(request);
|
||||
log.info("获取到IP: {}", ipAddr);
|
||||
log.info("获取到env", env);
|
||||
if (env.equals("dev") || env.equals("exp") || env.equals("danji") || env.equals("opentest")) {
|
||||
//这个是南京的IP
|
||||
//ipAddr = "114.222.185.168";
|
||||
//这个是南通的IP
|
||||
ipAddr = "221.227.154.59";
|
||||
}
|
||||
//通合的先显示南通的地址IP,后续再优化
|
||||
else if (EnvConstant.TONG_HE.equals(env)) {
|
||||
ipAddr = "221.227.154.59";
|
||||
}
|
||||
log.info("IP: {}", ipAddr);
|
||||
//根据IP缓存天气信息,避免解析过程漫长
|
||||
String key = RedisKeyConstant.WEATHER_IP + ipAddr;
|
||||
if (redisService.hasKey(key)) {
|
||||
WeatherRespVo weatherRespVo = (WeatherRespVo) redisService.get(key);
|
||||
return DataResult.success(weatherRespVo);
|
||||
}
|
||||
WeatherRespVo vo = weatherService.getWeather(ipAddr);
|
||||
if (vo == null) {
|
||||
return DataResult.success(DataResult.success(new WeatherRespVo()));
|
||||
}
|
||||
//保存10分钟
|
||||
redisService.set(key, vo, 10, TimeUnit.MINUTES);
|
||||
return DataResult.success(vo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("stationWeatherInfo")
|
||||
@ApiOperation(value = "查询站地区天气")
|
||||
@TokenIgnore
|
||||
public DataResult<WeatherRespVo> stationWeatherInfo(@RequestBody StationReq stationReq) {
|
||||
WeatherRespVo weatherRespVo = new WeatherRespVo();
|
||||
//根据电站地区信息
|
||||
DataResult<Station> stationDataResult = businessFeignClient.selectByStationId(stationReq.getStationId());
|
||||
if (!stationDataResult.isSuccess() || stationDataResult.getData() == null) {
|
||||
return DataResult.success(weatherRespVo);
|
||||
}
|
||||
try {
|
||||
// Station station = stationDataResult.getData();
|
||||
// //截取地址名 ,然后转为pinyin,再从缓存中取值
|
||||
// int idxShi = station.getAddress().indexOf("市");
|
||||
// String stationNameShort = station.getAddress().substring(0, idxShi+1);
|
||||
// String pinyin = PinyinUtil.getPinyin(stationNameShort);
|
||||
// String key = "weatherProvinceCity:" + pinyin;
|
||||
// WeatherRespVo info = (WeatherRespVo)redisService.get(key);
|
||||
// if(info !=null){
|
||||
// info.setCityzh(station.getDistrict());
|
||||
// return DataResult.success(info);
|
||||
// }
|
||||
Station station = stationDataResult.getData();
|
||||
String key = RedisKeyConstant.WEATHER_PROVINCE_CITY + station.getAdCode();
|
||||
WeatherRespVo info = (WeatherRespVo) redisService.get(key);
|
||||
if (info != null) {
|
||||
return DataResult.success(info);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("查询省市天气缓存出错:" + e.getMessage());
|
||||
}
|
||||
return DataResult.success(weatherRespVo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ApiIgnore
|
||||
@TokenIgnore
|
||||
@ApiOperation(value = "提供给外部查询天气的接口")
|
||||
@PostMapping("getWeatherForOther")
|
||||
public DataResult<WeatherRespVo> getWeatherForOther(@RequestBody WeatherReq weatherReq) {
|
||||
//先获取到IP,这个ip一定要是公网IP ,否则没有实际意义
|
||||
//URL resource = HttpUtil.class.getClassLoader().getResource("ip2region.db");
|
||||
String ipAddr = weatherReq.getIp();
|
||||
log.info("IP: {}", ipAddr);
|
||||
if (env.equals("dev") || env.equals("exp") || env.equals("danji") || env.equals("opentest")) {
|
||||
//这个是南通的IP
|
||||
ipAddr = "221.227.154.59";
|
||||
}
|
||||
log.info("IP: {}", ipAddr);
|
||||
//根据IP缓存天气信息,避免解析过程漫长
|
||||
String key = RedisKeyConstant.WEATHER_IP + ipAddr;
|
||||
if (redisService.hasKey(key)) {
|
||||
WeatherRespVo weatherRespVo = (WeatherRespVo) redisService.get(key);
|
||||
return DataResult.success(weatherRespVo);
|
||||
}
|
||||
WeatherRespVo vo = weatherService.getWeather(ipAddr);
|
||||
if (vo == null) {
|
||||
return DataResult.success(DataResult.success(new WeatherRespVo()));
|
||||
}
|
||||
//保存10分钟
|
||||
redisService.set(key, vo, 10, TimeUnit.MINUTES);
|
||||
return DataResult.success(vo);
|
||||
|
||||
}
|
||||
|
||||
@ApiIgnore
|
||||
@TokenIgnore
|
||||
@ApiOperation(value = "根据电站查询天气的接口")
|
||||
@PostMapping("getStationWeather")
|
||||
public DataResult<WeatherRespVo> getStationWeather(@RequestBody WeatherReq weatherReq) {
|
||||
log.info("weatherReq:{}", weatherReq);
|
||||
WeatherRespVo weather = null;
|
||||
try {
|
||||
weather = weatherService.getWeatherFromAddr(weatherReq.getStationId(), weatherReq.getAddr());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (weather == null) {
|
||||
return DataResult.success(DataResult.success(new WeatherRespVo()));
|
||||
}
|
||||
return DataResult.success(weather);
|
||||
|
||||
}
|
||||
|
||||
//每天的站级天气信息
|
||||
@PostMapping("jobStationWeathers")
|
||||
@TokenIgnore
|
||||
public DataResult jobStationWeathers() {
|
||||
log.info("jobStationWeathers ,start");
|
||||
//先查所有电站
|
||||
DataResult<List<Station>> listDataResult = businessFeignClient.selectAllStation();
|
||||
//不成功直接返回
|
||||
if (!listDataResult.isSuccess() || listDataResult.getData() == null) {
|
||||
return DataResult.success();
|
||||
}
|
||||
List<Station> stations = listDataResult.getData();
|
||||
if (!stations.isEmpty()) {
|
||||
//得到不重复的电站
|
||||
// List<Station> stationList = weatherStationService.dealStation(stations);
|
||||
//生成按省市为key的缓存
|
||||
long updateTime = System.currentTimeMillis();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Station station : stations) {
|
||||
//循环调用
|
||||
// String pinyin = PinyinUtil.getPinyin(station.getAddress());
|
||||
// log.info("pinyin:" + pinyin);
|
||||
// String longitude = String.valueOf(station.getLongitude());
|
||||
// String latitude = String.valueOf(station.getLatitude());
|
||||
// WeatherRespVo weather = weatherService.getWeatherFromApi(longitude, latitude);
|
||||
// weather.setUpdateTime(updateTime);
|
||||
// weather.setCityzh(station.getName());
|
||||
// //
|
||||
// String key = "weatherProvinceCity:" + pinyin;
|
||||
// redisService.set(key,weather );
|
||||
String adCode = station.getAdCode();
|
||||
if (null == adCode) {
|
||||
MyAddress address = AddressUntils.getAddress(String.valueOf(station.getLatitude()),String.valueOf(station.getLongitude()));
|
||||
if (null != address) {
|
||||
adCode = address.getAdcode();
|
||||
}
|
||||
}
|
||||
if (map.get(adCode) != null) {
|
||||
continue;
|
||||
}
|
||||
String key = RedisKeyConstant.WEATHER_PROVINCE_CITY + adCode;
|
||||
WeatherRespVo weatherRespVo = WeatherUntils.getWeatherRespVo(station.getAdCode());
|
||||
weatherRespVo.setUpdateTime(updateTime);
|
||||
redisService.set(key, weatherRespVo);
|
||||
map.put(adCode, adCode);
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
//每天的站级天气信息
|
||||
@PostMapping("test")
|
||||
@TokenIgnore
|
||||
public DataResult test() {
|
||||
log.info("jobStationWeathers ,start");
|
||||
//先查所有电站
|
||||
DataResult<List<Station>> listDataResult = businessFeignClient.selectAllStation();
|
||||
//不成功直接返回
|
||||
if (!listDataResult.isSuccess() || listDataResult.getData() == null) {
|
||||
return DataResult.success();
|
||||
}
|
||||
List<Station> stations = listDataResult.getData();
|
||||
if (!stations.isEmpty()) {
|
||||
//得到不重复的电站
|
||||
List<Station> stationList = weatherStationService.dealStation(stations);
|
||||
//生成按省市为key的缓存
|
||||
long updateTime = System.currentTimeMillis();
|
||||
for (Station station : stationList) {
|
||||
//循环调用
|
||||
String pinyin = PinyinUtil.getPinyin(station.getAddress());
|
||||
log.info("pinyin:" + pinyin);
|
||||
String longitude = String.valueOf(station.getLongitude());
|
||||
String latitude = String.valueOf(station.getLatitude());
|
||||
WeatherRespVo weather = new WeatherRespVo();
|
||||
//weather = weatherService.getWeatherFromApi(longitude, latitude);
|
||||
weather.setUpdateTime(updateTime);
|
||||
weather.setCityzh(station.getName());
|
||||
//
|
||||
String key = RedisKeyConstant.WEATHER_PROVINCE_CITY + pinyin;
|
||||
redisService.set(key, weather);
|
||||
}
|
||||
}
|
||||
return DataResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
|
||||
import com.ho.common.tools.vo.req.CardInfoReqVo;
|
||||
import com.ho.filecenter.entity.CardInfo;
|
||||
import com.ho.filecenter.vo.flowMonitor.MobileImportVO;
|
||||
import com.ho.filecenter.vo.flowMonitor.TeleReqVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【card_info】的数据库操作Service
|
||||
* @createDate 2024-01-16 11:23:54
|
||||
*/
|
||||
public interface CardInfoService{
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(CardInfo record);
|
||||
|
||||
int insertSelective(CardInfo record);
|
||||
|
||||
int updateByPrimaryKeySelective(CardInfo record);
|
||||
|
||||
int updateByPrimaryKey(CardInfo record);
|
||||
|
||||
void deletedByIds(List<Integer> ids);
|
||||
|
||||
void insertValue(CardInfo cardInfo);
|
||||
|
||||
Integer selectByCardTotal(Integer flowMonitorId);
|
||||
|
||||
List<CardInfo> selectByFlowCardList(int offset, int pageSize,Integer flowMonitorId);
|
||||
|
||||
|
||||
List<CardInfoReqVo> selectByCondition(CardInfoReqVo cardInfo);
|
||||
|
||||
List<CardInfo> selectNotStation(CardInfo vo);
|
||||
|
||||
int mobileInsertList(List<MobileImportVO> list, Integer flowMonitorId);
|
||||
|
||||
int List(List<TeleReqVo> list, Integer flowMonitorId);
|
||||
|
||||
CardInfo selectByCard(String card);
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.vo.flowMonitor.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 移动流量卡
|
||||
* @DateTime: 2024/1/16 19:49
|
||||
*/
|
||||
public interface FlowMonitorService {
|
||||
|
||||
int insertSelective(FlowMonitorAddVo vo);
|
||||
|
||||
void deletedByIds(List<Integer> ids);
|
||||
|
||||
int updateByPrimaryKeySelective(FlowMonitorPutVo vo);
|
||||
|
||||
|
||||
void getPackageInfo();
|
||||
|
||||
List<FlowMonitorAllData> selectAllPack(FlowMonitor vo);
|
||||
|
||||
|
||||
List<CardInfoDate> selectByCardInfo(CardSelectVO vo);
|
||||
|
||||
FlowMonitor selectById(Integer flowMonitorId);
|
||||
|
||||
FlowMonitor selectByPid(FlowMonitorAddVo vo);
|
||||
|
||||
void addCardInfo(CardAddVo vo);
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.vo.flowMonitor.PackageDetailRespVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2024/1/17 11:02
|
||||
*/
|
||||
public interface MobileApiService {
|
||||
|
||||
//查询移动token并且存入缓存
|
||||
String getMoveToken();
|
||||
|
||||
//查询套餐的流量数据
|
||||
void getMobileAllData(List<FlowMonitor> mobileFlowMonitors);
|
||||
|
||||
String getQueryPackage(FlowMonitor flowMonitor);
|
||||
|
||||
PackageDetailRespVo analysisPackage(String res);
|
||||
|
||||
String getSingleCard(String iccid);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.filecenter.entity.Otaupgrad;
|
||||
import com.ho.filecenter.vo.OtaFileVO;
|
||||
import com.ho.filecenter.vo.ScheduleReqVo;
|
||||
import com.ho.filecenter.vo.UpdateRecords;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: ota业务层
|
||||
* @DateTime: 2023/8/2 10:32
|
||||
*/
|
||||
public interface OtaupgradService {
|
||||
|
||||
|
||||
PageResult<Otaupgrad> page(OtaFileVO vo);
|
||||
|
||||
List<UpdateRecords> selectHisFile(OtaFileVO vo);
|
||||
|
||||
void upgradation(MultipartFile file, OtaFileVO vo, SimpleUser user) throws ParseException;
|
||||
|
||||
void tage(MultipartFile file,OtaFileVO vo) throws Exception;
|
||||
|
||||
List<ScheduleReqVo> getUpgradeProgress(OtaFileVO vo);
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.business.vo.SingleValueColVo;
|
||||
import com.ho.business.vo.resp.point.PointCurveHomeResp;
|
||||
import com.itextpdf.text.Font;
|
||||
import com.itextpdf.text.pdf.PdfPTable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: PDF文件处理
|
||||
* @date 2023/11/28
|
||||
*/
|
||||
public interface PdfService {
|
||||
|
||||
//曲线PDF文件列表
|
||||
List<PdfPTable> getPdfTableList(List<PointCurveHomeResp> pointCurveList, Font titleFont) throws Exception;
|
||||
|
||||
//单值的列表
|
||||
List<PdfPTable> getOneTableList(List<SingleValueColVo> pointSingleValueList, Font titleFont) throws Exception;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
|
||||
import com.ho.filecenter.entity.PowerDetail;
|
||||
import com.ho.filecenter.vo.DetailVo;
|
||||
import com.ho.filecenter.vo.PowerDetailVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【power_detail】的数据库操作Service
|
||||
* @createDate 2023-03-16 10:59:17
|
||||
*/
|
||||
public interface PowerDetailService {
|
||||
|
||||
List<PowerDetail> selectByPid(Integer id);
|
||||
|
||||
int deleteBatch(List<Integer> ids,List<Integer> pids);
|
||||
|
||||
void addBatch(List<PowerDetail> powerDetailList);
|
||||
|
||||
PowerDetailVo selectDetails(DetailVo vo);
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.filecenter.entity.Power;
|
||||
import com.ho.filecenter.vo.DetailVo;
|
||||
import com.ho.filecenter.vo.PowerDetailVo;
|
||||
import com.ho.filecenter.vo.PowerImport;
|
||||
import com.ho.filecenter.vo.QueryPower;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【power】的数据库操作Service
|
||||
* @createDate 2023-03-16 10:59:38
|
||||
*/
|
||||
public interface PowerService{
|
||||
|
||||
List<Power> queryList(Integer groupId, QueryPower power);
|
||||
|
||||
void update(PowerDetailVo vo);
|
||||
|
||||
Power selectById(DetailVo vo);
|
||||
|
||||
int insertSelective(Power power);
|
||||
|
||||
|
||||
List<Power> selectAll(Integer groupId, String settleMonth);
|
||||
|
||||
void batchDeletes(List<Integer> idList);
|
||||
|
||||
void importExcel(SimpleUser user,List<PowerImport> list);
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.filecenter.entity.PvEleAnalysis;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description 针对表【pv_ele_analysis】的数据库操作Service
|
||||
* @author xueweizhi
|
||||
* @createDate 2023-04-10
|
||||
*/
|
||||
public interface PvEleAnalysisService {
|
||||
|
||||
/**
|
||||
* 根据条件查询【pv_ele_analysis】表数据
|
||||
* @param pvEleAnalysis
|
||||
* @return
|
||||
*/
|
||||
List<PvEleAnalysis> getPvEleAnalysisList(PvEleAnalysis pvEleAnalysis);
|
||||
|
||||
/**
|
||||
* 保存【pv_ele_analysis】表数据
|
||||
* @param pvEleAnalysisList
|
||||
* @return
|
||||
*/
|
||||
int savePvEleAnalysisList(List<PvEleAnalysis> pvEleAnalysisList, SimpleUser user);
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
|
||||
import com.ho.filecenter.entity.StandingBook;
|
||||
import com.ho.filecenter.vo.StandingBookVo;
|
||||
import com.ho.filecenter.vo.standingbook.StandingBookImport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【standing_book】的数据库操作Service
|
||||
* @createDate 2023-03-15 13:52:18
|
||||
*/
|
||||
public interface StandingBookService {
|
||||
|
||||
List<StandingBook> queryList(StandingBookVo vo);
|
||||
|
||||
void update(StandingBook vo);
|
||||
|
||||
void deleteById( StandingBookVo vo);
|
||||
|
||||
void deleteByStationId(Integer stationId);
|
||||
|
||||
void addBatch(List<StandingBook> standingBookList);
|
||||
|
||||
void importCustomer(Integer stationId,List<StandingBookImport> list);
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.vo.flowMonitor.CardInfoDate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2024/1/17 12:09
|
||||
*/
|
||||
public interface TelecomApiService {
|
||||
void getTelecomAllData(List<FlowMonitor> telecomFlowMonitors);
|
||||
|
||||
String getTelecomRefresh();
|
||||
|
||||
|
||||
CardInfoDate getSingle(String iccid);
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.common.tools.entity.WeatherRespVo;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2022/11/15 8:45
|
||||
*/
|
||||
public interface WeatherService {
|
||||
|
||||
WeatherRespVo getWeather(String ipAddr) ;
|
||||
|
||||
//根据经纬度查询天气
|
||||
WeatherRespVo getWeatherFromAddr(Integer stationId , String addr) ;
|
||||
|
||||
//根据经纬度查天气对象
|
||||
WeatherRespVo getWeatherFromApi(String lat, String lon);
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.ho.filecenter.service;
|
||||
|
||||
import com.ho.business.entity.Station;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: 站级天气
|
||||
* @date 2023/5/16
|
||||
*/
|
||||
public interface WeatherStationService {
|
||||
|
||||
//按照省市给站分组
|
||||
List<Station> dealStation(List<Station> stations);
|
||||
}
|
||||
@ -0,0 +1,226 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.vo.req.CardInfoReqVo;
|
||||
import com.ho.filecenter.entity.CardInfo;
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.mapper.CardInfoMapper;
|
||||
import com.ho.filecenter.service.CardInfoService;
|
||||
import com.ho.filecenter.service.FlowMonitorService;
|
||||
import com.ho.filecenter.service.MobileApiService;
|
||||
import com.ho.filecenter.vo.flowMonitor.MobileImportVO;
|
||||
import com.ho.filecenter.vo.flowMonitor.TeleReqVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【card_info】的数据库操作Service实现
|
||||
* @createDate 2024-01-16 11:23:54
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CardInfoServiceImpl implements CardInfoService {
|
||||
@Autowired
|
||||
CardInfoMapper cardInfoMapper;
|
||||
|
||||
@Autowired
|
||||
FlowMonitorService flowMonitorService;
|
||||
|
||||
@Autowired
|
||||
MobileApiService mobileApiService;
|
||||
|
||||
|
||||
@Autowired
|
||||
CardInfoService cardInfoService;
|
||||
|
||||
@Autowired
|
||||
private BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Override
|
||||
public int deleteByPrimaryKey(Integer id) {
|
||||
return cardInfoMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(CardInfo record) {
|
||||
return cardInfoMapper.insert(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertSelective(CardInfo record) {
|
||||
return cardInfoMapper.insertSelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(CardInfo record) {
|
||||
return cardInfoMapper.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKey(CardInfo record) {
|
||||
return cardInfoMapper.updateByPrimaryKey(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletedByIds(List<Integer> ids) {
|
||||
//查询卡的信息关联电站不给删除
|
||||
for (Integer id : ids) {
|
||||
CardInfo cardInfo = cardInfoMapper.selectById(id);
|
||||
if (cardInfo.getStationId() == null) {
|
||||
cardInfoMapper.deleteByPrimaryKey(id);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.SELECT_CORRSTATION_NO_DELETED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertValue(CardInfo cardInfo) {
|
||||
int i = cardInfoMapper.insertSelective(cardInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
//根据套餐id查询卡号总条数
|
||||
@Override
|
||||
public Integer selectByCardTotal(Integer flowMonitorId) {
|
||||
return cardInfoMapper.selectByCardTotal(flowMonitorId);
|
||||
}
|
||||
|
||||
|
||||
//根据套餐id查询卡号
|
||||
@Override
|
||||
public List<CardInfo> selectByFlowCardList(int offset, int pageSize, Integer flowMonitorId) {
|
||||
return cardInfoMapper.selectByFlowCardList(offset, pageSize, flowMonitorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardInfoReqVo> selectByCondition(CardInfoReqVo vo) {
|
||||
List<CardInfoReqVo> list = new ArrayList<>();
|
||||
CardInfo cardInfo = new CardInfo();
|
||||
cardInfo.setCard(vo.getCard());
|
||||
cardInfo.setCardStatus(vo.getCardStatus());
|
||||
cardInfo.setPackageType(vo.getPackageType());
|
||||
cardInfo.setStationId(vo.getStationId());
|
||||
cardInfo.setFlowMonitorId(vo.getFlowMonitorId());
|
||||
List<CardInfo> cardInfos = cardInfoMapper.selectByCondition(cardInfo);
|
||||
for (CardInfo info : cardInfos) {
|
||||
CardInfoReqVo cardInfoReqVo = new CardInfoReqVo();
|
||||
BeanUtils.copyProperties(info, cardInfoReqVo);
|
||||
list.add(cardInfoReqVo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardInfo> selectNotStation(CardInfo vo) {
|
||||
List<CardInfo> dataList = new ArrayList<>();
|
||||
List<CardInfo> cardInfoList = cardInfoMapper.selectAll(vo);
|
||||
cardInfoList.stream().filter(i -> null == i.getStationId()).forEach(s -> dataList.add(s));
|
||||
return dataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int mobileInsertList(List<MobileImportVO> list, Integer flowMonitorId) {
|
||||
//根据套餐id查询运营商
|
||||
FlowMonitor flowMonitor = flowMonitorService.selectById(flowMonitorId);
|
||||
if (flowMonitor != null && !list.isEmpty()) {
|
||||
for (MobileImportVO mobileImportVO : list) {
|
||||
if (mobileImportVO.getICCID() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CONFIRM_CORRECT);
|
||||
}
|
||||
CardInfo cardInfo = new CardInfo();
|
||||
cardInfo.setCard(mobileImportVO.getICCID());
|
||||
if (flowMonitor.getPackageType() != null) {
|
||||
cardInfo.setPackageType(flowMonitor.getPackageType());
|
||||
}
|
||||
cardInfo.setFlowMonitorId(flowMonitorId);
|
||||
//已激活
|
||||
if (CommonConstant.MobileCardStatus.Active.equals(mobileImportVO.getCardStatus())) {
|
||||
cardInfo.setCardStatus(CommonConstant.ZERO);
|
||||
}
|
||||
//待激活
|
||||
if (CommonConstant.MobileCardStatus.NOTACTIVE.equals(mobileImportVO.getCardStatus())) {
|
||||
cardInfo.setCardStatus(CommonConstant.ONE);
|
||||
}
|
||||
cardInfo.setOpenDate(mobileImportVO.getOpenDate());
|
||||
cardInfo.setActivationDate(mobileImportVO.getActivationDate());
|
||||
//入库前查询卡号是否重复
|
||||
CardInfo cardInfo1 = selectByCard(cardInfo.getCard());
|
||||
if (cardInfo1 != null) {
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_ICCID_EXISTS);
|
||||
}
|
||||
insertValue(cardInfo);
|
||||
}
|
||||
List<FlowMonitor> flowMonitorList = new ArrayList<>();
|
||||
flowMonitorList.add(flowMonitor);
|
||||
flowMonitor.setId(flowMonitorId);
|
||||
mobileApiService.getMobileAllData(flowMonitorList);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardInfo selectByCard(String card) {
|
||||
CardInfo cardInfo = cardInfoMapper.selectByCard(card);
|
||||
return cardInfo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int List(List<TeleReqVo> list, Integer flowMonitorId) {
|
||||
//根据套餐id查询运营商
|
||||
FlowMonitor flowMonitor = flowMonitorService.selectById(flowMonitorId);
|
||||
if (flowMonitor != null && !list.isEmpty()) {
|
||||
for (TeleReqVo mobileImportVO : list) {
|
||||
if (mobileImportVO.getICCID() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CONFIRM_CORRECT);
|
||||
}
|
||||
CardInfo cardInfo = new CardInfo();
|
||||
cardInfo.setCard(mobileImportVO.getICCID());
|
||||
if (flowMonitor.getPackageType() != null) {
|
||||
cardInfo.setPackageType(flowMonitor.getPackageType());
|
||||
}
|
||||
cardInfo.setFlowMonitorId(flowMonitorId);
|
||||
//已激活
|
||||
if (CommonConstant.MobileCardStatus.Active.equals(mobileImportVO.getCardStatus())) {
|
||||
cardInfo.setCardStatus(CommonConstant.ZERO);
|
||||
}
|
||||
//待激活
|
||||
if (CommonConstant.MobileCardStatus.NOTACTIVE.equals(mobileImportVO.getCardStatus())) {
|
||||
cardInfo.setCardStatus(CommonConstant.ONE);
|
||||
}
|
||||
|
||||
//待激活
|
||||
if (CommonConstant.MobileCardStatus.HALT.equals(mobileImportVO.getCardStatus())) {
|
||||
cardInfo.setCardStatus(CommonConstant.TWO);
|
||||
}
|
||||
cardInfo.setOpenDate(mobileImportVO.getOpenDate());
|
||||
//入库前查询卡号是否重复
|
||||
CardInfo cardInfo1 = selectByCard(cardInfo.getCard());
|
||||
if (cardInfo1 != null) {
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_ICCID_EXISTS);
|
||||
}
|
||||
insertValue(cardInfo);
|
||||
}
|
||||
List<FlowMonitor> flowMonitorList = new ArrayList<>();
|
||||
flowMonitorList.add(flowMonitor);
|
||||
flowMonitor.setId(flowMonitorId);
|
||||
mobileApiService.getMobileAllData(flowMonitorList);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,554 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
|
||||
import com.ho.business.constant.DeviceTypeConstant;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.vo.req.CardInfoReqVo;
|
||||
import com.ho.filecenter.entity.CardInfo;
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.mapper.FlowMonitorMapper;
|
||||
import com.ho.filecenter.service.CardInfoService;
|
||||
import com.ho.filecenter.service.FlowMonitorService;
|
||||
import com.ho.filecenter.service.MobileApiService;
|
||||
import com.ho.filecenter.service.TelecomApiService;
|
||||
import com.ho.filecenter.vo.flowMonitor.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【flow_monitor】的数据库操作Service实现
|
||||
* @createDate 2024-01-16 11:24:15
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FlowMonitorServiceImpl implements FlowMonitorService {
|
||||
@Autowired
|
||||
private FlowMonitorMapper flowMonitorMapper;
|
||||
|
||||
@Autowired
|
||||
private MobileApiService mobileApiService;
|
||||
|
||||
@Autowired
|
||||
private CardInfoService cardInfoService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private TelecomApiService telecomApiService;
|
||||
|
||||
@Autowired
|
||||
private BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Value("${telecom.appId}")
|
||||
String telecomAppId;
|
||||
|
||||
@Value("${telecom.appId}")
|
||||
String appId;
|
||||
|
||||
public int deleteByPrimaryKey(Integer id) {
|
||||
return flowMonitorMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int insertSelective(FlowMonitorAddVo vo) {
|
||||
FlowMonitor record = new FlowMonitor();
|
||||
record.setPackageName(vo.getPackageName());
|
||||
record.setPackageType(vo.getPackageType());
|
||||
record.setGroupId(vo.getGroupId());
|
||||
record.setSingleOrGroup(vo.getSingleOrGroup());
|
||||
record.setTotalFlow(vo.getTotalAmount());
|
||||
record.setDeleted(CommonConstant.DELETED);
|
||||
int i = flowMonitorMapper.insertSelective(record);
|
||||
if (CommonConstant.ONE.equals(record.getPackageType()) && record.getGroupId() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PACKAGE_NO_GROUPID);
|
||||
}
|
||||
String queryPackage = mobileApiService.getQueryPackage(record);
|
||||
PackageDetailRespVo packageDetailRespVo = mobileApiService.analysisPackage(queryPackage);
|
||||
String key = "flowMonitor:mobile:" + record.getId();
|
||||
log.info("flowMonitorKey:" + key);
|
||||
log.info("packageDetailRespVo:" + packageDetailRespVo);
|
||||
redisService.set(key, packageDetailRespVo);
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(FlowMonitorPutVo vo) {
|
||||
FlowMonitor record = new FlowMonitor();
|
||||
record.setPackageName(vo.getPackageName());
|
||||
record.setPackageType(vo.getPackageType());
|
||||
record.setTotalFlow(vo.getTotalAmount());
|
||||
record.setSingleOrGroup(vo.getSingleOrGroup());
|
||||
record.setGroupId(vo.getGroupId());
|
||||
record.setId(vo.getId());
|
||||
record.setDeleted(vo.getDeleted());
|
||||
return flowMonitorMapper.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletedByIds(List<Integer> ids) {
|
||||
for (Integer id : ids) {
|
||||
//判断是否存在卡
|
||||
FlowMonitor flowMonitor = selectById(id);
|
||||
if (flowMonitor != null) {
|
||||
CardInfoReqVo vo = new CardInfoReqVo();
|
||||
vo.setFlowMonitorId(flowMonitor.getId());
|
||||
List<CardInfoReqVo> list = cardInfoService.selectByCondition(vo);
|
||||
if (!list.isEmpty()) {
|
||||
List<CardInfoReqVo> voList = list.stream().filter(s -> s.getStationId() != null).collect(Collectors.toList());
|
||||
if (!voList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.CARD_PACKAGE_ASSOCIATED_POWER_STATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
flowMonitorMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowMonitor selectById(Integer flowMonitorId) {
|
||||
FlowMonitor flowMonitor = flowMonitorMapper.selectById(flowMonitorId);
|
||||
return flowMonitor;
|
||||
}
|
||||
|
||||
public List<FlowMonitor> selectAll(FlowMonitor vo) {
|
||||
List<FlowMonitor> list = flowMonitorMapper.selectAll(vo);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowMonitor selectByPid(FlowMonitorAddVo vo) {
|
||||
FlowMonitor flowMonitor = flowMonitorMapper.selectByPid(vo.getGroupId());
|
||||
return flowMonitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCardInfo(CardAddVo vo) {
|
||||
//判断增加的卡号是否重复
|
||||
CardInfo cardValue = cardInfoService.selectByCard(vo.getCard());
|
||||
if (cardValue != null) {
|
||||
throw new BusinessException(BaseResponseCode.STATION_ICCID_EXISTS);
|
||||
}
|
||||
CardInfo cardInfo = new CardInfo();
|
||||
cardInfo.setCard(vo.getCard());
|
||||
cardInfo.setFlowMonitorId(vo.getFlowMonitorId());
|
||||
cardInfo.setCardStatus(vo.getStatus());
|
||||
//根据套餐id获取运营商
|
||||
FlowMonitor flowMonitor = selectById(vo.getFlowMonitorId());
|
||||
cardInfo.setPackageType(flowMonitor.getPackageType());
|
||||
//根据卡号查缓存(1:中国移动2:中国联通3:中国电信)
|
||||
//电信的需要到缓存中拿取数据
|
||||
if (CommonConstant.THREE.equals(flowMonitor.getPackageType())) {
|
||||
String key = "flowMonitor:telecom:appId:" + telecomAppId + ":iccId:" + vo.getCard();
|
||||
CardInfoDate cardInfoDate = (CardInfoDate) redisService.get(key);
|
||||
if (cardInfoDate != null) {
|
||||
//取开户激活时间
|
||||
if (cardInfoDate.getOpenDate() != null) {
|
||||
cardInfo.setOpenDate(cardInfoDate.getOpenDate());
|
||||
} else {
|
||||
cardInfo.setOpenDate(null);
|
||||
}
|
||||
if (cardInfoDate.getActivationDate() != null) {
|
||||
cardInfo.setActivationDate(cardInfoDate.getActivationDate());
|
||||
} else {
|
||||
cardInfo.setActivationDate(null);
|
||||
}
|
||||
} else {
|
||||
CardInfoDate single = telecomApiService.getSingle(vo.getCard());
|
||||
if (single != null) {
|
||||
single.setFlowMonitorId(vo.getFlowMonitorId());
|
||||
redisService.set(key, single);
|
||||
}
|
||||
if (single.getOpenDate() != null) {
|
||||
cardInfo.setOpenDate(single.getOpenDate());
|
||||
} else {
|
||||
cardInfo.setOpenDate(null);
|
||||
}
|
||||
if (single.getActivationDate() != null) {
|
||||
cardInfo.setActivationDate(single.getActivationDate());
|
||||
} else {
|
||||
cardInfo.setActivationDate(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
cardInfo.setStationId(vo.getStationId());
|
||||
cardInfoService.insertValue(cardInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FlowMonitorAllData> selectAllPack(FlowMonitor vo) {
|
||||
List<FlowMonitorAllData> data = new ArrayList<>();
|
||||
//先查询所有套餐
|
||||
List<FlowMonitor> flowMonitors = selectAll(vo);
|
||||
//将所有的的套餐进行分类
|
||||
Map<Integer, List<FlowMonitor>> flowMonitorMap = flowMonitors.stream().collect(Collectors.groupingBy(FlowMonitor::getPackageType));
|
||||
// 1:中国移动
|
||||
if (flowMonitorMap.containsKey(CommonConstant.ONE)) {
|
||||
//移动组缓存key
|
||||
List<FlowMonitor> mobileFlowMonitors = flowMonitorMap.get(CommonConstant.ONE);
|
||||
for (FlowMonitor mobileFlowMonitor : mobileFlowMonitors) {
|
||||
FlowMonitorAllData flowMonitorAllData = new FlowMonitorAllData();
|
||||
String key = "flowMonitor:mobile:" + mobileFlowMonitor.getId();
|
||||
PackageDetailRespVo packageDetailRespVo = (PackageDetailRespVo) redisService.get(key);
|
||||
if (null != packageDetailRespVo) {
|
||||
//公式换算 1mb=1024kb
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
flowMonitorAllData.setId(mobileFlowMonitor.getId());
|
||||
flowMonitorAllData.setGroupId(mobileFlowMonitor.getGroupId());
|
||||
flowMonitorAllData.setSingleOrGroup(mobileFlowMonitor.getSingleOrGroup());
|
||||
flowMonitorAllData.setPackageName(mobileFlowMonitor.getPackageName());
|
||||
flowMonitorAllData.setPackageType(mobileFlowMonitor.getPackageType());
|
||||
if (packageDetailRespVo.getRemainAmount() != null) {
|
||||
BigDecimal remainAmount = new BigDecimal(packageDetailRespVo.getRemainAmount()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP);
|
||||
flowMonitorAllData.setRemainAmount(remainAmount.toString());
|
||||
} else {
|
||||
flowMonitorAllData.setRemainAmount(null);
|
||||
}
|
||||
if (packageDetailRespVo.getTotalAmount() != null) {
|
||||
BigDecimal totalAmount = new BigDecimal(packageDetailRespVo.getTotalAmount()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP);
|
||||
flowMonitorAllData.setTotalAmount(totalAmount.toString());
|
||||
} else {
|
||||
if (mobileFlowMonitor.getTotalFlow() != null) {
|
||||
flowMonitorAllData.setTotalAmount(mobileFlowMonitor.getTotalFlow().toString());
|
||||
} else {
|
||||
flowMonitorAllData.setTotalAmount(null);
|
||||
}
|
||||
}
|
||||
if (packageDetailRespVo.getUseAmount() != null) {
|
||||
BigDecimal useAmount = new BigDecimal(packageDetailRespVo.getUseAmount()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP);
|
||||
flowMonitorAllData.setUseAmount(useAmount.toString());
|
||||
} else {
|
||||
flowMonitorAllData.setUseAmount(null);
|
||||
}
|
||||
data.add(flowMonitorAllData);
|
||||
} else {
|
||||
flowMonitorAllData.setId(mobileFlowMonitor.getId());
|
||||
flowMonitorAllData.setGroupId(mobileFlowMonitor.getGroupId());
|
||||
flowMonitorAllData.setSingleOrGroup(mobileFlowMonitor.getSingleOrGroup());
|
||||
flowMonitorAllData.setPackageName(mobileFlowMonitor.getPackageName());
|
||||
flowMonitorAllData.setPackageType(mobileFlowMonitor.getPackageType());
|
||||
flowMonitorAllData.setRemainAmount(CommonConstant.ZERO.toString());
|
||||
if (mobileFlowMonitor.getTotalFlow() != null) {
|
||||
flowMonitorAllData.setTotalAmount(mobileFlowMonitor.getTotalFlow().toString());
|
||||
} else {
|
||||
flowMonitorAllData.setTotalAmount(CommonConstant.ZERO.toString());
|
||||
}
|
||||
flowMonitorAllData.setUseAmount(CommonConstant.ZERO.toString());
|
||||
data.add(flowMonitorAllData);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2:中国联通
|
||||
if (flowMonitorMap.containsKey(CommonConstant.TWO)) {
|
||||
List<FlowMonitor> list = flowMonitorMap.get(CommonConstant.TWO);
|
||||
for (FlowMonitor monitor : list) {
|
||||
FlowMonitorAllData flowMonitorAllData = new FlowMonitorAllData();
|
||||
flowMonitorAllData.setId(monitor.getId());
|
||||
flowMonitorAllData.setGroupId(monitor.getGroupId());
|
||||
flowMonitorAllData.setSingleOrGroup(monitor.getSingleOrGroup());
|
||||
flowMonitorAllData.setPackageName(monitor.getPackageName());
|
||||
flowMonitorAllData.setPackageType(monitor.getPackageType());
|
||||
flowMonitorAllData.setRemainAmount(CommonConstant.ZERO.toString());
|
||||
flowMonitorAllData.setUseAmount(CommonConstant.ZERO.toString());
|
||||
if (monitor.getTotalFlow() != null) {
|
||||
flowMonitorAllData.setTotalAmount(monitor.getTotalFlow().toString());
|
||||
} else {
|
||||
flowMonitorAllData.setTotalAmount(CommonConstant.ZERO.toString());
|
||||
}
|
||||
data.add(flowMonitorAllData);
|
||||
}
|
||||
}
|
||||
// 3:中国电信
|
||||
if (flowMonitorMap.containsKey(CommonConstant.THREE)) {
|
||||
//电信(计算该套餐下几张卡和每个卡总流量相乘->总 每个卡的使用相加 —>已使用流量 两个相减就是剩余)
|
||||
List<FlowMonitor> telecomFlowMonitors = flowMonitorMap.get(CommonConstant.THREE);
|
||||
for (FlowMonitor telecomFlowMonitor : telecomFlowMonitors) {
|
||||
FlowMonitorAllData flowMonitorAllData = new FlowMonitorAllData();
|
||||
//根据套餐查询卡列表
|
||||
CardInfoReqVo cardInfo = new CardInfoReqVo();
|
||||
cardInfo.setFlowMonitorId(telecomFlowMonitor.getId());
|
||||
List<CardInfoReqVo> list = cardInfoService.selectByCondition(cardInfo);
|
||||
if (list.isEmpty()) {
|
||||
flowMonitorAllData.setId(telecomFlowMonitor.getId());
|
||||
flowMonitorAllData.setGroupId(telecomFlowMonitor.getGroupId());
|
||||
flowMonitorAllData.setSingleOrGroup(telecomFlowMonitor.getSingleOrGroup());
|
||||
flowMonitorAllData.setPackageName(telecomFlowMonitor.getPackageName());
|
||||
flowMonitorAllData.setPackageType(telecomFlowMonitor.getPackageType());
|
||||
flowMonitorAllData.setRemainAmount(CommonConstant.ZERO.toString());
|
||||
if (telecomFlowMonitor.getTotalFlow() != null) {
|
||||
flowMonitorAllData.setTotalAmount(telecomFlowMonitor.getTotalFlow().toString());
|
||||
} else {
|
||||
flowMonitorAllData.setTotalAmount(CommonConstant.ZERO.toString());
|
||||
}
|
||||
flowMonitorAllData.setUseAmount(CommonConstant.ZERO.toString());
|
||||
data.add(flowMonitorAllData);
|
||||
} else {
|
||||
BigDecimal UseAmount = new BigDecimal("0");
|
||||
for (CardInfoReqVo cardInfoReqVo : list) {
|
||||
String key = "flowMonitor:telecom:appId:" + telecomAppId + ":iccId:" + cardInfoReqVo.getCard();
|
||||
CardInfoDate cardInfoDate = (CardInfoDate) redisService.get(key);
|
||||
if (cardInfoDate != null && cardInfoDate.getUserAmount() != null) {
|
||||
String userAmount = cardInfoDate.getUserAmount();
|
||||
UseAmount = UseAmount.add(new BigDecimal(userAmount));
|
||||
} else {
|
||||
UseAmount = UseAmount.add(new BigDecimal("0"));
|
||||
}
|
||||
}
|
||||
//判断是否为 单卡流量
|
||||
String totalAmount = "0";
|
||||
if (CommonConstant.ONE.equals(telecomFlowMonitor.getSingleOrGroup())) {
|
||||
if (!list.isEmpty()) {
|
||||
if (telecomFlowMonitor.getTotalFlow() != null) {
|
||||
Integer totalFlow = list.size() * telecomFlowMonitor.getTotalFlow();
|
||||
totalAmount = totalFlow.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
flowMonitorAllData.setTotalAmount(totalAmount);
|
||||
//公式换算 1G=1024×1024=1048576KB
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
BigDecimal useAmount = UseAmount.divide(decimal, 2, BigDecimal.ROUND_HALF_UP);
|
||||
flowMonitorAllData.setUseAmount(useAmount.toString());
|
||||
BigDecimal subtract = new BigDecimal(totalAmount).subtract(useAmount);
|
||||
flowMonitorAllData.setRemainAmount(subtract.toString());
|
||||
flowMonitorAllData.setId(telecomFlowMonitor.getId());
|
||||
flowMonitorAllData.setGroupId(telecomFlowMonitor.getGroupId());
|
||||
flowMonitorAllData.setSingleOrGroup(telecomFlowMonitor.getSingleOrGroup());
|
||||
flowMonitorAllData.setPackageName(telecomFlowMonitor.getPackageName());
|
||||
flowMonitorAllData.setPackageType(telecomFlowMonitor.getPackageType());
|
||||
data.add(flowMonitorAllData);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardInfoDate> selectByCardInfo(CardSelectVO vo) {
|
||||
List<CardInfoDate> date = new ArrayList<>();
|
||||
//根据套餐id查询该套餐
|
||||
FlowMonitor flowMonitor = flowMonitorMapper.selectById(vo.getFlowMonitorId());
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
// 1:中国移动
|
||||
if (flowMonitor.getPackageType().equals(CommonConstant.ONE)) {
|
||||
CardInfoReqVo cardInfo = new CardInfoReqVo();
|
||||
cardInfo.setFlowMonitorId(flowMonitor.getId());
|
||||
List<CardInfoReqVo> list = cardInfoService.selectByCondition(cardInfo);
|
||||
List<Integer> stationIdList = list.stream().map(CardInfoReqVo::getStationId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, List<Station>> dataMap = getByStations(stationIdList);
|
||||
//移动组缓存key
|
||||
String key = "flowMonitor:mobile:" + flowMonitor.getId();
|
||||
PackageDetailRespVo packageDetailRespVo = (PackageDetailRespVo) redisService.get(key);
|
||||
Map<String, List<CardInfoDate>> map = new HashMap<>();
|
||||
if (packageDetailRespVo != null) {
|
||||
List<CardInfoDate> cardInfoList = packageDetailRespVo.getCardInfoList();
|
||||
if (cardInfoList != null) {
|
||||
map = cardInfoList.stream().collect(Collectors.groupingBy(CardInfoDate::getCardNo));
|
||||
}
|
||||
}
|
||||
for (CardInfoReqVo cardInfoReqVo : list) {
|
||||
if (map.containsKey(cardInfoReqVo.getCard())) {
|
||||
List<CardInfoDate> dates = map.get(cardInfoReqVo.getCard());
|
||||
for (CardInfoDate cardInfoDate : dates) {
|
||||
CardInfoDate resultDate = new CardInfoDate();
|
||||
resultDate.setId(cardInfoReqVo.getId());
|
||||
resultDate.setCardNo(cardInfoDate.getCardNo());
|
||||
resultDate.setStatus(cardInfoDate.getStatus());
|
||||
BigDecimal useAmount = new BigDecimal(CommonConstant.ZERO);
|
||||
if (cardInfoDate.getUserAmount() != null) {
|
||||
useAmount = new BigDecimal(cardInfoDate.getUserAmount()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
resultDate.setUserAmount(useAmount.toString());
|
||||
resultDate.setUpdateTime(cardInfoDate.getUpdateTime());
|
||||
resultDate.setStationId(cardInfoReqVo.getStationId());
|
||||
resultDate.setFlowMonitorId(flowMonitor.getId());
|
||||
resultDate.setOpenDate(cardInfoReqVo.getOpenDate());
|
||||
resultDate.setActivationDate(cardInfoReqVo.getActivationDate());
|
||||
if (dataMap.containsKey(cardInfoReqVo.getStationId())) {
|
||||
List<Station> stationList = dataMap.get(cardInfoReqVo.getStationId());
|
||||
Station station = stationList.get(0);
|
||||
resultDate.setStationName(station.getName());
|
||||
} else {
|
||||
resultDate.setStationName(null);
|
||||
}
|
||||
date.add(resultDate);
|
||||
}
|
||||
} else {
|
||||
CardInfoDate resultDate = new CardInfoDate();
|
||||
resultDate.setId(cardInfoReqVo.getId());
|
||||
resultDate.setCardNo(cardInfoReqVo.getCard());
|
||||
resultDate.setStatus(cardInfoReqVo.getCardStatus());
|
||||
resultDate.setUserAmount(CommonConstant.ZERO.toString());
|
||||
resultDate.setStationId(cardInfoReqVo.getStationId());
|
||||
resultDate.setFlowMonitorId(cardInfoReqVo.getFlowMonitorId());
|
||||
resultDate.setOpenDate(cardInfoReqVo.getOpenDate());
|
||||
resultDate.setActivationDate(cardInfoReqVo.getActivationDate());
|
||||
if (dataMap.containsKey(cardInfoReqVo.getStationId())) {
|
||||
List<Station> stationList = dataMap.get(cardInfoReqVo.getStationId());
|
||||
Station station = stationList.get(0);
|
||||
resultDate.setStationName(station.getName());
|
||||
} else {
|
||||
resultDate.setStationName(null);
|
||||
}
|
||||
date.add(resultDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
//todo 2:中国联通
|
||||
if (flowMonitor.getPackageType().equals(CommonConstant.TWO)) {
|
||||
CardInfoReqVo cardInfo = new CardInfoReqVo();
|
||||
cardInfo.setFlowMonitorId(flowMonitor.getId());
|
||||
List<CardInfoReqVo> list = cardInfoService.selectByCondition(cardInfo);
|
||||
List<Integer> stationIdList = list.stream().map(CardInfoReqVo::getStationId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, List<Station>> dataMap = getByStations(stationIdList);
|
||||
for (CardInfoReqVo cardInfoReqVo : list) {
|
||||
CardInfoDate card = new CardInfoDate();
|
||||
card.setId(cardInfoReqVo.getId());
|
||||
card.setCardNo(cardInfoReqVo.getCard());
|
||||
card.setStatus(cardInfoReqVo.getCardStatus());
|
||||
card.setUserAmount(CommonConstant.ZERO.toString());
|
||||
card.setStationId(cardInfoReqVo.getStationId());
|
||||
if (dataMap.containsKey(cardInfoReqVo.getStationId())) {
|
||||
List<Station> stationList = dataMap.get(cardInfoReqVo.getStationId());
|
||||
Station station = stationList.get(0);
|
||||
card.setStationName(station.getName());
|
||||
} else {
|
||||
card.setStationName(null);
|
||||
}
|
||||
card.setFlowMonitorId(cardInfoReqVo.getFlowMonitorId());
|
||||
date.add(card);
|
||||
}
|
||||
}
|
||||
// 3:中国电信
|
||||
if (flowMonitor.getPackageType().equals(CommonConstant.THREE)) {
|
||||
CardInfoReqVo cardInfo = new CardInfoReqVo();
|
||||
cardInfo.setFlowMonitorId(flowMonitor.getId());
|
||||
List<CardInfoReqVo> list = cardInfoService.selectByCondition(cardInfo);
|
||||
List<Integer> stationIdList = list.stream().map(CardInfoReqVo::getStationId)
|
||||
.collect(Collectors.toList());
|
||||
Map<Integer, List<Station>> dataMap = getByStations(stationIdList);
|
||||
if (!list.isEmpty()) {
|
||||
for (CardInfoReqVo cardInfoReqVo : list) {
|
||||
String key = "flowMonitor:telecom:appId:" + telecomAppId + ":iccId:" + cardInfoReqVo.getCard();
|
||||
CardInfoDate cardInfoDate = (CardInfoDate) redisService.get(key);
|
||||
if (cardInfoDate != null) {
|
||||
CardInfoDate card = new CardInfoDate();
|
||||
card.setId(cardInfoReqVo.getId());
|
||||
if (cardInfoDate.getCardNo() != null) {
|
||||
card.setCardNo(cardInfoDate.getCardNo());
|
||||
} else {
|
||||
card.setCardNo(cardInfoReqVo.getCard());
|
||||
}
|
||||
if (cardInfoDate.getStatus() != null) {
|
||||
card.setStatus(cardInfoDate.getStatus());
|
||||
} else {
|
||||
card.setStatus(cardInfoReqVo.getCardStatus());
|
||||
}
|
||||
if (cardInfoDate.getUserAmount() != null) {
|
||||
BigDecimal useAmount = new BigDecimal(cardInfoDate.getUserAmount()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP);
|
||||
card.setUserAmount(useAmount.toString());
|
||||
} else {
|
||||
card.setUserAmount(CommonConstant.ZERO.toString());
|
||||
}
|
||||
card.setUpdateTime(cardInfoDate.getUpdateTime());
|
||||
card.setOpenDate(cardInfoDate.getOpenDate());
|
||||
card.setActivationDate(cardInfoDate.getActivationDate());
|
||||
card.setGroupId(cardInfoDate.getGroupId());
|
||||
card.setStationId(cardInfoReqVo.getStationId());
|
||||
card.setFlowMonitorId(cardInfoReqVo.getFlowMonitorId());
|
||||
if (dataMap.containsKey(cardInfoReqVo.getStationId())) {
|
||||
List<Station> stationList = dataMap.get(cardInfoReqVo.getStationId());
|
||||
Station station = stationList.get(0);
|
||||
card.setStationName(station.getName());
|
||||
} else {
|
||||
card.setStationName(null);
|
||||
}
|
||||
//1 是单卡 2 套餐
|
||||
if (CommonConstant.ONE.equals(flowMonitor.getSingleOrGroup())) {
|
||||
card.setSingleTotalFlow(flowMonitor.getTotalFlow().toString());
|
||||
}
|
||||
date.add(card);
|
||||
} else {
|
||||
CardInfoDate card = new CardInfoDate();
|
||||
card.setId(cardInfoReqVo.getId());
|
||||
card.setCardNo(cardInfoReqVo.getCard());
|
||||
card.setStatus(cardInfoReqVo.getCardStatus());
|
||||
card.setOpenDate(cardInfoReqVo.getOpenDate());
|
||||
card.setActivationDate(cardInfoReqVo.getActivationDate());
|
||||
card.setUserAmount(CommonConstant.ZERO.toString());
|
||||
card.setStationId(cardInfoReqVo.getStationId());
|
||||
card.setFlowMonitorId(cardInfoReqVo.getFlowMonitorId());
|
||||
if (dataMap.containsKey(cardInfoReqVo.getStationId())) {
|
||||
List<Station> stationList = dataMap.get(cardInfoReqVo.getStationId());
|
||||
Station station = stationList.get(0);
|
||||
card.setStationName(station.getName());
|
||||
} else {
|
||||
card.setStationName(null);
|
||||
}
|
||||
//1 是单卡 2 套餐
|
||||
if (CommonConstant.ONE.equals(flowMonitor.getSingleOrGroup())) {
|
||||
card.setSingleTotalFlow(flowMonitor.getTotalFlow().toString());
|
||||
}
|
||||
date.add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
//根据电站list查询
|
||||
public Map<Integer, List<Station>> getByStations(List<Integer> stationIdList) {
|
||||
DataResult<List<Station>> listDataResult = businessFeignClient.selectByStationIds(stationIdList);
|
||||
Map<Integer, List<Station>> dataMap = new HashMap<>();
|
||||
if (listDataResult.isSuccess()) {
|
||||
List<Station> data = listDataResult.getData();
|
||||
dataMap = data.stream().collect(Collectors.groupingBy(Station::getId));
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPackageInfo() {
|
||||
//先查询所有套餐
|
||||
FlowMonitor vo = new FlowMonitor();
|
||||
List<FlowMonitor> flowMonitors = selectAll(vo);
|
||||
//将所有的的套餐进行分类
|
||||
Map<Integer, List<FlowMonitor>> flowMonitorMap = flowMonitors.stream().collect(Collectors.groupingBy(FlowMonitor::getPackageType));
|
||||
// 1:中国移动
|
||||
if (flowMonitorMap.containsKey(CommonConstant.ONE)) {
|
||||
List<FlowMonitor> mobileFlowMonitors = flowMonitorMap.get(CommonConstant.ONE);
|
||||
List<FlowMonitor> flowMonitorList = new ArrayList<>();
|
||||
mobileFlowMonitors.stream().filter(i -> null != i.getGroupId()).forEach(s -> flowMonitorList.add(s));
|
||||
mobileApiService.getMobileAllData(flowMonitorList);
|
||||
}
|
||||
// 2:中国联通
|
||||
if (flowMonitorMap.containsKey(CommonConstant.TWO)) {
|
||||
List<FlowMonitor> list = flowMonitorMap.get(CommonConstant.TWO);
|
||||
}
|
||||
// 3:中国电信
|
||||
if (flowMonitorMap.containsKey(CommonConstant.THREE)) {
|
||||
List<FlowMonitor> telecomFlowMonitors = flowMonitorMap.get(CommonConstant.THREE);
|
||||
telecomApiService.getTelecomAllData(telecomFlowMonitors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,456 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.filecenter.common.TransIdGenerator;
|
||||
import com.ho.filecenter.entity.CardInfo;
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.service.CardInfoService;
|
||||
import com.ho.filecenter.service.MobileApiService;
|
||||
import com.ho.filecenter.vo.flowMonitor.CardInfoDate;
|
||||
import com.ho.filecenter.vo.flowMonitor.PackageDetailRespVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.io.entity.StringEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 移动流量卡实现类
|
||||
* @DateTime: 2024/1/16 15:35
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class MobileApiServiceImpl implements MobileApiService {
|
||||
|
||||
@Autowired
|
||||
private TransIdGenerator transIdGenerator;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private CardInfoService cardInfoService;
|
||||
|
||||
|
||||
@Value("${mobile.appId}")
|
||||
String appId;
|
||||
|
||||
@Value("${mobile.password}")
|
||||
String password;
|
||||
|
||||
@Value("${mobile.ipAndPort}")
|
||||
String ipAndPort;
|
||||
|
||||
@Value("${mobile.version}")
|
||||
String version;
|
||||
|
||||
@Override
|
||||
public void getMobileAllData(List<FlowMonitor> mobileFlowMonitors) {
|
||||
//根据所有的套餐id查询查询卡列表
|
||||
for (FlowMonitor mobileFlowMonitor : mobileFlowMonitors) {
|
||||
String queryPackage = getQueryPackage(mobileFlowMonitor);
|
||||
log.info("queryPackage:" + queryPackage);
|
||||
PackageDetailRespVo packageDetailRespVo = analysisPackage(queryPackage);
|
||||
List<CardInfoDate> parameter = getParameter(mobileFlowMonitor.getId());
|
||||
packageDetailRespVo.setCardInfoList(parameter);
|
||||
String key = "flowMonitor:mobile:" + mobileFlowMonitor.getId();
|
||||
log.info("flowMonitorKey:" + key);
|
||||
log.info("packageDetailRespVo:" + packageDetailRespVo);
|
||||
redisService.set(key, packageDetailRespVo);
|
||||
}
|
||||
}
|
||||
|
||||
//电信的前置
|
||||
public List<CardInfoDate> getParameter(int id) {
|
||||
List<CardInfoDate> cardInfoList = new ArrayList<>();
|
||||
int total = cardInfoService.selectByCardTotal(id);
|
||||
double ceil = Math.ceil(total * 1.0 / 50);
|
||||
for (int i = 0; i < ceil; i++) {
|
||||
int offset = i * 50;
|
||||
int pageSize = 50;
|
||||
List<CardInfo> cardInfos = cardInfoService.selectByFlowCardList(offset, pageSize, id);
|
||||
List<CardInfo> realSrcIdList = cardInfos.stream().filter(h -> null != h.getStationId()).collect(Collectors.toList());
|
||||
Map<String, Integer> cardStationMap = realSrcIdList.stream().collect(Collectors.toMap(CardInfo::getCard, CardInfo::getStationId, (k1, k2) -> k2));
|
||||
Map<String, Integer> cardIdMap = cardInfos.stream().collect(Collectors.toMap(CardInfo::getCard, CardInfo::getId, (k1, k2) -> k2));
|
||||
String queryPackageCardInfo = getQueryPackageCardInfo(cardInfos);
|
||||
JSONObject cardInfoObject = JSON.parseObject(queryPackageCardInfo);
|
||||
if (cardInfoObject != null) {
|
||||
String status = (String) cardInfoObject.get("status");
|
||||
Integer statusInteger = Integer.valueOf(status);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONArray cardInfoJSONArray = (JSONArray) cardInfoObject.get("result");
|
||||
for (int h = 0; h <= cardInfoJSONArray.size(); h++) {
|
||||
JSONObject JSONObject = (JSONObject) cardInfoJSONArray.get(h);
|
||||
JSONArray dataAmountList = (JSONArray) JSONObject.get("dataAmountList");
|
||||
if (!dataAmountList.isEmpty()) {
|
||||
for (int m = 0; m < dataAmountList.size(); m++) {
|
||||
CardInfoDate cardInfoDate = new CardInfoDate();
|
||||
JSONObject dataAmountJSONObject = (JSONObject) dataAmountList.get(m);
|
||||
String dataAmount = (String) dataAmountJSONObject.get("dataAmount");
|
||||
String msisdn = (String) dataAmountJSONObject.get("iccid");
|
||||
cardInfoDate.setCardNo(msisdn);
|
||||
if (cardStationMap.containsKey(msisdn)) {
|
||||
Integer stationId = cardStationMap.get(msisdn);
|
||||
cardInfoDate.setStationId(stationId);
|
||||
}
|
||||
if (cardIdMap.containsKey(msisdn)) {
|
||||
Integer cardId = cardIdMap.get(msisdn);
|
||||
cardInfoDate.setId(cardId);
|
||||
}
|
||||
cardInfoDate.setUserAmount(dataAmount);
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
cardInfoDate.setUpdateTime(format);
|
||||
cardInfoDate.setStatus(CommonConstant.STATUS_FLAG);
|
||||
cardInfoList.add(cardInfoDate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cardInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录的token,将token存入缓存(移动)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getMoveToken() {
|
||||
com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
|
||||
json.put("appid", appId);
|
||||
json.put("password", password);
|
||||
String transId = transIdGenerator.generateTransIdForMobile(appId);
|
||||
json.put("transid", transId);
|
||||
String v1 = json.toJSONString();
|
||||
log.info("v1:" + v1);
|
||||
String url = "https://api.iot.10086.cn/v5/ec/get/token";
|
||||
log.info("url:" + url);
|
||||
String token = null;
|
||||
try {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.addHeader("Content-Type", "application/json");
|
||||
httpPost.setEntity(new StringEntity(v1));
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
HttpEntity entity = response.getEntity();
|
||||
String responseContent = EntityUtils.toString(entity, "UTF-8");
|
||||
response.close();
|
||||
httpClient.close();
|
||||
//{"status":"0","message":"正确","result":[{"token":"749b4f858d6f0ee43f3e2e9dff5062fcb761d37604629d23b8e0d9bac043fbdc","ttl":3600}]}
|
||||
JSONObject jsonObject = JSON.parseObject(responseContent);
|
||||
String status = (String) jsonObject.get("status");
|
||||
Integer statusInteger = Integer.valueOf(status);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONArray result = (JSONArray) jsonObject.get("result");
|
||||
for (int i = 0; i <= result.size(); i++) {
|
||||
JSONObject JSONObject = (JSONObject) result.get(i);
|
||||
token = (String) JSONObject.get("token");
|
||||
Integer ttl = (Integer) JSONObject.get("ttl");
|
||||
//将结果存入缓存
|
||||
String redisKey = "flowMonitor:mobile:appId:" + appId;
|
||||
JSONObject jsonRedisObject = new JSONObject();
|
||||
jsonRedisObject.put("token", token);
|
||||
jsonRedisObject.put("ttl", ttl);
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
jsonRedisObject.put("updateTime", format);
|
||||
redisService.hmset(redisKey, jsonRedisObject);
|
||||
//加入缓存时间
|
||||
//redisService.expire(redisKey, 50, TimeUnit.MINUTES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("移动token获取失败");
|
||||
}
|
||||
log.info("token:" + token);
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @author CMIOT_API23U04-群组本月套餐内流量使用量实时查询
|
||||
*/
|
||||
@Override
|
||||
public String getQueryPackage(FlowMonitor flowMonitor) {
|
||||
// 请求具体的接口名称
|
||||
String apiName = "/ec/query/group-data-margin";
|
||||
String redisKey = "flowMonitor:mobile:appId:" + appId;
|
||||
String token = getMoveToken();
|
||||
/* String token = null;
|
||||
Boolean flag = redisService.hasKey(redisKey);
|
||||
if (flag) {
|
||||
Map<Object, Object> hgetall = redisService.hgetall(redisKey);
|
||||
if (hgetall.containsKey("token")) {
|
||||
token = (String) hgetall.get("token");
|
||||
}
|
||||
} else {
|
||||
token = getMoveToken();
|
||||
}*/
|
||||
String transId = transIdGenerator.generateTransIdForMobile(appId);
|
||||
// 封装请求接口的参数,需要按实际环境修改
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("transid", transId);
|
||||
map.put("token", token);
|
||||
map.put("groupId", flowMonitor.getGroupId());
|
||||
// 通过参数构造请求URL和参数
|
||||
String url = buildUrl(map, ipAndPort, version, apiName);
|
||||
// 获取接口返回信息
|
||||
String result = sendRequest(url);
|
||||
//{"status":"0","message":"正确","result":[{"flowPoolSharingInfo":[{"offeringId":"100019020","offeringName":"2022版高速物联卡全国定向流量6元套餐(共享)","totalAmount":"198180864.00","remainAmount":"185371409.00","useAmount":"12809455.00"}]}]}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @autho 群组本月套餐内流量使用量实时查询(解析数据)
|
||||
*/
|
||||
@Override
|
||||
public PackageDetailRespVo analysisPackage(String res) {
|
||||
JSONObject jsonObject = JSON.parseObject(res);
|
||||
//{"status":"0","message":"正确","result":[{"flowPoolSharingInfo":[{"offeringId":"100019020","offeringName":"2022版高速物联卡全国定向流量6元套餐(共享)","totalAmount":"198180864.00","remainAmount":"173389002.00","useAmount":"24791862.00"}]}]}
|
||||
PackageDetailRespVo packageDetailRespVo = new PackageDetailRespVo();
|
||||
if (jsonObject != null) {
|
||||
String status = (String) jsonObject.get("status");
|
||||
Integer statusInteger = Integer.valueOf(status);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONArray result = (JSONArray) jsonObject.get("result");
|
||||
for (int i = 0; i <= result.size(); i++) {
|
||||
JSONObject JSONObject = (JSONObject) result.get(i);
|
||||
if (JSONObject != null) {
|
||||
JSONArray flowPoolSharingInfo = (JSONArray) JSONObject.get("flowPoolSharingInfo");
|
||||
JSONObject flowPoolSharingInfoObject = (JSONObject) flowPoolSharingInfo.get(i);
|
||||
String totalAmount = (String) flowPoolSharingInfoObject.get("totalAmount");
|
||||
log.info("totalAmount:" + totalAmount);
|
||||
String offeringName = (String) flowPoolSharingInfoObject.get("offeringName");
|
||||
log.info("offeringName:" + offeringName);
|
||||
String remainAmount = (String) flowPoolSharingInfoObject.get("remainAmount");
|
||||
log.info("remainAmount:" + remainAmount);
|
||||
String offeringId = (String) flowPoolSharingInfoObject.get("offeringId");
|
||||
String useAmount = (String) flowPoolSharingInfoObject.get("useAmount");
|
||||
log.info("useAmount:" + useAmount);
|
||||
packageDetailRespVo.setRemainAmount(remainAmount);
|
||||
packageDetailRespVo.setTotalAmount(totalAmount);
|
||||
packageDetailRespVo.setUseAmount(useAmount);
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
packageDetailRespVo.setUpdateTime(format);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return packageDetailRespVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 查询所有的套餐下卡的当月流量详情(批量查询)
|
||||
*/
|
||||
//(有入参移动套餐的所有的List)
|
||||
public String getQueryPackageCardInfo(List<CardInfo> list) {
|
||||
// 请求具体的接口名称
|
||||
String apiName = "/ec/query/sim-data-usage-monthly/batch";
|
||||
String token = getMoveToken();
|
||||
/* String redisKey = "flowMonitor:mobile:appId:" + appId;
|
||||
String token = null;
|
||||
Boolean flag = redisService.hasKey(redisKey);
|
||||
if (flag) {
|
||||
Map<Object, Object> hgetall = redisService.hgetall(redisKey);
|
||||
if (hgetall.containsKey("token")) {
|
||||
token = (String) hgetall.get("token");
|
||||
}
|
||||
} else {
|
||||
token = getMoveToken();
|
||||
}*/
|
||||
String transId = transIdGenerator.generateTransIdForMobile(appId);
|
||||
//对于卡号的拼接
|
||||
String msisdString = "";
|
||||
for (CardInfo cardInfo : list) {
|
||||
if (!cardInfo.getCard().isEmpty()) {
|
||||
msisdString = msisdString + "_" + cardInfo.getCard();
|
||||
}
|
||||
}
|
||||
String iccids = msisdString.substring(1, msisdString.length());
|
||||
//拿取当月时间
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE).substring(0, 7);
|
||||
String replace = format.replace("-", "");
|
||||
// 封装请求接口的参数,需要按实际环境修改
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("transid", transId);
|
||||
map.put("token", token);
|
||||
map.put("iccids", iccids); //msisdns、imsis、iccids 三个参数有且仅有一个即可
|
||||
map.put("queryDate", replace); // 仅支持查询近6个月中某月的使用量,其中本月数据截止为前一天
|
||||
// 通过参数构造请求URL和参数
|
||||
String url = buildUrl(map, ipAndPort, version, apiName);
|
||||
// 获取接口返回信息
|
||||
String result = sendRequest(url);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @author 单卡流量池内使用量实时查询(/ ec / query / sim - data - usage - inpool)
|
||||
*/
|
||||
@Override
|
||||
public String getSingleCard(String iccid) {
|
||||
// 请求具体的接口名称
|
||||
//String apiName = "/ec/query/sim-data-margin";
|
||||
String apiName = "/ec/query/sim-data-usage-inpool";
|
||||
String token = getMoveToken();
|
||||
/* String redisKey = "flowMonitor:mobile:appId:" + appId;
|
||||
String token = null;
|
||||
Boolean flag = redisService.hasKey(redisKey);
|
||||
if (flag) {
|
||||
Map<Object, Object> hgetall = redisService.hgetall(redisKey);
|
||||
if (hgetall.containsKey("token")) {
|
||||
token = (String) hgetall.get("token");
|
||||
}
|
||||
} else {
|
||||
token = getMoveToken();
|
||||
}*/
|
||||
String transId = transIdGenerator.generateTransIdForMobile(appId);
|
||||
// 封装请求接口的参数,需要按实际环境修改
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("transid", transId);
|
||||
map.put("token", token);
|
||||
map.put("iccid", iccid);
|
||||
// 通过参数构造请求URL和参数
|
||||
String url = buildUrl(map, ipAndPort, version, apiName);
|
||||
// 获取接口返回信息
|
||||
String result = sendRequest(url);
|
||||
log.info("result:" + result);
|
||||
//{"status":"0","message":"正确","result":[{"apnList":[{"apnName":"CMMTMHZCN.JS","apnUseAmount":"513593344"}]}]}
|
||||
//return result;
|
||||
JSONObject cardInfoObject = JSON.parseObject(result);
|
||||
String dataAmount = null;
|
||||
if (cardInfoObject != null) {
|
||||
String status = (String) cardInfoObject.get("status");
|
||||
Integer statusInteger = Integer.valueOf(status);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONArray cardInfoJSONArray = (JSONArray) cardInfoObject.get("result");
|
||||
for (int h = 0; h <= cardInfoJSONArray.size(); h++) {
|
||||
JSONObject JSONObject = (JSONObject) cardInfoJSONArray.get(h);
|
||||
JSONArray apnList = (JSONArray) JSONObject.get("apnList");
|
||||
for (int m = 0; m < apnList.size(); m++) {
|
||||
CardInfoDate cardInfoDate = new CardInfoDate();
|
||||
JSONObject dataAmountJSONObject = (JSONObject) apnList.get(m);
|
||||
dataAmount = (String) dataAmountJSONObject.get("apnUseAmount");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
* 获取请求接口的返回信息
|
||||
*
|
||||
* @param url 请求接口时需要传入的URL
|
||||
*/
|
||||
public static String sendRequest(String url) {
|
||||
InputStream inputStream = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
HttpURLConnection httpURLConnection = null;
|
||||
try {
|
||||
URL requestURL = new URL(url);
|
||||
// 获取连接
|
||||
httpURLConnection = (HttpURLConnection) requestURL.openConnection();
|
||||
httpURLConnection.setConnectTimeout(25000); //建立连接的超时时间,毫秒
|
||||
httpURLConnection.setReadTimeout(50000); //获得返回的超时时间,毫秒
|
||||
httpURLConnection.setRequestMethod("GET");
|
||||
// 通过输入流获取请求的内容
|
||||
inputStream = httpURLConnection.getInputStream();
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
String temp = null;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
// 循环读取返回的结果
|
||||
while ((temp = bufferedReader.readLine()) != null) {
|
||||
stringBuffer.append(temp);
|
||||
}
|
||||
|
||||
return stringBuffer.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
//断开连接
|
||||
if (httpURLConnection != null) {
|
||||
httpURLConnection.disconnect();
|
||||
}
|
||||
// 关闭流
|
||||
if (bufferedReader != null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造请求地址URL
|
||||
*
|
||||
* @param paramMap 请求参数
|
||||
* @return URL
|
||||
*/
|
||||
private static String buildUrl(Map<String, String> paramMap, String ipAndPort, String version, String
|
||||
apiName) {
|
||||
String url = null;
|
||||
StringBuffer urlString = new StringBuffer();
|
||||
urlString.append(ipAndPort).append(version).append(apiName);
|
||||
|
||||
if (!paramMap.isEmpty()) {
|
||||
log.info("paramMap:" + paramMap);
|
||||
// 参数列表不为空,地址尾部增加'?'
|
||||
urlString.append('?');
|
||||
// 拼接参数
|
||||
Set<Map.Entry<String, String>> entrySet = paramMap.entrySet();
|
||||
log.info("entrySet:" + entrySet);
|
||||
for (Map.Entry<String, String> entry : entrySet) {
|
||||
try {
|
||||
urlString.append(entry.getKey()).append('=').append(URLEncoder.encode(entry.getValue(), "UTF-8")).append('&');
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// 去掉最后一个字符“&”
|
||||
url = urlString.substring(0, urlString.length() - 1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,412 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.excel.util.DateUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ho.business.entity.Device;
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.business.vo.DeviceTransfer;
|
||||
import com.ho.business.vo.req.DeviceReqVO;
|
||||
import com.ho.business.vo.req.point.PointCurveReq;
|
||||
import com.ho.business.vo.resp.DeviceRespVO;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.DataResult;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.PageResult;
|
||||
import com.ho.common.tools.util.PageUtils;
|
||||
import com.ho.filecenter.entity.Otaupgrad;
|
||||
import com.ho.filecenter.feignclient.BusinessFeignClient;
|
||||
import com.ho.filecenter.mapper.OtaupgradMapper;
|
||||
import com.ho.filecenter.service.FileService;
|
||||
import com.ho.filecenter.service.OtaupgradService;
|
||||
import com.ho.filecenter.vo.OtaFileVO;
|
||||
import com.ho.filecenter.vo.ScheduleReqVo;
|
||||
import com.ho.filecenter.vo.UpdateRecords;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2023/8/2 10:33
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OtaupgradServiceImpl implements OtaupgradService {
|
||||
|
||||
@Value("${path.local}")
|
||||
String localPath;
|
||||
|
||||
@Autowired
|
||||
OtaupgradMapper otaupgradMapper;
|
||||
|
||||
@Autowired
|
||||
FileService fileService;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BusinessFeignClient businessFeignClient;
|
||||
|
||||
@Override
|
||||
public PageResult<Otaupgrad> page(OtaFileVO vo) {
|
||||
PointCurveReq pointCurveReq = new PointCurveReq();
|
||||
pointCurveReq.setIds(vo.getStationIdList());
|
||||
pointCurveReq.setDeviceName(vo.getDeviceName());
|
||||
pointCurveReq.setDeviceType(vo.getDeviceType());
|
||||
DataResult<List<Device>> deviceDataResult = businessFeignClient.getByStationId(pointCurveReq);
|
||||
List<Otaupgrad> list = new ArrayList<>();
|
||||
PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
|
||||
if (deviceDataResult.isSuccess() && !deviceDataResult.getData().isEmpty()) {
|
||||
List<Otaupgrad> otaupgradList = otaupgradMapper.selectAll(vo);
|
||||
List<Device> data = deviceDataResult.getData();
|
||||
for (Device datum : data) {
|
||||
Otaupgrad otaupgradValue = new Otaupgrad();
|
||||
otaupgradValue.setSrcId(datum.getSrcId());
|
||||
otaupgradValue.setDeviceName(datum.getDeviceName());
|
||||
otaupgradValue.setDeviceType(datum.getDeviceType());
|
||||
otaupgradValue.setStationId(datum.getStationId());
|
||||
DataResult<Station> stationDataResult = businessFeignClient.selectByStationId(datum.getStationId());
|
||||
Station station = stationDataResult.getData();
|
||||
otaupgradValue.setStationName(station.getName());
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setSrcId(datum.getSrcId());
|
||||
deviceReqVO.setStationId(station.getId());
|
||||
DataResult<DeviceRespVO> listDataResult = businessFeignClient.selectBySrcIdAndStationId(deviceReqVO);
|
||||
DeviceRespVO deviceRespVO = listDataResult.getData();
|
||||
String key = deviceRespVO.getDeviceType() + ":" + station.getId() + ":" + datum.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
//版本号
|
||||
DeviceTransfer totalChargeTransfer = (DeviceTransfer) redisService.hget(key, "fwareVerRead");
|
||||
if (totalChargeTransfer != null) {
|
||||
otaupgradValue.setVersion(totalChargeTransfer.getValue().toString());
|
||||
}
|
||||
}
|
||||
list.add(otaupgradValue);
|
||||
}
|
||||
//将查出的重复数据剔除,留下最新版本 otaupgradList
|
||||
Map<Integer, List<Otaupgrad>> otaupgradMap = otaupgradList.stream().collect(Collectors.groupingBy(Otaupgrad::getSrcId));
|
||||
List<Otaupgrad> otaupgradNewList = new ArrayList<>();
|
||||
for (Otaupgrad otaupgrad : otaupgradList) {
|
||||
List<Otaupgrad> st1 = otaupgradMap.get(otaupgrad.getSrcId());
|
||||
if (CommonConstant.ONE != st1.size()) {
|
||||
otaupgradNewList.add(st1.get(0));
|
||||
} else {
|
||||
otaupgradNewList.add(st1.get(0));
|
||||
}
|
||||
}
|
||||
List<Otaupgrad> sList = otaupgradNewList.stream().distinct().collect(Collectors.toList());
|
||||
for (Otaupgrad otaupgrad : list) {
|
||||
for (Otaupgrad value : sList) {
|
||||
if (otaupgrad.getSrcId().equals(value.getSrcId()) && otaupgrad.getStationId().equals(value.getStationId())) {
|
||||
otaupgrad.setId(value.getId());
|
||||
otaupgrad.setStationId(value.getStationId());
|
||||
otaupgrad.setSrcId(value.getSrcId());
|
||||
otaupgrad.setDeviceName(value.getDeviceName());
|
||||
otaupgrad.setDeviceType(value.getDeviceType());
|
||||
otaupgrad.setFileName(value.getFileName());
|
||||
// otaupgrad.setVersion(value.getVersion());
|
||||
otaupgrad.setUpdateCause(value.getUpdateCause());
|
||||
otaupgrad.setUpdatesTime(DateUtil.formatDateTime(value.getUpdateTime()));
|
||||
otaupgrad.setCreateTime(value.getCreateTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PageResult pageResult = PageUtils.getPageResult(new PageInfo<>(list));
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UpdateRecords> selectHisFile(OtaFileVO vo) {
|
||||
List<UpdateRecords> list = new ArrayList<>();
|
||||
List<Otaupgrad> otaupgradList = otaupgradMapper.selectAll(vo);
|
||||
for (int i = 0; i < otaupgradList.size(); i++) {
|
||||
Otaupgrad otaupgrad = otaupgradList.get(i);
|
||||
UpdateRecords updateRecords = new UpdateRecords();
|
||||
BeanUtils.copyProperties(otaupgrad, updateRecords);
|
||||
if (i + 1 < otaupgradList.size()) {
|
||||
Otaupgrad otaupgradValue = otaupgradList.get(i + 1);
|
||||
if (otaupgradValue.getUpdateTime() != null) {
|
||||
// Date updateTime = otaupgradValue.getUpdateTime();
|
||||
// DateFormat dateformat = new SimpleDateFormat(CommonConstant.DATE);
|
||||
// String format = dateformat.format(updateTime);
|
||||
updateRecords.setFrontUpdateTime(DateUtils.format(otaupgradValue.getUpdateTime(), CommonConstant.DATE));
|
||||
}
|
||||
updateRecords.setFrontVersion(otaupgradValue.getVersion());
|
||||
}
|
||||
list.add(updateRecords);
|
||||
}
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setSrcId(vo.getSrcId());
|
||||
deviceReqVO.setStationId(vo.getStationId());
|
||||
DataResult<DeviceRespVO> listDataResult = businessFeignClient.selectBySrcIdAndStationId(deviceReqVO);
|
||||
DeviceRespVO data = listDataResult.getData();
|
||||
String key = data.getDeviceType() + ":" + vo.getStationId() + ":" + vo.getSrcId();
|
||||
if (redisService.hasKey(key)) {
|
||||
//版本号
|
||||
DeviceTransfer totalChargeTransfer = (DeviceTransfer) redisService.hget(key, "fwareVerRead");
|
||||
if (totalChargeTransfer != null) {
|
||||
UpdateRecords updateRecords = list.get(CommonConstant.ZERO);
|
||||
updateRecords.setVersion(totalChargeTransfer.getValue().toString());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradation(MultipartFile file, OtaFileVO vo, SimpleUser user) throws ParseException {
|
||||
String userId = user.getUserId();
|
||||
String name = file.getOriginalFilename();
|
||||
//先把电站呵设备解出来
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
List<Integer> stationList = new ArrayList<>();
|
||||
List<String> deviceList = new ArrayList<>();
|
||||
for (String stationAndDevice : vo.getStationIdAndDeviceList()) {
|
||||
String[] temp;
|
||||
String delimiter = "-";// 指定分割字符
|
||||
temp = stationAndDevice.split(delimiter);
|
||||
int stationId = Integer.parseInt(temp[0]);
|
||||
for (int i = 1; i < temp.length; i++) {
|
||||
deviceList.add(temp[i]);
|
||||
map.put(temp[i], stationId);
|
||||
}
|
||||
stationList.add(stationId);
|
||||
}
|
||||
List<Otaupgrad> list = new ArrayList<>();
|
||||
if (!stationList.isEmpty()) {
|
||||
Set<String> keys = map.keySet();
|
||||
for (String key : keys) {
|
||||
Integer value = map.get(key);
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setSrcId(Integer.valueOf(key).intValue());
|
||||
deviceReqVO.setStationId(value);
|
||||
DataResult<DeviceRespVO> listDataResult = businessFeignClient.selectBySrcIdAndStationId(deviceReqVO);
|
||||
DeviceRespVO data = listDataResult.getData();
|
||||
Otaupgrad otaupgrad = new Otaupgrad();
|
||||
otaupgrad.setFileName(name);
|
||||
otaupgrad.setDeviceName(data.getDeviceName());
|
||||
otaupgrad.setSrcId(Integer.valueOf(key));
|
||||
otaupgrad.setStationId(value);
|
||||
otaupgrad.setUpdateCause(vo.getUpdateCause());
|
||||
otaupgrad.setUpdateTime(DateUtil.parse(vo.getUpdateTime()));
|
||||
otaupgrad.setVersion(vo.getVersion());
|
||||
otaupgrad.setCreateTime(new Date());
|
||||
otaupgrad.setUpdateName(userId);
|
||||
list.add(otaupgrad);
|
||||
}
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
int i = otaupgradMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tage(MultipartFile file, OtaFileVO vo) throws Exception {
|
||||
List<Integer> stationList = new ArrayList<>();
|
||||
for (String stationAndDevice : vo.getStationIdAndDeviceList()) {
|
||||
String[] temp;
|
||||
String delimiter = "-";// 指定分割字符
|
||||
temp = stationAndDevice.split(delimiter);
|
||||
int stationId = Integer.parseInt(temp[0]);
|
||||
stationList.add(stationId);
|
||||
}
|
||||
//生成配置文件
|
||||
getConfigFile(file, vo);
|
||||
//去获取生成的配置文件
|
||||
String fileName = "config";
|
||||
Path path3 = Paths.get(localPath + File.separator + fileName);
|
||||
String srcFilepath = localPath + File.separator + file.getOriginalFilename();
|
||||
//创建文件
|
||||
File uploadFile = new File(srcFilepath);
|
||||
//判断是否存在文件目录,没有就创建
|
||||
uploadFile.mkdirs();
|
||||
//上传文件到指定路径
|
||||
file.transferTo(uploadFile);
|
||||
List pathList = Arrays.asList(Paths.get(srcFilepath), path3);
|
||||
//输出文件压缩结果
|
||||
String name = "devUpgradePack.tar.gz";
|
||||
String value = localPath + File.separator + name;
|
||||
Path output = Paths.get(localPath + File.separator + name);
|
||||
//OutputStream输出流、BufferedOutputStream缓冲输出流
|
||||
//GzipCompressorOutputStream是gzip压缩输出流
|
||||
//TarArchiveOutputStream打tar包输出流(包含gzip压缩输出流)
|
||||
try (OutputStream fOut = Files.newOutputStream(output);
|
||||
BufferedOutputStream buffOut = new BufferedOutputStream(fOut);
|
||||
GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(buffOut);
|
||||
TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)) {
|
||||
for (Object path : pathList) {
|
||||
Path path1 = (Path) path;
|
||||
//该文件不是目录或者符号链接
|
||||
if (!Files.isRegularFile(path1)) {
|
||||
throw new IOException("Support only file!");
|
||||
}
|
||||
//将该文件放入tar包,并执行gzip压缩
|
||||
TarArchiveEntry tarEntry = new TarArchiveEntry(
|
||||
path1.toFile(),
|
||||
path1.getFileName().toString());
|
||||
tOut.putArchiveEntry(tarEntry);
|
||||
Files.copy(path1, tOut);
|
||||
|
||||
tOut.closeArchiveEntry();
|
||||
}
|
||||
//for循环完成之后,finish-tar包输出流
|
||||
tOut.finish();
|
||||
fileService.fileUploadDevice(name, stationList, value);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Long getCRCValue(MultipartFile file) throws Exception {
|
||||
byte[] bytes = file.getBytes();
|
||||
CRC32 crc32 = new CRC32();
|
||||
crc32.update(bytes);
|
||||
long crcValue = crc32.getValue();
|
||||
return crcValue;
|
||||
}
|
||||
|
||||
|
||||
public void getConfigFile(MultipartFile file, OtaFileVO vo) throws Exception {
|
||||
//先把电站呵设备解出来
|
||||
List<String> deviceList = new ArrayList<>();
|
||||
for (String stationAndDevice : vo.getStationIdAndDeviceList()) {
|
||||
String[] temp;
|
||||
String delimiter = "-";// 指定分割字符
|
||||
temp = stationAndDevice.split(delimiter);
|
||||
for (int i = 1; i < temp.length; i++) {
|
||||
deviceList.add(temp[i]);
|
||||
}
|
||||
}
|
||||
String srcId = "";
|
||||
if (CommonConstant.ONE < deviceList.size()) {
|
||||
for (int i = 0; i < deviceList.size(); i++) {
|
||||
srcId = srcId + deviceList.get(i) + ",";
|
||||
}
|
||||
} else {
|
||||
srcId = deviceList.get(CommonConstant.ZERO) + ",";
|
||||
|
||||
}
|
||||
String name = file.getOriginalFilename();
|
||||
byte[] bytes = file.getBytes();
|
||||
Long crcValue = getCRCValue(file);
|
||||
String version = vo.getVersion();
|
||||
String newStr = vo.getUpdateTime().replace(':', '-');
|
||||
String update = newStr.replace(' ', '-');
|
||||
String fileName = "config";
|
||||
Path path = Paths.get(localPath + "/" + fileName);
|
||||
// 使用newBufferedWriter创建文件并写文件
|
||||
// 这里使用了try-with-resources方法来关闭流,不用手动关闭
|
||||
String lineSeparator = System.getProperty("line.separator");
|
||||
try (BufferedWriter writer =
|
||||
Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
||||
writer.write("PARAM_NAME\t\tVALUE\t\t\t\t\t\t\tDESC\n");
|
||||
writer.write("FILENAME \t\t" + name + " \t\t\t\t\t升级文件名,最长64个字节" + lineSeparator);
|
||||
writer.write("FILELEN \t\t" + bytes.length + "\t\t\t\t\t\t\t升级文件长度 单位:字节" + lineSeparator);
|
||||
writer.write("CRC32 \t\t" + crcValue + "\t\t升级文件CRC32校验码" + lineSeparator);
|
||||
writer.write("FILEVER\t\t" + version + "\t\t\t\t\t\t\t升级文件版本号,最长4字节" + lineSeparator);
|
||||
writer.write("DEVID\t\t\t" + srcId.substring(0, srcId.length() - 1) + "\t\t升级机器id" + lineSeparator);
|
||||
writer.write("UPGRADE_TIME\t" + update + "\t机器升级时间点 YYYY-MM-DD-HH-mm-ss" + lineSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ScheduleReqVo> getUpgradeProgress(OtaFileVO vo) {
|
||||
List<ScheduleReqVo> list = new ArrayList<>();
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
List<Integer> stationList = new ArrayList<>();
|
||||
List<String> deviceList = new ArrayList<>();
|
||||
for (String stationAndDevice : vo.getStationIdAndDeviceList()) {
|
||||
String[] temp;
|
||||
String delimiter = "-";// 指定分割字符
|
||||
temp = stationAndDevice.split(delimiter);
|
||||
int stationId = Integer.parseInt(temp[0]);
|
||||
for (int i = 1; i < temp.length; i++) {
|
||||
deviceList.add(temp[i]);
|
||||
map.put(temp[i], stationId);
|
||||
}
|
||||
stationList.add(stationId);
|
||||
}
|
||||
Map<Integer, String> stationDeviceType = new HashMap<>();
|
||||
for (String stationIdAndDeviceType : vo.getStationIdAndDeviceTypeList()) {
|
||||
String[] temp;
|
||||
String delimiter = "-";// 指定分割字符
|
||||
temp = stationIdAndDeviceType.split(delimiter);
|
||||
int stationId = Integer.parseInt(temp[0]);
|
||||
for (int i = 1; i < temp.length; i++) {
|
||||
deviceList.add(temp[i]);
|
||||
stationDeviceType.put(stationId, temp[i]);
|
||||
}
|
||||
}
|
||||
for (String device : deviceList) {
|
||||
if (!device.equals("null")) {
|
||||
ScheduleReqVo scheduleReqVo = new ScheduleReqVo();
|
||||
if (map.containsKey(device)) {
|
||||
Integer stationId = map.get(device);
|
||||
DeviceReqVO deviceReqVO = new DeviceReqVO();
|
||||
deviceReqVO.setSrcId(Integer.valueOf(device).intValue());
|
||||
deviceReqVO.setStationId(stationId);
|
||||
DataResult<DeviceRespVO> listDataResult = businessFeignClient.selectBySrcIdAndStationId(deviceReqVO);
|
||||
DeviceRespVO data = listDataResult.getData();
|
||||
|
||||
String key = data.getDeviceType() + ":" + stationId + ":" + device;
|
||||
scheduleReqVo.setStationId(stationId);
|
||||
scheduleReqVo.setSrcId(Integer.valueOf(device));
|
||||
if (redisService.hasKey(key)) {
|
||||
//升级状态
|
||||
DeviceTransfer socTransfer = (DeviceTransfer) redisService.hget(key, "mstatusread");
|
||||
if (socTransfer != null) {
|
||||
scheduleReqVo.setUpgradeResult(socTransfer.getValue());
|
||||
} else {
|
||||
scheduleReqVo.setUpgradeResult(new BigDecimal(0));
|
||||
}
|
||||
//进度百分比
|
||||
DeviceTransfer sohTransfer = (DeviceTransfer) redisService.hget(key, "upgradeProcession");
|
||||
if (sohTransfer != null) {
|
||||
scheduleReqVo.setUpgradeProcession(sohTransfer.getValue());
|
||||
} else {
|
||||
scheduleReqVo.setUpgradeProcession(new BigDecimal(0));
|
||||
}
|
||||
//版本号
|
||||
DeviceTransfer totalChargeTransfer = (DeviceTransfer) redisService.hget(key, "fwareVerRead");
|
||||
if (totalChargeTransfer != null) {
|
||||
scheduleReqVo.setFwareVerRead(totalChargeTransfer.getValue());
|
||||
} else {
|
||||
scheduleReqVo.setFwareVerRead(new BigDecimal(2.3).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
} else {
|
||||
scheduleReqVo.setUpgradeResult(new BigDecimal(0));
|
||||
scheduleReqVo.setUpgradeProcession(new BigDecimal(0));
|
||||
scheduleReqVo.setFwareVerRead(new BigDecimal(2.3).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
}
|
||||
list.add(scheduleReqVo);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,197 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.business.vo.SingleValueColVo;
|
||||
import com.ho.business.vo.resp.point.PointCurveHomeResp;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.vo.req.StationHomeRespVo;
|
||||
import com.ho.filecenter.service.PdfService;
|
||||
import com.itextpdf.text.Element;
|
||||
import com.itextpdf.text.Font;
|
||||
import com.itextpdf.text.Image;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
import com.itextpdf.text.pdf.PdfPCell;
|
||||
import com.itextpdf.text.pdf.PdfPTable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartUtils;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.axis.CategoryAxis;
|
||||
import org.jfree.chart.axis.ValueAxis;
|
||||
import org.jfree.chart.plot.CategoryPlot;
|
||||
import org.jfree.chart.plot.PlotOrientation;
|
||||
import org.jfree.data.category.DefaultCategoryDataset;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc: PDF文件处理
|
||||
* @date 2023/11/28
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PdfServiceImpl implements PdfService {
|
||||
|
||||
@Value("${path.chartPath}")
|
||||
String charPath;
|
||||
|
||||
@Override
|
||||
public List<PdfPTable> getPdfTableList(List<PointCurveHomeResp> pointCurveList, Font titleFont) throws Exception {
|
||||
List<PdfPTable> pdfTableList = new ArrayList<>();
|
||||
// 创建两列的面板数据table
|
||||
PdfPTable panelImageTable = null;
|
||||
PdfPCell title= null;
|
||||
for (PointCurveHomeResp planPoint : pointCurveList) {
|
||||
panelImageTable = new PdfPTable(1);
|
||||
PdfPCell cellWithImage = null;
|
||||
//图片单独创建表格
|
||||
//设置表格宽度百分比
|
||||
panelImageTable.setWidthPercentage(100);
|
||||
float[] columnPanelImageWidths = {1.0f};
|
||||
panelImageTable.setWidths(columnPanelImageWidths);
|
||||
//第一列
|
||||
String lineStr = null;
|
||||
lineStr = planPoint.getColName() ;
|
||||
title = new PdfPCell(new Paragraph(lineStr, titleFont));
|
||||
title.setHorizontalAlignment(Element.ALIGN_LEFT);
|
||||
Image instance = null;
|
||||
//生成图片的路径
|
||||
//charPath
|
||||
Date now = new Date();
|
||||
String timeContent = DateUtil.format(now, CommonConstant.DATEYMDHSS);
|
||||
//判断文件夹是否存在,不存在就创建
|
||||
File fileFolder = new File(charPath);
|
||||
if (!fileFolder.exists()) {
|
||||
fileFolder.mkdirs();
|
||||
}
|
||||
String path = charPath + timeContent + ".jpg";
|
||||
List<StationHomeRespVo> staticCurveList = planPoint.getStaticCurveList();
|
||||
if(staticCurveList ==null || staticCurveList.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
instance = getImage(staticCurveList, path, planPoint.getColName());
|
||||
try (FileInputStream fis = new FileInputStream(path)) {
|
||||
byte[] buffer = new byte[(int) path.length()];
|
||||
fis.read(buffer);
|
||||
// 现在,buffer数组中保存了文件的二进制数据
|
||||
fis.close();
|
||||
instance = Image.getInstance(buffer);
|
||||
} catch (IOException e) {
|
||||
log.error("解析图片错误");
|
||||
}
|
||||
// 创建包含图片的单元格
|
||||
if (instance != null) {
|
||||
cellWithImage = new PdfPCell(instance, false);
|
||||
cellWithImage.setFixedHeight(50f);
|
||||
cellWithImage.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cellWithImage.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
|
||||
panelImageTable.addCell(instance);
|
||||
pdfTableList.add(panelImageTable);
|
||||
}
|
||||
}
|
||||
return pdfTableList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PdfPTable> getOneTableList(List<SingleValueColVo> pointSingleValueList, Font titleFont) throws Exception {
|
||||
List<PdfPTable> pdfPTableList = new ArrayList<>();
|
||||
if(pointSingleValueList!=null && !pointSingleValueList.isEmpty()){
|
||||
for (SingleValueColVo singleValueColVo : pointSingleValueList) {
|
||||
// 创建两列的面板数据table
|
||||
PdfPTable panelTable = new PdfPTable(1);
|
||||
// 设置表格宽度百分比
|
||||
panelTable.setWidthPercentage(100);
|
||||
float[] columnPanelWidths = {1.0f};
|
||||
panelTable.setWidths(columnPanelWidths);
|
||||
//第一列
|
||||
String lineStr = singleValueColVo.getColName() +"-" +singleValueColVo.getCol()+" 值:" + singleValueColVo.getValue();
|
||||
PdfPCell title = new PdfPCell(new Paragraph(lineStr, titleFont));
|
||||
title.setHorizontalAlignment(Element.ALIGN_LEFT);
|
||||
panelTable.addCell(title);
|
||||
pdfPTableList.add(panelTable);
|
||||
}
|
||||
}
|
||||
return pdfPTableList;
|
||||
|
||||
}
|
||||
|
||||
//根据
|
||||
Image getImage(List<StationHomeRespVo> staticCurveList, String path, String curveName) throws Exception {
|
||||
BaseFont bfCN = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
||||
Font titleFont = new Font(bfCN, 12f);
|
||||
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
|
||||
//
|
||||
for (StationHomeRespVo stationHomeRespVo : staticCurveList) {
|
||||
dataSet.addValue(stationHomeRespVo.getDigital(), curveName, stationHomeRespVo.getDate());
|
||||
}
|
||||
|
||||
//dataSet.addValue(30, "家储", "第二季度");
|
||||
//dataSet.addValue(40, "家储", "第三季度");
|
||||
//dataSet.addValue(50, "家储", "第四季度");
|
||||
|
||||
JFreeChart lineChart = ChartFactory.createLineChart(curveName, "", "", dataSet, PlotOrientation.VERTICAL, true, true, true);
|
||||
lineChart.getLegend().setItemFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 12));
|
||||
//获取title
|
||||
lineChart.getTitle().setFont(new java.awt.Font("宋体", java.awt.Font.BOLD, 16));
|
||||
|
||||
//获取绘图区对象
|
||||
CategoryPlot linePlot = lineChart.getCategoryPlot();
|
||||
//设置绘图区域背景的 alpha 透明度 ,在 0.0f 到 1.0f 的范围内
|
||||
linePlot.setBackgroundAlpha(0.5f);
|
||||
|
||||
//区域背景色
|
||||
linePlot.setBackgroundPaint(Color.white);
|
||||
|
||||
//背景底部横虚线
|
||||
linePlot.setRangeGridlinePaint(Color.gray);
|
||||
//linePlot.setRangeGridlinePaint(Color.white);
|
||||
//linePlot.setOutlinePaint(Color.RED);//边界线
|
||||
|
||||
// 设置水平方向背景线颜色
|
||||
// 设置是否显示水平方向背景线,默认值为true
|
||||
linePlot.setRangeGridlinesVisible(true);
|
||||
// 设置垂直方向背景线颜色
|
||||
linePlot.setDomainGridlinePaint(Color.gray);
|
||||
//linePlot.setDomainGridlinePaint(Color.gray);
|
||||
// 设置是否显示垂直方向背景线,默认值为false
|
||||
linePlot.setDomainGridlinesVisible(true);
|
||||
|
||||
|
||||
//获取坐标轴对象
|
||||
CategoryAxis lineAxis = linePlot.getDomainAxis();
|
||||
//设置坐标轴字体
|
||||
lineAxis.setLabelFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 12));
|
||||
//设置坐标轴标尺值字体(x轴)
|
||||
lineAxis.setTickLabelFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 12));
|
||||
//获取数据轴对象(y轴)
|
||||
ValueAxis rangeAxis = linePlot.getRangeAxis();
|
||||
rangeAxis.setLabelFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 12));
|
||||
|
||||
|
||||
//图片存放位置
|
||||
//String templatePath = "e:/1.jpg";
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(path);
|
||||
ChartUtils.writeChartAsJPEG(fos, 0.7f, lineChart, 400, 300);
|
||||
fos.close();
|
||||
Paragraph lineParagraph = new Paragraph(curveName, titleFont);
|
||||
lineParagraph.setAlignment(Paragraph.ALIGN_LEFT);
|
||||
//document.add(lineParagraph);
|
||||
com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(path);
|
||||
image.setAlignment(com.itextpdf.text.Image.ALIGN_CENTER);
|
||||
image.scaleAbsolute(400, 300);
|
||||
return image;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
|
||||
import com.ho.filecenter.entity.Power;
|
||||
import com.ho.filecenter.entity.PowerDetail;
|
||||
import com.ho.filecenter.mapper.PowerDetailMapper;
|
||||
import com.ho.filecenter.service.PowerDetailService;
|
||||
import com.ho.filecenter.service.PowerService;
|
||||
import com.ho.filecenter.vo.DetailVo;
|
||||
import com.ho.filecenter.vo.PowerDetailVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【power_detail】的数据库操作Service实现
|
||||
* @createDate 2023-03-16 10:59:17
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PowerDetailServiceImpl implements PowerDetailService {
|
||||
@Autowired
|
||||
PowerDetailMapper powerDetailMapper;
|
||||
|
||||
@Autowired
|
||||
PowerService powerService;
|
||||
|
||||
@Override
|
||||
public List<PowerDetail> selectByPid(Integer id) {
|
||||
List<PowerDetail> detailList = powerDetailMapper.selectByPid(id);
|
||||
return detailList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<Integer> ids, List<Integer> pids) {
|
||||
return powerDetailMapper.deleteBatch(ids, pids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBatch(List<PowerDetail> powerDetailList) {
|
||||
powerDetailMapper.addBatch(powerDetailList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerDetailVo selectDetails(DetailVo vo) {
|
||||
PowerDetailVo powerDetailVo = new PowerDetailVo();
|
||||
//根据id/月份/项目名称查询表信息
|
||||
Power power = powerService.selectById(vo);
|
||||
if (power == null) {
|
||||
return powerDetailVo;
|
||||
}
|
||||
//在根据主表id查询改主表的所有
|
||||
List<PowerDetail> powerDetails = selectByPid(power.getId());
|
||||
powerDetailVo.setPowerP(power.getPowerP());
|
||||
powerDetailVo.setPowerG(power.getPowerG());
|
||||
powerDetailVo.setPowerF(power.getPowerF());
|
||||
powerDetailVo.setPowerJ(power.getPowerJ());
|
||||
powerDetailVo.setPowerSelf(power.getPowerSelf());
|
||||
powerDetailVo.setPowerSigle(power.getPowerSigle());
|
||||
powerDetailVo.setPowerUp(power.getPowerUp());
|
||||
powerDetailVo.setProjectName(power.getProjectName());
|
||||
powerDetailVo.setReceivableFee(power.getReceivableFee());
|
||||
powerDetailVo.setSettleMonth(power.getSettleMonth());
|
||||
powerDetailVo.setBiCycle(power.getBiCycle());
|
||||
powerDetailVo.setChecker(power.getChecker());
|
||||
powerDetailVo.setConsumeRatio(power.getConsumeRatio());
|
||||
powerDetailVo.setCreateTime(power.getCreateTime());
|
||||
powerDetailVo.setCreator(power.getCreator());
|
||||
powerDetailVo.setDiscountPriceF(power.getDiscountPriceF());
|
||||
powerDetailVo.setDiscountPriceP(power.getDiscountPriceP());
|
||||
powerDetailVo.setDiscountPriceG(power.getDiscountPriceG());
|
||||
powerDetailVo.setDiscountPriceJ(power.getDiscountPriceJ());
|
||||
powerDetailVo.setDiscountPriceSigle(power.getDiscountPriceSigle());
|
||||
powerDetailVo.setFeeF(power.getFeeF());
|
||||
powerDetailVo.setFeeG(power.getFeeG());
|
||||
powerDetailVo.setFeeJ(power.getFeeJ());
|
||||
powerDetailVo.setFeeP(power.getFeeP());
|
||||
powerDetailVo.setFeeSigle(power.getFeeSigle());
|
||||
powerDetailVo.setId(power.getId());
|
||||
powerDetailVo.setMeterMan(power.getMeterMan());
|
||||
powerDetailVo.setOrigPriceF(power.getOrigPriceF());
|
||||
powerDetailVo.setOrigPriceG(power.getOrigPriceG());
|
||||
powerDetailVo.setOrigPriceJ(power.getOrigPriceJ());
|
||||
powerDetailVo.setOrigPriceP(power.getOrigPriceP());
|
||||
powerDetailVo.setOrigPriceSigle(power.getOrigPriceSigle());
|
||||
powerDetailVo.setPowerAll(power.getPowerAll());
|
||||
powerDetailVo.setPowerDetailList(powerDetails);
|
||||
return powerDetailVo;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,412 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.filecenter.constant.FileConstant;
|
||||
import com.ho.filecenter.entity.Power;
|
||||
import com.ho.filecenter.entity.PowerDetail;
|
||||
import com.ho.filecenter.mapper.PowerMapper;
|
||||
import com.ho.filecenter.service.PowerDetailService;
|
||||
import com.ho.filecenter.service.PowerService;
|
||||
import com.ho.filecenter.vo.DetailVo;
|
||||
import com.ho.filecenter.vo.PowerDetailVo;
|
||||
import com.ho.filecenter.vo.PowerImport;
|
||||
import com.ho.filecenter.vo.QueryPower;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【power】的数据库操作Service实现
|
||||
* @createDate 2023-03-16 10:59:38
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PowerServiceImpl implements PowerService {
|
||||
@Autowired
|
||||
PowerMapper powerMapper;
|
||||
|
||||
@Autowired
|
||||
PowerDetailService powerDetailService;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importExcel(SimpleUser user, List<PowerImport> list) {
|
||||
//导入功能
|
||||
//存放基本信息表
|
||||
Power power = new Power();
|
||||
//存放明细表
|
||||
List<PowerImport> powerDetailList = new ArrayList<>();
|
||||
//基本信息入库
|
||||
power.setGroupId(user.getGroupId());
|
||||
PowerImport powerImport1 = list.get(0);
|
||||
//判断是否为正确的模板(根据t1是否为项目名称确定)
|
||||
if (!FileConstant.PaymentStatement.PROJECT_NAME.equals(powerImport1.getT1())) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CONFIRM_WHETHER_IMPORTED_TEMPLATE_CORRECT);
|
||||
}
|
||||
if (powerImport1.getT2() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PROJECT_NAME_CANNOT_EMPTY);
|
||||
}
|
||||
power.setProjectName(powerImport1.getT2());
|
||||
PowerImport powerImport2 = list.get(1);
|
||||
//对时间都进行处理
|
||||
//(判断月份是否大于12月份)
|
||||
String time = powerImport2.getT2();
|
||||
if (time == null) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_ENTER_MONTH);
|
||||
}
|
||||
if (time.contains("(格式:yyyy-mm)")) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_DELETE_MONTH_FORMAT_PROMPTED_TEMPLATE);
|
||||
}
|
||||
if (time.length() != 7) {
|
||||
throw new BusinessException(BaseResponseCode.ERROR_FORMAT_SETTLEMENT_MONTH_ENTERED);
|
||||
}
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
|
||||
try {
|
||||
Date parse = sf.parse(time);
|
||||
} catch (ParseException e) {
|
||||
throw new BusinessException(BaseResponseCode.ERROR_FORMAT_SETTLEMENT_MONTH_ENTERED);
|
||||
}
|
||||
String replace = time.replace(".", "-");
|
||||
String substring = replace.substring(5, 7);
|
||||
int month = Integer.valueOf(substring);
|
||||
if (month > 12 || month == CommonConstant.ZERO) {
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_TABLE_EXCEEDS_MAXIMUM_MONTH_PLEASE_VERIFY);
|
||||
}
|
||||
//根据项目名称和月份进行查询 看是否有重复数据
|
||||
DetailVo vo = new DetailVo();
|
||||
vo.setProjectName(power.getProjectName());
|
||||
vo.setSettleMonth(power.getSettleMonth());
|
||||
Power powerValue = powerMapper.selectByMonthAndName(vo);
|
||||
if (powerValue != null) {
|
||||
throw new BusinessException(BaseResponseCode.PROJECT_DATA_THAT_MONTH_PLEASE_VERIFY_MONTH);
|
||||
}
|
||||
power.setSettleMonth(replace);
|
||||
power.setMeterMan(powerImport2.getT11());
|
||||
PowerImport powerImport3 = list.get(2);
|
||||
power.setBiCycle(powerImport3.getT2());
|
||||
power.setChecker(powerImport3.getT11());
|
||||
int num = 0;
|
||||
for (int i = 5; i < list.size(); i++) {
|
||||
num = i;
|
||||
PowerImport powerImport = list.get(i);
|
||||
if (FileConstant.PaymentStatement.GROSS_GENERATION.equals(powerImport.getT1())) {
|
||||
break;
|
||||
} else {
|
||||
powerDetailList.add(powerImport);
|
||||
}
|
||||
}
|
||||
for (int i = num; i < list.size(); i++) {
|
||||
PowerImport powerImport = list.get(i);
|
||||
if (FileConstant.PaymentStatement.GROSS_GENERATION.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerAll(new BigDecimal(powerImport.getT2()));
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (FileConstant.PaymentStatement.SELF_CONSUMPTION.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerSelf(new BigDecimal(powerImport.getT2()));
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (FileConstant.PaymentStatement.ON_GRID_ENERGY.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerUp(new BigDecimal(powerImport.getT2()));
|
||||
continue;
|
||||
}
|
||||
} else if (FileConstant.PaymentStatement.ABSORPTION_RATIO.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setConsumeRatio(powerImport.getT2());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (powerImport.getT1() != null) {
|
||||
if (FileConstant.PaymentStatement.PowerJ.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerJ(new BigDecimal(powerImport.getT2()));
|
||||
}
|
||||
if (powerImport.getT3() != null) {
|
||||
power.setOrigPriceJ(new BigDecimal(powerImport.getT3()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
power.setDiscountPriceJ(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT5() != null) {
|
||||
power.setFeeJ(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
continue;
|
||||
} else if (FileConstant.PaymentStatement.PowerF.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerF(new BigDecimal(powerImport.getT2()));
|
||||
}
|
||||
if (powerImport.getT3() != null) {
|
||||
power.setOrigPriceF(new BigDecimal(powerImport.getT3()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
power.setDiscountPriceF(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT5() != null) {
|
||||
power.setFeeF(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
continue;
|
||||
} else if (FileConstant.PaymentStatement.PowerP.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerP(new BigDecimal(powerImport.getT2()));
|
||||
}
|
||||
if (powerImport.getT3() != null) {
|
||||
power.setOrigPriceP(new BigDecimal(powerImport.getT3()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
power.setDiscountPriceP(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT5() != null) {
|
||||
power.setFeeP(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
continue;
|
||||
} else if (FileConstant.PaymentStatement.PowerG.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerG(new BigDecimal(powerImport.getT2()));
|
||||
}
|
||||
if (powerImport.getT3() != null) {
|
||||
power.setOrigPriceG(new BigDecimal(powerImport.getT3()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
power.setDiscountPriceG(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT5() != null) {
|
||||
power.setFeeG(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
continue;
|
||||
} else if (FileConstant.PaymentStatement.SINGLE_PRICE.equals(powerImport.getT1())) {
|
||||
if (powerImport.getT2() != null) {
|
||||
power.setPowerSigle(new BigDecimal(powerImport.getT2()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
power.setOrigPriceSigle(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
power.setDiscountPriceSigle(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT5() != null) {
|
||||
power.setFeeSigle(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
|
||||
continue;
|
||||
} else if (FileConstant.PaymentStatement.RECEIVABLES.equals(powerImport.getT1())) {
|
||||
|
||||
if (powerImport.getT5() != null) {
|
||||
power.setReceivableFee(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
power.setCreateTime(new Date());
|
||||
//根据groupId和月份进行比较,有相同的则进行删除 加一个项目名称的判断条件
|
||||
List<Power> powerList = powerMapper.selectAll(power.getGroupId(), power.getSettleMonth(), powerImport1.getT2());
|
||||
//根据id删除主表,
|
||||
List<Integer> idList = powerList.stream().map(s -> {
|
||||
return s.getId();
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
if (!idList.isEmpty()) {
|
||||
powerMapper.batchDeletes(idList);
|
||||
powerDetailService.deleteBatch(new ArrayList<>(), idList);
|
||||
}
|
||||
// 在将进行入库 -->根据Id = pid 删除子表的数据 -->在将子表的数据进行入库
|
||||
//主表入库
|
||||
int i = powerMapper.insertSelective(power);
|
||||
//明细表入库(根据基本信息表的id先进行删除,在进行入库)
|
||||
if (!powerDetailList.isEmpty()) {
|
||||
List<PowerDetail> powerDetails = new ArrayList<>();
|
||||
for (PowerImport powerImport : powerDetailList) {
|
||||
PowerDetail powerDetail = new PowerDetail();
|
||||
powerDetail.setPid(power.getId());
|
||||
if (powerImport.getT1() != null) {
|
||||
powerDetail.setGroupId(user.getGroupId());
|
||||
powerDetail.setMeterPoint(powerImport.getT1());
|
||||
if (powerImport.getT2() != null) {
|
||||
powerDetail.setTno(powerImport.getT2());
|
||||
}
|
||||
if (powerImport.getT3() != null) {
|
||||
powerDetail.setMultiFactor(new BigDecimal(powerImport.getT3()));
|
||||
}
|
||||
if (powerImport.getT4() != null) {
|
||||
powerDetail.setPowerStartJ(new BigDecimal(powerImport.getT4()));
|
||||
}
|
||||
if (powerImport.getT7() != null) {
|
||||
powerDetail.setPowerStartF(new BigDecimal(powerImport.getT7()));
|
||||
}
|
||||
if (powerImport.getT10() != null) {
|
||||
powerDetail.setPowerStartP(new BigDecimal(powerImport.getT10()));
|
||||
}
|
||||
if (powerImport.getT13() != null) {
|
||||
powerDetail.setPowerStartG(new BigDecimal(powerImport.getT13()));
|
||||
}
|
||||
if (powerImport.getT5() != null) {
|
||||
powerDetail.setPowerEndJ(new BigDecimal(powerImport.getT5()));
|
||||
}
|
||||
if (powerImport.getT8() != null) {
|
||||
powerDetail.setPowerEndF(new BigDecimal(powerImport.getT8()));
|
||||
}
|
||||
if (powerImport.getT11() != null) {
|
||||
powerDetail.setPowerEndP(new BigDecimal(powerImport.getT11()));
|
||||
}
|
||||
if (powerImport.getT14() != null) {
|
||||
powerDetail.setPowerEndG(new BigDecimal(powerImport.getT14()));
|
||||
}
|
||||
if (powerImport.getT6() != null) {
|
||||
powerDetail.setPowerJ(new BigDecimal(powerImport.getT6()));
|
||||
}
|
||||
if (powerImport.getT9() != null) {
|
||||
powerDetail.setPowerF(new BigDecimal(powerImport.getT9()));
|
||||
}
|
||||
if (powerImport.getT12() != null) {
|
||||
powerDetail.setPowerP(new BigDecimal(powerImport.getT12()));
|
||||
}
|
||||
if (powerImport.getT15() != null) {
|
||||
powerDetail.setPowerG(new BigDecimal(powerImport.getT15()));
|
||||
}
|
||||
if (powerImport.getT16() != null) {
|
||||
powerDetail.setTotalPowerStart(new BigDecimal(powerImport.getT16()));
|
||||
}
|
||||
if (powerImport.getT17() != null) {
|
||||
powerDetail.setTotalPowerEnd(new BigDecimal(powerImport.getT17()));
|
||||
}
|
||||
if (powerImport.getT18() != null) {
|
||||
powerDetail.setTotalAmount(new BigDecimal(powerImport.getT18()));
|
||||
}
|
||||
powerDetails.add(powerDetail);
|
||||
}else{
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
}
|
||||
if (!powerDetails.isEmpty()) {
|
||||
powerDetailService.addBatch(powerDetails);
|
||||
} else {
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Power> queryList(Integer groupId, QueryPower power) {
|
||||
if (power == null) {
|
||||
power = new QueryPower();
|
||||
}
|
||||
List<Power> powerList = powerMapper.selectAll(groupId, power.getSettleMonth(), power.getProjectName());
|
||||
return powerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertSelective(Power power) {
|
||||
return powerMapper.insertSelective(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(PowerDetailVo vo) {
|
||||
//根据id查询基础信息表
|
||||
//根据时间和月份进行查询,判断是否存在
|
||||
DetailVo update = new DetailVo();
|
||||
update.setSettleMonth(vo.getSettleMonth());
|
||||
update.setId(vo.getId());
|
||||
Power powerValue = powerMapper.selectById(update);
|
||||
if (powerValue == null) {
|
||||
throw new BusinessException(BaseResponseCode.POWER_BILLS_NOT_RELEVANT_DATA_MONTH);
|
||||
}
|
||||
//(先根据id将明细表中的数据重新入库,
|
||||
//明细表中的pid =id 进行查询
|
||||
List<PowerDetail> powerDetails = powerDetailService.selectByPid(vo.getId());
|
||||
//判断查询是否为空
|
||||
List<PowerDetail> powerDetailList = vo.getPowerDetailList();
|
||||
if (powerDetailList != null) {
|
||||
if (!powerDetails.isEmpty()) {
|
||||
//分解成ids,后批量删除
|
||||
List<Integer> ids = powerDetails.stream().map(s -> {
|
||||
return s.getId();
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
int i = powerDetailService.deleteBatch(ids, new ArrayList<>());
|
||||
//删除后入库
|
||||
if (!vo.getPowerDetailList().isEmpty()) {
|
||||
powerDetailService.addBatch(vo.getPowerDetailList());
|
||||
}
|
||||
} else {
|
||||
if (!vo.getPowerDetailList().isEmpty()) {
|
||||
powerDetailService.addBatch(vo.getPowerDetailList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 后将将基本信息进行更新)
|
||||
Power power = new Power();
|
||||
power.setId(vo.getId());
|
||||
if (powerValue != null) {
|
||||
power.setGroupId(powerValue.getGroupId());
|
||||
}
|
||||
power.setProjectName(vo.getProjectName());
|
||||
power.setSettleMonth(vo.getSettleMonth());
|
||||
power.setMeterMan(vo.getMeterMan());
|
||||
power.setBiCycle(vo.getBiCycle());
|
||||
power.setChecker(vo.getChecker());
|
||||
power.setPowerAll(vo.getPowerAll());
|
||||
power.setPowerSelf(vo.getPowerSelf());
|
||||
power.setPowerUp(vo.getPowerUp());
|
||||
power.setConsumeRatio(vo.getConsumeRatio());
|
||||
power.setPowerJ(vo.getPowerJ());
|
||||
power.setPowerF(vo.getPowerF());
|
||||
power.setPowerP(vo.getPowerP());
|
||||
power.setPowerG(vo.getPowerG());
|
||||
power.setPowerSigle(vo.getPowerSigle());
|
||||
power.setOrigPriceJ(vo.getOrigPriceJ());
|
||||
power.setOrigPriceF(vo.getOrigPriceF());
|
||||
power.setOrigPriceG(vo.getOrigPriceG());
|
||||
power.setOrigPriceP(vo.getOrigPriceP());
|
||||
power.setOrigPriceSigle(vo.getOrigPriceSigle());
|
||||
power.setDiscountPriceJ(vo.getDiscountPriceJ());
|
||||
power.setDiscountPriceF(vo.getDiscountPriceF());
|
||||
power.setDiscountPriceP(vo.getDiscountPriceP());
|
||||
power.setDiscountPriceG(vo.getDiscountPriceG());
|
||||
power.setDiscountPriceSigle(vo.getDiscountPriceSigle());
|
||||
power.setFeeJ(vo.getFeeJ());
|
||||
power.setFeeF(vo.getFeeF());
|
||||
power.setFeeP(vo.getFeeP());
|
||||
power.setFeeG(vo.getFeeG());
|
||||
power.setFeeSigle(vo.getFeeSigle());
|
||||
power.setReceivableFee(vo.getReceivableFee());
|
||||
power.setCreateTime(powerValue.getCreateTime());
|
||||
power.setCreator(vo.getCreator());
|
||||
powerMapper.updateByPrimaryKey(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Power selectById(DetailVo vo) {
|
||||
Power power = powerMapper.selectById(vo);
|
||||
return power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Power> selectAll(Integer groupId, String settleMonth) {
|
||||
List<Power> powerList = powerMapper.selectAll(groupId, settleMonth, null);
|
||||
return powerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDeletes(List<Integer> idList) {
|
||||
powerMapper.batchDeletes(idList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import com.ho.business.entity.DeviceTypeCol;
|
||||
import com.ho.common.tools.entity.SimpleUser;
|
||||
import com.ho.filecenter.entity.PvEleAnalysis;
|
||||
import com.ho.filecenter.mapper.PvEleAnalysisMapper;
|
||||
import com.ho.filecenter.service.PvEleAnalysisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xueweizhi
|
||||
* @description 针对表【pv_ele_analysis】的数据库操作Service实现
|
||||
* @createDate 2023-04-10
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PvEleAnalysisServiceImpl implements PvEleAnalysisService {
|
||||
|
||||
@Autowired
|
||||
PvEleAnalysisMapper pvEleAnalysisMapper;
|
||||
|
||||
@Override
|
||||
public List<PvEleAnalysis> getPvEleAnalysisList(PvEleAnalysis pvEleAnalysis) {
|
||||
List<PvEleAnalysis> pvEleAnalyses = pvEleAnalysisMapper.selectByParam(pvEleAnalysis);
|
||||
return pvEleAnalyses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int savePvEleAnalysisList(List<PvEleAnalysis> pvEleAnalysisList, SimpleUser user) {
|
||||
List<PvEleAnalysis> insertList = new ArrayList<>();
|
||||
List<PvEleAnalysis> updateList = new ArrayList<>();
|
||||
for (PvEleAnalysis pv : pvEleAnalysisList) {
|
||||
if (null != pv.getId()) {
|
||||
updateList.add(pv);
|
||||
} else {
|
||||
pv.setGroupId(user.getGroupId());
|
||||
pv.setCreator(user.getUserId());
|
||||
pv.setCreateTime(new Date());
|
||||
insertList.add(pv);
|
||||
}
|
||||
}
|
||||
if(insertList.size()>0){
|
||||
log.info("savePvEleAnalysisList 新增{}条",insertList.size());
|
||||
pvEleAnalysisMapper.insertList(insertList);
|
||||
}
|
||||
if (updateList.size()>0){
|
||||
log.info("savePvEleAnalysisList 更新{}条",updateList.size());
|
||||
pvEleAnalysisMapper.updateList(updateList);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.filecenter.constant.FileConstant;
|
||||
import com.ho.filecenter.entity.StandingBook;
|
||||
import com.ho.filecenter.mapper.StandingBookMapper;
|
||||
import com.ho.filecenter.service.StandingBookService;
|
||||
import com.ho.filecenter.vo.StandingBookVo;
|
||||
import com.ho.filecenter.vo.standingbook.StandingBookImport;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yy
|
||||
* @description 针对表【standing_book】的数据库操作Service实现
|
||||
* @createDate 2023-03-15 13:52:18
|
||||
*/
|
||||
@Service
|
||||
public class StandingBookServiceImpl implements StandingBookService {
|
||||
@Autowired
|
||||
StandingBookMapper standingBookMapper;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importCustomer(Integer stationId,List<StandingBookImport> list) {
|
||||
//导入
|
||||
List<StandingBookImport> standingBookImportList = new ArrayList<>();
|
||||
for (StandingBookImport standingBookImport : list) {
|
||||
//判断是否为正确的模板表格
|
||||
//序号
|
||||
if (standingBookImport.getDeviceModel() == null || standingBookImport.getDeviceType() == null
|
||||
|| standingBookImport.getModelCode() == null || standingBookImport.getDeviceNum() == null
|
||||
|| standingBookImport.getFactory() == null || standingBookImport.getManufacturer() == null
|
||||
|| standingBookImport.getWarrantyPeriod() == null || standingBookImport.getNotes() == null) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CONFIRM_WHETHER_IMPORTED_TEMPLATE_CORRECT);
|
||||
}
|
||||
if (!FileConstant.StandingBook.DEVICE_TYPE.equals(standingBookImport.getDeviceType())
|
||||
|| !FileConstant.StandingBook.DEVICE_MODEL.equals(standingBookImport.getDeviceModel())
|
||||
|| !FileConstant.StandingBook.DEVICE_MODEL.equals(standingBookImport.getDeviceModel())
|
||||
|| !FileConstant.StandingBook.MODEL_CODE.equals(standingBookImport.getModelCode())
|
||||
|| !FileConstant.StandingBook.DEVICE_NUM.equals(standingBookImport.getDeviceNum())
|
||||
|| !FileConstant.StandingBook.FACTORY.equals(standingBookImport.getFactory())
|
||||
|| !FileConstant.StandingBook.MANUFACTURER.equals(standingBookImport.getManufacturer())
|
||||
|| !FileConstant.StandingBook.WARRANTY_PERIOD.equals(standingBookImport.getWarrantyPeriod())
|
||||
|| !FileConstant.StandingBook.NOTES.equals(standingBookImport.getNotes())) {
|
||||
throw new BusinessException(BaseResponseCode.PLEASE_CONFIRM_WHETHER_IMPORTED_TEMPLATE_CORRECT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (StandingBookImport standingBookImport : list) {
|
||||
//判断是否为正确的模板表格
|
||||
if (!FileConstant.StandingBook.DEVICE_TYPE.equals(standingBookImport.getDeviceType())) {
|
||||
standingBookImportList.add(standingBookImport);
|
||||
}
|
||||
}
|
||||
if (standingBookImportList.isEmpty()) {
|
||||
throw new BusinessException(BaseResponseCode.EXCEL_DATA_TABLE_EMPTY);
|
||||
}
|
||||
|
||||
//判断表格中的数据大小
|
||||
for (StandingBookImport standingBookImport : standingBookImportList) {
|
||||
Boolean aBoolean = bigDecimalUtil.ifStringLength(standingBookImport);
|
||||
if (aBoolean) {
|
||||
//请核对excel表中的数据
|
||||
throw new BusinessException(BaseResponseCode.SJEKK_EXCEL_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
//根据电站id删除原本的数据
|
||||
standingBookMapper.deleteByStationId(stationId);
|
||||
//将新的数据进行入库
|
||||
List<StandingBook> standingBookList = new ArrayList<>();
|
||||
for (StandingBookImport standingBookImport : standingBookImportList) {
|
||||
StandingBook standingBook = new StandingBook();
|
||||
standingBook.setCreateTime(new Date());
|
||||
standingBook.setStationId(stationId);
|
||||
standingBook.setDeviceType(standingBookImport.getDeviceType());
|
||||
standingBook.setDeviceModel(standingBookImport.getDeviceModel());
|
||||
standingBook.setWarrantyPeriod(standingBookImport.getWarrantyPeriod());
|
||||
standingBook.setNotes(standingBookImport.getNotes());
|
||||
standingBook.setModelCode(standingBookImport.getModelCode());
|
||||
standingBook.setFactory(standingBookImport.getFactory());
|
||||
standingBook.setDeviceNum(standingBookImport.getDeviceNum());
|
||||
standingBook.setManufacturer(standingBookImport.getManufacturer());
|
||||
standingBookList.add(standingBook);
|
||||
}
|
||||
//批量新增
|
||||
standingBookMapper.addBatch(standingBookList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StandingBook> queryList(StandingBookVo vo) {
|
||||
List<StandingBook> standingBookList = standingBookMapper.selectAll(vo.getId());
|
||||
return standingBookList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(StandingBook vo) {
|
||||
vo.setUpdateTime(new Date());
|
||||
standingBookMapper.updateByPrimaryKeySelective(vo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(StandingBookVo vo) {
|
||||
standingBookMapper.deleteById(vo.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByStationId(Integer stationId) {
|
||||
standingBookMapper.deleteByStationId(stationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBatch(List<StandingBook> standingBookList) {
|
||||
standingBookMapper.addBatch(standingBookList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,439 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.filecenter.entity.FlowMonitor;
|
||||
import com.ho.filecenter.service.FlowMonitorService;
|
||||
import com.ho.filecenter.service.TelecomApiService;
|
||||
import com.ho.filecenter.vo.flowMonitor.CardInfoDate;
|
||||
import com.ho.filecenter.vo.flowMonitor.FlowMonitorAddVo;
|
||||
import com.ho.filecenter.vo.flowMonitor.FlowMonitorPutVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: 电信接口Api调用
|
||||
* @DateTime: 2024/1/16 15:37
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TelecomApiServiceImpl implements TelecomApiService {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private FlowMonitorService flowMonitorService;
|
||||
|
||||
@Value("${telecom.appId}")
|
||||
String appId;
|
||||
@Value("${telecom.keyNew}")
|
||||
String keyNew;
|
||||
@Value("${telecom.url}")
|
||||
String url;
|
||||
@Value("${telecom.pwd}")
|
||||
String pwd;
|
||||
|
||||
|
||||
/**
|
||||
* 电信定时任务
|
||||
* 存入的数据(卡的基本信息以及卡的用量数据)
|
||||
*/
|
||||
/* @Override
|
||||
public void getTelecomAllData(List<FlowMonitor> telecomFlowMonitors) {
|
||||
String monthBatch = getMonthBatch();
|
||||
if (monthBatch != null) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(monthBatch, JSONObject.class);
|
||||
String resultCode = (String) jsonObject.get("resultCode");
|
||||
Integer statusInteger = Integer.valueOf(resultCode);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONObject description = (JSONObject) jsonObject.get("description");
|
||||
if (description != null) {
|
||||
JSONArray simList = (JSONArray) description.get("simList");
|
||||
for (Object sim : simList) {
|
||||
CardInfoDate cardInfoDate = new CardInfoDate();
|
||||
JSONObject obj = (JSONObject) sim;
|
||||
//卡号
|
||||
String iccId = (String) obj.get("iccid");
|
||||
//状态 激活1 未激活 0 去激活2、停机3、拆机4")
|
||||
String state = (String) obj.get("state"); //已激活、去激活、停机、拆机
|
||||
if (state.equals("已激活")) {
|
||||
cardInfoDate.setStatus(1);
|
||||
} else if (state.equals("去激活")) {
|
||||
cardInfoDate.setStatus(2);
|
||||
} else if (state.equals("停机")) {
|
||||
cardInfoDate.setStatus(3);
|
||||
} else if (state.equals("拆机")) {
|
||||
cardInfoDate.setStatus(4);
|
||||
}
|
||||
//已使用流量 单位 b (字节)
|
||||
String totalVolumnGPRS = (String) obj.get("totalVolumnGPRS");
|
||||
cardInfoDate.setCardNo(iccId);
|
||||
//单位转换 1KB=1024B
|
||||
BigDecimal divide = new BigDecimal(totalVolumnGPRS).divide(new BigDecimal("1024"));
|
||||
cardInfoDate.setUserAmount(divide.toString());
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
cardInfoDate.setUpdateTime(format);
|
||||
String key = "flowMonitor:telecom:appId:" + appId + ":iccId:" + iccId;
|
||||
redisService.set(key, cardInfoDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//调用卡信息数据
|
||||
//SIM 卡列表查询接口
|
||||
//getCardList();
|
||||
|
||||
}*/
|
||||
@Override
|
||||
public void getTelecomAllData(List<FlowMonitor> telecomFlowMonitors) {
|
||||
String monthBatch = getCardList();
|
||||
if (monthBatch != null) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(monthBatch, JSONObject.class);
|
||||
String resultCode = (String) jsonObject.get("resultCode");
|
||||
Integer statusInteger = Integer.valueOf(resultCode);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONObject description = (JSONObject) jsonObject.get("description");
|
||||
if (description != null) {
|
||||
JSONArray simList = (JSONArray) description.get("simList");
|
||||
for (Object sim : simList) {
|
||||
CardInfoDate cardInfoDate = new CardInfoDate();
|
||||
JSONObject obj = (JSONObject) sim;
|
||||
//卡号
|
||||
String iccId = (String) obj.get("iccid");
|
||||
//状态 激活1 未激活 0 去激活2、停机3、拆机4")
|
||||
String state = (String) obj.get("simStatus"); //已激活、去激活、停机、拆机
|
||||
if (state.equals("已激活")) {
|
||||
cardInfoDate.setStatus(1);
|
||||
} else if (state.equals("去激活")) {
|
||||
cardInfoDate.setStatus(2);
|
||||
} else if (state.equals("停机")) {
|
||||
cardInfoDate.setStatus(3);
|
||||
} else if (state.equals("拆机")) {
|
||||
cardInfoDate.setStatus(4);
|
||||
}
|
||||
//已使用流量 单位 b (字节)
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
Object totalVolumnGPRS = obj.get("totalVolumnGPRS");
|
||||
cardInfoDate.setCardNo(iccId);
|
||||
//单位转换 1KB=1024B
|
||||
BigDecimal divide = new BigDecimal(String.valueOf(totalVolumnGPRS)).divide(decimal);
|
||||
cardInfoDate.setUserAmount(divide.toString());
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
//开卡时间
|
||||
String paddleDate = (String) obj.get("paddle_date");
|
||||
if (paddleDate != null) {
|
||||
cardInfoDate.setOpenDate(paddleDate.substring(0, 10));
|
||||
}
|
||||
//激活时间
|
||||
String activateDate = (String) obj.get("activate_date");
|
||||
if (activateDate != null) {
|
||||
cardInfoDate.setActivationDate(activateDate.substring(0, 10));
|
||||
}
|
||||
//套餐id
|
||||
String pid = (String) obj.get("pid");
|
||||
cardInfoDate.setGroupId(pid);
|
||||
cardInfoDate.setUpdateTime(format);
|
||||
String key = "flowMonitor:telecom:appId:" + appId + ":iccId:" + iccId;
|
||||
redisService.set(key, cardInfoDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取套餐列表/并存入套餐表中
|
||||
*/
|
||||
@Override
|
||||
public String getTelecomRefresh() {
|
||||
String allPack = getAllPack();
|
||||
if (allPack != null) {
|
||||
JSONObject packInfoObject = JSON.parseObject(allPack);
|
||||
if (packInfoObject != null) {
|
||||
String resultCode = (String) packInfoObject.get("resultCode");
|
||||
Integer statusInteger = Integer.valueOf(resultCode);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONArray packInfoJSONArray = (JSONArray) packInfoObject.get("description");
|
||||
for (int i = 0; i < packInfoJSONArray.size(); i++) {
|
||||
FlowMonitorAddVo vo = new FlowMonitorAddVo();
|
||||
JSONObject JSONObject = (JSONObject) packInfoJSONArray.get(i);
|
||||
Integer pid = (Integer) JSONObject.get("pid");
|
||||
String package_name = (String) JSONObject.get("package_name");
|
||||
String type = (String) JSONObject.get("type");
|
||||
//电信单位B-> 存储的是MB
|
||||
String flow = (String) JSONObject.get("flow");
|
||||
////运营商(1:中国移动2:中国联通3:中国电信)
|
||||
vo.setPackageName(package_name);
|
||||
vo.setGroupId(pid.toString());
|
||||
//2 是单卡 1 套餐
|
||||
if (type.equals(CommonConstant.TelecomType.SINGLE)) {
|
||||
vo.setSingleOrGroup(CommonConstant.TWO);
|
||||
}
|
||||
if (type.equals(CommonConstant.TelecomType.POOL)) {
|
||||
vo.setSingleOrGroup(CommonConstant.ONE);
|
||||
}
|
||||
vo.setPackageType(CommonConstant.THREE);
|
||||
//1MB=1024KB,1KB=1024B
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
BigDecimal divide = new BigDecimal(flow).divide(decimal);
|
||||
Integer flowValue = divide.intValue();
|
||||
vo.setTotalAmount(flowValue);
|
||||
//根据pid查询看数据是否存在/存在则更新 不存在则新增
|
||||
FlowMonitor flowMonitor = flowMonitorService.selectByPid(vo);
|
||||
if (flowMonitor == null) {
|
||||
int result = flowMonitorService.insertSelective(vo);
|
||||
} else {
|
||||
FlowMonitorPutVo putVo = new FlowMonitorPutVo();
|
||||
putVo.setTotalAmount(flowValue);
|
||||
BeanUtils.copyProperties(flowMonitor, putVo);
|
||||
flowMonitorService.updateByPrimaryKeySelective(putVo);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return allPack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电信批量
|
||||
*/
|
||||
public String getMonthBatch() {
|
||||
Integer pageIndex = 0;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", appId);
|
||||
jsonObject.put("pwd", pwd);
|
||||
jsonObject.put("pageIndex", pageIndex);
|
||||
String info = XorEncryptAndBaseNew(jsonObject.toJSONString(), keyNew);
|
||||
String body = "id=" + appId + "&info=" + info;
|
||||
log.info("body:" + body);
|
||||
//发送http请求
|
||||
String rsp = HttpRequest.post(url).contentType("application/x-www-form-urlencoded")
|
||||
.body(body)
|
||||
.execute().body();
|
||||
log.info("rsp:" + rsp);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
//查单卡
|
||||
//String iccid
|
||||
@Override
|
||||
public CardInfoDate getSingle(String iccid) {
|
||||
String url = "http://global.anhuiyk.cn:8006/m2m_api/v1/query/";
|
||||
String method = "getSIMInfo";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", appId);
|
||||
jsonObject.put("pwd", pwd);
|
||||
jsonObject.put("method", method);
|
||||
jsonObject.put("iccid", iccid);
|
||||
String info = XorEncryptAndBaseNew(jsonObject.toJSONString(), keyNew);
|
||||
String body = "id=" + appId + "&info=" + info;
|
||||
log.info("body:" + body);
|
||||
//发送http请求
|
||||
String rsp = HttpRequest.post(url).contentType("application/x-www-form-urlencoded")
|
||||
.body(body)
|
||||
.execute().body();
|
||||
log.info("rsp:" + rsp);
|
||||
CardInfoDate cardInfoDate = new CardInfoDate();
|
||||
if (rsp != null) {
|
||||
JSONObject json = JSONObject.parseObject(rsp, JSONObject.class);
|
||||
String resultCode = (String) json.get("resultCode");
|
||||
Integer statusInteger = Integer.valueOf(resultCode);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONObject obj = (JSONObject) json.get("description");
|
||||
//卡号
|
||||
String iccId = (String) obj.get("iccid");
|
||||
//状态 激活1 未激活 0 去激活2、停机3、拆机4")
|
||||
String state = (String) obj.get("simStatus"); //已激活、去激活、停机、拆机
|
||||
if (state.equals("已激活")) {
|
||||
cardInfoDate.setStatus(1);
|
||||
} else if (state.equals("去激活")) {
|
||||
cardInfoDate.setStatus(2);
|
||||
} else if (state.equals("停机")) {
|
||||
cardInfoDate.setStatus(3);
|
||||
} else if (state.equals("拆机")) {
|
||||
cardInfoDate.setStatus(4);
|
||||
}
|
||||
//已使用流量 单位 b (字节)
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
Object totalVolumnGPRS = obj.get("totalVolumnGPRS");
|
||||
cardInfoDate.setCardNo(iccId);
|
||||
//单位转换 1KB=1024B
|
||||
BigDecimal divide = new BigDecimal(String.valueOf(totalVolumnGPRS)).divide(decimal);
|
||||
cardInfoDate.setUserAmount(divide.toString());
|
||||
String format = DateFormatUtils.format(new Date(), CommonConstant.DATE);
|
||||
//开卡时间
|
||||
String paddleDate = (String) obj.get("paddle_date");
|
||||
if (paddleDate != null) {
|
||||
cardInfoDate.setOpenDate(paddleDate.substring(0, 10));
|
||||
}
|
||||
//激活时间
|
||||
String activateDate = (String) obj.get("activate_date");
|
||||
if (activateDate != null) {
|
||||
cardInfoDate.setActivationDate(activateDate.substring(0, 10));
|
||||
}
|
||||
//套餐id
|
||||
String pid = (String) obj.get("pid");
|
||||
cardInfoDate.setGroupId(pid);
|
||||
cardInfoDate.setUpdateTime(format);
|
||||
System.out.println("cardInfoDate:" + cardInfoDate);
|
||||
|
||||
}
|
||||
}
|
||||
return cardInfoDate;
|
||||
}
|
||||
|
||||
//查单卡
|
||||
public String getSingleCard(String iccid) {
|
||||
// 卡号:89860466121980600213
|
||||
String url = "http://global.anhuiyk.cn:8006/m2m_api/v1/query/";
|
||||
String id = "SHYXSYYXGS614@2022"; //appid
|
||||
String pwd = "4af95d820738fe35";
|
||||
String method = "queryTraffic";
|
||||
String key = "f3758fdd8a278d60";
|
||||
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", id);
|
||||
jsonObject.put("pwd", pwd);
|
||||
jsonObject.put("method", method);
|
||||
jsonObject.put("iccid", iccid);
|
||||
//将map转为info 字符串
|
||||
|
||||
String info = XorEncryptAndBaseNew(jsonObject.toJSONString(), key);
|
||||
String body = "id=" + id + "&info=" + info;
|
||||
log.info("body:" + body);
|
||||
//发送http请求
|
||||
String rsp = HttpRequest.post(url).contentType("application/x-www-form-urlencoded")
|
||||
.body(body)
|
||||
.execute().body();
|
||||
log.info("rsp:" + rsp);
|
||||
|
||||
String totalVolumnGPRS = null;
|
||||
if (rsp != null) {
|
||||
JSONObject infoObject = JSON.parseObject(rsp);
|
||||
if (infoObject != null) {
|
||||
String resultCode = (String) infoObject.get("resultCode");
|
||||
Integer statusInteger = Integer.valueOf(resultCode);
|
||||
if (CommonConstant.ZERO.equals(statusInteger)) {
|
||||
JSONObject packInfoJSONArray = (JSONObject) infoObject.get("description");
|
||||
//{"resultCode":"0","description":{"msisdn":"1440662294313","iccid":"89860466121980600213","totalVolumnGPRS":"98304"},"resultMsg":"查询成功"}
|
||||
//电信单位B-> 存储的是MB
|
||||
String flow = (String) packInfoJSONArray.get("totalVolumnGPRS");
|
||||
//1MB=1024KB,1KB=1024B
|
||||
BigDecimal decimal = new BigDecimal("1024");
|
||||
BigDecimal divide = new BigDecimal(flow).divide(decimal);
|
||||
totalVolumnGPRS = divide.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalVolumnGPRS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电信查询所有的套餐
|
||||
*/
|
||||
public String getAllPack() {
|
||||
String method = "packageList";
|
||||
String cardListUrl = "http://global.anhuiyk.cn:8006/m2m_api/v1/query/";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", appId);
|
||||
jsonObject.put("pwd", pwd);
|
||||
jsonObject.put("method", method);
|
||||
String info = XorEncryptAndBaseNew(jsonObject.toJSONString(), keyNew);
|
||||
String body = "id=" + appId + "&info=" + info;
|
||||
//发送http请求
|
||||
String rsp = HttpRequest.post(cardListUrl).contentType("application/x-www-form-urlencoded")
|
||||
.body(body)
|
||||
.execute().body();
|
||||
log.info("rsp:" + rsp);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 电信查询SIM 卡列表查询接口
|
||||
*/
|
||||
public String getCardList() {
|
||||
String cardListUrl = "http://global.anhuiyk.cn:8006/m2m_api/v1/query/";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", appId);
|
||||
jsonObject.put("pwd", pwd);
|
||||
jsonObject.put("method", "getSIMList");
|
||||
Integer pageIndex = 1;
|
||||
jsonObject.put("pageIndex", pageIndex);
|
||||
jsonObject.put("cardType", "4G");
|
||||
//cardType 卡片类型 4G 根据卡片类型查询卡列表
|
||||
//将map转为info 字符串
|
||||
String info = XorEncryptAndBaseNew(jsonObject.toJSONString(), keyNew);
|
||||
String body = "id=" + appId + "&info=" + info;
|
||||
log.info("body:" + body);
|
||||
//发送http请求
|
||||
String rsp = HttpRequest.post(cardListUrl).contentType("application/x-www-form-urlencoded")
|
||||
.body(body)
|
||||
.execute().body();
|
||||
log.info("rsp:" + rsp);
|
||||
return rsp;
|
||||
//dealTeleCom(rsp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理电信电信查询SIM 卡列表返回数据
|
||||
*/
|
||||
/* private List<> dealTeleCom(String res) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(res, JSONObject.class);
|
||||
String resultCode = (String) jsonObject.get("resultCode");
|
||||
if ("0".equals(resultCode)) {
|
||||
JSONObject description = (JSONObject) jsonObject.get("description");
|
||||
JSONArray simList = (JSONArray) description.get("simList");
|
||||
for (Object sim : simList) {
|
||||
JSONObject obj = (JSONObject) sim;
|
||||
//卡号
|
||||
String iccid = (String) obj.get("iccid");
|
||||
//状态
|
||||
String state = (String) obj.get("state"); //已激活、去激活、停机、拆机
|
||||
//已使用流量 单位 b (字节)
|
||||
String totalVolumnGPRS = (String) obj.get("totalVolumnGPRS");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 异或算法加密
|
||||
* *
|
||||
*
|
||||
* @param str 数 据
|
||||
* @return 返回解密/加密后的数据
|
||||
*/
|
||||
public static String XorEncryptAndBaseNew(String str, String key) {
|
||||
byte[] b1 = str.getBytes();
|
||||
byte[] b2 = key.getBytes();
|
||||
byte[] out = new byte[b1.length];
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
out[i] = (byte) (b1[i] ^ b2[i % b2.length]);
|
||||
}
|
||||
return URLEncoder.encode(Base64.getEncoder().encodeToString(out));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,234 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ho.common.tools.constant.RedisKeyConstant;
|
||||
import com.ho.common.tools.entity.WeatherRespVo;
|
||||
import com.ho.common.tools.service.RedisService;
|
||||
import com.ho.common.tools.util.BigDecimalUtil;
|
||||
import com.ho.filecenter.config.WeatherDbConfig;
|
||||
import com.ho.filecenter.constant.WeatherTypeConstant;
|
||||
import com.ho.filecenter.entity.City;
|
||||
import com.ho.filecenter.mapper.CityMapper;
|
||||
import com.ho.filecenter.service.WeatherService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.lionsoul.ip2region.DataBlock;
|
||||
import org.lionsoul.ip2region.DbSearcher;
|
||||
import org.lionsoul.ip2region.Util;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author gyan
|
||||
* @desc: TODO
|
||||
* @DateTime: 2022/11/15 8:45
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WeatherServiceImpl implements WeatherService {
|
||||
//weatherPath
|
||||
@Value("${weather.path}")
|
||||
String weatherPath;
|
||||
|
||||
//afterPath
|
||||
@Value("${weather.after}")
|
||||
String afterPath;
|
||||
|
||||
//token
|
||||
@Value("${weather.token}")
|
||||
String token;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
String env;
|
||||
|
||||
@Autowired
|
||||
CityMapper cityMapper;
|
||||
|
||||
@Autowired
|
||||
RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
BigDecimalUtil bigDecimalUtil;
|
||||
|
||||
@Value("${path.weather}")
|
||||
String path;
|
||||
|
||||
//DbSearcher
|
||||
@Override
|
||||
public WeatherRespVo getWeather(String ipAddr) {
|
||||
WeatherRespVo weather = new WeatherRespVo();
|
||||
try {
|
||||
//2023-01-03 fan update 改为从内存中读取 原来代码先注释掉
|
||||
//File file = new File(path);
|
||||
//log.info("file:{}",file);
|
||||
//if (file.exists()) {
|
||||
//DbConfig config = new DbConfig();
|
||||
//searcher = new DbSearcher(config, file.getPath());
|
||||
DbSearcher searcher = WeatherDbConfig.dbSearcher;
|
||||
log.info("searcher:{}", searcher);
|
||||
Method method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||
log.info("method:{}", method);
|
||||
if (!Util.isIpAddress(ipAddr)) {
|
||||
log.error("Error: Invalid ip address");
|
||||
}
|
||||
DataBlock dataBlock1 = (DataBlock) method.invoke(searcher, ipAddr);
|
||||
if (dataBlock1 == null) {
|
||||
log.error("DataBlock is null");
|
||||
return weather;
|
||||
}
|
||||
//进行判断 拿到城市名称 进行分割字符串
|
||||
//定义省份
|
||||
String provincezh = "";
|
||||
//定义城市
|
||||
String cityzh = "";
|
||||
if (dataBlock1.getRegion() != null) {
|
||||
String region = dataBlock1.getRegion();
|
||||
log.info("DataBlock.getRegion:{}", region);
|
||||
String[] regionList = region.split("\\|");
|
||||
provincezh = regionList[2].replace("省", "");
|
||||
cityzh = regionList[3].replace("市", "");
|
||||
}
|
||||
//根据城市名在本地库中查询城市编号
|
||||
City city = cityMapper.selectByProvinceAndCity(provincezh, cityzh);
|
||||
log.info("city: {}", city);
|
||||
weather.setCityzh(cityzh);
|
||||
//到缓存中查找是否存在
|
||||
StringBuilder sb = new StringBuilder(RedisKeyConstant.WEATHER_TEMPERATURE);
|
||||
StringBuilder append = sb.append(city.getProvinceen()).append(":").append(city.getLeaderen());
|
||||
String weatherName = append.toString();
|
||||
if (redisService.hasKey(weatherName)) {
|
||||
WeatherRespVo weatherRespVo = (WeatherRespVo) redisService.get(weatherName);
|
||||
return weatherRespVo;
|
||||
}
|
||||
//拼接url
|
||||
//https://api.caiyunapp.com/v2.6/TAkhjf8d1nlSlspN/101.6656,39.2072/daily?dailysteps=1
|
||||
//调用方法
|
||||
if (city != null) {
|
||||
weather = getWeatherFromApi(city.getLon(), city.getLat());
|
||||
weather.setCityzh(cityzh);
|
||||
//设置为12小时缓存
|
||||
redisService.set(weatherName, weather, 3, TimeUnit.HOURS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return weather;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WeatherRespVo getWeatherFromAddr(Integer stationId, String addr) {
|
||||
WeatherRespVo weather = new WeatherRespVo();
|
||||
if (addr == null || addr.isEmpty()) {
|
||||
return weather;
|
||||
}
|
||||
String provincezh = null;
|
||||
String cityzh = null;
|
||||
//对直辖市进行特殊处理,直辖市的省市都是同名
|
||||
if (bDirect(addr)) {
|
||||
int provinceIndex = addr.indexOf("市");
|
||||
provincezh = addr.substring(0, provinceIndex);
|
||||
cityzh = provincezh;
|
||||
} else {
|
||||
//将地址按照省市截取,从city表中取到对应数据
|
||||
int provinceIndex = addr.indexOf("省");
|
||||
int cityIndex = addr.indexOf("市");
|
||||
provincezh = addr.substring(0, provinceIndex);
|
||||
cityzh = addr.substring(provinceIndex + 1, cityIndex);
|
||||
}
|
||||
//根据城市名在本地库中查询城市编号
|
||||
City city = cityMapper.selectByProvinceAndCity(provincezh, cityzh);
|
||||
log.info("city: {}", city);
|
||||
weather.setCityzh(cityzh);
|
||||
|
||||
//这个方法不做缓存
|
||||
StringBuilder sb = new StringBuilder(RedisKeyConstant.WEATHER_TEMPERATURE);
|
||||
StringBuilder append = sb.append(city.getProvinceen()).append(":").append(city.getLeaderen());
|
||||
String weatherName = append.toString();
|
||||
log.info("weatherName:{}", weatherName);
|
||||
if (redisService.hasKey(weatherName)) {
|
||||
return (WeatherRespVo) redisService.get(weatherName);
|
||||
}
|
||||
//调用外部接口
|
||||
weather = getWeatherFromApi(city.getLon(), city.getLat());
|
||||
weather.setCityzh(cityzh);
|
||||
redisService.set(weatherName, weather, 3, TimeUnit.HOURS);
|
||||
//将数据放在redis中
|
||||
return weather;
|
||||
}
|
||||
|
||||
|
||||
private boolean bDirect(String addr) {
|
||||
if (addr.contains("北京市") || addr.contains("天津市") || addr.contains("上海市") || addr.contains("重庆市")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//抽取一个公共方法查询天气
|
||||
@Override
|
||||
public WeatherRespVo getWeatherFromApi(String lat, String lon) {
|
||||
WeatherRespVo vo = new WeatherRespVo();
|
||||
if (StringUtils.isEmpty(lon) || StringUtils.isEmpty(lat)) {
|
||||
return vo;
|
||||
}
|
||||
StringBuilder url = new StringBuilder();
|
||||
StringBuilder appendUrl = url.append(weatherPath).append("/").append(token).append("/").append(lon).append(",").append(lat).append(afterPath);
|
||||
String weatherUrl = appendUrl.toString();
|
||||
HttpResponse httpResponse = HttpRequest.get(weatherUrl).execute();
|
||||
String body = httpResponse.body();
|
||||
log.info("body:" + body);
|
||||
// String body ="{\"status\":\"ok\",\"api_version\":\"v2.6\",\"api_status\":\"alpha\",\"lang\":\"zh_CN\",\"unit\":\"metric\",\"tzshift\":28800,\"timezone\":\"Asia/Shanghai\",\"server_time\":1668741792,\"location\":[32.041544,118.767413],\"result\":{\"daily\":{\"status\":\"ok\",\"astro\":[{\"date\":\"2022-11-18T00:00+08:00\",\"sunrise\":{\"time\":\"06:36\"},\"sunset\":{\"time\":\"17:04\"}}],\"precipitation_08h_20h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":0.0,\"min\":0.0,\"avg\":0.0,\"probability\":0}],\"precipitation_20h_32h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":1.9782,\"min\":0.0,\"avg\":0.6893,\"probability\":70}],\"precipitation\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":1.1557,\"min\":0.0,\"avg\":0.0889,\"probability\":60}],\"temperature\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":16.0,\"min\":13.2,\"avg\":13.84}],\"temperature_08h_20h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":15.67,\"min\":13.6,\"avg\":14.25}],\"temperature_20h_32h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":16.0,\"min\":13.0,\"avg\":14.05}],\"wind\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":{\"speed\":18.02,\"direction\":86.38},\"min\":{\"speed\":7.76,\"direction\":46.14},\"avg\":{\"speed\":12.68,\"direction\":73.4}}],\"wind_08h_20h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":{\"speed\":18.02,\"direction\":86.38},\"min\":{\"speed\":11.02,\"direction\":74.0},\"avg\":{\"speed\":13.92,\"direction\":74.31}}],\"wind_20h_32h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":{\"speed\":13.42,\"direction\":62.13},\"min\":{\"speed\":4.44,\"direction\":21.79},\"avg\":{\"speed\":8.08,\"direction\":49.37}}],\"humidity\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":0.89,\"min\":0.77,\"avg\":0.82}],\"cloudrate\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":1.0,\"min\":0.3,\"avg\":0.89}],\"pressure\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":102020.52,\"min\":101780.52,\"avg\":101879.58}],\"visibility\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":24.13,\"min\":8.86,\"avg\":11.23}],\"dswrf\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":170.1,\"min\":0.0,\"avg\":68.1}],\"air_quality\":{\"aqi\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":{\"chn\":36,\"usa\":71},\"avg\":{\"chn\":25,\"usa\":60},\"min\":{\"chn\":16,\"usa\":30}}],\"pm25\":[{\"date\":\"2022-11-18T00:00+08:00\",\"max\":22,\"avg\":16,\"min\":7}]},\"skycon\":[{\"date\":\"2022-11-18T00:00+08:00\",\"value\":\"LIGHT_RAIN\"}],\"skycon_08h_20h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"value\":\"CLOUDY\"}],\"skycon_20h_32h\":[{\"date\":\"2022-11-18T00:00+08:00\",\"value\":\"MODERATE_RAIN\"}],\"life_index\":{\"ultraviolet\":[{\"date\":\"2022-11-18T00:00+08:00\",\"index\":\"3\",\"desc\":\"中等\"}],\"carWashing\":[{\"date\":\"2022-11-18T00:00+08:00\",\"index\":\"3\",\"desc\":\"较不适宜\"}],\"dressing\":[{\"date\":\"2022-11-18T00:00+08:00\",\"index\":\"5\",\"desc\":\"凉爽\"}],\"comfort\":[{\"date\":\"2022-11-18T00:00+08:00\",\"index\":\"6\",\"desc\":\"凉爽\"}],\"coldRisk\":[{\"date\":\"2022-11-18T00:00+08:00\",\"index\":\"3\",\"desc\":\"易发\"}]}},\"primary\":0}}";
|
||||
BigDecimal maxTemperature = BigDecimal.ZERO;
|
||||
BigDecimal minTemperature = BigDecimal.ZERO;
|
||||
String skyCon = "";
|
||||
String speedAndDirection = "";
|
||||
Map<String, JSONObject> map = JSONObject.parseObject(body, Map.class);
|
||||
if ("ok".equals(map.get("status"))) {
|
||||
JSONObject resultJSONObject = map.get("result");
|
||||
Map<String, Object> resultMap = resultJSONObject.getInnerMap();
|
||||
JSONObject dailyJSONObject = (JSONObject) resultMap.get("daily");
|
||||
Map<String, Object> dailyMap = dailyJSONObject.getInnerMap();
|
||||
JSONArray tempJSONArray = (JSONArray) dailyMap.get("temperature");
|
||||
JSONObject tempJSONObject = (JSONObject) tempJSONArray.get(0);
|
||||
Map<String, Object> temMap = tempJSONObject.getInnerMap();
|
||||
maxTemperature = (BigDecimal) temMap.get("max");
|
||||
minTemperature = (BigDecimal) temMap.get("min");
|
||||
//拿风向
|
||||
JSONArray windJSONArray = (JSONArray) dailyMap.get("wind");
|
||||
JSONObject windJSONObject = (JSONObject) windJSONArray.get(0);
|
||||
JSONObject windAvgJSONObject = (JSONObject) windJSONObject.getInnerMap().get("avg");
|
||||
Map<String, Object> windAvgMap = windAvgJSONObject.getInnerMap();
|
||||
BigDecimal speed = (BigDecimal) windAvgMap.get("speed");
|
||||
BigDecimal direction = (BigDecimal) windAvgMap.get("direction");
|
||||
double speedDouble = speed.doubleValue();
|
||||
double directionDouble = direction.doubleValue();
|
||||
String weatherSpeed = WeatherTypeConstant.getSpeed(speedDouble);
|
||||
String weatherDirection = WeatherTypeConstant.getDirection(directionDouble);
|
||||
speedAndDirection = weatherDirection + weatherSpeed;
|
||||
|
||||
//获取天气现象
|
||||
JSONArray skyconJSONArray = (JSONArray) dailyMap.get("skycon");
|
||||
JSONObject skyconJSONObject = (JSONObject) skyconJSONArray.get(0);
|
||||
Map<String, Object> skyconMap = skyconJSONObject.getInnerMap();
|
||||
String value = (String) skyconMap.get("value");
|
||||
skyCon = WeatherTypeConstant.getSkyCon(value);
|
||||
|
||||
}
|
||||
vo.setMaxTemperature(maxTemperature);
|
||||
vo.setMinTemperature(minTemperature);
|
||||
vo.setSkyCon(skyCon);
|
||||
vo.setSpeedAndDirection(speedAndDirection);
|
||||
log.info("vo:" + vo);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package com.ho.filecenter.service.impl;
|
||||
|
||||
import com.ho.business.entity.Station;
|
||||
import com.ho.filecenter.service.WeatherStationService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2023/5/16
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WeatherStationServiceImpl implements WeatherStationService {
|
||||
|
||||
//可以先取市前面的数据
|
||||
@Override
|
||||
public List<Station> dealStation(List<Station> stations) {
|
||||
List<Station> stationList = new ArrayList<>();
|
||||
Map<String, Station> stationNameMap = new HashMap<>();
|
||||
for (Station station : stations) {
|
||||
//如果包含省和市的,截取第一个市后面到下一个市或区或县
|
||||
String origAddress = station.getAddress();
|
||||
if(origAddress.contains("省")&&origAddress.contains("市") ){
|
||||
int idxShi = station.getAddress().indexOf("市");
|
||||
//找下一个市,区,县
|
||||
String suffixAddress = origAddress.substring(idxShi+1);
|
||||
//判断是否还有市, 区,县
|
||||
int idxSubCity = suffixAddress.indexOf("市");
|
||||
//没有市, 继续查区
|
||||
if(idxSubCity==-1){
|
||||
idxSubCity = suffixAddress.indexOf("区");
|
||||
}
|
||||
//没有区, 继续查县
|
||||
if(idxSubCity==-1){
|
||||
idxSubCity = suffixAddress.indexOf("县");
|
||||
}
|
||||
//要显示位置的信息,赋值
|
||||
String addressShow = suffixAddress.substring(0,idxSubCity+1);
|
||||
station.setName(addressShow);
|
||||
System.out.println();
|
||||
}
|
||||
int idxShi = station.getAddress().indexOf("市");
|
||||
if (idxShi != -1) {
|
||||
String stationNameShort = station.getAddress().substring(0, idxShi+1);
|
||||
log.info("截取后的站名:" + stationNameShort);
|
||||
stationNameMap.put(stationNameShort, station);
|
||||
} else {
|
||||
//没找打就继续下一轮
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for(Map.Entry<String, Station> entry:stationNameMap.entrySet()){
|
||||
Station station = entry.getValue();
|
||||
//把处理后的站名放在了address里,把要显示的地区名放在了stationName里
|
||||
|
||||
station.setAddress(entry.getKey());
|
||||
stationList.add(station);
|
||||
}
|
||||
return stationList;
|
||||
}
|
||||
}
|
||||
106
file-center/src/main/java/com/ho/filecenter/util/FileUtil.java
Normal file
106
file-center/src/main/java/com/ho/filecenter/util/FileUtil.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.ho.filecenter.util;
|
||||
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2023/1/6
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
public static void writeBytes(String filePath, OutputStream os) throws IOException
|
||||
{
|
||||
FileInputStream fis = null;
|
||||
try{
|
||||
File file = new File(filePath);
|
||||
if (!file.exists())
|
||||
{
|
||||
throw new FileNotFoundException(filePath);
|
||||
}
|
||||
fis = new FileInputStream(file);
|
||||
byte[] b = new byte[1024];
|
||||
int length;
|
||||
while ((length = fis.read(b)) > 0)
|
||||
{
|
||||
os.write(b, 0, length);
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally{
|
||||
if (os != null)
|
||||
{
|
||||
try{
|
||||
os.close();
|
||||
}
|
||||
catch(IOException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fis != null)
|
||||
{
|
||||
try{
|
||||
fis.close();
|
||||
}
|
||||
catch(IOException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件名重新编码
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @param fileName 文件名
|
||||
* @return 编码后的文件名
|
||||
*/
|
||||
public static String setFileDownloadHeader(HttpServletRequest request, String fileName)
|
||||
throws UnsupportedEncodingException {
|
||||
final String agent = request.getHeader("USER-AGENT");
|
||||
String filename = fileName;
|
||||
if (agent.contains("MSIE")) {
|
||||
//IE浏览器
|
||||
filename = URLEncoder.encode(filename, "utf-8");
|
||||
filename = filename.replace("+", " ");
|
||||
} else if (agent.contains("Firefox")) {
|
||||
//火狐浏览器
|
||||
filename = new String(fileName.getBytes(), "ISO8859-1");
|
||||
} else if (agent.contains("Chrome")) {
|
||||
//google浏览器
|
||||
filename = URLEncoder.encode(filename, "utf-8");
|
||||
} else {
|
||||
//其它浏览器
|
||||
filename = URLEncoder.encode(filename, "utf-8");
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将File转换成MultipartFile
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static MultipartFile fileToMultipartFile(File file) {
|
||||
MultipartFile result = null;
|
||||
if (null != file) {
|
||||
try (FileInputStream input = new FileInputStream(file)) {
|
||||
result = new MockMultipartFile(file.getName().concat("temp"), file.getName(), "text/plain", input);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
package com.ho.filecenter.util;
|
||||
|
||||
public class MqttConfigUtil {
|
||||
|
||||
public static String[] commonTopic = new String[]{
|
||||
"+/device/fa22fd97b39c04c8",
|
||||
"+/device/803274d9432df350",
|
||||
"+/device/e4067161c4ab1929",
|
||||
"+/device/f0e9a01d8b98e820",
|
||||
"+/device/f6c6c5b5dfcc73bb",
|
||||
"+/device/9038222e7fb8789d",
|
||||
"+/device/a707000000000000",
|
||||
"+/device/811b4eb0f8e99c12",
|
||||
"+/device/c2c574a5c691bf69",
|
||||
"+/device/5265899ad223c157",
|
||||
"+/device/517664ba87ac49ec",
|
||||
"+/device/27d83a2844ff5866",
|
||||
"+/device/77ba753718908d1a",
|
||||
"+/device/b602b10956119d39",
|
||||
"+/device/4c7dd125b6da91fd",
|
||||
"+/device/581bf6724737da0c",
|
||||
"+/device/8a2396ad453891b1",
|
||||
"+/device/917ca24a9ccdf809",
|
||||
"+/device/a8402702a1d41d88",
|
||||
"+/device/7a5202c7dc74afd6",
|
||||
"+/device/bfe7a19ced50c54d",
|
||||
"+/device/21f835330b485415",
|
||||
"+/device/a978d559eeb0a32e",
|
||||
"+/device/4dddf8b0caae7d8b",
|
||||
"+/device/beff9c2ea2d210c4",
|
||||
"+/device/a5af67550fd4dc50",
|
||||
"+/device/0c3e8eadd58f8a51",
|
||||
"+/device/14ed724c77b73494",
|
||||
"+/device/d12d361c6bfef025",
|
||||
"+/device/781c2bf41a6ffa5a",
|
||||
"+/device/ac10829b20169da0",
|
||||
"+/device/ec939740502f3a66",
|
||||
"+/device/e0c812e00ac4e006",
|
||||
"+/device/0000000000000000",
|
||||
"+/device/5e9b285116453b1a",
|
||||
"+/device/eeb34d0de2b6a953",
|
||||
"+/device/56501a13712f9a6e",
|
||||
"+/device/e8d98e91aaa7b04f",
|
||||
"+/device/6c6978a7fb9a8f6d",
|
||||
"+/device/6803ef0410fb7c02",
|
||||
"+/device/fe828101e353b919",
|
||||
"+/device/42ff4118453e41ca",
|
||||
"+/device/d9f866f14483c92d",
|
||||
"+/device/1deae4a5f1400666",
|
||||
"+/device/a608ea4ffb5221d7",
|
||||
"+/device/bd0ccfe06c1d3596",
|
||||
"+/device/262cdfc279065aa0",
|
||||
"+/device/3df87897c35ae0c5",
|
||||
"+/device/8ca0297304c266b6",
|
||||
"+/device/1200000000000000",
|
||||
"+/device/333470f1dccfb19b",
|
||||
"+/device/02bd28350b1c2619",
|
||||
"+/device/9688431d4f01806e",
|
||||
"+/device/a2f3973e0c3b4835",
|
||||
"+/device/f91779c511763a5b",
|
||||
"+/device/2b8924e509ee8559",
|
||||
"+/device/9e4ee680a26303f7",
|
||||
"+/device/56d9bb7131c724b5",
|
||||
"+/device/9511bebccc477456",
|
||||
"+/device/0a3146610bcc5440",
|
||||
"+/device/e817466c6127ab44",
|
||||
"+/device/99efbb96bc40fd15",
|
||||
"+/device/43687f5b1ebecb64",
|
||||
"+/device/b9e0cdfdd4df7736",
|
||||
"+/device/ed76d5ab39f6c42d",
|
||||
"+/device/63f8d5df0c9d647c",
|
||||
"+/device/98b61a1f166b8419",
|
||||
"+/device/201913c33e0318ee",
|
||||
"+/device/9c74bebb12d05635",
|
||||
"+/device/1f237999be964f42",
|
||||
"+/device/104cebca14ffa98c",
|
||||
"+/device/2d1cab6edbfaeb94",
|
||||
"+/device/c8c30d1decff167d",
|
||||
"+/device/984423fdfda19376",
|
||||
"+/device/18db1248acf66a3e",
|
||||
"+/device/e18710921a53bfff",
|
||||
"+/device/04878a29f87e237d",
|
||||
"+/device/c336512bd77d6cbc",
|
||||
"+/device/01ac2a161029e555",
|
||||
"+/device/4eeccb413407a4e4",
|
||||
"+/device/14e7f5c9b123360d",
|
||||
"+/device/daf25437cbc31a00",
|
||||
"+/device/44dfc09110e1f994",
|
||||
"+/device/2dd522056c132349",
|
||||
"+/device/bd7f78f9d070abe6",
|
||||
"+/device/e932c594ce083810",
|
||||
"+/device/b80c3b7513773c7f",
|
||||
"+/device/7f0d37c30d28ed0f",
|
||||
"+/device/53be81deba3b9c74",
|
||||
"+/device/fe5f56cc9029bf20",
|
||||
"+/device/60723affac3821a5",
|
||||
"+/device/d3e22616db04dc52",
|
||||
"+/device/36c12afabd8fa201",
|
||||
"+/device/71db70b8ce2eb0d1",
|
||||
"+/device/69f319418cfe13a2",
|
||||
"+/device/f043173d1fd8cb0d",
|
||||
"+/device/9b5084678310c4da",
|
||||
"+/device/fa3936fdeb8f8cd1",
|
||||
"+/device/0819c35644808b72",
|
||||
"+/device/40442c5a0a29de37",
|
||||
"+/device/75fa0ee5048bd500",
|
||||
"+/device/39674be356de68ad",
|
||||
"+/device/b490b672a5f76716",
|
||||
"+/device/6a3ba96ed146872b",
|
||||
"+/device/3a785a63862c213d",
|
||||
"+/device/2d29a0fbac938329",
|
||||
"+/device/7d97391a68f8d6af",
|
||||
"+/device/b50a1edd44549876",
|
||||
"+/device/7c31d3c5c077228f",
|
||||
"+/device/99e513be6075f8c6",
|
||||
"+/device/5d4297256f02ebc2",
|
||||
"+/device/67aa37e699e1e08f",
|
||||
"+/device/ea0ebfbfa1487bd2",
|
||||
"+/device/aa8a43d326dddb3f",
|
||||
"1/device/+"
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取文件请求监听主题
|
||||
* @return
|
||||
*/
|
||||
public static String[] getFileRequestTopic(){
|
||||
String log = "/file/request";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取文件响应监听主题
|
||||
* @return
|
||||
*/
|
||||
public static String[] getFileResponseTopic(){
|
||||
String log = "/file/response";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String[] getCurveResponseTopic(){
|
||||
String log = "/curve/response";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String[] getDispatchResponseTopic(){
|
||||
String log = "/dispatch/response";
|
||||
String[] str = new String[commonTopic.length];
|
||||
for (int i = 0; i < commonTopic.length; i++) {
|
||||
str[i] = commonTopic[i]+log;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
224
file-center/src/main/java/com/ho/filecenter/util/PDFutil.java
Normal file
224
file-center/src/main/java/com/ho/filecenter/util/PDFutil.java
Normal file
@ -0,0 +1,224 @@
|
||||
package com.ho.filecenter.util;
|
||||
|
||||
import com.itextpdf.text.*;
|
||||
import com.itextpdf.text.pdf.PdfPCell;
|
||||
import com.itextpdf.text.pdf.PdfPTable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class PDFutil {
|
||||
|
||||
/**
|
||||
* 设置标题
|
||||
* @param table PTable表格
|
||||
* @param textFont 字体样式
|
||||
* @param value 添加的内容
|
||||
* @param cols 合并几列
|
||||
* @param rows 合并几行
|
||||
* @param middleType 居中类型 0:不居中, 1:水平居中 2:垂直居中
|
||||
* @return PTable表格
|
||||
*/
|
||||
public PdfPTable getTitle(PdfPTable table, Font textFont, String value, Integer cols, Integer rows, Integer middleType){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
Paragraph p = new Paragraph(value, textFont);
|
||||
cell.setColspan(cols);
|
||||
cell.setRowspan(rows);
|
||||
if(middleType == 1){
|
||||
p.setAlignment(1);
|
||||
getHorizontalCenter(cell);
|
||||
}else if(middleType == 2){
|
||||
p.setAlignment(1);
|
||||
getVerticalCenter(cell);
|
||||
}
|
||||
cell.setBorderColor(BaseColor.WHITE);// 设置方向后会失效
|
||||
cell.addElement(p);
|
||||
table.addCell(cell);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单元格
|
||||
* @param table PTable表格
|
||||
* @param textFont 字体样式
|
||||
* @param value 添加的内容
|
||||
* @param middleType 居中类型 0:不居中, 1:水平居中 2:垂直居中
|
||||
* @return PTable表格
|
||||
*/
|
||||
public PdfPTable getPdfCell(PdfPTable table, Font textFont, String value, Integer middleType){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
Paragraph p = new Paragraph(value, textFont);
|
||||
if(middleType == 1){
|
||||
p.setAlignment(1);
|
||||
getHorizontalCenter(cell);
|
||||
}else if(middleType == 2){
|
||||
p.setAlignment(1); // -1:未定义,0:左,1:中,2:右,3:合适的,4:上,5:中,6:下,7:底线
|
||||
getVerticalCenter(cell);
|
||||
}
|
||||
cell.addElement(p);
|
||||
table.addCell(cell);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并行(合并行(上下合并)时,设置为垂直居中)
|
||||
* @param table PTable表格
|
||||
* @param textFont 字体样式
|
||||
* @param value 添加的内容
|
||||
* @param rows 合并几行
|
||||
* @param middleType 居中类型 0:不居中, 1:水平居中 2:垂直居中
|
||||
* @return PTable表格
|
||||
*/
|
||||
public PdfPTable getRowSpan(PdfPTable table, Font textFont, String value, Integer rows, Integer middleType){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
Paragraph p = new Paragraph(value, textFont);
|
||||
cell.setRowspan(rows);
|
||||
if(middleType == 2){
|
||||
p.setAlignment(1);
|
||||
getVerticalCenter(cell);
|
||||
}
|
||||
cell.addElement(p);
|
||||
table.addCell(cell);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并列(合并列(左右合并)时,设置为水平居中)
|
||||
* @param table PTable表格
|
||||
* @param textFont 字体样式
|
||||
* @param value 添加的内容
|
||||
* @param cols 合并几列
|
||||
* @param middleType 居中类型 0:不居中, 1:水平居中 2:垂直居中
|
||||
* @return PTable表格
|
||||
*/
|
||||
public PdfPTable getColSpan(PdfPTable table, Font textFont, String value, Integer cols, Integer middleType){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
Paragraph p = new Paragraph(value, textFont);
|
||||
cell.setColspan(cols);
|
||||
if(middleType == 1){
|
||||
p.setAlignment(1);
|
||||
getHorizontalCenter(cell);
|
||||
}else if(middleType == 2){
|
||||
p.setAlignment(1);
|
||||
getVerticalCenter(cell);
|
||||
}
|
||||
cell.addElement(p);
|
||||
table.addCell(cell);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并行和列
|
||||
* @param table PTable表格
|
||||
* @param textFont 字体样式
|
||||
* @param value 添加的内容
|
||||
* @param cols 合并几列
|
||||
* @param rows 合并几行
|
||||
* @param middleType 居中类型 0:不居中, 1:水平居中 2:垂直居中
|
||||
* @return PTable表格
|
||||
*/
|
||||
public PdfPTable getRowAndColSpan(PdfPTable table, Font textFont, String value,
|
||||
Integer cols, Integer rows, Integer middleType){
|
||||
PdfPCell cell = new PdfPCell();
|
||||
Paragraph p = new Paragraph(value, textFont);
|
||||
cell.setColspan(cols);
|
||||
cell.setRowspan(rows);
|
||||
if(middleType == 1){
|
||||
p.setAlignment(1);
|
||||
getHorizontalCenter(cell);
|
||||
}else if(middleType == 2){
|
||||
p.setAlignment(1);
|
||||
getVerticalCenter(cell);
|
||||
}
|
||||
cell.addElement(p);
|
||||
table.addCell(cell);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 水平居中
|
||||
* @param cell PdfPCell单元格
|
||||
* @return PdfPCell单元格
|
||||
*/
|
||||
public PdfPCell getHorizontalCenter(PdfPCell cell){
|
||||
cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);// 水平居中
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* 垂直居中
|
||||
* @param cell PdfPCell单元格
|
||||
* @return PdfPCell单元格
|
||||
*/
|
||||
public PdfPCell getVerticalCenter(PdfPCell cell){
|
||||
cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
|
||||
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
|
||||
cell.setPaddingTop(-2f);//把字垂直居中
|
||||
cell.setPaddingBottom(8f);//把字垂直居中
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* @param table 表
|
||||
* @param str 填充的数据
|
||||
* @param font 字体设置
|
||||
*/
|
||||
public void cellFillChar(PdfPTable table,String str,Font font){
|
||||
//如果str为空,不会报错,这个单元格为空
|
||||
PdfPCell cell = new PdfPCell(new Paragraph(str,font));
|
||||
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
|
||||
table.addCell(cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片填充方法
|
||||
* @param table 表
|
||||
* @param path 图片存在路径
|
||||
*/
|
||||
public void cellFillImage(PdfPTable table,String path){
|
||||
// 创建图片对象
|
||||
Image image = null;
|
||||
try {
|
||||
image = Image.getInstance(path);
|
||||
image.setScaleToFitHeight(true);
|
||||
image.setScaleToFitLineWhenOverflow(true);
|
||||
if (image != null){
|
||||
// 创建包含图片的单元格
|
||||
PdfPCell cellWithImage = new PdfPCell(image,true);
|
||||
cellWithImage.setFixedHeight(50f);
|
||||
cellWithImage.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
cellWithImage.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
|
||||
table.addCell(cellWithImage);
|
||||
}
|
||||
} catch (BadElementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片填充方法
|
||||
* @param table 表
|
||||
* @param path 图片存在路径
|
||||
* @param fileName 文件名
|
||||
* @param font 字体
|
||||
*/
|
||||
public void cellFillFile(PdfPTable table,String path,String fileName,Font font){
|
||||
// 创建图片对象
|
||||
Chunk imdb = new Chunk(fileName);
|
||||
if (imdb != null){
|
||||
PdfPCell fileCell = new PdfPCell();
|
||||
// 创建包含图片的单元格
|
||||
imdb.setFont(font);
|
||||
imdb.setAnchor(path);
|
||||
fileCell.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
fileCell.addElement(imdb);
|
||||
table.addCell(fileCell);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
111
file-center/src/main/resources/application-dev.yml
Normal file
111
file-center/src/main/resources/application-dev.yml
Normal file
@ -0,0 +1,111 @@
|
||||
#文件中心
|
||||
server:
|
||||
port: 8017
|
||||
servlet:
|
||||
#上下文统一使用api,屏蔽前端路径差异
|
||||
context-path: /api
|
||||
|
||||
#mqtt
|
||||
mqtt:
|
||||
url: tcp://123.60.190.77:1883
|
||||
userName: admin
|
||||
passWord: public
|
||||
timeout: 5000
|
||||
keepAlive: 60
|
||||
|
||||
#主题 todo 先死一个用于测试
|
||||
topic:
|
||||
cloudFileRequest: +/cloud/+/file/request
|
||||
cloudFileResponse: +/cloud/+/file/response
|
||||
edgeFileResponse: +/device/+/file/response
|
||||
edgeFileRequest: +/device/+/file/request
|
||||
|
||||
cloudControlRequest: +/cloud/+/control/request
|
||||
edgeControlResponse: +/device/+/control/response
|
||||
|
||||
#路径 todo 先再本地
|
||||
path:
|
||||
local: /opt/file_center
|
||||
#下发文件路径
|
||||
copy: /opt/file_copy
|
||||
#天气ip2region.db路径
|
||||
weather: /opt/ip2region.db
|
||||
chartPath: /opt/image/
|
||||
|
||||
#指定字节大小
|
||||
size:
|
||||
byteSize: 102400
|
||||
|
||||
|
||||
#通用文件
|
||||
files:
|
||||
upload:
|
||||
path: D:\upload
|
||||
format: .jpg,.png,.doc,.docx,.xlsx,.xls,.pdf
|
||||
maxByte: 10485760
|
||||
|
||||
#swagger2配置
|
||||
swagger2:
|
||||
enable: true #开启标志 生产环境要关闭
|
||||
projectName: 云平台-文件中心-接口
|
||||
controllerPath: com.ho.filecenter.controller
|
||||
|
||||
spring:
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
name: file-center
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.100.244:3306/file_center_db?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||
username: root
|
||||
password: 123456
|
||||
druid:
|
||||
initialSize: 5
|
||||
minIdle: 5
|
||||
maxActive: 5
|
||||
keepAlive: true #保持长连接
|
||||
connection-error-retry-attempts: 3
|
||||
#设备文件上传大小
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 500MB
|
||||
max-request-size: 500MB
|
||||
enabled: true
|
||||
#Redis
|
||||
redis:
|
||||
port: 6379 #端口
|
||||
timeout: 3000ms #连接超时
|
||||
host: 192.168.100.244 #单机
|
||||
password: 123456
|
||||
database: 0
|
||||
|
||||
#port: 6379 #端口
|
||||
#timeout: 5000ms #连接超时
|
||||
#host: 127.0.0.1 #单机
|
||||
#password:
|
||||
#database: 0
|
||||
#集群 真实环境开启
|
||||
# cluster:
|
||||
# nodes:
|
||||
# - 127.0.0.1:6379
|
||||
# - 127.0.0.1:6380
|
||||
# - 127.0.0.1:6381
|
||||
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 8 #连接池最大连接 默认8
|
||||
max-idle: 8 #连接池中最大空闲连接 默认8
|
||||
min-idle: 1 #连接池中最小空闲连接 默认0
|
||||
max-wait: 2000ms #连接池最大阻塞等待时间 使用负值表示没有限制
|
||||
|
||||
minio:
|
||||
accessKey: admin
|
||||
secretKey: zzkj@688737
|
||||
endpoint: http://192.168.0.236:9000
|
||||
prefixUrl: http://192.168.0.236:9000
|
||||
|
||||
3
file-center/src/main/resources/application.yml
Normal file
3
file-center/src/main/resources/application.yml
Normal file
@ -0,0 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
80
file-center/src/main/resources/bootstrap.yml
Normal file
80
file-center/src/main/resources/bootstrap.yml
Normal file
@ -0,0 +1,80 @@
|
||||
mybatis:
|
||||
type-aliases-package: com.ho.filecenter.entity
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
configuration:
|
||||
#驼峰
|
||||
mapUnderscoreToCamelCase: true
|
||||
#禁止servlet懒加载
|
||||
mvc:
|
||||
servlet:
|
||||
load-on-startup: 1
|
||||
|
||||
#ribbon的超时时间
|
||||
ribbon:
|
||||
ReadTimeout: 10000
|
||||
ConnectTimeout: 10000
|
||||
|
||||
#天气路径
|
||||
weather:
|
||||
path: https://api.caiyunapp.com/v2.6
|
||||
token: Qc9CsG4NkKY8XxyZ
|
||||
after: /daily?dailysteps=1
|
||||
|
||||
#Logging
|
||||
logging:
|
||||
config: classpath:logback.xml
|
||||
level:
|
||||
com.ho.filecenter.mapper: debug
|
||||
|
||||
#文件下发路径
|
||||
fileTransfer:
|
||||
directionDirectory: /semp1000/semp
|
||||
|
||||
#minio配置属性
|
||||
minio:
|
||||
accessKey: minioadmin
|
||||
secretKey: smArt{}tH81/
|
||||
endpoint: http://123.60.162.194:9000
|
||||
|
||||
|
||||
#173redeis密码
|
||||
openRedis:
|
||||
host: 124.70.135.173
|
||||
port: 6379
|
||||
pass: rD?vL&/26H
|
||||
|
||||
#183redeis密码
|
||||
openTestRedis:
|
||||
host: 192.168.1.183
|
||||
port: 6379
|
||||
pass: 123456
|
||||
|
||||
#移动流量监控Api调用参数
|
||||
mobile:
|
||||
appId: C5010250A25040653935
|
||||
password: KI8825P@KTbo
|
||||
ipAndPort: https://api.iot.10086.cn
|
||||
version: /v5
|
||||
|
||||
#电信流量监控Api调用参数
|
||||
telecom:
|
||||
keyNew: 5ec916b9c72fae4d
|
||||
url: http://global.anhuiyk.cn:8006/m2m_api/v2/batch/queryFlow/
|
||||
appId: HZCNNJSZJSYXGS1365@2024
|
||||
pwd: 8b05e9f4a704ba62
|
||||
|
||||
|
||||
topic:
|
||||
cloudPlanRequest: +/cloud/+/+/request
|
||||
edgePlanResponse: +/device/+/+/response
|
||||
cloudCurveRequest: +/cloud/+/curve/request
|
||||
edgeCurveResponse: +/device/+/curve/response
|
||||
cloudDispatchRequest: +/cloud/+/dispatch/request
|
||||
edgeDispatchResponse: +/device/+/dispatch/response
|
||||
|
||||
#文件和命令下发等默认逻辑实现的开关
|
||||
switch:
|
||||
#文件默认逻辑的开关 true 为打开 ,false为关闭
|
||||
fileDefaultLogic: true
|
||||
#命令下发默认逻辑的开关 true 为打开 ,false为关闭
|
||||
orderSendDefaultLogic: true
|
||||
BIN
file-center/src/main/resources/ip2region.db
Normal file
BIN
file-center/src/main/resources/ip2region.db
Normal file
Binary file not shown.
BIN
file-center/src/main/resources/lib/file-src-1.0.jar
Normal file
BIN
file-center/src/main/resources/lib/file-src-1.0.jar
Normal file
Binary file not shown.
39
file-center/src/main/resources/logback.xml
Normal file
39
file-center/src/main/resources/logback.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration>
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS,CTT} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/home/hocloud/logs/file-center/file-center.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/home/hocloud/logs/file-center/file-center.%d{yyyy-MM-dd}-%i.log
|
||||
</fileNamePattern>
|
||||
<maxHistory>10</maxHistory>
|
||||
<!-- 除按日志记录之外,还配置了日志文件不能超过2M,若超过2M,日志文件会以索引0开始,
|
||||
命名日志文件,例如log-error-2013-12-21.0.log -->
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>256MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS,CTT} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- project default level -->
|
||||
<logger name="com.sinoinfo.filecenter" level="DEBUG"/>
|
||||
|
||||
<!--log4jdbc -->
|
||||
<logger name="jdbc.sqltiming" level="DEBUG"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="rollingFile"/>
|
||||
</root>
|
||||
</configuration>
|
||||
165
file-center/src/main/resources/mapper/CameraMapper.xml
Normal file
165
file-center/src/main/resources/mapper/CameraMapper.xml
Normal file
@ -0,0 +1,165 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.CameraMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ho.filecenter.entity.Camera">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="groupId" column="group_id" jdbcType="INTEGER"/>
|
||||
<result property="stationId" column="station_id" jdbcType="INTEGER"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="address" column="address" jdbcType="VARCHAR"/>
|
||||
<result property="appkey" column="appkey" jdbcType="VARCHAR"/>
|
||||
<result property="appSecret" column="app_secret" jdbcType="VARCHAR"/>
|
||||
<result property="code" column="code" jdbcType="VARCHAR"/>
|
||||
<result property="validateCode" column="validate_code" jdbcType="VARCHAR"/>
|
||||
<result property="deviceSerial" column="device_serial" jdbcType="VARCHAR"/>
|
||||
<result property="accessToken" column="access_token" jdbcType="VARCHAR"/>
|
||||
<result property="appTime" column="app_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,group_id,station_id,
|
||||
name,address,appkey,
|
||||
app_secret,code,validate_code,
|
||||
device_serial,access_token,app_time
|
||||
</sql>
|
||||
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from camera
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<select id="selectByCondition" resultType="com.ho.filecenter.entity.Camera">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from camera
|
||||
<where>
|
||||
<if test="stationId != null">
|
||||
station_id = #{stationId}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
name LIKE concat('%',#{name},'%')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete
|
||||
from camera
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<delete id="deleteByIds">
|
||||
delete
|
||||
from camera
|
||||
<where>
|
||||
<if test="ids != null and ids.size() != 0">
|
||||
and id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.Camera"
|
||||
useGeneratedKeys="true">
|
||||
insert into camera
|
||||
( id, group_id, station_id
|
||||
, name, address, appkey
|
||||
, app_secret, code, validate_code
|
||||
, device_serial, access_token, app_time)
|
||||
values ( #{id,jdbcType=INTEGER}, #{groupId,jdbcType=INTEGER}, #{stationId,jdbcType=INTEGER}
|
||||
, #{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{appkey,jdbcType=VARCHAR}
|
||||
, #{appSecret,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{validateCode,jdbcType=VARCHAR}
|
||||
, #{deviceSerial,jdbcType=VARCHAR}, #{accessToken,jdbcType=VARCHAR}, #{appTime,jdbcType=TIMESTAMP})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.Camera"
|
||||
useGeneratedKeys="true">
|
||||
insert into camera
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="groupId != null">group_id,</if>
|
||||
<if test="stationId != null">station_id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="address != null">address,</if>
|
||||
<if test="appkey != null">appkey,</if>
|
||||
<if test="appSecret != null">app_secret,</if>
|
||||
<if test="code != null">code,</if>
|
||||
<if test="validateCode != null">validate_code,</if>
|
||||
<if test="deviceSerial != null">device_serial,</if>
|
||||
<if test="accessToken != null">access_token,</if>
|
||||
<if test="appTime != null">app_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id,jdbcType=INTEGER},</if>
|
||||
<if test="groupId != null">#{groupId,jdbcType=INTEGER},</if>
|
||||
<if test="stationId != null">#{stationId,jdbcType=INTEGER},</if>
|
||||
<if test="name != null">#{name,jdbcType=VARCHAR},</if>
|
||||
<if test="address != null">#{address,jdbcType=VARCHAR},</if>
|
||||
<if test="appkey != null">#{appkey,jdbcType=VARCHAR},</if>
|
||||
<if test="appSecret != null">#{appSecret,jdbcType=VARCHAR},</if>
|
||||
<if test="code != null">#{code,jdbcType=VARCHAR},</if>
|
||||
<if test="validateCode != null">#{validateCode,jdbcType=VARCHAR},</if>
|
||||
<if test="deviceSerial != null">#{deviceSerial,jdbcType=VARCHAR},</if>
|
||||
<if test="accessToken != null">#{accessToken,jdbcType=VARCHAR},</if>
|
||||
<if test="appTime != null">#{appTime,jdbcType=TIMESTAMP},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.Camera">
|
||||
update camera
|
||||
<set>
|
||||
<if test="groupId != null">
|
||||
group_id = #{groupId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="stationId != null">
|
||||
station_id = #{stationId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="address != null">
|
||||
address = #{address,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="appkey != null">
|
||||
appkey = #{appkey,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="appSecret != null">
|
||||
app_secret = #{appSecret,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="code != null">
|
||||
code = #{code,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="validateCode != null">
|
||||
validate_code = #{validateCode,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="deviceSerial != null">
|
||||
device_serial = #{deviceSerial,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="accessToken != null">
|
||||
access_token = #{accessToken,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="appTime != null">
|
||||
app_time = #{appTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.Camera">
|
||||
update camera
|
||||
set group_id = #{groupId,jdbcType=INTEGER},
|
||||
station_id = #{stationId,jdbcType=INTEGER},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
address = #{address,jdbcType=VARCHAR},
|
||||
appkey = #{appkey,jdbcType=VARCHAR},
|
||||
app_secret = #{appSecret,jdbcType=VARCHAR},
|
||||
code = #{code,jdbcType=VARCHAR},
|
||||
validate_code = #{validateCode,jdbcType=VARCHAR},
|
||||
device_serial = #{deviceSerial,jdbcType=VARCHAR},
|
||||
access_token = #{accessToken,jdbcType=VARCHAR},
|
||||
app_time = #{appTime,jdbcType=TIMESTAMP}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
||||
180
file-center/src/main/resources/mapper/CardInfoMapper.xml
Normal file
180
file-center/src/main/resources/mapper/CardInfoMapper.xml
Normal file
@ -0,0 +1,180 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.CardInfoMapper">
|
||||
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ho.filecenter.entity.CardInfo">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="card" column="card" jdbcType="VARCHAR"/>
|
||||
<result property="flowMonitorId" column="flow_monitor_id" jdbcType="INTEGER"/>
|
||||
<result property="stationId" column="station_id" jdbcType="INTEGER"/>
|
||||
<result property="packageType" column="package_type" jdbcType="INTEGER"/>
|
||||
<result property="cardStatus" column="card_status" jdbcType="INTEGER"/>
|
||||
<result property="openDate" column="open_date" jdbcType="VARCHAR"/>
|
||||
<result property="activationDate" column="activation_date" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,card,flow_monitor_id,
|
||||
station_id,package_type,card_status,
|
||||
open_date,activation_date
|
||||
</sql>
|
||||
|
||||
<delete id="deleteByPrimaryKey">
|
||||
delete
|
||||
from card_info
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
|
||||
<select id="selectByFlowId" resultType="com.ho.filecenter.entity.CardInfo">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from card_info
|
||||
where flow_monitor_id = #{id}
|
||||
</select>
|
||||
<select id="selectByCondition" resultType="com.ho.filecenter.entity.CardInfo">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
from `card_info`
|
||||
<where>
|
||||
<if test="flowMonitorId != null ">
|
||||
flow_monitor_id = #{flowMonitorId}
|
||||
</if>
|
||||
<if test="stationId != null ">
|
||||
station_id = #{stationId}
|
||||
</if>
|
||||
<if test="card != null">
|
||||
and card = #{card}
|
||||
</if>
|
||||
<if test="packageType != null">
|
||||
and package_type= # {packageType}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectByCardTotal" resultType="java.lang.Integer">
|
||||
select count(*)
|
||||
from card_info
|
||||
where flow_monitor_id = #{flowMonitorId}
|
||||
</select>
|
||||
|
||||
<select id="selectByFlowCardList" resultType="com.ho.filecenter.entity.CardInfo">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from card_info
|
||||
where flow_monitor_id = #{flowMonitorId}
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
|
||||
<select id="selectAll" resultType="com.ho.filecenter.entity.CardInfo">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from card_info
|
||||
<if test="card != null">
|
||||
card = #{card},
|
||||
</if>
|
||||
<if test="packageType != null">
|
||||
package_type = #{packageType},
|
||||
</if>
|
||||
<if test="flowMonitorId != null">
|
||||
flow_monitor_id = #{flowMonitorId},
|
||||
</if>
|
||||
<if test="stationId != null">
|
||||
station_id = #{stationId},
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="com.ho.filecenter.entity.CardInfo">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from card_info
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectByCard" resultType="com.ho.filecenter.entity.CardInfo">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from card_info
|
||||
where card = #{card}
|
||||
</select>
|
||||
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.CardInfo"
|
||||
useGeneratedKeys="true">
|
||||
insert into card_info
|
||||
(id, card, flow_monitor_id, station_id,
|
||||
package_type, card_status)
|
||||
values ( #{id}, #{card}, #{flowMonitorId}, #{stationId}
|
||||
, #{packageType}, #{cardStatus})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.CardInfo"
|
||||
useGeneratedKeys="true">
|
||||
insert into card_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="card != null">card,</if>
|
||||
<if test="flowMonitorId != null">flow_monitor_id,</if>
|
||||
<if test="stationId != null">station_id,</if>
|
||||
<if test="packageType != null">package_type,</if>
|
||||
<if test="cardStatus != null">card_status,</if>
|
||||
<if test="openDate != null">open_date,</if>
|
||||
<if test="activationDate != null">activation_date</if>
|
||||
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="card != null">#{card},</if>
|
||||
<if test="flowMonitorId != null">#{flowMonitorId},</if>
|
||||
<if test="stationId != null">#{stationId},</if>
|
||||
<if test="packageType != null">#{packageType},</if>
|
||||
<if test="cardStatus != null">#{cardStatus},</if>
|
||||
<if test="openDate != null">#{openDate},</if>
|
||||
<if test="activationDate != null">#{activationDate}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.CardInfo">
|
||||
update card_info
|
||||
<set>
|
||||
<if test="card != null">
|
||||
card = #{card},
|
||||
</if>
|
||||
<if test="flowMonitorId != null">
|
||||
flow_monitor_id = #{flowMonitorId},
|
||||
</if>
|
||||
<if test="stationId != null">
|
||||
station_id = #{stationId},
|
||||
</if>
|
||||
<if test="stationId == null">
|
||||
station_id = null,
|
||||
</if>
|
||||
<if test="packageType != null">
|
||||
package_type = #{packageType},
|
||||
</if>
|
||||
<if test="cardStatus != null">
|
||||
card_status = #{cardStatus},
|
||||
</if>
|
||||
<if test="openDate != null">
|
||||
open_date = #{openDate},
|
||||
</if>
|
||||
<if test="activationDate != null">
|
||||
activation_date = #{activationDate}
|
||||
</if>
|
||||
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.CardInfo">
|
||||
update card_info
|
||||
set flow_monitor_id = #{flowMonitorId},
|
||||
card = #{card},
|
||||
station_id = #{stationId},
|
||||
package_type = #{packageType},
|
||||
card_status = #{cardStatus},
|
||||
open_date = #{openDate},
|
||||
activation_date = #{activationDate}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
134
file-center/src/main/resources/mapper/CityMapper.xml
Normal file
134
file-center/src/main/resources/mapper/CityMapper.xml
Normal file
@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.CityMapper">
|
||||
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,cityEn,cityZh,
|
||||
provinceEn,provinceZh,countryEn,
|
||||
countryZh,leaderEn,leaderZh,
|
||||
lat,lon
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||
delete from city
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<select id="selectByPrimaryKey" resultType="com.ho.filecenter.entity.City">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from city
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectByProvinceAndCity" resultType="com.ho.filecenter.entity.City">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from city
|
||||
<where>
|
||||
<if test="cityzh != null">
|
||||
and cityZh = #{cityzh}
|
||||
</if>
|
||||
|
||||
<if test="provincezh != null">
|
||||
and provinceZh= #{provincezh}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.City" useGeneratedKeys="true">
|
||||
insert into city
|
||||
( id,cityEn,cityZh
|
||||
,provinceEn,provinceZh,countryEn
|
||||
,countryZh,leaderEn,leaderZh
|
||||
,lat,lon)
|
||||
values (#{id,jdbcType=VARCHAR},#{cityen,jdbcType=VARCHAR},#{cityzh,jdbcType=VARCHAR}
|
||||
,#{provinceen,jdbcType=VARCHAR},#{provincezh,jdbcType=VARCHAR},#{countryen,jdbcType=VARCHAR}
|
||||
,#{countryzh,jdbcType=VARCHAR},#{leaderen,jdbcType=VARCHAR},#{leaderzh,jdbcType=VARCHAR}
|
||||
,#{lat,jdbcType=VARCHAR},#{lon,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.City" useGeneratedKeys="true">
|
||||
insert into city
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="cityen != null">cityEn,</if>
|
||||
<if test="cityzh != null">cityZh,</if>
|
||||
<if test="provinceen != null">provinceEn,</if>
|
||||
<if test="provincezh != null">provinceZh,</if>
|
||||
<if test="countryen != null">countryEn,</if>
|
||||
<if test="countryzh != null">countryZh,</if>
|
||||
<if test="leaderen != null">leaderEn,</if>
|
||||
<if test="leaderzh != null">leaderZh,</if>
|
||||
<if test="lat != null">lat,</if>
|
||||
<if test="lon != null">lon,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id,jdbcType=VARCHAR},</if>
|
||||
<if test="cityen != null">#{cityen,jdbcType=VARCHAR},</if>
|
||||
<if test="cityzh != null">#{cityzh,jdbcType=VARCHAR},</if>
|
||||
<if test="provinceen != null">#{provinceen,jdbcType=VARCHAR},</if>
|
||||
<if test="provincezh != null">#{provincezh,jdbcType=VARCHAR},</if>
|
||||
<if test="countryen != null">#{countryen,jdbcType=VARCHAR},</if>
|
||||
<if test="countryzh != null">#{countryzh,jdbcType=VARCHAR},</if>
|
||||
<if test="leaderen != null">#{leaderen,jdbcType=VARCHAR},</if>
|
||||
<if test="leaderzh != null">#{leaderzh,jdbcType=VARCHAR},</if>
|
||||
<if test="lat != null">#{lat,jdbcType=VARCHAR},</if>
|
||||
<if test="lon != null">#{lon,jdbcType=VARCHAR},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.City">
|
||||
update city
|
||||
<set>
|
||||
<if test="cityen != null">
|
||||
cityEn = #{cityen,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="cityzh != null">
|
||||
cityZh = #{cityzh,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="provinceen != null">
|
||||
provinceEn = #{provinceen,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="provincezh != null">
|
||||
provinceZh = #{provincezh,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="countryen != null">
|
||||
countryEn = #{countryen,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="countryzh != null">
|
||||
countryZh = #{countryzh,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="leaderen != null">
|
||||
leaderEn = #{leaderen,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="leaderzh != null">
|
||||
leaderZh = #{leaderzh,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="lat != null">
|
||||
lat = #{lat,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="lon != null">
|
||||
lon = #{lon,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.City">
|
||||
update city
|
||||
set
|
||||
cityEn = #{cityen,jdbcType=VARCHAR},
|
||||
cityZh = #{cityzh,jdbcType=VARCHAR},
|
||||
provinceEn = #{provinceen,jdbcType=VARCHAR},
|
||||
provinceZh = #{provincezh,jdbcType=VARCHAR},
|
||||
countryEn = #{countryen,jdbcType=VARCHAR},
|
||||
countryZh = #{countryzh,jdbcType=VARCHAR},
|
||||
leaderEn = #{leaderen,jdbcType=VARCHAR},
|
||||
leaderZh = #{leaderzh,jdbcType=VARCHAR},
|
||||
lat = #{lat,jdbcType=VARCHAR},
|
||||
lon = #{lon,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
||||
119
file-center/src/main/resources/mapper/FlowMonitorMapper.xml
Normal file
119
file-center/src/main/resources/mapper/FlowMonitorMapper.xml
Normal file
@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.FlowMonitorMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ho.filecenter.entity.FlowMonitor">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="groupId" column="group_id" jdbcType="VARCHAR"/>
|
||||
<result property="packageName" column="package_name" jdbcType="VARCHAR"/>
|
||||
<result property="packageType" column="package_type" jdbcType="INTEGER"/>
|
||||
<result property="singleOrGroup" column="single_or_group" jdbcType="INTEGER"/>
|
||||
<result property="totalFlow" column="total_flow" jdbcType="INTEGER"/>
|
||||
<result property="deleted" column="deleted" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,group_id,package_name,
|
||||
package_type,single_or_group,total_flow,
|
||||
deleted
|
||||
</sql>
|
||||
<delete id="deleteByPrimaryKey">
|
||||
delete
|
||||
from flow_monitor
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
|
||||
<select id="selectAll" resultType="com.ho.filecenter.entity.FlowMonitor">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM flow_monitor
|
||||
<where>
|
||||
<if test="packageName != null and packageName != ''">
|
||||
and package_name LIKE concat('%',#{packageName},'%')
|
||||
</if>
|
||||
<if test="packageType != null">
|
||||
and package_type = #{packageType}
|
||||
</if>
|
||||
and deleted =1
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="com.ho.filecenter.entity.FlowMonitor">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from flow_monitor
|
||||
where id = #{flowMonitorId}
|
||||
</select>
|
||||
|
||||
<select id="selectByPid" resultType="com.ho.filecenter.entity.FlowMonitor">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from flow_monitor
|
||||
where group_id = #{groupId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.FlowMonitor"
|
||||
useGeneratedKeys="true">
|
||||
insert into flow_monitor
|
||||
(id, package_name, package_type, deleted)
|
||||
values (#{id}, #{packageName}, #{packageType}, #{deleted})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.FlowMonitor"
|
||||
useGeneratedKeys="true">
|
||||
insert into flow_monitor
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="groupId != null">group_id,</if>
|
||||
<if test="packageType != null">package_type,</if>
|
||||
<if test="packageName != null">package_name,</if>
|
||||
<if test="singleOrGroup != null">single_or_group,</if>
|
||||
<if test="totalFlow != null">total_flow,</if>
|
||||
<if test="deleted != null">deleted</if>
|
||||
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="groupId != null">#{groupId},</if>
|
||||
<if test="packageType != null">#{packageType},</if>
|
||||
<if test="packageName != null">#{packageName},</if>
|
||||
<if test="singleOrGroup != null">#{singleOrGroup},</if>
|
||||
<if test="totalFlow != null">#{totalFlow},</if>
|
||||
<if test="deleted != null">#{deleted}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.FlowMonitor">
|
||||
update flow_monitor
|
||||
<set>
|
||||
<if test="groupId != null">
|
||||
group_id = #{groupId},
|
||||
</if>
|
||||
<if test="packageName != null">
|
||||
package_name = #{packageName},
|
||||
</if>
|
||||
<if test="packageType != null">
|
||||
package_type = #{packageType},
|
||||
</if>
|
||||
<if test="singleOrGroup != null">
|
||||
single_or_group = #{singleOrGroup},
|
||||
</if>
|
||||
<if test="totalFlow != null">
|
||||
total_flow = #{totalFlow},
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.FlowMonitor">
|
||||
update flow_monitor
|
||||
set package_name = #{packageName},
|
||||
package_type = #{packageType},
|
||||
deleted = #{deleted}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
||||
166
file-center/src/main/resources/mapper/MediaFileMapper.xml
Normal file
166
file-center/src/main/resources/mapper/MediaFileMapper.xml
Normal file
@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.MediaFileMapper">
|
||||
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,user_id,group_id,
|
||||
dept_id,file_suffix,file_path,
|
||||
file_name,create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectByPrimaryKey" resultType="com.ho.filecenter.entity.MediaFile">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from media_file
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectByInfo" resultType="com.ho.filecenter.entity.MediaFile">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from media_file
|
||||
<where>
|
||||
<if test="groupId != null">
|
||||
and group_id = #{groupId}
|
||||
</if>
|
||||
<if test="vo.fileName != null">
|
||||
and file_name LIKE concat('%',#{vo.fileName},'%')
|
||||
</if>
|
||||
</where>
|
||||
order by
|
||||
create_time desc
|
||||
</select>
|
||||
<select id="selectByPath" resultType="com.ho.filecenter.entity.MediaFile">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from media_file
|
||||
<where>
|
||||
<if test="directory != null ">
|
||||
file_path = #{directory}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectAll" resultType="com.ho.filecenter.entity.MediaFile">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from media_file
|
||||
<where>
|
||||
<if test="fileName != null">
|
||||
file_name LIKE concat('%',#{fileName},'%')
|
||||
</if>
|
||||
</where>
|
||||
order by
|
||||
create_time desc
|
||||
</select>
|
||||
<select id="selectByIds" resultType="com.ho.filecenter.entity.MediaFile">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from media_file
|
||||
<where>
|
||||
<if test="ids != null and ids.size != 0 ">
|
||||
id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||
delete
|
||||
from media_file
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByIds">
|
||||
delete
|
||||
from media_file
|
||||
<where>
|
||||
<if test="ids != null and ids.size != 0">
|
||||
id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.MediaFile"
|
||||
useGeneratedKeys="true">
|
||||
insert into media_file
|
||||
( id, user_id, group_id
|
||||
, dept_id, file_suffix, file_path
|
||||
, file_name, create_time)
|
||||
values ( #{id,jdbcType=BIGINT}, #{userId,jdbcType=VARCHAR}, #{groupId,jdbcType=INTEGER}
|
||||
, #{deptId,jdbcType=INTEGER}, #{fileSuffix,jdbcType=VARCHAR}, #{filePath,jdbcType=VARCHAR}
|
||||
, #{fileName,jdbcType=VARCHAR}, #{createTime})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.MediaFile"
|
||||
useGeneratedKeys="true">
|
||||
insert into media_file
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="groupId != null">group_id,</if>
|
||||
<if test="deptId != null">dept_id,</if>
|
||||
<if test="fileSuffix != null">file_suffix,</if>
|
||||
<if test="filePath != null">file_path,</if>
|
||||
<if test="fileName != null">file_name,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id,jdbcType=BIGINT},</if>
|
||||
<if test="userId != null">#{userId,jdbcType=VARCHAR},</if>
|
||||
<if test="groupId != null">#{groupId,jdbcType=INTEGER},</if>
|
||||
<if test="deptId != null">#{deptId,jdbcType=INTEGER},</if>
|
||||
<if test="fileSuffix != null">#{fileSuffix,jdbcType=VARCHAR},</if>
|
||||
<if test="filePath != null">#{filePath,jdbcType=VARCHAR},</if>
|
||||
<if test="fileName != null">#{fileName,jdbcType=VARCHAR},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.MediaFile">
|
||||
update media_file
|
||||
<set>
|
||||
<if test="userId != null">
|
||||
user_id = #{userId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="groupId != null">
|
||||
group_id = #{groupId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="deptId != null">
|
||||
dept_id = #{deptId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="fileSuffix != null">
|
||||
file_suffix = #{fileSuffix,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="filePath != null">
|
||||
file_path = #{filePath,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="fileName != null">
|
||||
file_name = #{fileName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=DATE},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.MediaFile">
|
||||
update media_file
|
||||
set user_id = #{userId,jdbcType=VARCHAR},
|
||||
group_id = #{groupId,jdbcType=INTEGER},
|
||||
dept_id = #{deptId,jdbcType=INTEGER},
|
||||
file_suffix = #{fileSuffix,jdbcType=VARCHAR},
|
||||
file_path = #{filePath,jdbcType=VARCHAR},
|
||||
file_name = #{fileName,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=DATE}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
</mapper>
|
||||
67
file-center/src/main/resources/mapper/OtaupgradMapper.xml
Normal file
67
file-center/src/main/resources/mapper/OtaupgradMapper.xml
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.OtaupgradMapper">
|
||||
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,station_id,src_id,
|
||||
device_name,file_name,version,
|
||||
update_cause,update_name,create_time,update_time
|
||||
</sql>
|
||||
|
||||
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO otaupgrad
|
||||
(station_id,src_id,
|
||||
device_name,file_name,version,
|
||||
update_cause,update_name,create_time,update_time)
|
||||
VALUES
|
||||
<foreach item="item" collection="list" index="index" separator=",">
|
||||
(
|
||||
#{item.stationId},#{item.srcId},
|
||||
#{item.deviceName},#{item.fileName},#{item.version} ,
|
||||
#{item.updateCause},#{item.updateName},#{item.createTime},#{item.updateTime}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="selectAll" resultType="com.ho.filecenter.entity.Otaupgrad">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from otaupgrad
|
||||
<where>
|
||||
<if test="stationIdList != null and stationIdList.size !=0">
|
||||
and station_id in
|
||||
<foreach collection="stationIdList" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="stationId != null">
|
||||
and station_id = #{stationId}
|
||||
</if>
|
||||
<if test="srcId != null">
|
||||
and src_id = #{srcId}
|
||||
</if>
|
||||
<if test="deviceName != null and deviceName != ''">
|
||||
and device_name LIKE concat('%',#{deviceName},'%')
|
||||
</if>
|
||||
|
||||
</where>
|
||||
ORDER BY update_time DESC
|
||||
</select>
|
||||
|
||||
<!-- <select id="selectByStationIdAndSrcId" resultType="com.ho.filecenter.entity.Otaupgrad">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from otaupgrad
|
||||
where
|
||||
station_id =#{stationId}
|
||||
and src_id = #{srcId}
|
||||
ORDER BY create_time DESC
|
||||
LIMIT 1
|
||||
</select>-->
|
||||
|
||||
</mapper>
|
||||
219
file-center/src/main/resources/mapper/PowerDetailMapper.xml
Normal file
219
file-center/src/main/resources/mapper/PowerDetailMapper.xml
Normal file
@ -0,0 +1,219 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.PowerDetailMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ho.filecenter.entity.PowerDetail">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<id property="powerEndF" column="power_end_f" jdbcType="DECIMAL"/>
|
||||
<result property="pid" column="pid" jdbcType="INTEGER"/>
|
||||
<result property="groupId" column="group_id" jdbcType="INTEGER"/>
|
||||
<result property="tno" column="tno" jdbcType="VARCHAR"/>
|
||||
<result property="multiFactor" column="multi_factor" jdbcType="DECIMAL"/>
|
||||
<result property="powerStartJ" column="power_start_j" jdbcType="DECIMAL"/>
|
||||
<result property="powerStartF" column="power_start_f" jdbcType="DECIMAL"/>
|
||||
<result property="powerStartP" column="power_start_p" jdbcType="DECIMAL"/>
|
||||
<result property="powerStartG" column="power_start_g" jdbcType="DECIMAL"/>
|
||||
<result property="powerEndJ" column="power_end_j" jdbcType="DECIMAL"/>
|
||||
<result property="powerEndP" column="power_end_p" jdbcType="DECIMAL"/>
|
||||
<result property="powerEndG" column="power_end_g" jdbcType="DECIMAL"/>
|
||||
<result property="powerJ" column="power_j" jdbcType="DECIMAL"/>
|
||||
<result property="powerF" column="power_f" jdbcType="DECIMAL"/>
|
||||
<result property="powerP" column="power_p" jdbcType="DECIMAL"/>
|
||||
<result property="powerG" column="power_g" jdbcType="DECIMAL"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,group_id
|
||||
,power_end_f,pid, meter_point,
|
||||
tno,multi_factor,power_start_j,
|
||||
power_start_f,power_start_p,power_start_g,
|
||||
power_end_j,power_end_p,power_end_g,
|
||||
power_j,power_f,power_p,
|
||||
power_g,
|
||||
total_power_start,total_power_end,total_amount
|
||||
</sql>
|
||||
|
||||
<insert id="addBatch" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into power_detail (<include refid="Base_Column_List"/>)
|
||||
values
|
||||
<foreach item="item" collection="list" index="index" separator=",">
|
||||
(
|
||||
#{item.id},#{item.groupId},
|
||||
#{item.powerEndF},#{item.pid}, #{item.MeterPoint},
|
||||
#{item.tno},#{item.multiFactor},#{item.powerStartJ},
|
||||
#{item.powerStartF},#{item.powerStartP},#{item.powerStartG},
|
||||
#{item.powerEndJ},#{item.powerEndP},#{item.powerEndG},
|
||||
#{item.powerJ},#{item.powerF},#{item.powerP},
|
||||
#{item.powerG},
|
||||
#{item.totalPowerStart},#{item.totalPowerEnd},#{item.totalAmount}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into power_detail
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="groupId != null">group_id,</if>
|
||||
<if test="powerEndF != null">power_end_f,</if>
|
||||
<if test="pid != null">pid,</if>
|
||||
<if test="MeterPoint != null">meter_point,</if>
|
||||
<if test="tno != null">tno,</if>
|
||||
<if test="multiFactor != null">multi_factor,</if>
|
||||
<if test="powerStartJ != null">power_start_j,</if>
|
||||
<if test="powerStartF != null">power_start_f,</if>
|
||||
<if test="powerStartP != null">power_start_p,</if>
|
||||
<if test="powerStartG != null">power_start_g,</if>
|
||||
<if test="powerEndJ != null">power_end_j</if>
|
||||
<if test="powerEndF != null">power_end_f</if>
|
||||
<if test="powerEndP != null">power_end_p</if>
|
||||
<if test="powerEndG != null">power_end_g</if>
|
||||
<if test="powerJ != null">power_j</if>
|
||||
<if test="powerF != null">power_f</if>
|
||||
<if test="powerP != null">power_p</if>
|
||||
<if test="powerG != null">power_g</if>
|
||||
<if test="totalPowerStart != null">total_power_start</if>
|
||||
<if test="totalPowerEnd != null">total_power_end</if>
|
||||
<if test="totalAmount != null">total_amount</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="groupId != null">#{groupId},</if>
|
||||
<if test="powerEndF != null">#{powerEndF},</if>
|
||||
<if test="pid != null">#{pid},</if>
|
||||
<if test="MeterPoint != null">#{MeterPoint},</if>
|
||||
<if test="tno != null">#{tno},</if>
|
||||
<if test="multiFactor != null">#{multiFactor},</if>
|
||||
<if test="powerStartJ != null">#{powerStartJ},</if>
|
||||
<if test="powerStartF != null">#{powerStartF},</if>
|
||||
<if test="powerStartP != null">#{powerStartP},</if>
|
||||
<if test="powerStartG != null">#{powerStartG},</if>
|
||||
<if test="powerEndJ != null">#{powerEndJ},</if>
|
||||
<if test="powerEndF != null">#{powerEndF},</if>
|
||||
<if test="powerEndP != null">#{powerEndP},</if>
|
||||
<if test="powerEndG != null">#{powerEndG},</if>
|
||||
<if test="powerJ != null">#{powerJ},</if>
|
||||
<if test="powerF != null">#{powerF},</if>
|
||||
<if test="powerP != null">#{powerP},</if>
|
||||
<if test="powerG != null">#{powerG}</if>
|
||||
<if test="totalPowerStart != null">#{totalPowerStart}</if>
|
||||
<if test="totalPowerEnd != null">#{totalPowerEnd}</if>
|
||||
<if test="totalAmount != null">#{totalAmount}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update power_detail
|
||||
<set>
|
||||
<if test="powerEndF != null">
|
||||
power_end_f = #{powerEndF},
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
pid = #{pid},
|
||||
</if>
|
||||
<if test="groupId != null">
|
||||
group_id = #{groupId},
|
||||
</if>
|
||||
<if test="MeterPoint != null">
|
||||
meter_point = #{MeterPoint},
|
||||
</if>
|
||||
<if test="tno != null">
|
||||
tno = #{tno},
|
||||
</if>
|
||||
<if test="multiFactor != null">
|
||||
multi_factor = #{multiFactor},
|
||||
</if>
|
||||
<if test="powerStartJ != null">
|
||||
power_start_j = #{powerStartJ},
|
||||
</if>
|
||||
<if test="powerStartF != null">
|
||||
power_start_f = #{powerStartF},
|
||||
</if>
|
||||
<if test="powerStartP != null">
|
||||
power_start_p = #{powerStartP},
|
||||
</if>
|
||||
<if test="powerStartG != null">
|
||||
power_start_g = #{powerStartG},
|
||||
</if>
|
||||
<if test="powerEndJ!= null">
|
||||
power_end_j= #{powerEndJ},
|
||||
</if>
|
||||
<if test="powerEndF!= null">
|
||||
power_end_f= #{powerEndF},
|
||||
</if>
|
||||
<if test="powerEndP!= null">
|
||||
power_end_P= #{powerEndP},
|
||||
</if>
|
||||
<if test="powerEndG!= null">
|
||||
power_end_g= #{powerEndG},
|
||||
</if>
|
||||
|
||||
<if test="powerJ!= null">
|
||||
power_j = #{powerJ},
|
||||
</if>
|
||||
<if test="powerF!= null">
|
||||
power_f= #{powerF},
|
||||
</if>
|
||||
<if test="powerP!= null">
|
||||
power_p= #{powerP},
|
||||
</if>
|
||||
<if test="powerG!= null">
|
||||
power_g= #{powerG},
|
||||
</if>
|
||||
<if test="totalPowerStart != null">
|
||||
total_power_start = #{totalPowerStart},
|
||||
</if>
|
||||
<if test="totalPowerEnd != null">
|
||||
total_power_end = #{totalPowerEnd},
|
||||
</if>
|
||||
<if test="totalAmount != null">
|
||||
total_amount = #{totalAmount}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
|
||||
<delete id="deleteByPrimaryKey">
|
||||
delete
|
||||
from power_detail
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
|
||||
<select id="selectByPid" resultType="com.ho.filecenter.entity.PowerDetail">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from power_detail
|
||||
where pid= #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectDetails" resultType="com.ho.filecenter.entity.PowerDetail">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from power_detail
|
||||
where id= #{id}
|
||||
</select>
|
||||
|
||||
<delete id="deleteBatch">
|
||||
delete
|
||||
from power_detail
|
||||
<where>
|
||||
<if test="ids != null and ids.size !=0">
|
||||
and id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="pids != null and pids.size !=0">
|
||||
and pid in
|
||||
<foreach collection="pids" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
|
||||
</mapper>
|
||||
350
file-center/src/main/resources/mapper/PowerMapper.xml
Normal file
350
file-center/src/main/resources/mapper/PowerMapper.xml
Normal file
@ -0,0 +1,350 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.PowerMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ho.filecenter.entity.Power">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<id property="groupId" column="group_id" jdbcType="INTEGER"/>
|
||||
<result property="projectName" column="project_name" jdbcType="VARCHAR"/>
|
||||
<result property="settleMonth" column="settle_month" jdbcType="VARCHAR"/>
|
||||
<result property="meterMan" column="meter_man" jdbcType="VARCHAR"/>
|
||||
<result property="biCycle" column="bi_cycle" jdbcType="VARCHAR"/>
|
||||
<result property="checker" column="checker" jdbcType="VARCHAR"/>
|
||||
<result property="powerAll" column="power_all" jdbcType="DECIMAL"/>
|
||||
<result property="powerSelf" column="power_self" jdbcType="DECIMAL"/>
|
||||
<result property="powerUp" column="power_up" jdbcType="DECIMAL"/>
|
||||
<result property="consumeRatio" column="consume_ratio" jdbcType="VARCHAR"/>
|
||||
<result property="powerJ" column="power_j" jdbcType="DECIMAL"/>
|
||||
<result property="powerF" column="power_f" jdbcType="DECIMAL"/>
|
||||
<result property="powerP" column="power_p" jdbcType="DECIMAL"/>
|
||||
<result property="powerG" column="power_g" jdbcType="DECIMAL"/>
|
||||
<result property="powerSigle" column="power_sigle" jdbcType="DECIMAL"/>
|
||||
<result property="origPriceJ" column="orig_price_j" jdbcType="DECIMAL"/>
|
||||
<result property="origPriceF" column="orig_price_f" jdbcType="DECIMAL"/>
|
||||
<result property="origPriceP" column="orig_price_p" jdbcType="DECIMAL"/>
|
||||
<result property="origPriceG" column="orig_price_g" jdbcType="DECIMAL"/>
|
||||
<result property="origPriceSigle" column="orig_price_sigle" jdbcType="DECIMAL"/>
|
||||
<result property="discountPriceJ" column="discount_price_j" jdbcType="DECIMAL"/>
|
||||
<result property="discountPriceF" column="discount_price_f" jdbcType="DECIMAL"/>
|
||||
<result property="discountPriceP" column="discount_price_p" jdbcType="DECIMAL"/>
|
||||
<result property="discountPriceG" column="discount_price_g" jdbcType="DECIMAL"/>
|
||||
<result property="discountPriceSigle" column="discount_price_sigle" jdbcType="DECIMAL"/>
|
||||
<result property="feeJ" column="fee_j" jdbcType="DECIMAL"/>
|
||||
<result property="feeF" column="fee_f" jdbcType="DECIMAL"/>
|
||||
<result property="feeP" column="fee_p" jdbcType="DECIMAL"/>
|
||||
<result property="feeG" column="fee_g" jdbcType="DECIMAL"/>
|
||||
<result property="feeSigle" column="fee_sigle" jdbcType="DECIMAL"/>
|
||||
<result property="receivableFee" column="receivable_fee" jdbcType="DECIMAL"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="creator" column="creator" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,group_id
|
||||
,project_name,settle_month,
|
||||
meter_man,bi_cycle,checker,
|
||||
power_all,power_self,power_up,
|
||||
consume_ratio,power_j,power_f,
|
||||
power_p,power_g,power_sigle,
|
||||
orig_price_j,orig_price_f,orig_price_p,
|
||||
orig_price_g,orig_price_sigle,discount_price_j,
|
||||
discount_price_f,discount_price_p,discount_price_g,
|
||||
discount_price_sigle,fee_j,fee_f,
|
||||
fee_p,fee_g,fee_sigle,
|
||||
receivable_fee,create_time,creator
|
||||
</sql>
|
||||
|
||||
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into power
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="groupId != null">group_id,</if>
|
||||
<if test="projectName != null">project_name,</if>
|
||||
<if test="settleMonth != null">settle_month,</if>
|
||||
<if test="meterMan != null">meter_man,</if>
|
||||
<if test="biCycle != null">bi_cycle,</if>
|
||||
<if test="checker != null">checker,</if>
|
||||
<if test="powerAll != null">power_all,</if>
|
||||
<if test="powerSelf != null">power_self,</if>
|
||||
<if test="powerUp != null">power_up,</if>
|
||||
<if test="consumeRatio != null">consume_ratio,</if>
|
||||
<if test="powerJ != null">power_j,</if>
|
||||
<if test="powerF != null">power_f,</if>
|
||||
<if test="powerP != null">power_p,</if>
|
||||
<if test="powerG != null">power_g,</if>
|
||||
<if test="powerSigle != null">power_sigle,</if>
|
||||
<if test="origPriceJ != null">orig_price_j,</if>
|
||||
<if test="origPriceF != null">orig_price_f,</if>
|
||||
<if test="origPriceP != null">orig_price_p,</if>
|
||||
<if test="origPriceG != null">orig_price_g,</if>
|
||||
<if test="origPriceSigle != null">orig_price_sigle,</if>
|
||||
<if test="discountPriceJ != null">discount_price_j,</if>
|
||||
<if test="discountPriceF != null">discount_price_f,</if>
|
||||
<if test="discountPriceP != null">discount_price_p,</if>
|
||||
<if test="discountPriceG != null">discount_price_g,</if>
|
||||
<if test="discountPriceSigle != null">discount_price_sigle,</if>
|
||||
<if test="feeJ != null">fee_j,</if>
|
||||
<if test="feeF != null">fee_f,</if>
|
||||
<if test="feeP != null">fee_p,</if>
|
||||
<if test="feeG != null">fee_g,</if>
|
||||
<if test="feeSigle != null">fee_sigle,</if>
|
||||
<if test="receivableFee != null">receivable_fee,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="creator != null">creator</if>
|
||||
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="groupId != null">#{groupId},</if>
|
||||
<if test="projectName != null">#{projectName},</if>
|
||||
<if test="settleMonth != null">#{settleMonth},</if>
|
||||
<if test="meterMan != null">#{meterMan},</if>
|
||||
<if test="biCycle != null">#{biCycle},</if>
|
||||
<if test="checker != null">#{checker},</if>
|
||||
<if test="powerAll != null">#{powerAll},</if>
|
||||
<if test="powerSelf != null">#{powerSelf},</if>
|
||||
<if test="powerUp != null">#{powerUp},</if>
|
||||
<if test="consumeRatio != null">#{consumeRatio},</if>
|
||||
<if test="powerJ != null">#{powerJ},</if>
|
||||
<if test="powerF != null">#{powerF},</if>
|
||||
<if test="powerP != null">#{powerP},</if>
|
||||
<if test="powerG != null">#{powerG},</if>
|
||||
<if test="powerSigle != null">#{powerSigle},</if>
|
||||
<if test="origPriceJ != null">#{origPriceJ},</if>
|
||||
<if test="origPriceF != null">#{origPriceF},</if>
|
||||
<if test="origPriceP != null">#{origPriceP},</if>
|
||||
<if test="origPriceG != null">#{origPriceG},</if>
|
||||
<if test="origPriceSigle != null">#{origPriceSigle},</if>
|
||||
<if test="discountPriceJ != null">#{discountPriceJ},</if>
|
||||
<if test="discountPriceF != null">#{discountPriceF},</if>
|
||||
<if test="discountPriceP != null">#{discountPriceP},</if>
|
||||
<if test="discountPriceG != null">#{discountPriceG},</if>
|
||||
<if test="discountPriceSigle != null">#{discountPriceSigle},</if>
|
||||
<if test="feeJ != null">#{feeJ},</if>
|
||||
<if test="feeF != null">#{feeF},</if>
|
||||
<if test="feeP != null">#{feeP},</if>
|
||||
<if test="feeG != null">#{feeG},</if>
|
||||
<if test="feeSigle != null">#{feeSigle},</if>
|
||||
<if test="receivableFee != null">#{receivableFee},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="creator != null">#{creator}</if>
|
||||
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateByPrimaryKey">
|
||||
update power
|
||||
set group_id = #{groupId},
|
||||
project_name = #{projectName},
|
||||
settle_month = #{settleMonth},
|
||||
meter_man = #{meterMan},
|
||||
bi_cycle = #{biCycle},
|
||||
checker = #{checker},
|
||||
power_all = #{powerAll},
|
||||
power_self = #{powerSelf},
|
||||
power_up = #{powerUp},
|
||||
consume_ratio = #{consumeRatio},
|
||||
power_j = #{powerJ},
|
||||
power_f = #{powerF},
|
||||
power_p = #{powerP},
|
||||
power_g = #{powerG},
|
||||
power_sigle = #{powerSigle},
|
||||
orig_price_j = #{origPriceJ},
|
||||
orig_price_f = #{origPriceF},
|
||||
orig_price_p = #{origPriceP},
|
||||
orig_price_g = #{origPriceG},
|
||||
orig_price_sigle = #{origPriceSigle},
|
||||
discount_price_j = #{discountPriceJ},
|
||||
discount_price_f = #{discountPriceF},
|
||||
discount_price_p = #{discountPriceP},
|
||||
discount_price_g = #{discountPriceG},
|
||||
discount_price_sigle = #{discountPriceSigle},
|
||||
fee_j = #{feeJ},
|
||||
fee_f = #{feeF},
|
||||
fee_p = #{feeP},
|
||||
fee_g = #{feeG},
|
||||
fee_sigle = #{feeSigle},
|
||||
receivable_fee = #{receivableFee},
|
||||
create_time= #{createTime},
|
||||
creator= #{creator}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update power
|
||||
<set>
|
||||
<if test="groupId != null">
|
||||
group_id = #{groupId},
|
||||
</if>
|
||||
<if test="projectName != null">
|
||||
project_name = #{projectName},
|
||||
</if>
|
||||
<if test="settleMonth != null">
|
||||
settle_month = #{settleMonth},
|
||||
</if>
|
||||
<if test="settleMonth != null">
|
||||
meter_man = #{meterMan},
|
||||
</if>
|
||||
<if test="settleMonth != null">
|
||||
bi_cycle = #{biCycle},
|
||||
</if>
|
||||
<if test="checker != null">
|
||||
checker = #{checker},
|
||||
</if>
|
||||
<if test="powerAll != null">
|
||||
power_all = #{powerAll},
|
||||
</if>
|
||||
<if test="powerSelf != null">
|
||||
power_self = #{powerSelf},
|
||||
</if>
|
||||
<if test="powerUp != null">
|
||||
power_up = #{powerUp},
|
||||
</if>
|
||||
|
||||
<if test="consumeRatio != null">
|
||||
consume_ratio = #{consumeRatio},
|
||||
</if>
|
||||
<if test="powerJ != null">
|
||||
power_j = #{powerJ},
|
||||
</if>
|
||||
<if test="powerF != null">
|
||||
power_f = #{powerF},
|
||||
</if>
|
||||
<if test="powerP != null">
|
||||
power_p = #{powerP},
|
||||
</if>
|
||||
<if test="powerG != null">
|
||||
power_g = #{powerG},
|
||||
</if>
|
||||
<if test="powerSigle != null">
|
||||
power_sigle = #{powerSigle},
|
||||
</if>
|
||||
<if test="consumeRatio != null">
|
||||
orig_price_j = #{origPriceJ},
|
||||
</if>
|
||||
<if test="consumeRatio != null">
|
||||
orig_price_f = #{origPriceF},
|
||||
</if>
|
||||
<if test="consumeRatio != null">
|
||||
orig_price_p = #{origPriceP},
|
||||
</if>
|
||||
<if test="consumeRatio != null">
|
||||
orig_price_g = #{origPriceG},
|
||||
</if>
|
||||
|
||||
<if test="origPriceSigle != null">
|
||||
orig_price_sigle = #{origPriceSigle},
|
||||
</if>
|
||||
<if test="discountPriceJ != null">
|
||||
discount_price_j = #{discountPriceJ},
|
||||
</if>
|
||||
<if test="discountPriceF != null">
|
||||
discount_price_f = #{discountPriceF},
|
||||
</if>
|
||||
<if test="discountPriceP != null">
|
||||
discount_price_p = #{discountPriceP},
|
||||
</if>
|
||||
<if test="discountPriceG != null">
|
||||
discount_price_g = #{discountPriceG},
|
||||
</if>
|
||||
<if test="discountPriceSigle != null">
|
||||
discount_price_sigle = #{discountPriceSigle},
|
||||
</if>
|
||||
<if test="feeJ != null">
|
||||
fee_j = #{feeJ},
|
||||
</if>
|
||||
<if test="feeF != null">
|
||||
fee_f = #{feeF},
|
||||
</if>
|
||||
<if test="feeP != null">
|
||||
fee_p = #{feeP},
|
||||
</if>
|
||||
<if test="feeG != null">
|
||||
fee_g = #{feeG},
|
||||
</if>
|
||||
<if test="feeSigle != null">
|
||||
fee_sigle = #{feeSigle},
|
||||
</if>
|
||||
<if test="receivableFee != null">
|
||||
receivable_fee = #{receivableFee},
|
||||
</if>
|
||||
<if test="createTime!= null">
|
||||
create_time= #{createTime},
|
||||
</if>
|
||||
<if test="creator!= null">
|
||||
creator= #{creator}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<delete id="batchDeletes">
|
||||
<!--循环删除 -->
|
||||
delete
|
||||
from power
|
||||
<where>
|
||||
<if test="list != null and list.size !=0">
|
||||
and id in
|
||||
<foreach collection="list" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByPrimaryKey">
|
||||
delete
|
||||
from power
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
|
||||
<select id="selectAll" resultType="com.ho.filecenter.entity.Power">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from power
|
||||
<where>
|
||||
<if test="groupId != null">
|
||||
and group_id = #{groupId}
|
||||
</if>
|
||||
<if test="settleMonth != null">
|
||||
and settle_month = #{settleMonth}
|
||||
</if>
|
||||
<if test="projectName != null">
|
||||
and project_name = #{projectName}
|
||||
</if>
|
||||
order by create_time desc
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="com.ho.filecenter.entity.Power">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from power
|
||||
<where>
|
||||
<if test="id != null">
|
||||
and id= #{id}
|
||||
</if>
|
||||
<if test="settleMonth != null">
|
||||
and settle_month = #{settleMonth}
|
||||
</if>
|
||||
<if test="projectName != null">
|
||||
and project_name = #{projectName}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectByMonthAndName" resultType="com.ho.filecenter.entity.Power">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from power
|
||||
where
|
||||
settle_month = #{settleMonth}
|
||||
and project_name = #{projectName}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.PvEleAnalysisMapper">
|
||||
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,group_id,`year`,
|
||||
`month`,theory_power,plan_power,
|
||||
real_power,create_time,creator
|
||||
</sql>
|
||||
|
||||
<select id="selectByParam" resultType="com.ho.filecenter.entity.PvEleAnalysis">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from pv_ele_analysis
|
||||
<where>
|
||||
<if test="pvEleAnalysis.id != null">
|
||||
and id = #{pvEleAnalysis.id}
|
||||
</if>
|
||||
<if test="pvEleAnalysis.groupId != null">
|
||||
and group_id = #{pvEleAnalysis.groupId}
|
||||
</if>
|
||||
<if test="pvEleAnalysis.year != null">
|
||||
and `year` = #{pvEleAnalysis.year}
|
||||
</if>
|
||||
<if test="pvEleAnalysis.month != null">
|
||||
and `month` = #{pvEleAnalysis.month}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertList" keyColumn="id" keyProperty="id" parameterType="java.util.List" useGeneratedKeys="true">
|
||||
insert into pv_ele_analysis (group_id,year,month,theory_power,plan_power,real_power,create_time,creator) values
|
||||
<foreach collection="pvEleAnalysisList" item="item" index="index" separator=",">
|
||||
(#{item.groupId},#{item.year},#{item.month},#{item.theoryPower},#{item.planPower},#{item.realPower},#{item.createTime},#{item.creator})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateList" keyColumn="id" keyProperty="id" parameterType="java.util.List" useGeneratedKeys="true">
|
||||
<foreach collection="pvEleAnalysisList" item="item" index="index" separator=";">
|
||||
update pv_ele_analysis set theory_power = #{item.theoryPower},plan_power = #{item.planPower}, real_power = #{item.realPower}
|
||||
where id = #{item.id}
|
||||
</foreach>
|
||||
</update>
|
||||
</mapper>
|
||||
103
file-center/src/main/resources/mapper/StandingBookMapper.xml
Normal file
103
file-center/src/main/resources/mapper/StandingBookMapper.xml
Normal file
@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ho.filecenter.mapper.StandingBookMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ho.filecenter.entity.StandingBook">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="stationId" column="station_id" jdbcType="INTEGER"/>
|
||||
<result property="deviceType" column="device_type" jdbcType="VARCHAR"/>
|
||||
<result property="deviceModel" column="device_model" jdbcType="VARCHAR"/>
|
||||
<result property="modelCode" column="model_code" jdbcType="VARCHAR"/>
|
||||
<result property="deviceNum" column="device_num" jdbcType="VARCHAR"/>
|
||||
<result property="factory" column="factory" jdbcType="VARCHAR"/>
|
||||
<result property="manufacturer" column="manufacturer" jdbcType="VARCHAR"/>
|
||||
<result property="warrantyPeriod" column="warranty_period" jdbcType="VARCHAR"/>
|
||||
<result property="notes" column="notes" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id
|
||||
,station_id,device_type,device_model,
|
||||
model_code,device_num,factory,
|
||||
manufacturer,warranty_period,notes,
|
||||
create_time,update_time
|
||||
</sql>
|
||||
|
||||
|
||||
<insert id="addBatch" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into standing_book (<include refid="Base_Column_List"/>)
|
||||
values
|
||||
<foreach item="item" collection="list" index="index" separator=",">
|
||||
(
|
||||
#{item.id}
|
||||
,#{item.stationId},#{item.deviceType},#{item.deviceModel},
|
||||
#{item.modelCode},#{item.deviceNum},#{item.factory},
|
||||
#{item.manufacturer},#{item.warrantyPeriod},#{item.notes},
|
||||
#{item.createTime},#{item.updateTime}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
from standing_book
|
||||
where id = #{id}
|
||||
</delete>
|
||||
<delete id="deleteByStationId">
|
||||
delete
|
||||
from standing_book
|
||||
where station_id = #{stationId}
|
||||
</delete>
|
||||
|
||||
<select id="selectAll" resultType="com.ho.filecenter.entity.StandingBook">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from standing_book
|
||||
where station_id = #{id}
|
||||
</select>
|
||||
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update standing_book
|
||||
<set>
|
||||
<if test="stationId != null">
|
||||
station_id = #{stationId},
|
||||
</if>
|
||||
<if test="deviceType != null">
|
||||
device_type = #{deviceType},
|
||||
</if>
|
||||
<if test="deviceModel != null">
|
||||
device_model = #{deviceModel},
|
||||
</if>
|
||||
<if test="modelCode != null">
|
||||
model_code = #{modelCode},
|
||||
</if>
|
||||
<if test="deviceNum != null">
|
||||
device_num = #{deviceNum},
|
||||
</if>
|
||||
<if test="factory != null">
|
||||
factory = #{factory},
|
||||
</if>
|
||||
<if test="manufacturer != null">
|
||||
manufacturer = #{manufacturer},
|
||||
</if>
|
||||
<if test="warrantyPeriod != null">
|
||||
warranty_period = #{warrantyPeriod},
|
||||
</if>
|
||||
<if test="notes != null">
|
||||
notes = #{notes},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
BIN
file-center/src/main/resources/template/template.xls
Normal file
BIN
file-center/src/main/resources/template/template.xls
Normal file
Binary file not shown.
19
file-center/src/test/java/ParseTest.java
Normal file
19
file-center/src/test/java/ParseTest.java
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/12/15
|
||||
*/
|
||||
public class ParseTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int onLine = 5;
|
||||
int inverterCount = 3;
|
||||
double rate = Math.ceil((double)onLine/ inverterCount);
|
||||
System.out.println(rate);
|
||||
|
||||
int i = 1;
|
||||
int j=3;
|
||||
double d = (double) i/ j;
|
||||
System.out.println("d:"+d);
|
||||
}
|
||||
}
|
||||
65
file-center/src/test/java/com/ho/filecenter/FileRead.java
Normal file
65
file-center/src/test/java/com/ho/filecenter/FileRead.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.ho.filecenter;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import com.ho.common.tools.exception.BaseResponseCode;
|
||||
import com.ho.common.tools.exception.BusinessException;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2023/1/5
|
||||
*/
|
||||
public class FileRead {
|
||||
public static void main(String[] args) {
|
||||
String path = "d:/2.png";
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
try {
|
||||
byte[] bytes = readBlock(path, 0);
|
||||
|
||||
BufferedImage bufferedImage = ImageIO.read(new File(path));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(bufferedImage, "png", baos);
|
||||
byte[] bytes2 = baos.toByteArray();
|
||||
String encode = Base64.encode(bytes);
|
||||
String trim2 = encoder.encodeBuffer(bytes).trim();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//按位置分块读取文件内容
|
||||
public static byte[] readBlock(String path, int pointer) throws Exception {
|
||||
if (!new File(path).exists()){
|
||||
throw new BusinessException(BaseResponseCode.FILE_NOT_EXISTS) ;
|
||||
}
|
||||
RandomAccessFile raf = new RandomAccessFile(path, "r");
|
||||
long length = raf.length();
|
||||
System.out.println("文件大小:" + length);
|
||||
//设置指针的位置,每次有偏移
|
||||
raf.seek(pointer * 102400);
|
||||
//每次读取102400字节,这个应该改为参数配置
|
||||
byte[] bytes = new byte[102400];
|
||||
int readSize = raf.read(bytes);
|
||||
//如果没有读到102400个字节,需要做数组拷贝
|
||||
//读取时判断是否还有剩余字节
|
||||
if (readSize < 102400) {
|
||||
byte[] copy = new byte[readSize];
|
||||
System.arraycopy(bytes, 0, copy, 0, readSize);
|
||||
raf.close();
|
||||
return copy;
|
||||
}
|
||||
raf.close();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
31
file-center/src/test/java/com/ho/filecenter/Test2.java
Normal file
31
file-center/src/test/java/com/ho/filecenter/Test2.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.ho.filecenter;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ho.common.tools.constant.CommonConstant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fancl
|
||||
* @desc:
|
||||
* @date 2022/12/26
|
||||
*/
|
||||
public class Test2 {
|
||||
public static void main(String[] args) {
|
||||
Date now = new Date();
|
||||
//开始时间,currentMaxDay之前的那天
|
||||
String beginTime = DateUtil.format(DateUtil.offsetDay(now, -30), CommonConstant.DATE_YMD)
|
||||
+ CommonConstant.START_SUFFIX_TIMESTAMP;
|
||||
//今天的23:59:59
|
||||
String endTime = DateUtil.format(DateUtil.endOfDay(now), CommonConstant.DATE);
|
||||
System.out.println();
|
||||
|
||||
List<Integer> list =new ArrayList();
|
||||
list.add(1);
|
||||
System.out.println( list.size());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user