|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.constant.Constant;
|
|
@@ -14,6 +15,7 @@ import com.management.platform.entity.vo.SysRichFunction;
|
|
|
import com.management.platform.entity.vo.UserVO;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.*;
|
|
|
+import com.management.platform.task.SFTPAsyncUploader;
|
|
|
import com.management.platform.util.*;
|
|
|
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
@@ -22,6 +24,8 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
|
import org.apache.commons.collections4.Put;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.log4j.LogManager;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
@@ -101,6 +105,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
@Value("${configEnv.isPrivateDeploy}")
|
|
|
private boolean isPrivateDeploy;
|
|
|
|
|
|
+ Logger logger = LogManager.getLogger(org.apache.logging.log4j.LogManager.ROOT_LOGGER_NAME);
|
|
|
+ @Autowired
|
|
|
+ public SFTPAsyncUploader sftpAsyncUploader;
|
|
|
+
|
|
|
public static final String GET_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
|
|
|
public static final String GET_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=accessToken&openid=openId&lang=zh_CN";
|
|
|
public static final String[] MATCHING_FILED = {"corpwx_userid","phone","job_number"};
|
|
@@ -1967,6 +1975,64 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg uploadImage(MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ // 处理文件
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ String[] split = fileName.split("\\.");
|
|
|
+ String fileExtension = split.length > 1 ? split[split.length - 1].toLowerCase() : ""; // 获取文件扩展名
|
|
|
+ String[] allowedExtensions = {"jpg", "jpeg", "png", "gif"}; // 允许的图片扩展名
|
|
|
+
|
|
|
+ // 检查扩展名是否有效
|
|
|
+ boolean isValidImage = Arrays.stream(allowedExtensions).anyMatch(fileExtension::equals);
|
|
|
+ if (!isValidImage) {
|
|
|
+ msg.setError("只允许上传图片格式的文件!");
|
|
|
+ return msg; // 返回错误信息
|
|
|
+ }
|
|
|
+
|
|
|
+ String serverName = UUID.randomUUID().toString().replaceAll("-", "") + "." + fileExtension;
|
|
|
+
|
|
|
+ // 检查目录
|
|
|
+ File dir = new File(path);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+ File file = new File(dir, serverName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp;
|
|
|
+ while ((temp = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭流
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+
|
|
|
+ msg.data = serverName;
|
|
|
+
|
|
|
+ // 更新用户头像 URL
|
|
|
+ userMapper.update(null, new UpdateWrapper<User>()
|
|
|
+ .eq("id", request.getHeader("token"))
|
|
|
+ .set("portrait_url", serverName));
|
|
|
+
|
|
|
+ // 上传到 SFTP 服务器
|
|
|
+ sftpAsyncUploader.uploadFileAsync(file);
|
|
|
+
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ logger.error(exception.getMessage());
|
|
|
+ msg.data = "文件上传失败!";
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
//
|
|
|
// private String getAccessToken(String code) {
|
|
|
// String accessToken = "";
|