Commit 31158925 authored by 周健威's avatar 周健威

修改代码

parent 8debb8a6
......@@ -12,6 +12,15 @@ public class MD5 {
return MD5Util.MD5Encode(data, "utf-8").toUpperCase();
}
/**
* MD5加密
* @param data
* @return
*/
public static String GetMD5StringLower(String data) {
return MD5Util.MD5Encode(data, "utf-8").toLowerCase();
}
/**
* MD5加密
* @param data
......@@ -372,4 +381,8 @@ public class MD5 {
return s;
}
public static void main(String[] args) {
System.out.println(MD5.GetMD5StringLower(123456+""));;
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@
*/
package com.upyuns.platform.rs.gtdata;
import cn.hutool.core.collection.CollUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
......@@ -20,15 +22,14 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.nio.file.FileSystem;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -860,14 +861,13 @@ public class GtDataRestClient {
*
* Description:单独上传文件的MD5值
*
* @param filePath
* @param path
* @param sign
* @param time
* @return
*
*/
public Map<String, Object> md5(String filePath, String path, String sign,
public Map<String, Object> md5(String path, String sign,
String time, String md5) {// xsx modified
String resourceUrlMd5 = MessageFormat.format(
......@@ -931,7 +931,7 @@ public class GtDataRestClient {
return error;
}
Map<String, Object> responseMap = md5(filePath, path, sign, time, md5);
Map<String, Object> responseMap = md5(path, sign, time, md5);
if (responseMap != null
&& (200 == (Integer) responseMap.get("HttpStatusCode") || 404 != (Integer) responseMap
.get("HttpStatusCode"))) {
......@@ -1028,7 +1028,7 @@ public class GtDataRestClient {
return error;
}
Map<String, Object> responseMap = md5(filePath, path, sign, time, md5);
Map<String, Object> responseMap = md5(path, sign, time, md5);
if (responseMap != null
&& (200 == (Integer) responseMap.get("HttpStatusCode") || 404 != (Integer) responseMap
.get("HttpStatusCode"))) {
......@@ -1060,6 +1060,121 @@ public class GtDataRestClient {
}
/**
*
* Description:(小文件,1G以内的)根据路径创建并写入文件(包含上传文件的MD5)
* 如果出现内存溢出,请使用createLarge(只能在Linux环境使用)
*
* @see #createLarge(String, String, String, String, boolean)
*
* @param file
* @param path
* @return
*
*/
public Map<String, Object> createMultipartFile(MultipartFile file, String path) {
return createMultipartFile(file, path, defaultSign, defaultTime, Boolean.TRUE);
}
/**
*
* Description:(小文件,1G以内的)根据路径创建并写入文件(包含上传文件的MD5)
* 如果出现内存溢出,请使用createLarge(只能在Linux环境使用)
*
* @see #createLarge(String, String, String, String, boolean)
*
* @param file
* @param path
* @param sign
* @param time
* @param overwrite
* @return
*
*/
public Map<String, Object> createMultipartFile(MultipartFile file, String path,
String sign, String time, boolean overwrite) {
InputStream inputStream = null;
try {
byte [] byteArr=file.getBytes();
inputStream = new ByteArrayInputStream(byteArr);
return createInputStream(inputStream, path, sign, time, overwrite);
}catch (Exception e){
logger.error(e.getMessage(), e);
}finally {
if (inputStream != null) {
try {
inputStream.close();
}catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
}
Map<String, Object> error = CollUtil.newHashMap();
error.put("HttpStatusCode", 500);// 调用失败
return error;
}
/**
*
* Description:(小文件,1G以内的)根据路径创建并写入文件(包含上传文件的MD5)
* 如果出现内存溢出,请使用createLarge(只能在Linux环境使用)
*
* @see #createLarge(String, String, String, String, boolean)
*
* @param file
* @param path
* @param sign
* @param time
* @param overwrite
* @return
*
*/
public Map<String, Object> createInputStream(InputStream file, String path,
String sign, String time, boolean overwrite) {
String md5 = "";
try {
md5 = fileToMd5(file);
} catch (Exception e) {
Map<String, Object> error = new HashMap<String, Object>();
error.put("HttpStatusCode", 0);// 上传文件不存在
return error;
}
Map<String, Object> responseMap = md5(path, sign, time, md5);
if (responseMap != null
&& (200 == (Integer) responseMap.get("HttpStatusCode") || 404 != (Integer) responseMap
.get("HttpStatusCode"))) {
return responseMap;// 已存在该文件,无需上传(秒传) 或 异常
}
String resourceUrl = MessageFormat.format(
"{0}{1}?op=CREATE&md5={2}&sign={3}&time={4}&overwrite={5}",
gtDataUrl, path, md5, sign, time, overwrite);
try {
HttpEntity<byte[]> httpEntity = new HttpEntity(
IOUtils.toByteArray(file));
Map<String, Object> responseMap2 = rest(resourceUrl,
HttpMethod.PUT, httpEntity);
return responseMap2;
} catch (Exception e) {
String message = MessageFormat.format(
"call gtdata rest api [{0}] by linux curl throw exception",
resourceUrl);
logger.error(message, e);
Map<String, Object> error = new HashMap<String, Object>();
error.put("HttpStatusCode", 500);// 调用失败
return error;
}
}
public Map<String, Object> createByHttpCilent(String filePath, String path) {
return createByHttpCilent(filePath, path, defaultSign, defaultTime,
true);
......@@ -1078,7 +1193,7 @@ public class GtDataRestClient {
return error;
}
Map<String, Object> responseMap = md5(filePath, path, sign, time, md5);
Map<String, Object> responseMap = md5(path, sign, time, md5);
if (responseMap != null
&& (200 == (Integer) responseMap.get("HttpStatusCode") || 404 != (Integer) responseMap
.get("HttpStatusCode"))) {
......@@ -1324,6 +1439,19 @@ public class GtDataRestClient {
return Encodes.encodeHex(Digests.md5(new FileInputStream(file)));
}
/**
*
* Description:计算文件的md5值
*
* @param file
* @return
* @throws IOException
*
*/
protected String fileToMd5(InputStream file) throws IOException {
return Encodes.encodeHex(Digests.md5(file));
}
/**
* Description:Map转ShareFile
*
......
......@@ -46,4 +46,9 @@ public class AppUserLogin {
@Column(name = "last_time")
private Long lastTime;
/**
* 最后登录时间
*/
@Column(name = "gtdata_pass")
private String gtdataPass;
}
package com.github.wxiaoqi.security.admin.rpc.service;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.biz.*;
......@@ -16,13 +17,11 @@ import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo;
import com.github.wxiaoqi.security.api.vo.user.AppUserInfo;
import com.github.wxiaoqi.security.common.config.rabbit.RabbitConstant;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.EmojiFilter;
import com.github.wxiaoqi.security.common.util.ReferralCodeUtil;
import com.github.wxiaoqi.security.common.util.UUIDUtils;
import com.github.wxiaoqi.security.common.util.VerificationUtils;
import com.github.wxiaoqi.security.common.util.*;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.upyuns.platform.rs.gtdata.GtDataRestClient;
import com.upyuns.platform.rs.universal.dto.SmsTemplateDTO;
import com.upyuns.platform.rs.universal.feign.MQSenderFeign;
import com.upyuns.platform.rs.universal.feign.RegionFeign;
......@@ -104,6 +103,9 @@ public class AppPermissionService {
@Autowired
private AppUserAlipayBiz alipayBiz;
@Autowired
GtDataRestClient gtDataRestClient;
private static final Integer maxNumber=5;
......@@ -1092,6 +1094,14 @@ public class AppPermissionService {
JSONObject data = autoLogin(userid, username, headimgurl, nickname,code,activityCode,1);
log.info("注册:处理im账号: " + userid+"---time===="+System.currentTimeMillis()/1000L);
//注册gtdata账号
String gtdataPass = MD5.GetMD5StringLower(appUserLogin.getId().toString());
Map<String, Object> result = gtDataRestClient.register(appUserLogin.getId()+"", MD5.GetMD5StringLower(gtdataPass), (1024L* 1024L* 1024L* 100)+ "");
appUserLoginBiz.updateSelectiveById(new AppUserLogin(){{
setId(appUserLogin.getId());
setGtdataPass(gtdataPass);
}});
if (data != null) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("userId", userid);
......
package com.upyuns.platform.rs.datacenter.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Table;
@Data
@Table(name = "rscp_image_statistics")
@ApiModel(description = "")
public class RscpImageStatistics implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 678376971319983494L;
/* This code was generated by TableGo tools, mark 1 begin. */
/** id标识 */
@ApiModelProperty(value = "id标识")
private String id;
/** 统计类型 1--全部;2--最近七天 */
@ApiModelProperty(value = "统计类型 1--全部;2--最近七天")
private Integer type;
/** 统计条件 */
@ApiModelProperty(value = "统计条件")
private String imageJson;
/** 名称 */
@ApiModelProperty(value = "名称")
private String name;
/** 数量 */
@ApiModelProperty(value = "数量")
private Integer num;
/** 排序 */
@ApiModelProperty(value = "排序")
private Integer sort;
/** 删除 */
@ApiModelProperty(value = "删除")
private Integer isDel;
/** 创建时间 */
@ApiModelProperty(value = "创建时间")
private Long crtTime;
/** 更新时间 */
@ApiModelProperty(value = "更新时间")
private Long updTime;
/** 年份 */
@ApiModelProperty(value = "年份")
private Integer dateyear;
}
\ No newline at end of file
package com.upyuns.platform.rs.datacenter.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.upyuns.platform.rs.datacenter.entity.RscpImageStatistics;
import com.upyuns.platform.rs.datacenter.entity.RscpResolution;
import com.upyuns.platform.rs.datacenter.mapper.RscpImageStatisticsMapper;
import com.upyuns.platform.rs.datacenter.mapper.RscpResolutionMapper;
import org.springframework.stereotype.Service;
@Service
public class RscpImageStatisticsBiz extends BaseBiz<RscpImageStatisticsMapper, RscpImageStatistics> {
}
package com.upyuns.platform.rs.datacenter.job;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.time.LocalDateTime;
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j
public class SaticScheduleTask {
//3.添加定时任务
@Scheduled(cron = "0/5 * * * * ?")
//或直接指定时间间隔,例如:5秒
//@Scheduled(fixedRate=5000)
public void configureTasks() {
//查询是否有线上并且代发货的订单
//log.info("执行静态定时任务时间: " + LocalDateTime.now());
}
}
\ No newline at end of file
package com.upyuns.platform.rs.datacenter.mapper;
import com.upyuns.platform.rs.datacenter.entity.RscpImageStatistics;
import com.upyuns.platform.rs.datacenter.entity.RscpResolution;
import tk.mybatis.mapper.common.Mapper;
public interface RscpImageStatisticsMapper extends Mapper<RscpImageStatistics> {
}
\ No newline at end of file
......@@ -10,10 +10,7 @@ import com.upyuns.platform.rs.gtdata.GtDataRestClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
......
......@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.Query;
......@@ -41,6 +42,7 @@ import java.util.List;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
import static com.github.wxiaoqi.security.common.util.process.ResultCode.PARAM_ILLEGAL_CODE;
@RestController
@RequestMapping("/web/imageData")
......@@ -104,9 +106,19 @@ public class RscpImageDataTotalController extends BaseController<RscpImageDataTo
}
}
@RequestMapping(value = "/app/unauth/detailById", method = RequestMethod.GET)
@IgnoreUserToken
public ObjectRestResponse<List<RscpImageDataTotal>> detailById(String id){
List<RscpImageDataTotal> list2 = baseBiz.selectByAttrs(RscpImageDataTotal::getId, CollUtil.newArrayList(id));
if(list2.size() > 0) {
return ObjectRestResponse.succ(list2.get(0));
}
throw new BaseException("数据不存在", PARAM_ILLEGAL_CODE);
}
@RequestMapping(value = "/app/unauth/Fegin/queryByIds", method = RequestMethod.GET)
@IgnoreUserToken
public ObjectRestResponse<List<RscpImageDataTotal>> queryByIds(String ids){
public ObjectRestResponse<List<ImageDataVO>> queryByIds(String ids){
List<RscpImagePrice> list = rscpImagePriceBiz.selectByWeekend(w -> {
w.andEqualTo(RscpImagePrice::getStatus, SYS_TRUE);
return w;
......
......@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
@RestController
......@@ -33,6 +34,7 @@ public class RscpImagePriceController extends BaseController<RscpImagePriceBiz,
List<RscpImagePrice> list = baseBiz.selectByWeekend(w -> {
w.andEqualTo(RscpImagePrice::getStatus, SYS_TRUE);
w.andEqualTo(RscpImagePrice::getIsDel, SYS_FALSE);
return w;
}, " daily_sort asc");
......
package com.upyuns.platform.rs.datacenter.rest;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.upyuns.platform.rs.datacenter.biz.RscpImageStatisticsBiz;
import com.upyuns.platform.rs.datacenter.biz.RscpResolutionBiz;
import com.upyuns.platform.rs.datacenter.entity.RscpImageStatistics;
import com.upyuns.platform.rs.datacenter.entity.RscpResolution;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
@RestController
@RequestMapping("/web/statistics")
public class RscpImageStatisticsController extends BaseController<RscpImageStatisticsBiz, RscpImageStatistics> {
// @Override
// public ObjectRestResponse<PageDataVO<RscpImageStatistics>> pages(Map<String, Object> params) {
// //查询列表数据
// Query query = new Query(params);
// return ObjectRestResponse.succ(baseBiz.selectByQueryLogicPage(query));
// }
@RequestMapping(value = "/app/unauth/all", method = RequestMethod.GET)
@IgnoreUserToken
public ObjectRestResponse unauthQuery(RscpImageStatistics entity) {
List<RscpImageStatistics> list = baseBiz.selectByWeekend(w -> {
w.andEqualTo(RscpImageStatistics::getIsDel, SYS_FALSE);
if(null != entity.getType()) {
w.andEqualTo(RscpImageStatistics::getType, entity.getType());
}
if(null != entity.getDateyear()) {
w.andEqualTo(RscpImageStatistics::getDateyear, entity.getDateyear());
}
return w;
}, " sort asc");
return ObjectRestResponse.succ(list);
}
}
\ No newline at end of file
package com.upyuns.platform.rs.datacenter.rest.backstage;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.CommonBaseController;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.upyuns.platform.rs.gtdata.GtDataRestClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
@RestController
@Slf4j
@RequestMapping("/bg/gtdata/")
public class BgGtdataController extends CommonBaseController {
@Autowired
GtDataRestClient gtDataRestClient;
public static final String uploadP = "/rscloudmart/bg/upload/";
@RequestMapping(value = "/app/unauth/upload", method = RequestMethod.POST)
@IgnoreUserToken
public ObjectRestResponse uploads(
@RequestParam("file") MultipartFile file,
@RequestParam(value = "prefix",defaultValue = "admin")String prefix
)throws Exception {
String contentType = file.getContentType(); //图片文件类型
Map<String, Object> existMap = gtDataRestClient.isExist(uploadP);
if(existMap.get("HttpStatusCode") == null || !"200".equals(existMap.get("HttpStatusCode"))){
gtDataRestClient.mkdirs(uploadP);
}
gtDataRestClient.createMultipartFile(file, uploadP+file.getName());
return ObjectRestResponse.succ();
}
public void downloadVideoById(String fileName, String filePath, HttpServletResponse response) throws Exception {
log.info("下载请求start>>");
try {
if (StrUtil.isEmpty(fileName) || StrUtil.isEmpty(filePath)) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=UTF-8");
response.getWriter().print("参数错误,请联系管理员!");
response.flushBuffer();
return;
}
URL pathUrl = new URL(filePath);
HttpURLConnection urlcon = (HttpURLConnection) pathUrl.openConnection();
if(urlcon.getResponseCode()>=400){
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=UTF-8");
response.getWriter().print("文件不存在,请联系管理员!");
response.flushBuffer();
return;
}
//获取输入流对象(用于读文件) 网络流
InputStream inputStream = new URL(filePath).openStream();
//本地流文件
// FileInputStream fis = new FileInputStream(new File(filePath));
//动态设置响应类型,根据前台传递文件类型设置响应类型
response.setContentType("image/" + fileName.substring(fileName.lastIndexOf(".")+1));
//设置响应头,attachment表示以附件的形式下载,inline表示在线打开
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));//下载时浏览器显示的名称
//获取输出流对象(用于写文件)
ServletOutputStream os = response.getOutputStream();
//下载文件,使用spring框架中的FileCopyUtils工具
FileCopyUtils.copy(inputStream, os);
} catch (Exception e) {
log.error("下载失败 start >>",e);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=UTF-8");
response.getWriter().print("下载失败,请联系管理员!");
response.flushBuffer();
}
}
}
<?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">
<!-- rscp_image_statistics -->
<mapper namespace="com.upyuns.platform.rs.datacenter.mapper.RscpImageStatisticsMapper">
<!-- This code was generated by TableGo tools, mark 1 begin. -->
<!-- 字段映射 -->
<resultMap id="rscpImageStatisticsMap" type="com.upyuns.platform.rs.datacenter.entity.RscpImageStatistics">
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="image_json" property="imageJson" jdbcType="VARCHAR" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="num" property="num" jdbcType="INTEGER" />
<result column="sort" property="sort" jdbcType="INTEGER" />
<result column="is_del" property="isDel" jdbcType="INTEGER" />
<result column="crt_time" property="crtTime" jdbcType="INTEGER" />
<result column="upd_time" property="updTime" jdbcType="INTEGER" />
</resultMap>
<!-- This code was generated by TableGo tools, mark 1 end. -->
<!-- This code was generated by TableGo tools, mark 2 begin. -->
<!-- 表查询字段 -->
<sql id="allColumns">
ris.id, ris.type, ris.image_json, ris.name, ris.num, ris.sort, ris.is_del, ris.crt_time,
ris.upd_time
</sql>
<!-- This code was generated by TableGo tools, mark 2 end. -->
</mapper>
\ No newline at end of file
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