package com.edu.njupt.finance.controller;
import com.edu.njupt.finance.core.http.HttpResult;
import com.edu.njupt.finance.entity.BaseStuStaff;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.regex.*;
/**
- @author khl
- @date 2022年06月18日 10:03
- @description
*/
@RestController
@RequestMapping(“/test”)
@Api(tags = “字符串测试接口”)
public class TestString {
private String inputString = "2022/5/9 15:44\n" +
"欢迎访问财务处综合信息门户\n" +
"https://vpn.njupt.edu.cn:8443/http/webvpn57afe37d2e9443239bf57340fd5e0cef90c5f4e5d4033b4347c7263353da5aa7/WFManager/home2.jsp 1/1\n" +
"签字(盖章):\n" +
"经费负责人 经办人 \n" +
"南京邮电大学预约报销单\n" +
"预约号: 507325 预约时间: 2022-05-10 08:20-11:30 预约窗口: 三牌楼001\n" +
"报销人工号 2020 姓名 陈 联系电话 131\n" +
"项目编号 J066 项目负责人 陈\n" +
"项目名称 \n" +
"摘要 业务招待费 手机 130641 附件张数 2\n" +
"实际报销人 陈\n" +
"费用项 报销金额 费用项 报销金额\n" +
"横向科研业务费 报销金额:461.00 \n" +
"申请总金额: 461.00 大写金额:肆佰陆拾壹圆\n" +
"财务核准报销金额:\n" +
"支付方式\n" +
"转卡\n" +
"工号 姓名 卡号 金额\n" +
"20020 陈 45101006304 461.00 \n" +
"报销人承诺:本人对以上经济事项及所提供的票据的真实性和合法性负责\n";
@PostMapping("/testString")
@ApiOperation(value = "测试字符串函数——正则表达式",notes = "参数为string,由pdf复制得到")
public HttpResult addOrEditStuStaff(){
String result = "good";
// 按指定模式在字符串查找
String line = inputString;
String pattern = "(.*)(报销人工号 +)(.*)( 姓名+)";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find( )) {
//System.out.println("Found value: " + m.group(0) );
//System.out.println("Found value: " + m.group(1) );
result = "Found value1:" + m.group(3) ;
//System.out.println("Found value: " + m.group(3) );
} else {
result = "识别失败";
}
return HttpResult.success(result);
}
}