Compare commits

..

2 Commits

Author SHA1 Message Date
ic_excellent 40b268455b Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
2023-06-16 18:14:11 +08:00
ic_excellent e4787fc0c6 动态生成class 2023-06-16 18:12:23 +08:00
10 changed files with 526 additions and 8 deletions

View File

@ -38,6 +38,12 @@
<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.27.0-GA</version>
</dependency>
<!-- mapstruct -->
<dependency>
<groupId>org.mapstruct</groupId>

View File

@ -0,0 +1,73 @@
package com.api.bokang.xiao.cus_login.controller;
import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import com.api.bokang.xiao.cus_login.service.VerifyCodeService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;
/**
* @ClassName InvoiceSelectController
* @Author
* @Date 2023/2/2 16:21
* @Description <h1></h1>
**/
@Path("/xbk/cusLogin")
public class VerifyController {
private final Logger log = Util.getLogger();
private final VerifyCodeService verifyCodeService = new VerifyCodeService();
/**
* <h2></h2>
* @param request
* @param response
* @param param
* @return
*/
@Path("/getCode")
@POST
@Produces(MediaType.APPLICATION_JSON)
public String getCode(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
try{
log.info("into getCode success params ==> "+param);
String verifyCode = verifyCodeService.getVerifyCode(param);
return ApiResult.success(verifyCode);
}catch (Exception e){
log.error("getCode error ==> \n"+Util.getErrString(e));
return ApiResult.error(e.getMessage());
}
}
/**
* <h2></h2>
* @param request
* @param response
* @param param
* @return
*/
@Path("/checkCode")
@POST
@Produces(MediaType.APPLICATION_JSON)
public String checkCode(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
try{
log.info("into checkCode success params ==> "+param);
return ApiResult.success(verifyCodeService.checkVerifyCode(param));
}catch (Exception e){
log.error("checkCode error ==> \n"+Util.getErrString(e));
return ApiResult.error(e.getMessage());
}
}
}

View File

@ -0,0 +1,60 @@
package com.api.bokang.xiao.cus_login.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import aiyh.utils.annotation.recordset.Update;
import java.util.List;
import java.util.Map;
/**
* @ClassName DzInvoiceMapper
* @Author
* @Date 2023/2/2 17:03
* @Description <h1></h1>
**/
@SqlMapper
public interface DzInvoiceMapper {
/**
* <h2>id</h2>
* @param ids id
* @return
*/
@Select("select * from APInvoice where id in ($t{ids})")
List<Map<String,Object>> queryInvoiceList(@ParamMapper("ids") String ids);
/**
* <h2></h2>
* @param checkStatus
* @param fieldId
* @param fieldValue
* @return
*/
@Update("update fnaInvoiceLedger set check_status = #{checkStatus} where $t{fieldId} = #{fieldValue}")
boolean updateInvoiceCheckStatus(@ParamMapper("checkStatus") int checkStatus,
@ParamMapper("fieldId") String fieldId,
@ParamMapper("fieldValue") Object fieldValue);
/**
* <h2></h2>
* @param checkStatus
* @param fieldId
* @param fieldValue
* @return
*/
@Update("update fnaInvoiceLedger set check_status = #{checkStatus} where $t{fieldId} in ($t{fieldValue})")
boolean batchUpdateInvoiceCheckStatus(@ParamMapper("checkStatus") int checkStatus,
@ParamMapper("fieldId") String fieldId,
@ParamMapper("fieldValue") String fieldValue);
/**
* <h2></h2>
* @return
*/
@Select("select * from fnaInvoiceLedger where (check_status = 2 or check_status = 3) and hxjksflr = 'Y'")
List<Map<String,Object>> queryOnChooseInvoices();
}

View File

@ -0,0 +1,54 @@
package com.api.bokang.xiao.cus_login.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.cloudstore.dev.api.util.Util_DataCache;
import org.apache.log4j.Logger;
import java.util.Map;
/**
* @ClassName VerifyCodeService
* @Author
* @Date 2023/6/14 14:49
* @Description <h1></h1>
**/
public class VerifyCodeService {
private final HttpUtils httpUtils = new HttpUtils();
private final Logger log = Util.getLogger();
/**
*
* @param param
* @return
*/
public String getVerifyCode(Map<String,Object> param){
String loginUser = Util.null2String(param.get("loginUser"));
//todo 发送请求获取验证码
//将验证码加入缓存中
Util_DataCache.setObjVal(loginUser,"9088",60);
return "";
}
/**
*
* @param param
* @return
*/
public boolean checkVerifyCode(Map<String,Object> param){
String loginUser = Util.null2String(param.get("loginUser"));
String verifyCode = Util.null2String(param.get("verifyCode"));
String tempVerifyCode = Util.null2String(Util_DataCache.getObjVal(loginUser));
if("".equals(tempVerifyCode)){
throw new CustomerException("验证码已过期!请重新获取验证码");
}
if(verifyCode.equals(tempVerifyCode)){
Util_DataCache.clearVal(loginUser);
return true;
}
throw new CustomerException("验证码不正确!请重新输入");
}
}

View File

@ -12,11 +12,14 @@ import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
@ -77,4 +80,28 @@ public class BankController {
}
}
@POST
@Path("/export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response exportExcel(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) throws IOException {
try {
log.info("====== into exportExcel success =======");
log.info("param:"+param);
String dialogTitle = Util.null2String(param.get("dialogTitle"));
String fileName = dialogTitle + Util.getTime("yyyy-MM-dd") + ".xlsx";
StreamingOutput streamingOutput = outputStream -> {
bankService.export(outputStream,param);
};
log.info("fileName==>"+fileName);
String encodedFileName = URLEncoder.encode(fileName, "UTF-8");
return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM)
// 指定编码方式为 UTF-8
.header("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName)
.build();
}catch (Exception e){
log.error("exportExcel error ==> "+Util.getErrString(e));
return Response.ok(ApiResult.error("导出文件失败!"), MediaType.APPLICATION_JSON).build();
}
}
}

View File

@ -1,13 +1,19 @@
package com.api.bokang.xiao.zhenn.service;
import aiyh.utils.Util;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.fastjson.JSON;
import com.api.bokang.xiao.zhenn.mapper.BankMapper;
import com.api.bokang.xiao.zhenn.util.GenerateClassUtil;
import org.apache.log4j.Logger;
import weaver.bokang.xiao.common.CommonUtil;
import weaver.bokang.xiao.common.mapper.WorkflowMapper;
import weaver.hrm.User;
import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -107,8 +113,8 @@ public class BankService {
bankBaseInfo.put("bankAccount",bankAccount);
//求总和
Map<String, Object> amountMap = new HashMap<>();
double bankDayAmount = this.queryBankDayAmount(param);
double bankStatementBalance = this.queryBankStatementBalance(param);
double bankDayAmount = this.queryBankStatementBalance(param);//sap余额信息
double bankStatementBalance = this.queryBankDayAmount(param);//银行余额信息
double bankInDifference = bankInTable.stream().mapToDouble(item -> Double.parseDouble(item.get("amount").toString())).sum();
double oaInDifference = 0;
double bankOutDifference = bankOutTable.stream().mapToDouble(item -> Double.parseDouble(item.get("amount").toString())).sum();
@ -165,4 +171,22 @@ public class BankService {
return bankMapper.queryBankStatementBalance(param);
}
/**
* Excel
* @param outputStream
* @param param
*/
public void export(OutputStream outputStream, Map<String, Object> param) {
log.info("导出Excel export");
List<Map<String,Object>> columns = (List<Map<String, Object>>) param.get("columns");
List<Map<String,Object>> dataSource = (List<Map<String, Object>>) param.get("dataSource");
String className = Util.null2String(param.get("type"));
Map<String,Object> classMessage = new HashMap<>();
classMessage.put("columns",columns);
classMessage.put("className",className);
Class<?> aClass = GenerateClassUtil.generateClassByMap(classMessage);
List<Object> objects = GenerateClassUtil.covertClassList(dataSource, aClass);
log.info("excel List ==>"+objects.size());
EasyExcel.write(outputStream, aClass).sheet("Sheet1").doWrite(objects);
}
}

View File

@ -0,0 +1,129 @@
package com.api.bokang.xiao.zhenn.util;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.excel.annotation.ExcelProperty;
import javassist.*;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ConstPool;
import javassist.bytecode.annotation.Annotation;
import javassist.bytecode.annotation.ArrayMemberValue;
import javassist.bytecode.annotation.MemberValue;
import javassist.bytecode.annotation.StringMemberValue;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.stream.Collectors;
/**
* @ClassName GenerateClassUtil
* @Author
* @Date 2023/6/16 11:04
* @Description <h1></h1>
**/
public class GenerateClassUtil {
private static final Logger log = Util.getLogger();
private static final Map<String,Class<?>> CLASS_MAP = new HashMap<>();
/**
* javassistclass
* @param classMessage
* @return Class<?>
*/
public static Class<?> generateClassByMap(Map<String,Object> classMessage){
String className = Util.null2String(classMessage.get("className"));
//className = className+System.currentTimeMillis();
List<Map<String, String>> columns = (List<Map<String, String>>) classMessage.get("columns");
if(StringUtils.isBlank(className)){
throw new CustomerException("GenerateClass Exception 类名不能为空!!!");
}
if(Objects.isNull(columns) || columns.isEmpty()){
throw new CustomerException("GenerateClass Exception 列信息不能为空!!!");
}
try {
Class<?> cacheClass = CLASS_MAP.get(className);
if(Objects.nonNull(cacheClass)){
return cacheClass;
}
// 创建 ClassPool 对象
ClassPool pool = ClassPool.getDefault();
CtClass cc = null;
//从缓存中获取类
try {
cc = pool.getCtClass(className);
if(Objects.isNull(cc)) {
// 创建一个新的类
cc = pool.makeClass(className);
}
return cc.toClass();
}catch (NotFoundException e){
// 创建一个新的类
cc = pool.makeClass(className);
}
for (Map<String, String> column : columns) {
String title = column.get("title");
String dataIndex = column.get("dataIndex");
CtField field = new CtField(ClassPool.getDefault().get(String.class.getName()), dataIndex, cc);
field.setModifiers(Modifier.PRIVATE);
cc.addField(field);
cc.addMethod(CtNewMethod.setter("set" + dataIndex.substring(0, 1).toUpperCase() + dataIndex.substring(1), field));
cc.addMethod(CtNewMethod.getter("get" + dataIndex.substring(0, 1).toUpperCase() + dataIndex.substring(1), field));
field.getFieldInfo().addAttribute(new AnnotationsAttribute(field.getFieldInfo().getConstPool(), AnnotationsAttribute.visibleTag));
// 添加 ExcelProperty 注解
ConstPool cp = cc.getClassFile().getConstPool();
AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
Annotation annotation = new Annotation(ExcelProperty.class.getName(), cp);
//annotation.addMemberValue("value", new StringMemberValue(Arrays.toString(new String[] {title}), cp));
StringMemberValue stringMemberValue = new StringMemberValue(title, cp);
MemberValue[] memberValues = new MemberValue[]{stringMemberValue};
ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cp);
arrayMemberValue.setValue(memberValues);
annotation.addMemberValue("value", arrayMemberValue);
annotationsAttribute.addAnnotation(annotation);
field.getFieldInfo().addAttribute(annotationsAttribute);
}
Class<?> aClass = cc.toClass();
CLASS_MAP.put(className,aClass);
return aClass;
}catch (Exception e){
log.error("GenerateClass error!"+Util.getErrString(e));
throw new CustomerException("GenerateClass error "+e.getMessage());
}
}
/**
* Map
* @param dataSource map
* @param clazz
* @return List
*/
public static List<Object> covertClassList(List<Map<String,Object>> dataSource,Class<?> clazz){
if(Objects.isNull(dataSource) || dataSource.isEmpty()){
return new ArrayList<>();
}
return dataSource.stream().map(item ->{
try {
Object data = clazz.newInstance();
Field[] declaredFields = clazz.getDeclaredFields();
for (Field declaredField : declaredFields) {
declaredField.setAccessible(true);
String name = declaredField.getName();
String fieldVal = Util.null2String(item.get(name));
declaredField.set(data,fieldVal);
}
return data;
} catch (Exception e) {
log.error("covertClass error "+Util.getErrString(e));
throw new CustomerException("covertClass error 反射异常"+e.getMessage());
}
}).collect(Collectors.toList());
}
}

View File

@ -31,8 +31,30 @@ public class SyncAccountTradeInfoJob extends BaseCronJob {
private String interfaceName;
/** 同步开始日期 */
private String fromDate;
/** 同步结束日期 */
private String toDate;
private final static String JobName = " SyncAccountTradeInfoJob ";
public String getFromDate() {
return fromDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public String getToDate() {
return toDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
public String getInterfaceName() {
return interfaceName;
}
@ -48,6 +70,7 @@ public class SyncAccountTradeInfoJob extends BaseCronJob {
ZennerApiService zennerApiService = new ZennerApiService();
try {
logger.writeLog("-----" + JobName + " getInterfaceName------" + getInterfaceName());
logger.writeLog(String.format("params --- fromDate:%s toDate:%s",fromDate,toDate));
//银行
String bankApiUrl = zennerApiService.getSystemConfigValue("BANK_API_URL");
@ -103,8 +126,10 @@ public class SyncAccountTradeInfoJob extends BaseCronJob {
//xmlParams.put("from", "20220919");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, -1);
xmlParams.put("from", ZennerUtil.parseToDateString(cal.getTime(), ZennerUtil.formatYYYYMMDD_NoSplit));
xmlParams.put("to", ZennerUtil.parseToDateString(new Date(), ZennerUtil.formatYYYYMMDD_NoSplit));
String from = !"".equals(Util.null2String(this.fromDate)) ? this.fromDate : ZennerUtil.parseToDateString(cal.getTime(), ZennerUtil.formatYYYYMMDD_NoSplit);
String to = !"".equals(Util.null2String(this.toDate)) ? this.toDate : ZennerUtil.parseToDateString(new Date(), ZennerUtil.formatYYYYMMDD_NoSplit);
xmlParams.put("from", from);
xmlParams.put("to", to);
xmlParams.put("amountFrom", "1");
xmlParams.put("amountTo", "100000");
xmlParams.put("begnum", start + "");
@ -312,6 +337,11 @@ public class SyncAccountTradeInfoJob extends BaseCronJob {
tradeInfo.setDirection(l4Element.getStringValue());
}
}
if ("insid".equals(l4Element.getName())) {
if (!"".equals(l4Element.getStringValue())){
tradeInfo.setInsid(l4Element.getStringValue());
}
}
}
tradeInfoList.add(tradeInfo);

View File

@ -11,14 +11,24 @@ import bokang.xiao.entity.TeacherEntity;
import bokang.xiao.util.XmlParser;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.api.bokang.xiao.porsche_review.mapper.ReviewMapper;
import com.api.bokang.xiao.wx_report.mapper.ReportMapper;
import com.api.bokang.xiao.wx_report.service.ReportService;
import com.api.bokang.xiao.wx_report.service.impl.ReportServiceImpl;
import com.api.bokang.xiao.zhenn.service.BankService;
import com.api.bokang.xiao.zscq.service.ReserveService;
import com.api.bokang.xiao.zscq.service.impl.ReserveServiceImpl;
import javassist.*;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ConstPool;
import javassist.bytecode.annotation.Annotation;
import javassist.bytecode.annotation.ArrayMemberValue;
import javassist.bytecode.annotation.MemberValue;
import javassist.bytecode.annotation.StringMemberValue;
import org.apache.log4j.Logger;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
@ -51,7 +61,9 @@ import weaver.xiao.commons.utils.DocImageFileUtil;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
@ -72,6 +84,103 @@ public class NormalTest extends BaseTest {
//GenerateFileUtil.createActionDocument(DateFieldUpdateAction.class);
}
@Test
public void testReport1() throws FileNotFoundException {
BankService bankService = new BankService();
Map<String,Object> param = new HashMap<>();
List<Map<String,Object>> dataSource = new ArrayList<>();
Map<String,Object> data = new HashMap<>();
data.put("requestId",123445);
data.put("outAmount",2444);
data.put("inCompany","公司");
data.put("outDate","2023-06-16");
dataSource.add(data);
param.put("columns",getColumn());
param.put("dataSource",dataSource);
param.put("type","oaOut");
bankService.export(new FileOutputStream("/Users/ic_excellent/Downloads/test.xlsx"),param);
bankService.export(new FileOutputStream("/Users/ic_excellent/Downloads/test1.xlsx"),param);
}
@Test
public void testGen() throws CannotCompileException, NotFoundException, InstantiationException, IllegalAccessException, IOException {
// 创建 ClassPool 对象
ClassPool pool = ClassPool.getDefault();
// 创建一个新的类
CtClass cc = pool.makeClass("Person");
List<Map<String, String>> columns = getColumn();
for (Map<String, String> column : columns) {
String title = column.get("title");
String dataIndex = column.get("dataIndex");
CtField field = new CtField(ClassPool.getDefault().get(String.class.getName()), dataIndex, cc);
field.setModifiers(Modifier.PRIVATE);
cc.addField(field);
cc.addMethod(CtNewMethod.setter("set" + dataIndex.substring(0, 1).toUpperCase() + dataIndex.substring(1), field));
cc.addMethod(CtNewMethod.getter("get" + dataIndex.substring(0, 1).toUpperCase() + dataIndex.substring(1), field));
field.getFieldInfo().addAttribute(new AnnotationsAttribute(field.getFieldInfo().getConstPool(), AnnotationsAttribute.visibleTag));
// 添加 ExcelProperty 注解
ConstPool cp = cc.getClassFile().getConstPool();
AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
Annotation annotation = new Annotation(ExcelProperty.class.getName(), cp);
//annotation.addMemberValue("value", new StringMemberValue(Arrays.toString(new String[] {title}), cp));
StringMemberValue stringMemberValue = new StringMemberValue(title, cp);
MemberValue[] memberValues = new MemberValue[]{stringMemberValue};
ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cp);
arrayMemberValue.setValue(memberValues);
annotation.addMemberValue("value", arrayMemberValue);
annotationsAttribute.addAnnotation(annotation);
field.getFieldInfo().addAttribute(annotationsAttribute);
}
Class<?> aClass = cc.toClass();
List<Object> dataList = new ArrayList<>();
// 构造实体类
Object data = aClass.newInstance();
Field[] declaredFields = aClass.getDeclaredFields();
for (Field declaredField : declaredFields) {
declaredField.setAccessible(true);
declaredField.set(data,"test");
}
dataList.add(data);
// cc.writeFile();
EasyExcel.write(new File("/Users/ic_excellent/Downloads/test.xlsx"), aClass).sheet("Sheet1").doWrite(dataList);
}
public List<Map<String, String>> getColumn() {
List<Map<String, String>> list = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map = new HashMap<>();
map.put("title", "OA流程号");
map.put("dataIndex", "requestId");
map.put("key", "requestId");
list.add(map);
map = new HashMap<>();
map.put("title", "收款金额");
map.put("dataIndex", "outAmount");
map.put("key", "inAmount");
list.add(map);
map = new HashMap<>();
map.put("title", "付款单位");
map.put("dataIndex", "inCompany");
map.put("key", "outCompany");
list.add(map);
map = new HashMap<>();
map.put("title", "收款日期");
map.put("dataIndex", "outDate");
map.put("key", "inDate");
list.add(map);
return list;
}
@Test
public void testChain(){
GenerateReportSchedule generateReportSchedule = new GenerateReportSchedule();

6
web/WEB-INF/web.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>