Commit 213c1e71 authored by 王蔡翾's avatar 王蔡翾
Browse files

优化

parent e9db104a
......@@ -135,6 +135,23 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- 阿里短信 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.1.0</version>
</dependency>
<!-- Alibaba FastJSON 依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version> <!-- 请检查最新版本 -->
</dependency>
<dependency>
<groupId>com.ruzhoukj</groupId>
......
......@@ -62,13 +62,17 @@ public class BsWorkController extends BaseController {
@ApiOperation("关闭")
@PostMapping("/close")
public Result<Boolean> close(@RequestBody BsWorkDTO bsWorkDTO) {
public Result<Boolean> close(@RequestBody BsWorkDTO bsWorkDTO,@RequestHeader("Authorization") String token) {
String name = jwtUtil.getUserNameFromToken(token);
bsWorkDTO.setLoginName(name);
return Result.data(bsWorkService.closeWork(bsWorkDTO));
}
@ApiOperation("转单")
@PostMapping("/transfer")
public Result<Boolean> transfer(@RequestBody BsWorkDTO bsWorkDTO) {
public Result<Boolean> transfer(@RequestBody BsWorkDTO bsWorkDTO,@RequestHeader("Authorization") String token) {
String name = jwtUtil.getUserNameFromToken(token);
bsWorkDTO.setLoginName(name);
return Result.data(bsWorkService.transferWork(bsWorkDTO));
}
......
......@@ -17,4 +17,7 @@ public class BsWorkDTO extends BsWorkEntity {
@ApiModelProperty("工单处理流程描述")
private String remark;
@ApiModelProperty("项目名称")
private String projectName;
}
package com.example.operation_platform.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* @author wujipeng
* @version 1.0
* @create 2024-10-29 9:53
*/
@Data
@TableName("bs_file_upload")
public class BsFileUploadEntity {
@TableId(type = IdType.ASSIGN_ID)
private String id;
@TableField("file_name")
private String fileName;
private String path;
@TableField("upload_by")
private String uploadBy;
@TableField("create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@TableField("report_flag")//0:其他 1:生产汇总word
private String reportFlag;
}
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -35,12 +36,15 @@ public class BsWorkEntity {
@ApiModelProperty ("任务状态")
private String status;
@TableField("create_time")
@JsonFormat (pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty ("创建时间")
private Date createTime;
@TableField("end_time")
@JsonFormat (pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("截止时间")
private Date endTime;
@TableField("handle_time")
@JsonFormat (pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("处理时间")
private Date handleTime;
@TableField("create_by")
......
package com.example.operation_platform.model.vo;
import com.example.operation_platform.model.entity.BsFileUploadEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author : wujipeng
* @date : 2025/4/8 16:27
* @Version: 1.0
* @Desc : 描述信息
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class BsFileUploadVO extends BsFileUploadEntity {
}
package com.example.operation_platform.service;
import com.example.operation_platform.model.vo.BsFileUploadVO;
import org.springframework.web.multipart.MultipartFile;
public interface FileService {
/**
* 本地文件上传
*
* @param file 文件
* @return BsFileUploadVO
*/
BsFileUploadVO uploadFile(MultipartFile file);
}
......@@ -16,8 +16,11 @@ import com.platform.utils.DozerUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity> implements BsWorkService {
......@@ -41,11 +44,11 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
@Override
public List<BsWorkVO> queryWorkList(BsWorkDTO bsWorkDTO){
UserEntity userEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("name", bsWorkDTO.getLoginName()));
// 判断是否是部门领导
if (!DEPT_LEADER.equals(bsWorkDTO.getLoginName())) {
bsWorkDTO.setHandleBy(userEntity.getId());
}
// UserEntity userEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("name", bsWorkDTO.getLoginName()));
// // 判断是否是部门领导
// if (!DEPT_LEADER.equals(bsWorkDTO.getLoginName())) {
// bsWorkDTO.setHandleBy(userEntity.getId());
// }
// 查询工单列表
List<BsWorkVO> workVOS = baseMapper.queryWorkList(bsWorkDTO);
//根据当前登录人进行按钮标记赋值
......@@ -88,25 +91,39 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
bsWorkDTO.setCreateBy(userEntity.getId());
bsWorkDTO.setCreateTime( new Date());
bsWorkDTO.setStatus("待处理");
//查找处理人电话
UserEntity handleUserEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("id", bsWorkDTO.getHandleBy()));
//获取处理时长
Integer handleTime = bsWorkLevelVO.getHandleTime();
//设置工单结束时间
if (handleTime == null){
handleTime =0;
}
long endTimeMillis = bsWorkDTO.getCreateTime().getTime() + handleTime * 60 * 1000L;
long endTimeMillis = bsWorkDTO.getCreateTime().getTime() + handleTime * 60 * 60 * 1000L;
bsWorkDTO.setEndTime(new java.util.Date(endTimeMillis));
String code = "T" + System.currentTimeMillis() % 10000000000L;
bsWorkDTO.setCode(code);
save(bsWorkDTO);
//查询新增工单id
BsWorkEntity bsWorkEntity = getOne(new QueryWrapper<BsWorkEntity>().eq("code", bsWorkDTO.getCode()));
//创建操作记录数据
BsWorkOperationEntity bsWorkOperationEntity =new BsWorkOperationEntity();
bsWorkOperationEntity.setWorkId(bsWorkEntity.getId());
bsWorkOperationEntity.setHandleTime( new Date());
bsWorkOperationEntity.setHandler(bsWorkDTO.getLoginName());
bsWorkOperationEntity.setRemark("新增工单");
bsWorkOperationEntity.setWorkId(bsWorkDTO.getId());
// 构造短信参数
// 格式化 endTime
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String endTimeStr = sdf.format(bsWorkDTO.getEndTime());
Map<String, String> map = new HashMap<>();
map.put("code",bsWorkDTO.getCode());
map.put("endTime", endTimeStr);
//发送工单处理提醒
// smsSendUtils.sendSms(userEntity.getPhone(),bsWorkDTO);
return save(bsWorkDTO)&&bsWorkOperationService .save(bsWorkOperationEntity);
smsSendUtils.sendMsg(handleUserEntity.getPhone(),"SMS_500840272",map);
return bsWorkOperationService .save(bsWorkOperationEntity);
}
/*
......@@ -115,9 +132,9 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
@Override
public Boolean handleWork(BsWorkDTO bsWorkDTO){
bsWorkDTO.setStatus("待确认");
//查找部门领导用户id
UserEntity userEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("name", DEPT_LEADER));
bsWorkDTO.setHandleBy(userEntity.getId());
// //查找部门领导用户id
// UserEntity userEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("name", DEPT_LEADER));
// bsWorkDTO.setHandleBy(userEntity.getId());
Date now = new Date();
//设置 工单处理时间
bsWorkDTO.setHandleTime(now);
......@@ -127,7 +144,8 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
bsWorkOperationEntity.setHandler(bsWorkDTO.getLoginName());
bsWorkOperationEntity.setRemark("处理工单:"+ bsWorkDTO.getRemark());
bsWorkOperationEntity.setWorkId(bsWorkDTO.getId());
bsWorkOperationEntity .setFilePath(bsWorkDTO.getFilePath());
bsWorkOperationEntity.setFilePath(bsWorkDTO.getFilePath());
bsWorkDTO.setFilePath(null);
//更新工单状态,并 保存操作记录
return updateById(bsWorkDTO) && bsWorkOperationService.save(bsWorkOperationEntity);
}
......@@ -147,7 +165,7 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
//创建操作记录数据
BsWorkOperationEntity bsWorkOperationEntity = new BsWorkOperationEntity();
bsWorkOperationEntity.setHandleTime(new Date());
bsWorkOperationEntity.setHandler(bsWorkDTO.getLoginName());
bsWorkOperationEntity.setHandler(DEPT_LEADER);
bsWorkOperationEntity.setRemark("完结确认");
bsWorkOperationEntity.setWorkId(bsWorkDTO.getId());
bsWorkOperationEntity .setFilePath(bsWorkDTO.getFilePath());
......@@ -169,6 +187,7 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
bsWorkOperationEntity.setRemark("关闭工单");
bsWorkOperationEntity.setWorkId(bsWorkDTO.getId());
bsWorkOperationEntity .setFilePath(bsWorkDTO.getFilePath());
bsWorkDTO.setFilePath(null);
//更新工单状态,并 保存操作记录
return updateById(bsWorkDTO) && bsWorkOperationService.save(bsWorkOperationEntity);
}
......@@ -178,14 +197,26 @@ public class BsWorkServiceImpl extends ServiceImpl <BsWorkMapper, BsWorkEntity>
*/
@Override
public Boolean transferWork(BsWorkDTO bsWorkDTO){
UserEntity handleUserEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("id", bsWorkDTO.getHandleBy()));
BsWorkEntity bsWorkEntity = getById(bsWorkDTO.getId());
//创建操作记录数据
BsWorkOperationEntity bsWorkOperationEntity = new BsWorkOperationEntity();
bsWorkOperationEntity.setHandleTime(new Date());
bsWorkOperationEntity.setHandler(bsWorkDTO.getLoginName());
bsWorkOperationEntity.setRemark("转派工单:"+bsWorkDTO.getRemark());
bsWorkOperationEntity.setWorkId(bsWorkDTO.getId());
bsWorkOperationEntity .setFilePath(bsWorkDTO.getFilePath());
bsWorkOperationEntity.setFilePath(bsWorkDTO.getFilePath());
bsWorkDTO.setFilePath(null);
// 构造短信参数
// 格式化 endTime
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String endTimeStr = sdf.format(bsWorkEntity.getEndTime());
Map<String, String> map = new HashMap<>();
map.put("code",bsWorkEntity.getCode());
map.put("endTime", endTimeStr);
//发送工单处理提醒
smsSendUtils.sendMsg(handleUserEntity.getPhone(),"SMS_500840272",map);
//更新工单,并 保存操作记录
return updateById(bsWorkDTO) && bsWorkOperationService.save(bsWorkOperationEntity);
}
......
package com.example.operation_platform.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.operation_platform.model.entity.BsFileUploadEntity;
import com.example.operation_platform.model.vo.BsFileUploadVO;
import com.example.operation_platform.service.FileService;
import com.platform.exception.BusinessException;
import com.platform.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@Slf4j
@Service
public class FileServiceImpl implements FileService {
private static final String UPLOAD_DIR = "/home/back/operation/file/";
public static String getFileExtension(String fileName) {
if (fileName == null) {
return null;
}
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex == -1 || lastDotIndex == fileName.length() - 1) {
return ""; // 没有后缀名或点号在最后
}
return fileName.substring(lastDotIndex + 1).toLowerCase();
}
@Override
public BsFileUploadVO uploadFile(MultipartFile file) {
if (file.isEmpty()) {
throw new BusinessException("文件为空");
}
// 定义允许的传统文件类型白名单
Set<String> ALLOWED_EXTENSIONS = new HashSet<>(Arrays.asList(
"jpg", "jpeg", "png", "gif", "bmp", // 图片
"pdf", // PDF文档
"doc", "docx", // Word文档
"xls", "xlsx" // Excel表格
));
try {
String originalFilename = file.getOriginalFilename();
if (originalFilename == null || !originalFilename.contains(".")) {
throw new BusinessException("文件名格式不正确,必须包含扩展名");
}
// 获取文件扩展名并转为小写
String fileExtension = getFileExtension(originalFilename).toLowerCase();
// 验证文件扩展名是否在白名单中
if (!ALLOWED_EXTENSIONS.contains(fileExtension)) {
throw new BusinessException("不支持的文件类型,仅支持: jpg, jpeg, png, gif, bmp, pdf, doc, docx, xls, xlsx");
}
// 确保上传目录存在
File uploadDir = new File(UPLOAD_DIR);
if (!uploadDir.exists()) {
boolean mkdirs = uploadDir.mkdirs();
log.info("创建文件夹" + mkdirs);
}
// 保存文件到本地
Path path = Paths.get(UPLOAD_DIR + file.getOriginalFilename());
Files.write(path, file.getBytes());
//获取文件名
String fileName = file.getOriginalFilename();
//获取文件绝对路径
String fileUrl = path.toAbsolutePath().toString();
//获取当前登陆人信息
String loginUserId = SecurityUtils.getLoginUserId();
BsFileUploadVO bsFileUploadVO = new BsFileUploadVO();
bsFileUploadVO.setFileName(fileName);
bsFileUploadVO.setPath(fileUrl);
bsFileUploadVO.setUploadBy(loginUserId);
bsFileUploadVO.setCreateTime(new Date());
return bsFileUploadVO;
} catch (IOException e) {
throw new BusinessException("文件上传失败");
}
}
}
package com.example.operation_platform.util;
import com.example.operation_platform.model.dto.BsWorkDTO;
import com.example.operation_platform.model.vo.BsWorkVO;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.platform.utils.AliSmsUtil;
import org.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
@Component
@Slf4j
public class SmsSendUtils {
@Resource
private AliSmsUtil aliSmsUtil;
/**
* 发送工单处理提醒
* @param phone
* @param bsWorkDTO
*/
public void sendSms(String phone, BsWorkDTO bsWorkDTO){
// 构建短信模板参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", bsWorkDTO.getCode());
jsonObject.put("endTime", bsWorkDTO.getEndTime());
aliSmsUtil.sendSms(phone, jsonObject, "SMS_500580249");
// /**
// * 发送工单处理提醒
// * @param phone
// * @param bsWorkDTO
// */
// public void sendSms(String phone, BsWorkDTO bsWorkDTO){
// // 构建短信模板参数
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("code", bsWorkDTO.getCode());
// jsonObject.put("endTime", bsWorkDTO.getEndTime().toString());
// aliSmsUtil.sendSms(phone, jsonObject, "SMS_500580249");
// }
public boolean sendMsg(String phoneNum, String template, Map<String, String> param) {
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
//accessKeyId
"LTAI5tCAKQWmKVuJZeHCt8gA",
//accessSecret
"c3fbBO2cXozBtENz9hjFThdvLamfq9");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("RegionId", "cn-hangzhou");
//接收号码
request.putQueryParameter("PhoneNumbers", phoneNum);
//短信签名(如某某科技有限公司)
request.putQueryParameter("SignName", "南京如昼信息科技");
//短信模板
request.putQueryParameter("TemplateCode", template);
//验证码
request.putQueryParameter("TemplateParam", JSON.toJSONString(param));
CommonResponse response;
try {
response = client.getCommonResponse(request);
} catch (com.aliyuncs.exceptions.ClientException e) {
throw new RuntimeException(e);
}
log.info(response.getData());
return true;
}
}
......@@ -10,6 +10,9 @@ spring:
username: root
password: ruzhoukj@2022
url: jdbc:mysql://192.168.10.3:3307/pump_station_robot_business?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true
# url: jdbc:mysql://p1.ruzhoukj.com:3306/operation_platform?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
# username: root
# password: Rzkj<2022>_0418
data:
mongodb:
database: pump_station_robot
......
......@@ -17,6 +17,7 @@
bwl.id id,
bwl.level level,
bwl.color color,
bwl.handle_time handleTime,
bwl.description description
from
bs_work_level bwl
......
......@@ -11,6 +11,7 @@
bw.detail detail,
bw.status status,
bw.create_time createTime,
bw.end_time endTime,
u.name createByName,
ur.name handleByName,
bwl.color color,
......@@ -39,10 +40,16 @@
bw.handle_by = #{handleBy}
</if>
<if test="level != null and level != ''">
bw.level = #{level}
and bw.level = #{level}
</if>
<if test="type != null and type != ''">
bw.type = #{type}
and bw.type = #{type}
</if>
<if test="projectName != null and projectName != ''">
and bp.project_name like concat('%',#{projectName},'%')
</if>
<if test="status != null and status != ''">
and bw.status = #{status}
</if>
</where>
order by
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment