This commit is contained in:
zhouwentao 2024-06-14 09:46:48 +08:00
parent 29efeb309b
commit 329833e5a8
4 changed files with 146 additions and 14 deletions

View File

@ -22,7 +22,7 @@ public class RestUtil {
private static String domain = null;
private static String path = null;
private static String getDomain() {
if (domain == null) {
domain = SpringContextUtils.getDomain();
@ -117,6 +117,13 @@ public class RestUtil {
return postNative(url, variables, params).getBody();
}
/**
* 发送 Post 请求
*/
public static JSONObject post(String url, JSONObject variables, JSONObject params,JSONObject headers) {
return postNative(url, variables, params,headers).getBody();
}
/**
* 发送 POST 请求返回原生 ResponseEntity 对象
*/
@ -124,6 +131,14 @@ public class RestUtil {
return request(url, HttpMethod.POST, variables, params);
}
/**
* 发送 POST 请求返回原生 ResponseEntity 对象
*/
public static ResponseEntity<JSONObject> postNative(String url, JSONObject variables, JSONObject params,JSONObject headers) {
return request(url, HttpMethod.POST, variables, params,headers);
}
/**
* 发送 put 请求
*/
@ -180,6 +195,18 @@ public class RestUtil {
return request(url, method, getHeaderApplicationJson(), variables, params, JSONObject.class);
}
/**
* 发送请求
*/
public static ResponseEntity<JSONObject> request(String url, HttpMethod method, JSONObject variables, JSONObject params,JSONObject headers) {
HttpHeaders headerApplicationJson = getHeaderApplicationJson();
for (String s : headers.keySet()) {
headerApplicationJson.add(s,headers.getString(s));
}
return request(url, method, headerApplicationJson, variables, params, JSONObject.class);
}
/**
* 发送请求
*

View File

@ -1,10 +1,7 @@
package org.jeecg.modules.yx.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
@ -18,24 +15,19 @@ import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.modules.yx.constant.YxConstant;
import org.jeecg.modules.yx.dto.LiNianShuJuBenDTO;
import org.jeecg.modules.yx.dto.LiNianShuJuDTO;
import org.jeecg.modules.yx.dto.LiNianShuJuZhuanDTO;
import org.jeecg.modules.yx.entity.*;
import org.jeecg.modules.yx.service.IYxHistoryMajorEnrollService;
import org.jeecg.modules.yx.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.yx.service.IYxHistoryScoreControlLineService;
import org.jeecg.modules.yx.service.IYxMajorService;
import org.jeecg.modules.yx.service.IYxSchoolService;
import org.jeecg.modules.yx.util.ScoreUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -62,6 +54,10 @@ public class YxHistoryMajorEnrollController extends JeecgController<YxHistoryMaj
@Autowired
private IYxSchoolService yxSchoolService;
@Autowired
private IYxSchoolChildService yxSchoolChildService;
@Autowired
private IYxSchoolMajorService yxSchoolMajorService;
@Autowired
private IYxHistoryMajorEnrollService yxHistoryMajorEnrollService;
@Autowired
private IYxHistoryScoreControlLineService yxHistoryScoreControlLineService;
@ -237,6 +233,58 @@ public class YxHistoryMajorEnrollController extends JeecgController<YxHistoryMaj
return super.exportXls(request, yxHistoryMajorEnroll, YxHistoryMajorEnroll.class, "历年录取数据表");
}
/**
* 导出excel
*
* @param request
*/
@RequiresPermissions("yx:yx_history_major_enroll:exportXls")
@RequestMapping(value = "/exportXlsBySchoolMajor")
public ModelAndView exportXlsBySchoolMajor(HttpServletRequest request) {
List<YxHistoryMajorEnroll> dataList = yxHistoryMajorEnrollService.list(new LambdaQueryWrapper<YxHistoryMajorEnroll>()
.eq(YxHistoryMajorEnroll::getYear,"2023")
.in(YxHistoryMajorEnroll::getBatch,"高职高专"));
Set<String> notAddSet = new LinkedHashSet<>();
for (YxHistoryMajorEnroll y : dataList) {
notAddSet.add(y.getSchoolCode()+"_"+y.getEnrollmentCode()+"_"+y.getMajorType()+"_"+y.getCategory());
}
List<YxSchoolMajor> schoolMajorList = yxSchoolMajorService.list(new LambdaQueryWrapper<YxSchoolMajor>()
.in(YxSchoolMajor::getBatch,"高职高专"));
List<YxSchoolChild> schoolChildList = yxSchoolChildService.list();
Map<String, String> schoolNameMap = schoolChildList.stream().collect(Collectors.toMap(YxSchoolChild::getSchoolCode, YxSchoolChild::getSchoolName));
String schoolName = "";
YxHistoryMajorEnroll yxHistoryMajorEnroll = null;
for (YxSchoolMajor yxSchoolMajor : schoolMajorList) {
if (notAddSet.contains(yxSchoolMajor.getSchoolCode()+"_"+yxSchoolMajor.getEnrollmentCode()+"_"+yxSchoolMajor.getMajorType()+"_"+yxSchoolMajor.getCategory())) {
continue;
}
yxHistoryMajorEnroll = new YxHistoryMajorEnroll();
schoolName = schoolNameMap.getOrDefault(yxSchoolMajor.getSchoolCode(), "");
BeanUtils.copyProperties(yxSchoolMajor,yxHistoryMajorEnroll);
yxHistoryMajorEnroll.setSchoolName(schoolName);
yxHistoryMajorEnroll.setEnrollNum(yxSchoolMajor.getPlanNum());
yxHistoryMajorEnroll.setRulesEnrollProbability(yxSchoolMajor.getPrivateRulesEnrollProbability());
yxHistoryMajorEnroll.setProbabilityOperator(yxSchoolMajor.getPrivateProbabilityOperator());
if (yxSchoolMajor.getTuition()!=null) {
yxHistoryMajorEnroll.setTuition(yxSchoolMajor.getTuition().toString());
}
dataList.add(yxHistoryMajorEnroll);
}
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
// 导出文件名称
mv.addObject(NormalExcelConstants.FILE_NAME, "23高职高专待录数据");
// 注解对象Class
mv.addObject(NormalExcelConstants.CLASS, YxHistoryMajorEnroll.class);
// 自定义表格参数
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("历年录取数据表", "导出人:admin", "历年录取数据表"));
// 导出数据列表
mv.addObject(NormalExcelConstants.DATA_LIST, dataList);
return mv;
}
/**
* 通过excel导入数据
*/

View File

@ -213,6 +213,7 @@ public class YxCalculationMajorServiceImpl extends ServiceImpl<YxCalculationMajo
pageList.setTotal(total);//总记录数
pageList.setCurrent(pageNum);
pageList.setSize(pageSize);
convertRecommendMajorListToNull(recommendMajorDTOList);
pageList.setRecords(recommendMajorDTOList);
artRecommendMajorBaseDTO.setPageList(pageList);
return artRecommendMajorBaseDTO;
@ -250,10 +251,25 @@ public class YxCalculationMajorServiceImpl extends ServiceImpl<YxCalculationMajo
List<RecommendMajorDTO> recommendMajorList = baseMapper.recommendMajorList(activeCurrentUserScore.getCalculationTableName(),queryRecommendMajorVO);
yxHistoryMajorEnrollService.recommendMajorDTOListSetHistoryInfo(recommendMajorList);
ArtRecommendMajorBaseDTO artRecommendMajorBaseDTO = new ArtRecommendMajorBaseDTO();
convertRecommendMajorListToNull(recommendMajorList);
artRecommendMajorBaseDTO.setList(recommendMajorList);
return artRecommendMajorBaseDTO;
}
/**
* 转变要隐藏的数据
* @param recommendMajorList
*/
private static void convertRecommendMajorListToNull(List<RecommendMajorDTO> recommendMajorList) {
List<String> rulesEnrollProbabilitySxList = Arrays.asList("专过文排", "文8专2", "文*0.8+文*0.5", "文7专3", "文*0.7+文*0.75", "文6专4", "文*0.6+专*1", "文5专5", "文*0.5+专*1.25");
recommendMajorList.forEach(r->{
r.setPlanNum(null);
if (StringUtils.isNotBlank(r.getRulesEnrollProbabilitySx()) && !rulesEnrollProbabilitySxList.contains(r.getRulesEnrollProbabilitySx())) {
r.setRulesEnrollProbability(null);
}
});
}
@Override
public ArtRecommendMajorBaseDTO checkLevelNum(List<RecommendMajorDTO> recommendMajorList) {
int number = 0;
@ -340,6 +356,7 @@ public class YxCalculationMajorServiceImpl extends ServiceImpl<YxCalculationMajo
pageList.setTotal(total);//总记录数
pageList.setCurrent(pageNum);
pageList.setSize(pageSize);
convertRecommendMajorListToNull(recommendMajorDTOList);
pageList.setRecords(recommendMajorDTOList);
artRecommendMajorBaseDTO.setPageList(pageList);
return artRecommendMajorBaseDTO;

View File

@ -1,5 +1,14 @@
package org.jeecg.modules.yx.util;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.util.RestUtil;
import javax.servlet.http.HttpServletRequest;
/**
@ -10,6 +19,37 @@ import javax.servlet.http.HttpServletRequest;
public class IpKit {
private final static String UNKNOWN = "unknown";
public static void main(String[] args) {
String url = "http://ai.izcsz.com/api/v1/chat/completions";
String authorization = "Bearer fastgpt-MBOxnysyhuzMMuLijtq1qYQa6dwIo6AsB0lR5L2r5ommMhBrRd0g9OKNwx4E6";
String contentType = "application/json";
JSONObject jsonObject = new JSONObject();
jsonObject.put("chatId", "abcd");
jsonObject.put("stream", false);
jsonObject.put("detail", false);
JSONObject variables = new JSONObject();
variables.put("nick", "亮亮");
jsonObject.put("variables", variables);
// 创建一个 JSONArray 来包含消息对象
JSONArray messagesArray = new JSONArray();
JSONObject messageObject = new JSONObject();
messageObject.put("content", "坦克700北京多少钱能买");
messageObject.put("role", "user");
// 将消息对象添加到数组中
messagesArray.add(messageObject);
// 将数组赋值给 "messages" 字段
jsonObject.put("messages", messagesArray);
JSONObject headerJson = new JSONObject();
headerJson.put("Authorization", authorization);
headerJson.put("Content-Type", contentType);
JSONObject post = RestUtil.post(url, null, jsonObject,headerJson);
System.out.println(post);
}
public static String getRealIp(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {