修改bug
This commit is contained in:
parent
7cc33aa937
commit
44fb5facee
|
@ -0,0 +1,53 @@
|
|||
package org.jeecg.modules.kc.grab.SynchronizationService;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.jeecg.modules.kc.grab.SynchronizationService.base.BaseSync;
|
||||
import org.jeecg.modules.kc.grab.exports.entity.TBks;
|
||||
import org.jeecg.modules.kc.grab.exports.service.ITBksService;
|
||||
import org.jeecg.modules.kc.grab.imports.entity.Xxhbbks;
|
||||
import org.jeecg.modules.kc.grab.imports.entity.Xxhbsynclog;
|
||||
import org.jeecg.modules.kc.grab.imports.service.IXxhbbksService;
|
||||
import org.jeecg.modules.kc.zyInfoStudent.service.IZyInfoStudentService;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class SyncGjtz extends BaseSync {
|
||||
|
||||
@Autowired
|
||||
private IZyInfoStudentService zyInfoStudentService;
|
||||
|
||||
/**
|
||||
* 若参数变量名修改 QuartzJobController中也需对应修改
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) {
|
||||
start();
|
||||
run(getParamMap());
|
||||
end();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 有参定时任务实现
|
||||
* @param param
|
||||
*/
|
||||
public void run(Map<String, Object> param){
|
||||
zyInfoStudentService.getWpcccs();//获取维普剩余查重次数
|
||||
}
|
||||
|
||||
/**
|
||||
* 无参定时任务实现
|
||||
*/
|
||||
public void run(){
|
||||
run(null);
|
||||
}
|
||||
|
||||
}
|
|
@ -42,4 +42,6 @@ public interface IWjxWjxxService extends IService<WjxWjxx> {
|
|||
Page<WjxWjxx> listOther(WjxWjxx wjxWjxx, Page<Object> objectPage);
|
||||
|
||||
void batchZyinfoKhcl(String id);
|
||||
|
||||
String getAccessToken();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import org.jeecg.common.util.SftpConfig;
|
|||
import org.jeecg.common.util.text.StringUtils;
|
||||
import org.jeecg.modules.kc.grab.imports.entity.Xxhbbks;
|
||||
import org.jeecg.modules.kc.grab.imports.service.IXxhbbksService;
|
||||
import org.jeecg.modules.kc.kcSysConfig.entity.KcSysConfig;
|
||||
import org.jeecg.modules.kc.kcSysConfig.service.IKcSysConfigService;
|
||||
import org.jeecg.modules.kc.kcWechatSendLog.entity.KcWechatSendLog;
|
||||
import org.jeecg.modules.kc.ktgl.entity.KcKechengbiao;
|
||||
import org.jeecg.modules.kc.ktgl.service.IKcKechengbiaoService;
|
||||
|
@ -38,9 +40,10 @@ import org.jeecg.modules.kc.zyInfo.entity.ZyInfo;
|
|||
import org.jeecg.modules.kc.zyInfoScjl.entity.ZyInfoScjl;
|
||||
import org.jeecg.modules.kc.zyInfoScjl.service.IZyInfoScjlService;
|
||||
import org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudent;
|
||||
import org.jeecg.modules.tools.dbsdkfzpt.RestTemplateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
@ -80,6 +83,8 @@ public class WjxWjxxServiceImpl extends ServiceImpl<WjxWjxxMapper, WjxWjxx> impl
|
|||
private IKcKechengbiaoService kcKechengbiaoService;
|
||||
@Autowired
|
||||
private IZyInfoScjlService zyInfoScjlService;
|
||||
@Autowired
|
||||
private IKcSysConfigService kcSysConfigService;
|
||||
|
||||
|
||||
@Autowired
|
||||
|
@ -553,27 +558,66 @@ public class WjxWjxxServiceImpl extends ServiceImpl<WjxWjxxMapper, WjxWjxx> impl
|
|||
@Override
|
||||
public void batchZyinfoKhcl(String ids) {
|
||||
try {
|
||||
|
||||
String token = getAccessToken();//获取东北师大开放平台token
|
||||
System.out.println("=======================================");
|
||||
System.out.println("token:"+token);
|
||||
System.out.println("=======================================");
|
||||
if(StringUtils.isNotEmpty(token)){//判断如果token不为空则继续操作
|
||||
|
||||
KcSysConfig kcSysConfig = kcSysConfigService.getById("1");
|
||||
String idsList[] = ids.split(",");
|
||||
|
||||
if(idsList.length>0){
|
||||
|
||||
String yyyy = DateUtils.formatDate(new Date(),"yyyy");
|
||||
String mm = DateUtils.formatDate(new Date(),"MM");
|
||||
for(String zyId:idsList){
|
||||
|
||||
|
||||
WjxWjxx wjxWjxx = baseMapper.selectById(zyId);
|
||||
|
||||
|
||||
//判断没有上传考核材料的数据,才进行上传,否则不上传
|
||||
if(wjxWjxx!=null && !StringUtils.equals("1",wjxWjxx.getSfsckhcl())){
|
||||
QueryWrapper<KcKechengbiao> kcKechengbiaoQueryWrapper = new QueryWrapper<>();
|
||||
kcKechengbiaoQueryWrapper.eq("xqxn",kcSysConfig.getFlag1());
|
||||
kcKechengbiaoQueryWrapper.eq("rwbh",wjxWjxx.getRwbh());
|
||||
kcKechengbiaoQueryWrapper.eq("jgh",wjxWjxx.getCreateBy());
|
||||
kcKechengbiaoQueryWrapper.eq("xqxn",wjxWjxx.getXqxn());
|
||||
kcKechengbiaoQueryWrapper.last("limit 1");
|
||||
KcKechengbiao kcKechengbiao = kcKechengbiaoService.getOne(kcKechengbiaoQueryWrapper);
|
||||
|
||||
|
||||
//调用师大接口将数据上传
|
||||
String interfaceUrl = "https://intf.nenu.edu.cn/api/bd-api/post/JW_FXCJXMB";
|
||||
List<Map<String, String>> paramsList =new ArrayList<>();
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("CJR",wjxWjxx.getCreateBy());//创建人
|
||||
paramMap.put("TEABH",wjxWjxx.getCreateBy());//教工号
|
||||
paramMap.put("FXCJMC","课程测验"+wjxWjxx.getSort());//分项成绩名称
|
||||
paramMap.put("TEADM",wjxWjxx.getCreateBy());//教工代码
|
||||
paramMap.put("TEAXM",kcKechengbiao.getSkjs());//教师姓名
|
||||
paramMap.put("FXCJBH",wjxWjxx.getId());//分项成绩编号
|
||||
paramMap.put("XNXQMC",kcKechengbiao.getXnxq());//学年学期
|
||||
paramMap.put("ZYYQ",null);//作业要求
|
||||
paramMap.put("CJSJ",DateUtils.formatDate(wjxWjxx.getCreateTime(),"yyyy-MM-dd"));//创建时间
|
||||
paramMap.put("FXCJBL",wjxWjxx.getScore());//比例,成绩占比
|
||||
paramMap.put("FXCJLXMC","3");//分项成绩类型
|
||||
paramMap.put("KCMC",kcKechengbiao.getKcmc());//课程名称
|
||||
paramMap.put("KCRWDM",wjxWjxx.getRwbh());//开课任务编号
|
||||
paramMap.put("PFBZ",null);//评分标准
|
||||
paramMap.put("FXCJDM",wjxWjxx.getId());//主键
|
||||
// paramMap.put("OPERATE_STATUS","i");//操作状态
|
||||
paramsList.add(paramMap);
|
||||
String data = RestTemplateUtils.post(interfaceUrl,token, paramsList, MediaType.APPLICATION_JSON_UTF8, String.class);
|
||||
System.out.println("=======================================");
|
||||
System.out.println("data:"+data);
|
||||
System.out.println("=======================================");
|
||||
|
||||
|
||||
|
||||
QueryWrapper<WjxDjxx> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("vid",wjxWjxx.getVid());
|
||||
queryWrapper.eq("sfsckhcl","0");
|
||||
List<WjxDjxx> list = wjxDjxxMapper.selectList(queryWrapper);
|
||||
|
||||
List<Map<String, String>> paramsList2 =new ArrayList<>();
|
||||
for(WjxDjxx wjxDjxx:list){
|
||||
|
||||
|
||||
|
@ -606,19 +650,91 @@ public class WjxWjxxServiceImpl extends ServiceImpl<WjxWjxxMapper, WjxWjxx> impl
|
|||
zyInfoScjl.setStudentNo(wjxDjxx.getCreateBy());
|
||||
zyInfoScjl.setStudentName(wjxDjxx.getUserName());
|
||||
zyInfoScjlService.save(zyInfoScjl);
|
||||
|
||||
Map<String, String> paramMap2 = new HashMap<>();
|
||||
paramMap2.put("CJ",wjxDjxx.getScore()+"");//成绩
|
||||
paramMap2.put("CJR",wjxDjxx.getCreateBy());//创建人
|
||||
paramMap2.put("CJSJ",DateUtils.formatDate(wjxDjxx.getCreateTime(),"yyyy-MM-dd"));//创建时间
|
||||
paramMap2.put("KCRWDM",wjxWjxx.getRwbh());//开课任务编号
|
||||
paramMap2.put("KCMC",kcKechengbiao.getKcmc());//课程名称
|
||||
paramMap2.put("FXCJMC","课程测验"+wjxWjxx.getSort());//分项成绩名称
|
||||
paramMap2.put("TEAXM",kcKechengbiao.getSkjs());//教师姓名
|
||||
paramMap2.put("XSXM",wjxDjxx.getUserName());//学生姓名
|
||||
paramMap2.put("KID",wjxDjxx.getId());//主键
|
||||
paramMap2.put("XSBH",wjxDjxx.getCreateBy());//学号
|
||||
paramMap2.put("FXCJBH",wjxWjxx.getId());//分项成绩编号
|
||||
paramMap2.put("PATH","");//附件路径
|
||||
paramMap2.put("TEABH",wjxWjxx.getCreateBy());//教工号
|
||||
// paramMap2.put("OPERATE_STATUS","i");//操作状态
|
||||
paramsList2.add(paramMap2);
|
||||
|
||||
}
|
||||
|
||||
System.out.println("=======================================");
|
||||
System.out.println("paramsList2:"+paramsList2);
|
||||
System.out.println("=======================================");
|
||||
//调用师大接口进行上传
|
||||
String interfaceUrl2 = "https://intf.nenu.edu.cn/api/bd-api/post/JW_FXXSCJMX";
|
||||
String data2 = RestTemplateUtils.post(interfaceUrl2,token, paramsList2, MediaType.APPLICATION_JSON_UTF8, String.class);
|
||||
System.out.println("=======================================");
|
||||
System.out.println("data2:"+data2);
|
||||
System.out.println("=======================================");
|
||||
|
||||
wjxWjxx.setSfsckhcl("1");
|
||||
wjxWjxx.setSfsckhclTime(new Date());
|
||||
baseMapper.updateById(wjxWjxx);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getAccessToken(){
|
||||
String token="";
|
||||
try {
|
||||
// 获取令牌URL前缀
|
||||
String prefixUrl = "https://intf.nenu.edu.cn/api/bd-api";
|
||||
// 开发者帐号,以实际为准
|
||||
String userName = "D64A8E04B63AE18D1D796914279AEEE3";
|
||||
// 开发者密码,以实际为准
|
||||
String password = "6413C873CD49C96D301B0D7A0EBFA51D";
|
||||
//NO.1:通过client_id:client_secret 和开发者账号和密码获取授权令牌access_token
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
//构建请求头信息
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// headers.add("Content-Type", "application/json");
|
||||
headers.add("Authorization", "Basic ZDhiZGU5NjZjYmEyNGVjX3V1aWQ6YTE4MjY3ZjExOTBmZTRjYzcyMTMxNDQ5ZDIyY2FhMDg=");
|
||||
|
||||
//获取access_token
|
||||
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||
|
||||
// userName=DesUtil.encrypt(userName);
|
||||
// password=DesUtil.encrypt(password);
|
||||
String url= prefixUrl+"/oauth/token?grant_type=password&scope=read&username="+userName+"&password="+password;
|
||||
|
||||
ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.POST, request, Object.class);;
|
||||
|
||||
LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>)response.getBody();
|
||||
|
||||
//从返回结果中获取 access_token
|
||||
token = (String)map.get("access_token");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
// appId
|
||||
private static final String appId = "wx031697a8ca09a5ce";//东师
|
||||
|
||||
|
|
|
@ -758,7 +758,7 @@ public class ZyInfoController extends JeecgController<ZyInfo, IZyInfoService> {
|
|||
//删除老师留过的作业,重新生成新的
|
||||
QueryWrapper<ZyInfo> query = new QueryWrapper<>();
|
||||
query.eq("rwbh", zyInfo.getRwbh());
|
||||
query.eq("create_by",zyInfo.getCreateBy());
|
||||
// query.eq("create_by",zyInfo.getCreateBy());
|
||||
query.eq("zy_leixing","0");
|
||||
List<ZyInfo> oldList = zyInfoService.list(query);
|
||||
zyInfoService.remove(query);
|
||||
|
|
|
@ -454,12 +454,19 @@ public class ZyInfoStudentController extends JeecgController<ZyInfoStudent, IZyI
|
|||
}else{//不相等则是帧数据,直接修改
|
||||
UpdateWrapper<ZyInfoStudent> zyInfoStudentUp = new UpdateWrapper<>();
|
||||
zyInfoStudentUp.eq("id",par.getId());
|
||||
|
||||
String a = StringUtils.isNotEmpty(par.getScore())?par.getScore():"0";
|
||||
String b = StringUtils.isNotEmpty(par.getJxfs())?par.getJxfs():"0";
|
||||
String e = StringUtils.isNotEmpty(par.getJxfs2())?par.getJxfs2():"0";
|
||||
Double d = Double.parseDouble(a)+Double.parseDouble(b)+Double.parseDouble(e);
|
||||
if(d>100){
|
||||
d = 100.0;
|
||||
}
|
||||
String c = String.format("%.1f",d);
|
||||
if(StringUtils.isEmpty(par.getScore())){
|
||||
zyInfoStudentUp.set("score","0");
|
||||
zyInfoStudentUp.set("zzdf","0");
|
||||
}else{
|
||||
zyInfoStudentUp.set("zzdf",par.getScore());
|
||||
}
|
||||
zyInfoStudentUp.set("zzdf",c);
|
||||
zyInfoStudentUp.set("score_fabu","1");
|
||||
zyInfoStudentService.update(zyInfoStudentUp);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import io.swagger.annotations.ApiModel;
|
|||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.NumberFormat;
|
||||
|
||||
/**
|
||||
* @Description: 学生提交作业
|
||||
|
@ -65,14 +66,19 @@ public class ZyInfoStudent implements Serializable {
|
|||
@Excel(name = "提交时间", width = 15,format = "yyyy-MM-dd")
|
||||
private java.util.Date publishTime;
|
||||
|
||||
@Excel(name = "教师评分", width = 15)
|
||||
@Excel(name = "教师评分", width = 15, type = 4)
|
||||
private java.lang.String score;
|
||||
|
||||
@Excel(name = "互评分数", width = 15)
|
||||
private String xshpfs;
|
||||
|
||||
@Excel(name = "绩效分", width = 15)
|
||||
@TableField(exist = false)
|
||||
private String jxzf;
|
||||
|
||||
private String jxfs;
|
||||
@Excel(name = "最终得分", width = 15)
|
||||
|
||||
@Excel(name = "最终得分", width = 15,type=4)
|
||||
private String zzdf;
|
||||
@Excel(name = "最高查重率", width = 15)
|
||||
@TableField(exist = false)
|
||||
|
@ -136,8 +142,6 @@ public class ZyInfoStudent implements Serializable {
|
|||
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String jxzf;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String catename;
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
package org.jeecg.modules.kc.zyInfoStudent.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 io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 学生提交作业
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-05-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("zy_info_student")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="zy_info_student对象", description="学生提交作业")
|
||||
public class ZyInfoStudentExport implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "id")
|
||||
private String id;
|
||||
/**updateBy*/
|
||||
@ApiModelProperty(value = "updateBy")
|
||||
private String updateBy;
|
||||
/**updateTime*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@ApiModelProperty(value = "updateTime")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
@Excel(name = "学生姓名", width = 15)
|
||||
@ApiModelProperty(value = "studentName")
|
||||
private String studentName;
|
||||
@Excel(name = "学生学号", width = 15)
|
||||
@ApiModelProperty(value = "createBy")
|
||||
private String createBy;
|
||||
@Excel(name = "专业名称", width = 15)
|
||||
@ApiModelProperty(value = "zymc")
|
||||
@TableField(exist = false)
|
||||
private String zymc;
|
||||
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@ApiModelProperty(value = "createTime")
|
||||
private Date createTime;
|
||||
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@Excel(name = "提交时间", width = 15,format = "yyyy-MM-dd")
|
||||
private Date publishTime;
|
||||
|
||||
@Excel(name = "教师评分", width = 15)
|
||||
private int score;
|
||||
|
||||
@Excel(name = "互评分数", width = 15)
|
||||
private String xshpfs;
|
||||
@Excel(name = "绩效分", width = 15)
|
||||
private String jxfs;
|
||||
@Excel(name = "最终得分", width = 15)
|
||||
private int zzdf;
|
||||
@Excel(name = "最高查重率", width = 15)
|
||||
@TableField(exist = false)
|
||||
private String zgccl;//最高相似律
|
||||
|
||||
/**外网相似律*/
|
||||
// @Excel(name = "维普查重(%)", width = 15)
|
||||
@ApiModelProperty(value = "维普查重(%)")
|
||||
private String wwxsl;
|
||||
/**内网相似律*/
|
||||
// @Excel(name = "作业查重(%)", width = 15)
|
||||
@ApiModelProperty(value = "作业查重(%)")
|
||||
private String nwxsl;
|
||||
/**aigc相似律*/
|
||||
// @Excel(name = "aigc查重(%)", width = 15)
|
||||
@ApiModelProperty(value = "aigc查重(%)")
|
||||
private String aigcxsl;
|
||||
/**校内相似律*/
|
||||
// @Excel(name = "校内查重(%)", width = 15)
|
||||
@ApiModelProperty(value = "校内查重(%)")
|
||||
private String xnxsl;
|
||||
// @Excel(name = "标记作业", width = 15,dicCode = "cdlx")
|
||||
@Dict(dicCode = "cdlx")
|
||||
private String cdlx;//存档类型
|
||||
|
||||
|
||||
/**作业名称*/
|
||||
@ApiModelProperty(value = "作业名称")
|
||||
private String mainId;
|
||||
/**作业附件*/
|
||||
@ApiModelProperty(value = "作业附件")
|
||||
private String filePath;
|
||||
/**外网是否通过*/
|
||||
@ApiModelProperty(value = "外网是否通过")
|
||||
private String wwsftg;
|
||||
/**内网是否通过*/
|
||||
@ApiModelProperty(value = "内网是否通过")
|
||||
private String nwsftg;
|
||||
/**aigc是否通过*/
|
||||
@ApiModelProperty(value = "aigc是否通过")
|
||||
private String aigcsftg;
|
||||
/**校内是否通过*/
|
||||
@ApiModelProperty(value = "校内是否通过")
|
||||
private String xnsftg;
|
||||
|
||||
private String pdfPath;
|
||||
private String scoreFabu;
|
||||
private String hpcs;
|
||||
private String jxfs2;
|
||||
private String zyLeixing;//作业类型 0课程作业 1期末作业
|
||||
private String pyContent;//批阅内容
|
||||
private String pyFilePath;//批阅附件
|
||||
private String sfsckhcl;//是否上传考核材料(0否 1是)
|
||||
private String fwqPath;//文件服务器存储地址
|
||||
private String pyFwqFilePath;//评阅附件存储地址
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "考核材料提交时间", width = 15,format = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date khclTime;
|
||||
|
||||
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String jxzf;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String catename;
|
||||
@TableField(exist = false)
|
||||
private String cateid;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String wwcc;
|
||||
@TableField(exist = false)
|
||||
private String nwcc;
|
||||
@TableField(exist = false)
|
||||
private String aigccc;
|
||||
@TableField(exist = false)
|
||||
private String xncc;
|
||||
@TableField(exist = false)
|
||||
private String zyname;
|
||||
@TableField(exist = false)
|
||||
private String teacherNo;
|
||||
@TableField(exist = false)
|
||||
private String rwbh;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String ccType;
|
||||
@TableField(exist = false)
|
||||
private String paperviewurl;
|
||||
@TableField(exist = false)
|
||||
private String paperdownurl;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String wwpaperviewurl;//外网预览
|
||||
@TableField(exist = false)
|
||||
private String wwpaperdownurl;//外网下载
|
||||
@TableField(exist = false)
|
||||
private String zypaperviewurl;//作业预览
|
||||
@TableField(exist = false)
|
||||
private String zypaperdownurl;//作业下载
|
||||
@TableField(exist = false)
|
||||
private String xxpaperviewurl;//学校预览
|
||||
@TableField(exist = false)
|
||||
private String xxpaperdownurl;//学校下载
|
||||
@TableField(exist = false)
|
||||
private String aigcpaperviewurl;//aigc预览
|
||||
@TableField(exist = false)
|
||||
private String aigcpaperdownurl;//aigc外网下载
|
||||
|
||||
@TableField(exist = false)
|
||||
private String filestateid;//
|
||||
@TableField(exist = false)
|
||||
private String message;//
|
||||
@TableField(exist = false)
|
||||
private String wwfilestateid;//外网状态
|
||||
@TableField(exist = false)
|
||||
private String wwmessage;//外网说明
|
||||
@TableField(exist = false)
|
||||
private String zyfilestateid;//作业状态
|
||||
@TableField(exist = false)
|
||||
private String zymessage;//作业说明
|
||||
@TableField(exist = false)
|
||||
private String aigcfilestateid;//aigc状态
|
||||
@TableField(exist = false)
|
||||
private String aigcmessage;//aigc说明
|
||||
@TableField(exist = false)
|
||||
private String xxfilestateid;//学校状态
|
||||
@TableField(exist = false)
|
||||
private String xxmessage;//学校说明
|
||||
@TableField(exist = false)
|
||||
private String queryType;//作业状态查询
|
||||
@TableField(exist = false)
|
||||
private String alltgl;//通过率
|
||||
@TableField(exist = false)
|
||||
private String sfpf;//是否评分
|
||||
@TableField(exist = false)
|
||||
private String zytitle;//作业名称
|
||||
@TableField(exist = false)
|
||||
private String stuScore;//作业名称
|
||||
@TableField(exist = false)
|
||||
private String pfbz;//评分标准
|
||||
@TableField(exist = false)
|
||||
private String sturead;//评分标准是否允许学生查看
|
||||
@TableField(exist = false)
|
||||
private String ywid;//业务id
|
||||
@TableField(exist = false)
|
||||
private String stuId;//学生作业临时id
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@
|
|||
</select>
|
||||
<select id="selectList" resultType="org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudent">
|
||||
select a.*,round(IFNULL(a.jxfs,'0') + IFNULL(a.jxfs2,'0'),2) as jxzf,b.wwcc,b.nwcc,b.aigccc,b.xncc,b.title as zyname, GREATEST(ifnull(a.wwxsl,0),ifnull(a.nwxsl,0),ifnull(a.aigcxsl,0),ifnull(a.xnxsl,0)) as zgccl,b.wwtgl as alltgl,c.zymc
|
||||
,a.score as expscore ,a.zzdf as expzzdf
|
||||
from zy_info_student a
|
||||
left join zy_info b on a.main_id = b.id
|
||||
left join xxhbbks c on a.create_by = c.xh
|
||||
|
@ -25,7 +26,7 @@
|
|||
a.nwxsl,a.aigcxsl,a.wwsftg,a.nwsftg,a.aigcsftg,a.score,d.xm as student_name,a.pdf_path,a.score_fabu,
|
||||
a.cdlx,a.xnxsl,a.xnsftg,a.publish_time,a.hpcs,a.xshpfs,a.jxfs,a.zzdf,a.jxfs2,a.zy_leixing,a.py_content,
|
||||
a.py_file_path,a.sfsckhcl,a.fwq_path,a.khcl_time,
|
||||
round(IFNULL(a.jxfs,'0') + IFNULL(a.jxfs2,'0'),2) as jxzf,b.wwcc,b.nwcc,b.aigccc,b.xncc,b.title as zyname, GREATEST(ifnull(a.wwxsl,0),ifnull(a.nwxsl,0),ifnull(a.aigcxsl,0),ifnull(a.xnxsl,0)) as zgccl,b.wwtgl as alltgl
|
||||
round(IFNULL(a.jxfs,'0') + IFNULL(a.jxfs2,'0'),2) as jxzf,b.wwcc,b.nwcc,b.aigccc,b.xncc,b.title as zyname, GREATEST(ifnull(a.wwxsl-0,0),ifnull(a.nwxsl-0,0),ifnull(a.aigcxsl-0,0),ifnull(a.xnxsl-0,0)) as zgccl,b.wwtgl as alltgl
|
||||
from zy_info b
|
||||
join xxhbxsxkb c on c.kcapzbbh = b.rwbh
|
||||
join xxhbbks d on c.xh = d.xh
|
||||
|
|
|
@ -62,4 +62,6 @@ public interface IZyInfoStudentService extends IService<ZyInfoStudent> {
|
|||
void sysWpKsjc(ZyInfoStudent zyInfoStudent, HttpServletResponse response);
|
||||
|
||||
List<JSONObject> getWpSycccs();
|
||||
|
||||
void getWpcccs();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.xkcoding.http.HttpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
|
@ -14,8 +15,10 @@ import org.jeecg.common.system.vo.LoginUser;
|
|||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.SFTPUtil;
|
||||
import org.jeecg.common.util.SftpConfig;
|
||||
import org.jeecg.modules.kc.kcWechatSendLog.entity.KcWechatSendLog;
|
||||
import org.jeecg.modules.kc.ktgl.entity.KcKechengbiao;
|
||||
import org.jeecg.modules.kc.ktgl.service.IKcKechengbiaoService;
|
||||
import org.jeecg.modules.kc.wjxWjxx.service.IWjxWjxxService;
|
||||
import org.jeecg.modules.kc.zyCcjg.entity.ZyCcjg;
|
||||
import org.jeecg.modules.kc.zyCcjg.mapper.ZyCcjgMapper;
|
||||
import org.jeecg.modules.kc.zyInfo.entity.ZyInfo;
|
||||
|
@ -26,12 +29,16 @@ import org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudent;
|
|||
import org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudentSys;
|
||||
import org.jeecg.modules.kc.zyInfoStudent.mapper.ZyInfoStudentMapper;
|
||||
import org.jeecg.modules.kc.zyInfoStudent.service.IZyInfoStudentService;
|
||||
import org.jeecg.modules.tools.dbsdkfzpt.RestTemplateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.activation.MimetypesFileTypeMap;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -63,6 +70,9 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
@Autowired
|
||||
private IKcKechengbiaoService kcKechengbiaoService;
|
||||
|
||||
@Autowired
|
||||
private IWjxWjxxService wjxWjxxService;
|
||||
|
||||
@Autowired
|
||||
SftpConfig sftpConfig;
|
||||
|
||||
|
@ -274,7 +284,6 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
@Override
|
||||
public ZyInfoStudent scccjg(ZyInfoStudent zyInfoStudent, HttpServletRequest req, HttpServletResponse response) {
|
||||
ZyInfoStudent zyInfoStudent1 = baseMapper.selectById(zyInfoStudent.getId());
|
||||
// delweipulunwen(zyInfoStudent1, response);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -283,29 +292,77 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
public void batchZyinfoKhcl(String ids) {
|
||||
|
||||
try {
|
||||
String token = wjxWjxxService.getAccessToken();//获取东北师大开放平台token
|
||||
System.out.println("=======================================");
|
||||
System.out.println("token:"+token);
|
||||
System.out.println("=======================================");
|
||||
if(org.jeecg.common.util.text.StringUtils.isNotEmpty(token)) {//判断如果token不为空则继续操作
|
||||
|
||||
String idsList[] = ids.split(",");
|
||||
String yyyy = DateUtils.formatDate(new Date(), "yyyy");
|
||||
String mm = DateUtils.formatDate(new Date(), "MM");
|
||||
if (idsList.length > 0) {
|
||||
for (String zyId : idsList) {
|
||||
ZyInfo zyInfo = zyInfoService.getById(zyId);
|
||||
|
||||
|
||||
//判断没有上传考核材料的数据,才进行上传,否则不上传
|
||||
if (zyInfo != null && !org.jeecg.common.util.text.StringUtils.equals("1", zyInfo.getSfsckhcl())) {
|
||||
QueryWrapper<KcKechengbiao> kcKechengbiaoQueryWrapper = new QueryWrapper<>();
|
||||
kcKechengbiaoQueryWrapper.eq("rwbh", zyInfo.getRwbh());
|
||||
kcKechengbiaoQueryWrapper.eq("jgh", zyInfo.getCreateBy());
|
||||
kcKechengbiaoQueryWrapper.eq("xqxn", zyInfo.getXnxq());
|
||||
kcKechengbiaoQueryWrapper.last("limit 1");
|
||||
KcKechengbiao kcKechengbiao = kcKechengbiaoService.getOne(kcKechengbiaoQueryWrapper);
|
||||
zyInfo.setSfsckhcl("1");
|
||||
zyInfo.setSfsckhclTime(new Date());
|
||||
zyInfoService.updateById(zyInfo);
|
||||
|
||||
|
||||
//调用师大接口将数据上传
|
||||
String interfaceUrl = "https://intf.nenu.edu.cn/api/bd-api/post/JW_FXCJXMB";
|
||||
List<Map<String, String>> paramsList = new ArrayList<>();
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("CJR", zyInfo.getCreateBy());//创建人
|
||||
paramMap.put("TEABH", zyInfo.getCreateBy());//教工号
|
||||
if(StringUtils.equals(zyInfo.getZyLeixing(),"0")){
|
||||
paramMap.put("FXCJMC", "课程作业" + zyInfo.getSort());//分项成绩名称
|
||||
paramMap.put("FXCJLXMC", "0");//分项成绩类型
|
||||
}else{
|
||||
paramMap.put("FXCJMC", "期末考试" + zyInfo.getSort());//分项成绩名称
|
||||
paramMap.put("FXCJLXMC", "1");//分项成绩类型
|
||||
}
|
||||
paramMap.put("TEADM", zyInfo.getCreateBy());//教工代码
|
||||
paramMap.put("TEAXM", kcKechengbiao.getSkjs());//教师姓名
|
||||
paramMap.put("FXCJBH", zyInfo.getId());//分项成绩编号
|
||||
paramMap.put("XNXQMC", kcKechengbiao.getXnxq());//学年学期
|
||||
paramMap.put("ZYYQ", zyInfo.getContent());//作业要求
|
||||
paramMap.put("CJSJ", DateUtils.formatDate(zyInfo.getCreateTime(), "yyyy-MM-dd"));//创建时间
|
||||
paramMap.put("FXCJBL", zyInfo.getScore());//比例,成绩占比
|
||||
paramMap.put("KCMC", kcKechengbiao.getKcmc());//课程名称
|
||||
paramMap.put("KCRWDM", zyInfo.getRwbh());//开课任务编号
|
||||
paramMap.put("PFBZ", zyInfo.getPfbz());//评分标准
|
||||
paramMap.put("FXCJDM", zyInfo.getId());//主键
|
||||
// paramMap.put("OPERATE_STATUS","i");//操作状态
|
||||
paramsList.add(paramMap);
|
||||
String data = RestTemplateUtils.post(interfaceUrl, token, paramsList, MediaType.APPLICATION_JSON_UTF8, String.class);
|
||||
System.out.println("=======================================");
|
||||
System.out.println("data:" + data);
|
||||
System.out.println("=======================================");
|
||||
|
||||
|
||||
QueryWrapper<ZyInfoStudent> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("a.main_id", zyId);
|
||||
queryWrapper.isNotNull("a.file_path");
|
||||
// queryWrapper.isNotNull("a.file_path");
|
||||
List<ZyInfoStudent> list = baseMapper.selectList(queryWrapper);
|
||||
|
||||
|
||||
List<Map<String, String>> paramsList2 =new ArrayList<>();
|
||||
for (ZyInfoStudent zyInfoStudentPar2 : list) {
|
||||
if (StringUtils.isNotEmpty(zyInfoStudentPar2.getFilePath())) {
|
||||
//上传作业文件
|
||||
Map<String, String> uploadMap = SFTPUtil.upload(sftpConfig, upLoadPath + "/" + zyInfoStudentPar2.getFilePath(), yyyy + "/" + mm + "/" + zyInfo.getRwbh() + "/" + zyInfoStudentPar2.getFilePath().replace("temp/", "/"));
|
||||
if (StringUtils.equals(uploadMap.get("code"), "0")) {
|
||||
zyInfoStudentPar2.setFwqPath(uploadMap.get("data"));
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(zyInfoStudentPar2.getPyFilePath())) {
|
||||
//上传评阅附件
|
||||
|
@ -315,9 +372,7 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
}
|
||||
}
|
||||
|
||||
if(StringUtils.equals(uploadMap.get("code"),"0")){
|
||||
zyInfoStudentPar2.setSfsckhcl("1");
|
||||
zyInfoStudentPar2.setFwqPath(uploadMap.get("data"));
|
||||
zyInfoStudentPar2.setKhclTime(new Date());
|
||||
baseMapper.updateById(zyInfoStudentPar2);
|
||||
|
||||
|
@ -337,8 +392,48 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
zyInfoScjl.setStudentNo(zyInfoStudentPar2.getCreateBy());
|
||||
zyInfoScjl.setStudentName(zyInfoStudentPar2.getStudentName());
|
||||
zyInfoScjlService.save(zyInfoScjl);
|
||||
|
||||
Map<String, String> paramMap2 = new HashMap<>();
|
||||
paramMap2.put("CJ",zyInfoStudentPar2.getZzdf()+"");//成绩
|
||||
paramMap2.put("CJR",zyInfoStudentPar2.getCreateBy());//创建人
|
||||
paramMap2.put("CJSJ",DateUtils.formatDate(zyInfoStudentPar2.getCreateTime(),"yyyy-MM-dd"));//创建时间
|
||||
paramMap2.put("KCRWDM",zyInfo.getRwbh());//开课任务编号
|
||||
paramMap2.put("KCMC",kcKechengbiao.getKcmc());//课程名称
|
||||
if(StringUtils.equals(zyInfo.getZyLeixing(),"0")){
|
||||
paramMap2.put("FXCJMC", "课程作业" + zyInfo.getSort());//分项成绩名称
|
||||
}else{
|
||||
paramMap2.put("FXCJMC", "期末考试" + zyInfo.getSort());//分项成绩名称
|
||||
}
|
||||
paramMap2.put("TEAXM",kcKechengbiao.getSkjs());//教师姓名
|
||||
paramMap2.put("XSXM",zyInfoStudentPar2.getStudentName());//学生姓名
|
||||
paramMap2.put("KID",zyInfoStudentPar2.getId());//主键
|
||||
paramMap2.put("XSBH",zyInfoStudentPar2.getCreateBy());//学号
|
||||
paramMap2.put("FXCJBH",zyInfoStudentPar2.getMainId());//分项成绩编号
|
||||
paramMap2.put("PATH",zyInfoStudentPar2.getFwqPath());//附件路径
|
||||
paramMap2.put("TEABH",zyInfo.getCreateBy());//教工号
|
||||
// paramMap2.put("OPERATE_STATUS","i");//操作状态
|
||||
paramsList2.add(paramMap2);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
System.out.println("=======================================");
|
||||
System.out.println("paramsList2:"+paramsList2);
|
||||
System.out.println("=======================================");
|
||||
//调用师大接口进行上传
|
||||
String interfaceUrl2 = "https://intf.nenu.edu.cn/api/bd-api/post/JW_FXXSCJMX";
|
||||
String data2 = RestTemplateUtils.post(interfaceUrl2,token, paramsList2, MediaType.APPLICATION_JSON_UTF8, String.class);
|
||||
System.out.println("=======================================");
|
||||
System.out.println("data2:"+data2);
|
||||
System.out.println("=======================================");
|
||||
|
||||
zyInfo.setSfsckhcl("1");
|
||||
zyInfo.setSfsckhclTime(new Date());
|
||||
zyInfoService.updateById(zyInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,6 +501,30 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWpcccs() {
|
||||
String url = "https://vims.fanyu.com/toole/jianceorgan/papercheckcount.aspx";
|
||||
//获取外网检测剩余查重次数
|
||||
JSONObject object= getSycs(url,"1");
|
||||
int wwremaincount = object.getIntValue("remaincount");
|
||||
if(wwremaincount<=200){
|
||||
KcWechatSendLog kcWechatSendLog = new KcWechatSendLog();
|
||||
kcWechatSendLog.setOpenid("2016900057");
|
||||
kcWechatSendLog.setYtkcs("维普【外网检测】查重次数不足,剩余"+wwremaincount+"次,请及时充值!");
|
||||
sendWxmessage(kcWechatSendLog);
|
||||
}
|
||||
|
||||
//获取AIGC检测剩余查重次数
|
||||
JSONObject object2= getSycs(url,"3");
|
||||
int aigcremaincount = object2.getIntValue("remaincount");
|
||||
if(aigcremaincount<=200){
|
||||
KcWechatSendLog kcWechatSendLog = new KcWechatSendLog();
|
||||
kcWechatSendLog.setOpenid("2016900057");
|
||||
kcWechatSendLog.setYtkcs("维普【AIGC检测】查重次数不足,剩余"+aigcremaincount+"次,请及时充值!");
|
||||
sendWxmessage(kcWechatSendLog);
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject getSycs(String url,String type){
|
||||
Map<String, String> textMap = new HashMap<String, String>();
|
||||
//可以设置多个input的name,value
|
||||
|
@ -1084,4 +1203,55 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// appId
|
||||
private static final String appId = "wx031697a8ca09a5ce";//东师
|
||||
|
||||
private static final String agentid = "1000065";//
|
||||
// appIdSecret
|
||||
private static final String appIdSecret = "6Qhnge3xfzAQMDX2TcjEyE0vUGP96hP9OTYUsYBze2Y";//东师
|
||||
|
||||
//微信通知点击后跳转的页面
|
||||
private static final String domainTo = "https://smartedu.nenu.edu.cn";
|
||||
|
||||
public void sendWxmessage(KcWechatSendLog kcWechatSendLog) {
|
||||
String openId = kcWechatSendLog.getOpenid();//曹老师账号
|
||||
System.out.println("openId:" + openId + "");
|
||||
if (org.apache.commons.lang3.StringUtils.isNotEmpty(openId)) {
|
||||
try {
|
||||
String urlToken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + appId + "&corpsecret=" + appIdSecret;
|
||||
System.out.println("urlToken: " + urlToken);
|
||||
String res = HttpUtil.get(urlToken);
|
||||
JSONObject jsonObjectToken = JSONObject.parseObject(res);
|
||||
System.out.println("jsonObjectToken:{}" + jsonObjectToken);
|
||||
String accessToken = jsonObjectToken.getString("access_token");
|
||||
System.out.println("accessToken:{}" + accessToken);
|
||||
|
||||
// 微信的基础accessToken
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken;
|
||||
Map<String, Object> sendMag = new HashMap<>();
|
||||
|
||||
// 1、xx老师,你好,您本学期(2023秋)听课要求为:5次,当前实际听课次数:3次,请尽快完成本学期的听课任务。
|
||||
String html = kcWechatSendLog.getYtkcs();
|
||||
html = html ;
|
||||
sendMag.put("content", html);//授课老师推送内容
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
//拼接base参数
|
||||
Map<String, Object> sendBody = new HashMap<>();
|
||||
sendBody.put("touser", openId); // openId
|
||||
sendBody.put("msgtype", "text"); // 消息类型,此时固定为:text
|
||||
sendBody.put("agentid", agentid); // 企业id
|
||||
sendBody.put("text", sendMag); //发送内容
|
||||
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, sendBody, String.class);
|
||||
JSONObject jsonObject2 = JSONObject.parseObject(forEntity.getBody());
|
||||
System.out.println("jsonObject2 : " + jsonObject2);
|
||||
String messageCode = jsonObject2.getString("errcode");
|
||||
String msgId = jsonObject2.getString("msgid");
|
||||
System.out.println("messageCode : " + messageCode + ", msgId: " + msgId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package org.jeecg.modules.tools.dbsdkfzpt;
|
||||
|
||||
import org.apache.tomcat.util.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESKeySpec;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* 字符串加密解密工具,可逆加密,秘钥很重要,一定要自己改秘钥,打死也不要告诉其他人
|
||||
* @author 夏增明
|
||||
* @version 1.0
|
||||
*/
|
||||
public class DesUtil {
|
||||
|
||||
// 密钥,是加密解密的凭据,长度为8的倍数
|
||||
private static final String PASSWORD_CRYPT_KEY = "LianYi37621040";
|
||||
private final static String DES = "DES";
|
||||
|
||||
/**
|
||||
* 加密
|
||||
* @param src 数据源
|
||||
* @param key 密钥,长度必须是8的倍数
|
||||
* @return 返回加密后的数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
|
||||
|
||||
// DES算法要求有一个可信任的随机数源
|
||||
SecureRandom sr = new SecureRandom();
|
||||
|
||||
// 从原始密匙数据创建DESKeySpec对象
|
||||
DESKeySpec dks = new DESKeySpec(key);
|
||||
|
||||
// 创建一个密匙工厂,然后用它把DESKeySpec转换成
|
||||
// 一个SecretKey对象
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
|
||||
|
||||
SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
|
||||
// Cipher对象实际完成加密操作
|
||||
Cipher cipher = Cipher.getInstance(DES);
|
||||
|
||||
// 用密匙初始化Cipher对象
|
||||
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
|
||||
|
||||
// 现在,获取数据并加密
|
||||
// 正式执行加密操作
|
||||
return cipher.doFinal(src);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param src 数据源
|
||||
* @param key 密钥,长度必须是8的倍数
|
||||
* @return 返回解密后的原始数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
|
||||
|
||||
// DES算法要求有一个可信任的随机数源
|
||||
SecureRandom sr = new SecureRandom();
|
||||
// 从原始密匙数据创建一个DESKeySpec对象
|
||||
DESKeySpec dks = new DESKeySpec(key);
|
||||
|
||||
// 创建一个密匙工厂,然后用它把DESKeySpec对象转换成
|
||||
// 一个SecretKey对象
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
|
||||
|
||||
SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
|
||||
// Cipher对象实际完成解密操作
|
||||
Cipher cipher = Cipher.getInstance(DES);
|
||||
|
||||
// 用密匙初始化Cipher对象
|
||||
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
|
||||
|
||||
// 现在,获取数据并解密
|
||||
// 正式执行解密操作
|
||||
return cipher.doFinal(src);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码解密
|
||||
* @param data
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public final static String decrypt(String data) {
|
||||
|
||||
try {
|
||||
String result = new String(decrypt(hex2byte(data.getBytes()), PASSWORD_CRYPT_KEY.getBytes()));
|
||||
System.out.println(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return data;
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码加密
|
||||
* @param password
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public final static String encrypt(String password) {
|
||||
try {
|
||||
return byte2hex(encrypt(password.getBytes(), PASSWORD_CRYPT_KEY.getBytes()));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二行制转字符串
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public static String byte2hex(byte[] b) {
|
||||
|
||||
String hs = "";
|
||||
String stmp = "";
|
||||
for (int n = 0; n < b.length; n++) {
|
||||
stmp = (Integer.toHexString(b[n] & 0XFF));
|
||||
if (stmp.length() == 1)
|
||||
hs = hs + "0" + stmp;
|
||||
else
|
||||
hs = hs + stmp;
|
||||
}
|
||||
return hs.toUpperCase();
|
||||
}
|
||||
|
||||
public static byte[] hex2byte(byte[] b) {
|
||||
|
||||
if ((b.length % 2) != 0)
|
||||
throw new IllegalArgumentException("长度不是偶数");
|
||||
byte[] b2 = new byte[b.length / 2];
|
||||
for (int n = 0; n < b.length; n += 2) {
|
||||
String item = new String(b, n, 2);
|
||||
b2[n / 2] = (byte) Integer.parseInt(item, 16);
|
||||
}
|
||||
return b2;
|
||||
}
|
||||
|
||||
// 测试用例,不需要传递任何参数,直接执行即可。
|
||||
public static void main(String[] args) {
|
||||
// String basestr = "this is 我的 #$%^&()first encrypt program 知道吗?DES算法要求有一个可信任的随机数源 --//*。@@@1";
|
||||
String basestr = "panpan";
|
||||
String str1 = encrypt(basestr);
|
||||
|
||||
System.out.println("原始值: " + basestr);
|
||||
System.out.println("加密后: " + str1);
|
||||
System.out.println("解密后: " + decrypt(str1));
|
||||
System.out.println("为空时 is : " + decrypt(encrypt("")));
|
||||
|
||||
|
||||
System.out.println("======================");
|
||||
System.out.println(decrypt("FA"));
|
||||
|
||||
String plainClientCredentials="b49d35b7704e41f_uuid:0683126daa811b7da48c67ccd3c498aa";
|
||||
|
||||
String base64ClientCredentials = new String(Base64.encodeBase64(plainClientCredentials.getBytes()));
|
||||
System.out.println(base64ClientCredentials);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,313 @@
|
|||
package org.jeecg.modules.tools.dbsdkfzpt;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
public class HttpUtil {
|
||||
|
||||
public static JSONObject SendRequest(String url,String param){
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject SendGetRequest(String url,String param){
|
||||
String res = doGet(url,param);
|
||||
JSONObject obj = JSONObject.fromObject(res);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static JSONObject SendPostRequest(String url,List<NameValuePair> param){
|
||||
String res = doPost2(url,param);
|
||||
JSONObject obj = JSONObject.fromObject(res);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject SendPostTokenRequest(String url,List<NameValuePair> param){
|
||||
String res = doPost(url,param);
|
||||
JSONObject obj = JSONObject.fromObject(res);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static JSONObject SendPostRequest(String url, String param){
|
||||
String res = doPost(url,param);
|
||||
JSONObject obj = JSONObject.fromObject(res);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static String doGet(String url,String param){
|
||||
String result = null;
|
||||
// 获取httpclient
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
url = url+"&"+param;
|
||||
try {
|
||||
//创建post请求
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
// 设置请求和传输超时时间
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(10000).setConnectTimeout(10000).build();
|
||||
httpGet.setConfig(requestConfig);
|
||||
|
||||
response = httpclient.execute(httpGet);
|
||||
// 得到响应信息
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
// 判断响应信息是否正确
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
// 终止并抛出异常
|
||||
httpGet.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
//result = EntityUtils.toString(entity);//不进行编码设置
|
||||
result = EntityUtils.toString(entity, "UTF-8");
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
//关闭所有资源连接
|
||||
if (response != null) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static String doPost(String url,List<NameValuePair> parameForToken){
|
||||
String result = null;
|
||||
// 获取httpclient
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
//创建post请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 设置请求和传输超时时间
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(10000).setConnectTimeout(10000).build();
|
||||
httpPost.setConfig(requestConfig);
|
||||
|
||||
// 提交参数发送请求
|
||||
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(parameForToken, "utf-8");
|
||||
httpPost.setEntity(urlEncodedFormEntity);
|
||||
httpPost.setHeader(new BasicHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"));
|
||||
|
||||
|
||||
System.out.println(EntityUtils.toString(httpPost.getEntity()));
|
||||
|
||||
response = httpclient.execute(httpPost);
|
||||
// 得到响应信息
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
// 判断响应信息是否正确
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
// 终止并抛出异常
|
||||
httpPost.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
//result = EntityUtils.toString(entity);//不进行编码设置
|
||||
result = EntityUtils.toString(entity, "UTF-8");
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
//关闭所有资源连接
|
||||
if (response != null) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static String doPost2(String url,List<NameValuePair> parameForToken){
|
||||
String result = null;
|
||||
// 获取httpclient
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
//创建post请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 设置请求和传输超时时间
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(10000).setConnectTimeout(10000).build();
|
||||
httpPost.setConfig(requestConfig);
|
||||
|
||||
// 提交参数发送请求
|
||||
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(parameForToken, "utf-8");
|
||||
httpPost.setEntity(urlEncodedFormEntity);
|
||||
httpPost.setHeader(new BasicHeader("Content-Type", "application/json"));
|
||||
httpPost.setHeader(new BasicHeader("Authorization", "Basic ZDhiZGU5NjZjYmEyNGVjX3V1aWQ6YTE4MjY3ZjExOTBmZTRjYzcyMTMxNDQ5ZDIyY2FhMDg="));
|
||||
|
||||
|
||||
System.out.println(EntityUtils.toString(httpPost.getEntity()));
|
||||
|
||||
response = httpclient.execute(httpPost);
|
||||
// 得到响应信息
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
// 判断响应信息是否正确
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
// 终止并抛出异常
|
||||
httpPost.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
//result = EntityUtils.toString(entity);//不进行编码设置
|
||||
result = EntityUtils.toString(entity, "UTF-8");
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
//关闭所有资源连接
|
||||
if (response != null) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static String doPost(String httpUrl, String param){
|
||||
StringBuffer result = new StringBuffer();
|
||||
//连接
|
||||
HttpURLConnection connection = null;
|
||||
OutputStream os = null;
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
try{
|
||||
//创建连接对象
|
||||
URL url = new URL(httpUrl);
|
||||
//创建连接
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
//设置请求方式
|
||||
connection.setRequestMethod("POST");
|
||||
//设置连接超时时间
|
||||
connection.setConnectTimeout(15000);
|
||||
//设置读取超时时间
|
||||
connection.setReadTimeout(15000);
|
||||
//设置是否可读取
|
||||
connection.setDoOutput(true);
|
||||
//设置响应是否可读取
|
||||
connection.setDoInput(true);
|
||||
//设置参数类型
|
||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
|
||||
|
||||
if(param!=null&&!param.equals("")){
|
||||
os = connection.getOutputStream();
|
||||
os.write(param.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
//开始连接
|
||||
connection.connect();
|
||||
if(connection.getResponseCode()==200){
|
||||
//获取返回的数据
|
||||
is=connection.getInputStream();
|
||||
if(is!=null){
|
||||
br=new BufferedReader(new InputStreamReader(is,"UTF-8"));
|
||||
String temp = null;
|
||||
while((temp=br.readLine())!=null){
|
||||
result.append(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (MalformedURLException e){
|
||||
e.printStackTrace();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(br!=null){
|
||||
try{
|
||||
br.close();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(is!=null){
|
||||
try{
|
||||
is.close();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
connection.disconnect();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,306 @@
|
|||
package org.jeecg.modules.tools.dbsdkfzpt;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.tomcat.util.codec.binary.Base64;
|
||||
import org.jeecg.modules.wps.controller.KsoSign;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
public class InterfaceDemo {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 获取令牌URL前缀
|
||||
String prefixOauthUrl = "https://intf.nenu.edu.cn/api/bd-api";
|
||||
|
||||
// 调用接口URL
|
||||
String interfaceUrl = "http://192.168.36.25:8082/get/studentsInfoInterface";
|
||||
|
||||
// 开发者帐号,以实际为准
|
||||
String userName = "zhjxfwzx";
|
||||
// 开发者密码,以实际为准
|
||||
String password = "A9BYf7TZDpxg";
|
||||
// 应用编号,以实际为准
|
||||
String appNum = "d8bde966cba24ec_uuid";
|
||||
// 认证码,以实际为准
|
||||
String oauthCode = "a18267f1190fe4cc72131449d22caa08";
|
||||
//第几页(page,pageSize都不填不分页)
|
||||
String pageNum="1";
|
||||
//每页大小(page,pageSize都不填不分页)
|
||||
String pageSize="10";
|
||||
|
||||
// 接口如果定义有参数,则将参数列表添加到此处
|
||||
List<Map<String, String>> paramsList =new ArrayList<>();
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("aaa","bbb");
|
||||
paramsList.add(paramMap);
|
||||
|
||||
//获取token
|
||||
String token=getAccessToken();
|
||||
|
||||
// String token=getAccessToken(prefixOauthUrl,userName,password,appNum,oauthCode);
|
||||
// net.sf.json.JSONObject token=getAccessToken4();
|
||||
System.out.println("================response token====================");
|
||||
System.out.println(token);
|
||||
System.out.println("================response token====================");
|
||||
//获取数据
|
||||
// String data=getInterfaceData(interfaceUrl,token,pageNum,pageSize, paramsList);
|
||||
// System.out.println("================response interfaceData====================");
|
||||
// System.out.println(data);
|
||||
// System.out.println("================response interfaceData====================");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getAccessToken(String prefixUrl,String userName,String password,String appNum,String oauthCode){
|
||||
String token="";
|
||||
try {
|
||||
//NO.1:通过client_id:client_secret 和开发者账号和密码获取授权令牌access_token
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
//通过client_id:client_secret构建认证信息
|
||||
String plainClientCredentials=appNum+":"+oauthCode;
|
||||
String base64ClientCredentials = new String(Base64.encodeBase64(plainClientCredentials.getBytes()));
|
||||
|
||||
//构建请求头信息
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
||||
headers.add("Authorization", "Basic " + base64ClientCredentials);
|
||||
|
||||
//获取access_token
|
||||
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||
|
||||
userName=DesUtil.encrypt(userName);
|
||||
password=DesUtil.encrypt(password);
|
||||
String url= prefixUrl+"/oauth/token?grant_type=password&scope=read&username="+userName+"&password="+password;
|
||||
|
||||
ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.POST, request, Object.class);;
|
||||
|
||||
LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>)response.getBody();
|
||||
|
||||
//从返回结果中获取 access_token
|
||||
token = (String)map.get("access_token");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求无参接口
|
||||
* @param interfaceUrl 请求URL前缀
|
||||
* @param access_token
|
||||
* @param pageNum 第几页(page,pageSize都不填不分页)
|
||||
* @param pageSize 每页大小(page,pageSize都不填不分页)
|
||||
* @return data
|
||||
*/
|
||||
public static String getInterfaceData(String interfaceUrl,String access_token,String pageNum,String pageSize){
|
||||
//NO.2:通过NO.1返回的access_token访问输出接口
|
||||
//构建调用具体接口访问地址
|
||||
// String url = prefixUrl+"/get/studentsInfoInterface";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("access_token", access_token);
|
||||
jsonObject.put("page", pageNum); //第几页(page,pageSize都不填不分页)
|
||||
jsonObject.put("pageSize", pageSize); //每页大小(page,pageSize都不填不分页)
|
||||
//调用restful请求工具类发送请求
|
||||
String reString = RestTemplateUtils.get(interfaceUrl, jsonObject);
|
||||
return reString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求含有参数的接口
|
||||
* @param interfaceUrl 请求URL前缀
|
||||
* @param access_token
|
||||
* @param pageNum 第几页(page,pageSize都不填不分页)
|
||||
* @param pageSize 每页大小(page,pageSize都不填不分页)
|
||||
* @param list 自定义参数
|
||||
* @return data
|
||||
*/
|
||||
public static String getInterfaceData(String interfaceUrl,String access_token,String pageNum,String pageSize,List<Map<String, String>> list){
|
||||
//NO.2:通过NO.1返回的access_token访问输出接口
|
||||
//构建接口访问地址
|
||||
// String url = prefixUrl+"/get/studentsInfoInterface";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("access_token", access_token);
|
||||
jsonObject.put("page", pageNum); //第几页(page,pageSize都不填不分页)
|
||||
jsonObject.put("pageSize", pageSize); //每页大小(page,pageSize都不填不分页)
|
||||
if(list.size()>0){
|
||||
for (Map<String,String> map:list){
|
||||
jsonObject.putAll(map);
|
||||
}
|
||||
}
|
||||
// System.out.println(jsonObject);
|
||||
//调用restful请求工具类发送请求
|
||||
return RestTemplateUtils.get(interfaceUrl, jsonObject);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取access_token令牌
|
||||
* @return access_token
|
||||
*/
|
||||
public static String getAccessToken(){
|
||||
String token="";
|
||||
try {
|
||||
// 获取令牌URL前缀
|
||||
String prefixUrl = "https://intf.nenu.edu.cn/api/bd-api";
|
||||
// 开发者帐号,以实际为准
|
||||
String userName = "D64A8E04B63AE18D1D796914279AEEE3";
|
||||
// 开发者密码,以实际为准
|
||||
String password = "6413C873CD49C96D301B0D7A0EBFA51D";
|
||||
// 应用编号,以实际为准
|
||||
String appNum = "d8bde966cba24ec_uuid";
|
||||
// 认证码,以实际为准
|
||||
String oauthCode = "a18267f1190fe4cc72131449d22caa08";
|
||||
//NO.1:通过client_id:client_secret 和开发者账号和密码获取授权令牌access_token
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
//构建请求头信息
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// headers.add("Content-Type", "application/json");
|
||||
headers.add("Authorization", "Basic ZDhiZGU5NjZjYmEyNGVjX3V1aWQ6YTE4MjY3ZjExOTBmZTRjYzcyMTMxNDQ5ZDIyY2FhMDg=");
|
||||
|
||||
//获取access_token
|
||||
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||
|
||||
// userName=DesUtil.encrypt(userName);
|
||||
// password=DesUtil.encrypt(password);
|
||||
String url= prefixUrl+"/oauth/token?grant_type=password&scope=read&username="+userName+"&password="+password;
|
||||
|
||||
ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.POST, request, Object.class);;
|
||||
|
||||
LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>)response.getBody();
|
||||
|
||||
//从返回结果中获取 access_token
|
||||
token = (String)map.get("access_token");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
public static String getAccessToken3(){
|
||||
try {
|
||||
URL url = new URL("https://intf.nenu.edu.cn/api/bd-api/oauth/token?grant_type=password&scope=read&username=D64A8E04B63AE18D1D796914279AEEE3&password=6413C873CD49C96D301B0D7A0EBFA51D");
|
||||
|
||||
// 打开连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
// connection.setRequestProperty("Host","<calculated when request is sent>");
|
||||
connection.setRequestProperty("Authorization", "Basic ZDhiZGU5NjZjYmEyNGVjX3V1aWQ6YTE4MjY3ZjExOTBmZTRjYzcyMTMxNDQ5ZDIyY2FhMDg=");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
|
||||
// 发送POST请求的数据
|
||||
String postData = "";
|
||||
byte[] outputInBytes = postData.getBytes(StandardCharsets.UTF_8);
|
||||
connection.setDoOutput(true);
|
||||
|
||||
// 写入数据到请求体
|
||||
try (OutputStream out = connection.getOutputStream()) {
|
||||
out.write(outputInBytes);
|
||||
}
|
||||
|
||||
// 获取响应码
|
||||
int responseCode = connection.getResponseCode();
|
||||
System.out.println("Response Code: " + responseCode);
|
||||
|
||||
// 读取响应内容
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 处理响应内容
|
||||
// String response = new String(connection.getInputStream(), StandardCharsets.UTF_8);
|
||||
// System.out.println(response);
|
||||
} else {
|
||||
// 处理错误响应
|
||||
// String errorResponse = new String(connection.getErrorStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
// System.out.println("Error Response: " + errorResponse);
|
||||
}
|
||||
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public static String getAccessToken5() {
|
||||
try {
|
||||
String targetURL = "https://intf.nenu.edu.cn/api/bd-api/oauth/token";
|
||||
URL url = new URL(targetURL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
|
||||
// 设置通用请求属性
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
|
||||
// 如果需要,添加认证
|
||||
// String authentication = "username:password";
|
||||
// String encodedAuthentication = new String(Base64.getEncoder().encode(authentication.getBytes()));
|
||||
connection.setRequestProperty ("Authorization", "Basic ZDhiZGU5NjZjYmEyNGVjX3V1aWQ6YTE4MjY3ZjExOTBmZTRjYzcyMTMxNDQ5ZDIyY2FhMDg=");
|
||||
|
||||
// 发送POST请求必须设置如下两行
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
|
||||
// 发送请求参数
|
||||
String jsonInputString = "{\"grant_type\":\"password\",\"scope\":\"read\",\"username\":\"D64A8E04B63AE18D1D796914279AEEE3\",\"password\":\"6413C873CD49C96D301B0D7A0EBFA51D\"}";
|
||||
try(OutputStream os = connection.getOutputStream()) {
|
||||
byte[] input = jsonInputString.getBytes();
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
// 获取响应码
|
||||
int responseCode = connection.getResponseCode();
|
||||
System.out.println("POST Response Code :: " + responseCode);
|
||||
|
||||
// 根据需要处理响应内容
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 处理响应
|
||||
}
|
||||
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static net.sf.json.JSONObject getAccessToken4(){
|
||||
try {
|
||||
List<NameValuePair> params=null;
|
||||
try {
|
||||
params = new ArrayList<>();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String httpUrl = "https://intf.nenu.edu.cn/api/bd-api/oauth/token?grant_type=password&scope=read&username=D64A8E04B63AE18D1D796914279AEEE3&password=6413C873CD49C96D301B0D7A0EBFA51D";
|
||||
//String httpUrl = url+course+"?action=addClassStudentMultiple";
|
||||
return HttpUtil.SendPostRequest(httpUrl, params);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,325 @@
|
|||
package org.jeecg.modules.tools.dbsdkfzpt;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.FormHttpMessageConverter;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Class Name: RestTemplateUtils
|
||||
* Description:
|
||||
* @author: linweisen
|
||||
* @mail: linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
* @version: 1.0
|
||||
*
|
||||
*/
|
||||
public class RestTemplateUtils {
|
||||
/**
|
||||
* Class Name: HttpEntityEnclosingDeleteRequest
|
||||
* Description: 重写delete方法 为了RestTemplate支持Delete方法
|
||||
* @author: linweisen
|
||||
* @mail: linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
* @version: 1.0
|
||||
*
|
||||
*/
|
||||
public static class HttpEntityEnclosingDeleteRequest extends HttpEntityEnclosingRequestBase {
|
||||
|
||||
public HttpEntityEnclosingDeleteRequest(final URI uri) {
|
||||
super();
|
||||
setURI(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return "DELETE";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Name: DefaultResponseErrorHandler
|
||||
* Description:
|
||||
* @author: linweisen
|
||||
* @mail: linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
* @version: 1.0
|
||||
*/
|
||||
private static class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse response) throws IOException {
|
||||
return response.getStatusCode().value() != HttpServletResponse.SC_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(response.getBody()));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = null;
|
||||
while ((str = br.readLine()) != null) {
|
||||
sb.append(str);
|
||||
}
|
||||
try {
|
||||
throw new Exception(sb.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Name: get
|
||||
* Description:
|
||||
* @param url
|
||||
* @param params
|
||||
* @return
|
||||
* @return String
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
public static String get(String url, JSONObject params) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
|
||||
String response = restTemplate.getForObject(expandURL(url, params.keySet()), String.class, params);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Name: post
|
||||
* Description: 将参数都拼接在url之后
|
||||
* @param url
|
||||
* @param params
|
||||
* @param mediaType
|
||||
* @return
|
||||
* @return String
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
public static String post(String url, JSONObject params, MediaType mediaType) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
// 拿到header信息
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.setContentType(mediaType);
|
||||
HttpEntity<JSONObject> requestEntity = (mediaType == MediaType.APPLICATION_JSON || mediaType == MediaType.APPLICATION_JSON_UTF8) ?
|
||||
new HttpEntity<JSONObject>(params, requestHeaders) : new HttpEntity<JSONObject>(null, requestHeaders);
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
|
||||
String result = (mediaType == MediaType.APPLICATION_JSON || mediaType == MediaType.APPLICATION_JSON_UTF8) ?
|
||||
restTemplate.postForObject(url, requestEntity, String.class) :
|
||||
restTemplate.postForObject(expandURL(url, params.keySet()), requestEntity, String.class, params);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Name: post
|
||||
* Description: 发送json格式数据
|
||||
* @param url
|
||||
* @param params
|
||||
* @param mediaType
|
||||
* @param clz
|
||||
* @return
|
||||
* @return T
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static <T> T post(String url, String access_token, List list, MediaType mediaType, Class<T> clz) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
// 这是为 MediaType.APPLICATION_FORM_URLENCODED 格式HttpEntity 数据 添加转换器
|
||||
// 还有就是,如果是APPLICATION_FORM_URLENCODED方式发送post请求,
|
||||
// 也可以直接HttpHeaders requestHeaders = new
|
||||
// HttpHeaders(createMultiValueMap(params),true),就不用增加转换器了
|
||||
restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
|
||||
// 设置header信息
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.setContentType(mediaType);
|
||||
url += "?access_token=" + access_token;
|
||||
|
||||
/*HttpEntity<?> requestEntity = (mediaType == MediaType.APPLICATION_JSON || mediaType == MediaType.APPLICATION_JSON_UTF8) ? new HttpEntity<JSONObject>(params, requestHeaders) :
|
||||
(mediaType == MediaType.APPLICATION_FORM_URLENCODED ? new HttpEntity<MultiValueMap>(createMultiValueMap(params), requestHeaders) : new HttpEntity<>(null, requestHeaders));*/
|
||||
HttpEntity<?> requestEntity = new HttpEntity<List>(list, requestHeaders);
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
|
||||
|
||||
T result = restTemplate.postForObject(url, requestEntity, clz);
|
||||
// T result = (mediaType == MediaType.APPLICATION_JSON || mediaType == MediaType.APPLICATION_JSON_UTF8) ? restTemplate.postForObject(url, requestEntity, clz)
|
||||
// : restTemplate.postForObject(mediaType == MediaType.APPLICATION_FORM_URLENCODED ? url : expandURL(url, params.keySet()), requestEntity, clz, params);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Name: put
|
||||
* Description:
|
||||
* @param url
|
||||
* @param params
|
||||
* @param mediaType
|
||||
* @return
|
||||
* @return String
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
public static String put(String url, JSONObject params, MediaType mediaType) {
|
||||
try {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
// 拿到header信息
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.setContentType(mediaType);
|
||||
HttpEntity<JSONObject> requestEntity = (mediaType == MediaType.APPLICATION_JSON || mediaType == MediaType.APPLICATION_JSON_UTF8) ? new HttpEntity<JSONObject>(params, requestHeaders) : new HttpEntity<JSONObject>(null, requestHeaders);
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
|
||||
restTemplate.put(url, requestEntity, String.class);
|
||||
|
||||
return "success";
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Name: delete
|
||||
* Description:
|
||||
* @param url
|
||||
* @param params
|
||||
* @param mediaType
|
||||
* @return
|
||||
* @return String
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
public static String delete(String url, JSONObject params, MediaType mediaType) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {
|
||||
@Override
|
||||
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
|
||||
if (HttpMethod.DELETE == httpMethod) {
|
||||
return new HttpEntityEnclosingDeleteRequest(uri);
|
||||
}
|
||||
return super.createHttpUriRequest(httpMethod, uri);
|
||||
}
|
||||
});
|
||||
|
||||
// 拿到header信息
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.setContentType(mediaType);
|
||||
HttpEntity<JSONObject> requestEntity = (mediaType == MediaType.APPLICATION_JSON || mediaType == MediaType.APPLICATION_JSON_UTF8) ? new HttpEntity<JSONObject>(params, requestHeaders) : new HttpEntity<JSONObject>(null, requestHeaders);
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
|
||||
// restTemplate.delete(url, requestEntity, Map.class);
|
||||
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class);
|
||||
|
||||
return exchange.getBody();
|
||||
}
|
||||
|
||||
public static <T> T exchange(String url, HttpMethod method, JSONObject params, Class<T> bodyType) {
|
||||
// 请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
MimeType mimeType = MimeTypeUtils.parseMimeType("application/json");
|
||||
MediaType mediaType = new MediaType(mimeType.getType(), mimeType.getSubtype(), Charset.forName("UTF-8"));
|
||||
// 请求体
|
||||
headers.setContentType(mediaType);
|
||||
// 提供json转化功能
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = null;
|
||||
try {
|
||||
if (!params.isEmpty()) {
|
||||
str = mapper.writeValueAsString(params);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 发送请求
|
||||
HttpEntity<String> entity = new HttpEntity<>(str, headers);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<T> resultEntity = restTemplate.exchange(url, method, entity, bodyType);
|
||||
return resultEntity.getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Method Name: createMultiValueMap
|
||||
* Description:
|
||||
* @param params
|
||||
* @return
|
||||
* @return MultiValueMap<String,String>
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MultiValueMap<String, String> createMultiValueMap(JSONObject params) {
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
for (String key : params.keySet()) {
|
||||
if (params.get(key) instanceof List) {
|
||||
for (Iterator<String> it = ((List<String>) params.get(key)).iterator(); it.hasNext();) {
|
||||
String value = it.next();
|
||||
map.add(key, value);
|
||||
}
|
||||
} else {
|
||||
map.add(key, params.getString(key));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Name: expandURL
|
||||
* Description:
|
||||
* @param url
|
||||
* @param keys
|
||||
* @return
|
||||
* @return String
|
||||
* @exception
|
||||
* @author linweisen
|
||||
* @mail linweisen@ly-sky.com
|
||||
* @date: 2017年8月23日
|
||||
*/
|
||||
private static String expandURL(String url, Set<?> keys) {
|
||||
final Pattern QUERY_PARAM_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?");
|
||||
Matcher mc = QUERY_PARAM_PATTERN.matcher(url);
|
||||
StringBuilder sb = new StringBuilder(url);
|
||||
if (!mc.find()) {
|
||||
sb.append("&");
|
||||
} else {
|
||||
sb.append("?");
|
||||
}
|
||||
|
||||
for (Object key : keys) {
|
||||
sb.append(key).append("=").append("{").append(key).append("}").append("&");
|
||||
}
|
||||
return sb.deleteCharAt(sb.length() - 1).toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package org.jeecg.modules.tools.dbsdkfzpt;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
/**
|
||||
* classin转换工具
|
||||
**/
|
||||
public class TransformUtils {
|
||||
|
||||
/**
|
||||
* map转换SID=2339736&safeKey=f834fff59eb3bc8a2ff26a3cb59155f0类型字符串
|
||||
*/
|
||||
public static String mapToParam(Map<String,String> map) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String[] keyArr = (String[]) map.keySet().toArray(new String[map.keySet().size()]);//获取map中的key转为array
|
||||
for (int i=0;i<keyArr.length;i++) {
|
||||
if(i==keyArr.length-1){
|
||||
sb.append(keyArr[i] + "=" + map.get(keyArr[i]));
|
||||
}else{
|
||||
sb.append(keyArr[i] + "=" + map.get(keyArr[i]) + "&");
|
||||
}
|
||||
}
|
||||
String param = sb.toString();
|
||||
return param;
|
||||
}
|
||||
|
||||
/***
|
||||
* MD5加密 生成32位md5码
|
||||
*/
|
||||
public static String stringToMD5(String str){
|
||||
if (str == null || str.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
try {
|
||||
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
||||
mdTemp.update(str.getBytes("UTF-8"));
|
||||
|
||||
byte[] md = mdTemp.digest();
|
||||
int j = md.length;
|
||||
char buf[] = new char[j * 2];
|
||||
int k = 0;
|
||||
for (int i = 0; i < j; i++) {
|
||||
byte byte0 = md[i];
|
||||
buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
|
||||
buf[k++] = hexDigits[byte0 & 0xf];
|
||||
}
|
||||
return new String(buf).toLowerCase();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<NameValuePair> mapToList(Map<String,String> map)throws Exception{
|
||||
List<NameValuePair> parameForToken = new ArrayList<NameValuePair>();
|
||||
String[] keyArr = (String[]) map.keySet().toArray(new String[map.keySet().size()]);//获取map中的key转为array
|
||||
for (int i=0;i<keyArr.length;i++) {
|
||||
System.out.print(keyArr[i]+":");
|
||||
System.out.println(map.get(keyArr[i]));
|
||||
parameForToken.add(new BasicNameValuePair(keyArr[i], map.get(keyArr[i])));
|
||||
}
|
||||
return parameForToken;
|
||||
}
|
||||
|
||||
}
|
|
@ -99,6 +99,13 @@ public class CommonController {
|
|||
// 获取上传文件对象
|
||||
MultipartFile file = multipartRequest.getFile("file");
|
||||
|
||||
Long fileSize = file.getSize();
|
||||
if (fileSize > 1024 * 1024 * 200) {
|
||||
result.setMessage("文件大小不能超过10M");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
savePath = upload(bizPath, file);
|
||||
if(oConvertUtils.isNotEmpty(savePath)){
|
||||
result.setMessage(savePath);
|
||||
|
@ -128,6 +135,9 @@ public class CommonController {
|
|||
bizPath = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
|
||||
//update-begin-author:liusq date:20221102 for: 过滤上传文件类型
|
||||
FileTypeFilter.fileTypeFilter(file);
|
||||
|
@ -320,6 +330,12 @@ public class CommonController {
|
|||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = multipartRequest.getFile("file");
|
||||
// 5242880
|
||||
// 1,048,576
|
||||
Long fileSize = file.getSize();
|
||||
if (fileSize > 1024 * 1024 * 100){
|
||||
throw new JeecgBootException("上传文件大小不能超过200M!");
|
||||
}
|
||||
|
||||
String savePath = this.uploadLocal(file, partNumber, bizPath + File.separator + fileMd5);
|
||||
|
||||
|
|
Loading…
Reference in New Issue