he2802 2 年 前
コミット
012500f0b2

+ 6 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -663,4 +663,10 @@ public class CommonController extends BaseController {
     public AjaxResult pushPeriod(@RequestBody List<ClassGradeUserQueryBo>  list) {
         return AjaxResult.success(iClassGradeUserService.pushOfficialPeriodMore(list));
     }
+
+    @ApiOperation("旧系统post请求")
+    @PostMapping("/common/free/clientPost")
+    public AjaxResult<Void> clientPost(@RequestBody ClientPostAddBo bo) {
+        return AjaxResult.success(iClassGradeUserService.sendClientPost(bo));
+    }
 }

+ 45 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/http/HttpUtils.java

@@ -125,6 +125,16 @@ public class HttpUtils
 
     }
 
+    public static String postFormBodyHeader(String url, Map<String, String> paramMap, Map<String, String> headersMap) throws IOException{
+        try{
+            String result = postHead(url, paramMap, null,headersMap);
+            return result;
+        }catch (Exception e){
+            return null;
+        }
+
+    }
+
     public static String sendPost(String url, JSONObject param)
     {
         HttpClient client = HttpClients.createDefault();
@@ -472,6 +482,41 @@ public class HttpUtils
         return url;
     }
 
+    private static String postHead(String url, Map<String, String> paramMap, String encoding, Map<String, String> headersMap) throws IOException, NoSuchAlgorithmException, KeyManagementException {
+        log.debug("http 请求 url: {} , 请求参数: {}", url, appendUrl("", paramMap).replace("?", ""));
+        encoding = encoding == null ? UTF8 : encoding;
+        // 创建post方式请求对象
+        HttpPost httpPost = new HttpPost(url);
+        // 装填参数
+        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+        if (paramMap != null) {
+            for (Map.Entry<String, String> entry : paramMap.entrySet()) {
+                String value = entry.getValue();
+                //去掉如下判断会造成String类型的value为null时
+                if (value != null) {
+                    nameValuePairs.add(new BasicNameValuePair(entry.getKey(), value));
+                }
+            }
+        }
+        // 设置参数到请求对象中
+        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, encoding));
+        // 设置header信息
+        // 指定报文头【Content-type】、【User-Agent】
+        httpPost.setHeader("Content-type", APPLICATION_FORM_URLENCODED);
+        headersMap.forEach(httpPost::setHeader);
+        return post(url, httpPost, encoding, new DataParse<String>() {
+            @Override
+            public String parseData(HttpEntity httpEntity, String encoding) throws IOException {
+                if(Validator.isNotEmpty(httpEntity)){
+                    return EntityUtils.toString(httpEntity, encoding);
+                }else{
+                    return null;
+                }
+
+            }
+        });
+    }
+
     /**
      * 向url发送post请求表单提交数据
      * @param url 请求url

+ 39 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/bo/ClientPostAddBo.java

@@ -0,0 +1,39 @@
+package com.zhongzheng.modules.grade.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+
+/**
+ * 班级添加对象 class_grade
+ *
+ * @author ruoyi
+ * @date 2021-11-10
+ */
+@Data
+@ApiModel("班级添加对象")
+public class ClientPostAddBo {
+
+    @ApiModelProperty("请求文本")
+    @NotBlank(message = "请求文本")
+    private String content;
+
+    @ApiModelProperty("当前时间戳")
+    @NotBlank(message = "当前时间戳不能为空")
+    private Long stamp;
+
+    @ApiModelProperty("签名")
+    @NotBlank(message = "签名不能为空")
+    private String sign;
+
+    @ApiModelProperty("请求文本")
+    @NotBlank(message = "请求文本")
+    private String token;
+
+    @ApiModelProperty("url")
+    @NotBlank(message = "url")
+    private String url;
+}

+ 2 - 5
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/IClassGradeUserService.java

@@ -1,21 +1,16 @@
 package com.zhongzheng.modules.grade.service;
 
-import com.zhongzheng.common.core.domain.AjaxResult;
-import com.zhongzheng.modules.base.bo.UserProfileQueryBo;
-import com.zhongzheng.modules.base.vo.UserProfileExportGaiVo;
 import com.zhongzheng.modules.course.vo.CourseChapterVo;
 import com.zhongzheng.modules.grade.bo.*;
 import com.zhongzheng.modules.grade.domain.ClassGradeUser;
 import com.zhongzheng.modules.grade.vo.*;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zhongzheng.modules.user.bo.UserQueryBo;
-import com.zhongzheng.modules.user.bo.UserStudyRecordQueryBo;
 import com.zhongzheng.modules.user.domain.User;
 
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.zip.ZipOutputStream;
 
 /**
  * 学员记录Service接口
@@ -70,6 +65,8 @@ public interface IClassGradeUserService extends IService<ClassGradeUser> {
 
 	Map<String,Object> exportWeekPo(ClassGradeUserQueryBo bo);
 
+	String sendClientPost(ClientPostAddBo bo);
+
 
 	/**
 	 * 根据编辑业务对象修改学员记录

+ 24 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/impl/ClassGradeUserServiceImpl.java

@@ -36,7 +36,6 @@ import com.zhongzheng.modules.course.vo.CourseBusinessVo;
 import com.zhongzheng.modules.course.vo.CourseChapterVo;
 import com.zhongzheng.modules.course.vo.CourseProjectTypeVo;
 import com.zhongzheng.modules.goods.domain.Goods;
-import com.zhongzheng.modules.goods.domain.GoodsCourse;
 import com.zhongzheng.modules.goods.service.IGoodsService;
 import com.zhongzheng.modules.goods.vo.GoodsVo;
 import com.zhongzheng.modules.grade.bo.*;
@@ -72,7 +71,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.security.core.token.TokenService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -1434,6 +1432,30 @@ public class ClassGradeUserServiceImpl extends ServiceImpl<ClassGradeUserMapper,
         return totalRs;
     }
 
+    @Override
+    public String sendClientPost(ClientPostAddBo bo) {
+        if(Validator.isEmpty(bo.getContent())){
+            throw new CustomException("参数错误");
+        }
+        String respone = "";
+        try {
+            Map<String, String> params = Splitter.on("&").withKeyValueSeparator("=").split(bo.getContent());
+            Map<String, String> head = new HashMap<>();
+            if(Validator.isNotEmpty(bo.getToken())){
+                head.put("token", bo.getToken());
+            }
+            respone = HttpUtils.postFormBodyHeader(bo.getUrl(), params,head);
+            if (Validator.isEmpty(respone)) {
+                return "响应信息空";
+            }
+            return respone;
+
+        } catch (IOException e) {
+            //    throw new CustomException("请求错误");
+            return null;
+        }
+    }
+
     //填充满列表的用户信息
     private Map<String, Object> fillListWeek(List<ClassPeriodStudentExportVo> list) {
         List<ClassPeriodStudentExportWeekAllVo> newList = new ArrayList<>();