Compare commits

...

2 Commits

12 changed files with 328 additions and 84 deletions

View File

@ -40,6 +40,7 @@ public class InvoiceSelectController {
@Produces(MediaType.APPLICATION_JSON)
public String checkInvoice(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
try{
request.getParameter("");
log.info("into checkInvoice success params ==> "+param);
List<Map<String, Object>> maps = dzInvoiceService.checkInvoice(param);
return ApiResult.success(maps);

View File

@ -23,7 +23,7 @@ public interface DzInvoiceMapper {
* @param ids id
* @return
*/
@Select("select * from APInvoice where id in (${ids})")
@Select("select * from APInvoice where id in ($t{ids})")
List<Map<String,Object>> queryInvoiceList(@ParamMapper("ids") String ids);
/**
@ -34,7 +34,7 @@ public interface DzInvoiceMapper {
* @return
*/
@Update("update fnaInvoiceLedger set check_status = #{checkStatus} where $t{fieldId} = #{fieldValue}")
boolean updateInvoiceCheckStatus(@ParamMapper("check_status") int checkStatus,
boolean updateInvoiceCheckStatus(@ParamMapper("checkStatus") int checkStatus,
@ParamMapper("fieldId") String fieldId,
@ParamMapper("fieldValue") Object fieldValue);
@ -45,11 +45,10 @@ public interface DzInvoiceMapper {
* @param fieldValue
* @return
*/
@Update("update fnaInvoiceLedger set check_status = #{checkStatus} where $t{fieldId} in ${fieldValue}")
boolean batchUpdateInvoiceCheckStatus(@ParamMapper("check_status") int checkStatus,
@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") Object fieldValue);
@ParamMapper("fieldValue") String fieldValue);
/**
* <h2></h2>

View File

@ -5,6 +5,7 @@ import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.api.bokang.xiao.dz_invoice.mapper.DzInvoiceMapper;
import com.api.bokang.xiao.dz_invoice.service.DzInvoiceService;
import org.apache.log4j.Logger;
import weaver.xiao.commons.config.entity.RequestMappingConfig;
import weaver.xiao.commons.config.service.DealWithMapping;
@ -26,6 +27,8 @@ public class DzInvoiceServiceImpl implements DzInvoiceService {
private final DealWithMapping dealWithMapping = new DealWithMapping();
private final Logger log = Util.getLogger();
private final HttpUtils httpUtils = new HttpUtils();
/** 已申请抵扣 */
@ -57,21 +60,28 @@ public class DzInvoiceServiceImpl implements DzInvoiceService {
String reqUniqueCode = handleType == 1 ? Util.null2String(param.get("checkInvoiceUniqueCode")) : Util.null2String(param.get("unCheckInvoiceUniqueCode"));
List<Map<String, Object>> invoiceList = dzInvoiceMapper.queryInvoiceList(ids);
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(reqUniqueCode);
Map<String,String> header = new HashMap<>();
header.put("Content-Type","application/json");
for (Map<String, Object> invoice : invoiceList) {
Map<String,Object> result = new HashMap<>();
Map<String, Object> requestParam = dealWithMapping.getRequestParam(invoice, requestMappingConfig);
String invoiceId = Util.null2String(invoice.get("id"));
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam);
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam,header);
if(responeVo.getCode() == 200){
result.put("reqFlag",true);
Map entity = responeVo.getResponseEntity(Map.class);
log.info("调用勾选接口处理结果 ==>"+entity);
boolean reqStatus = "E0000".equals(Util.null2String(entity.get("code")));
String describe = Util.null2String(entity.get("describe"));
result.put("checkStatus",reqStatus);
result.put("describe",describe);
result.put("invoiceNumber",invoice.get("invoicenumber"));
int checkStatus = handleType == 1 ? REQ_DEDUCTION : REQ_UN_DEDUCTION;
if(reqStatus) {
dzInvoiceMapper.updateInvoiceCheckStatus(checkStatus, "id", invoiceId);
}
}else {
log.info("调用勾选接口失败 ==>"+responeVo);
result.put("reqFlag",false);
}
results.add(result);

View File

@ -23,7 +23,7 @@ public interface ReviewMapper {
* @return
*/
@Select("select count(*) from workflow_requestbase where creater = #{uid} " +
"and (createdate between #{param.startDate} and #{param.endDate}) and workflowid not in (${param.workflowIds})")
"and (createdate between #{param.startDate} and #{param.endDate}) and workflowid not in ($t{param.workflowIds})")
int queryCreateCount(@ParamMapper("param") Map<String,Object> param,@ParamMapper("uid") int uid);
/**
@ -32,7 +32,7 @@ public interface ReviewMapper {
* @return
*/
@Select("select count(*) from workflow_requestbase " +
"where (createdate between #{startDate} and #{endDate}) and workflowid not in (${workflowIds})")
"where (createdate between #{startDate} and #{endDate}) and workflowid not in ($t{workflowIds})")
int queryTotalCount(Map<String,Object> param);
/**
@ -49,17 +49,18 @@ public interface ReviewMapper {
* @param param
* @return
*/
@Select("select @row := @row + 1 as rowindex " +
@Select("select rowindex from (" +
"select @row := @row + 1 as rowindex,creater" +
"from ( " +
" select " +
" creater,count(*) wcount " +
" from workflow_requestbase wrb " +
" where createdate between #{param.startDate} and #{param.endDate} " +
" and workflowid not in (${param.workflowIds})" +
" and workflowid not in ($t{param.workflowIds})" +
" group by creater " +
" order by wcount desc " +
") w,(SELECT @row := 0) t " +
"where creater = #{uid}")
") w,(SELECT @row := 0) t ) ranking" +
"where ranking.creater = #{uid}")
int queryRankingMsg(@ParamMapper("param") Map<String,Object> param,@ParamMapper("uid") int uid);
/**
@ -68,20 +69,22 @@ public interface ReviewMapper {
* @param uid id
* @return
*/
@Select("select @row := @row + 1 as rowindex " +
@Select("select rowindex from (" +
"select @row := @row + 1 as rowindex,operatorid " +
"from " +
"( " +
" select " +
" wfo.operatorid,count(*) wcount " +
" operatorid,count(*) wcount " +
" from workflow_requestoperatelog wfo " +
" inner join workflow_requestbase wrb on wfo.requestid = wrb.requestid " +
" inner join workflow_base wb on wrb.workflowid = wb.id " +
" inner join workflow_nodebase wnb on wfo.nodeid = wnb.id " +
" where (wfo.operatorid <> wrb.creater || (wfo.operatorid = wrb.creater && wnb.isstart <> 1)) " +
" and (wfo.operatedate between #{param.startDate} and #{param.endDate}) and workflowid not in (${param.workflowIds})" +
" and (wfo.operatedate between #{param.startDate} and #{param.endDate}) and workflowid not in ($t{param.workflowIds})" +
" group by operatorid " +
" order by wcount desc " +
")w,(SELECT @row := 0) t where w.operatorid = #{uid}")
")w,(SELECT @row := 0) t ) ranking" +
" where ranking.operatorid = #{uid}")
int queryOperateRankingMsg(@ParamMapper("param") Map<String,Object> param,@ParamMapper("uid") int uid);
/**
@ -96,7 +99,7 @@ public interface ReviewMapper {
"inner join workflow_requestbase wrb on wfo.requestid = wrb.requestid " +
"inner join workflow_nodebase wnb on wfo.nodeid = wnb.id " +
"where (wfo.operatorid <> wrb.creater || (wfo.operatorid = wrb.creater && wnb.isstart <> 1)) " +
" and (wfo.operatedate between #{param.startDate} and #{param.endDate}) and wfo.operatorid = #{uid} and workflowid not in (${param.workflowIds})")
" and (wfo.operatedate between #{param.startDate} and #{param.endDate}) and wfo.operatorid = #{uid} and workflowid not in ($t{param.workflowIds})")
int queryDealCount(@ParamMapper("param") Map<String,Object> param,@ParamMapper("uid") int uid);
/**
@ -109,7 +112,7 @@ public interface ReviewMapper {
"from workflow_requestbase wr " +
"inner join workflow_base wb on wr.workflowid = wb.id " +
"where wr.creater = #{uid} and (createdate between #{param.startDate} and #{param.endDate}) " +
" and workflowid not in (${param.workflowIds})" +
" and workflowid not in ($t{param.workflowIds})" +
"group by workflowid " +
"ORDER BY wcount desc" +
"limit ${param.limit}")
@ -143,7 +146,7 @@ public interface ReviewMapper {
*/
@Select("select createdate,count(*) tcount from workflow_requestbase " +
" where creater = #{uid} and (createdate between #{param.startDate} and #{param.endDate}) " +
" and workflowid not in (${param.workflowIds}) " +
" and workflowid not in ($t{param.workflowIds}) and createdate is not null " +
" group by createdate " +
" order by count(*) desc " +
" limit 1")
@ -162,7 +165,7 @@ public interface ReviewMapper {
"inner join workflow_nodebase wnb on wfo.nodeid = wnb.id " +
"where (wfo.operatorid <> wrb.creater || (wfo.operatorid = wrb.creater && wnb.isstart <> 1)) " +
" and (wfo.operatedate between #{param.startDate} and #{param.endDate}) " +
" and operatorid = #{uid} and workflowid not in (${param.workflowIds}) " +
" and operatorid = #{uid} and workflowid not in ($t{param.workflowIds}) and operatedate is not null " +
"group by operatedate " +
"order by count(*) desc " +
"limit 1")
@ -176,8 +179,14 @@ public interface ReviewMapper {
*/
@Select("select count(*) from $t{tableName} where $t{cusSql}")
int queryCountByParam(@ParamMapper("tableName") String tableName,
@ParamMapper("cusSql") String cusSql);
@ParamMapper("cusSql") String cusSql,
@ParamMapper("param")Map<String, Object> param);
/**
* <h2>id</h2>
* @param tableId id
* @return
*/
@Select("select tablename workflow_bill where id = #{tableId}")
String queryTableName(@ParamMapper("tableId")String tableId);
}

View File

@ -3,6 +3,7 @@ package com.api.bokang.xiao.porsche_review.service.impl;
import aiyh.utils.Util;
import com.api.bokang.xiao.porsche_review.mapper.ReviewMapper;
import com.api.bokang.xiao.porsche_review.service.ReviewService;
import io.swagger.models.auth.In;
import org.apache.log4j.Logger;
import weaver.hrm.User;
@ -32,6 +33,9 @@ public class ReviewServiceImpl implements ReviewService {
int createCount = reviewMapper.queryCreateCount(param,user.getUID());
int ranking = reviewMapper.queryRankingMsg(param,user.getUID());
resourceCount = resourceCount > 0 ? resourceCount : reviewMapper.queryResourceCount(new HashMap<>());
ranking = ranking < 0 ? resourceCount : ranking;
log.info("rankingMsg ==>"+ranking);
log.info("resourceCount ==>"+resourceCount);
double exceed = 1 - (1.00*ranking/resourceCount);
res.put("totalCount",createCount);
res.put("exceed",exceed);
@ -44,7 +48,11 @@ public class ReviewServiceImpl implements ReviewService {
int operateCount = reviewMapper.queryDealCount(param, user.getUID());
resourceCount = resourceCount > 0 ? resourceCount : reviewMapper.queryResourceCount(new HashMap<>());
int rankingMsg = reviewMapper.queryOperateRankingMsg(param, user.getUID());
rankingMsg = rankingMsg < 0 ? resourceCount : rankingMsg;
log.info("rankingMsg ==>"+rankingMsg);
log.info("resourceCount ==>"+resourceCount);
double exceed = 1 - (1.00*rankingMsg/resourceCount);
log.info("exceed ==>"+exceed);
res.put("totalCount",operateCount);
res.put("exceed",exceed);
return res;
@ -80,48 +88,101 @@ public class ReviewServiceImpl implements ReviewService {
Map<String,Object> result = new HashMap<>(8);
String contractTableStr= Util.null2String(param.get("contractTable"));
String sealTableStr = Util.null2String(param.get("sealTable"));
int contractCount = 0;
int sealCount = 0;
Map<String, String> contractTable = getModelTableSql(contractTableStr);
Map<String, String> sealTable = getModelTableSql(sealTableStr);
Map<String,Map<String,String>> contractTable = getModelTableSql(contractTableStr);
Map<String,Map<String,String>> sealTable = getModelTableSql(sealTableStr);
log.info("contractTable ==>"+contractTable);
log.info("sealTable ==>"+sealTable);
//计算合同总数
for (Map.Entry<String, String> entry : contractTable.entrySet()) {
String tableName = entry.getKey();
int count = reviewMapper.queryCountByParam(tableName,entry.getValue());
contractCount += count;
}
Map<String,Integer> contractMap = this.getTotalCountByMap(contractTable, param);
int contractCount = Math.max(contractMap.get("totalCount"),0);
//计算电子章总数
for (Map.Entry<String, String> entry : sealTable.entrySet()) {
String tableName = entry.getKey();
int count = reviewMapper.queryCountByParam(tableName,entry.getValue());
sealCount += count;
Map<String, Integer> sealMap = this.getTotalCountByMap(sealTable, param);
int sealCount = Math.max(sealMap.get("totalCount"),0);
double exceed;
try{
exceed = 1.00*sealCount/contractCount;
}catch (Exception e){
log.info("电子章总数为0");
exceed = 0;
}
double exceed = 1.00*contractCount/sealCount;
result.put("contractCount",contractCount);
result.put("sealCount",sealCount);
result.put("sealMsg",sealMap);
result.put("contractMsg",contractMap);
result.put("exceed",exceed);
return result;
}
/**
* <h2></h2>
* <h2></h2>
* @param queryMap
* @param param
* @return
*/
private Map<String,Integer> getTotalCountByMap(Map<String,Map<String,String>> queryMap,Map<String, Object> param){
int totalCount = 0;
Map<String,Integer> result = new HashMap<>();
for (Map.Entry<String, Map<String, String>> entry : queryMap.entrySet()) {
String tableName = entry.getKey();
Map<String, String> cusMap = entry.getValue();
String cusSql = cusMap.get("cusSql");
String dateField = cusMap.get("dateField");
String showName = cusMap.get("showName");
String dateSql = " and (" + dateField + " between #{param.startDate} and #{param.endDate})";
cusSql = cusSql + dateSql;
int count = reviewMapper.queryCountByParam(tableName,cusSql,param);
result.put(showName,count);
totalCount += count;
}
result.put("totalCount",totalCount);
return result;
}
/**
* <h2>sql</h2>
* @param sourceStr
* @return
*/
public Map<String,String> getModelTableSql(String sourceStr){
Map<String,String> modelTableMap = new HashMap<>();
String regx = "\\{(?<tableName>\\S+):(?<cusSql>\\S+)}";
public Map<String,Map<String,String>> getModelTableSql(String sourceStr){
Map<String,Map<String,String>> modelTableMap = new HashMap<>();
sourceStr = toDbc(sourceStr);
String[] split = sourceStr.split(",");
String regx = "\\{(?<tableName>\\S+):(?<cusSql>[\\S\\s]+):(?<dateField>\\S+):(?<showName>\\S+)}";
Pattern compile = Pattern.compile(regx);
Matcher matcher = compile.matcher(sourceStr);
for (String str : split) {
Matcher matcher = compile.matcher(str);
while (matcher.find()){
Map<String,String> cusMap = new HashMap<>();
String tableName = matcher.group("tableName");
String cusSql = matcher.group("cusSql");
cusSql = cusSql.replaceAll("&"," and ").replaceAll("/|"," or ");
modelTableMap.put(tableName,cusSql);
String dateField = matcher.group("dateField");
String showName = matcher.group("showName");
cusSql = cusSql.replaceAll("&"," and ").replaceAll("\\|"," or ");
cusMap.put("dateField",dateField);
cusMap.put("cusSql",cusSql);
cusMap.put("showName",showName);
modelTableMap.put(tableName,cusMap);
}
}
return modelTableMap;
}
/**
* <h2></h2>
* @param input
* @return
*/
public String toDbc(String input) {
char c[] = input.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == '\u3000') {
c[i] = ' ';
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
c[i] = (char) (c[i] - 65248);
}
}
return new String(c);
}
}

View File

@ -150,6 +150,7 @@ public class ReportServiceImpl implements ReportService {
return netTotalMap.entrySet().stream().map(netEntry -> ReportEntityVO.builder()
.day(netEntry.getKey())
.amount(netEntry.getValue())
.category(e.getKey())
.build()).collect(Collectors.toList());
}));
}
@ -231,6 +232,7 @@ public class ReportServiceImpl implements ReportService {
result.put(groupEntry.getKey(), ReportEntityVO.builder()
.amount(sum)
.day(groupEntry.getValue().get(0).getDay())
.category(groupEntry.getKey())
.build());
}
return result;

View File

@ -18,6 +18,7 @@ import weaver.xiao.commons.config.service.DealWithMapping;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -62,11 +63,13 @@ public class InvoiceDeductionAction extends SafeCusBaseAction {
log.info(String.format("=================== {%s} begin ======================", this.getClass().getName()));
log.info(String.format("params:[requestId ==>%s],[requestUnique ==>%s]", requestId,requestUnique));
Map<String, Object> workflowMessage = workflowMapper.queryWorkflowByRequestId(requestId, billTable);
dealWithMapping.setMainTable(billTable);
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(requestUnique);
Map<String, Object> requestParam = dealWithMapping.getRequestParam(workflowMessage, requestMappingConfig);
dealWithMapping.setMainTable(billTable);
try {
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam);
Map<String,String> header = new HashMap<>();
header.put("Content-Type","application/json");
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam,header);
if(responeVo.getCode() == 200){
Map result = responeVo.getResponseEntity(Map.class);
String code = Util.null2String(result.get("code"));

View File

@ -7,14 +7,18 @@ import aiyh.utils.annotation.RequiredMark;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.alibaba.fastjson.JSON;
import com.api.bokang.xiao.dz_invoice.mapper.DzInvoiceMapper;
import lombok.Data;
import org.apache.log4j.Logger;
import weaver.interfaces.schedule.BaseCronJob;
import weaver.xiao.commons.config.entity.RequestMappingConfig;
import weaver.xiao.commons.config.service.DealWithMapping;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* @ClassName InvoiceQuerySchedule
@ -24,6 +28,7 @@ import java.util.Map;
**/
@ActionDesc(value = "定时查询发票勾选状态", author = "bokang.xiao")
@Data
public class InvoiceQuerySchedule extends BaseCronJob {
@RequiredMark("发票查询接口唯一标识")
@ -45,16 +50,20 @@ public class InvoiceQuerySchedule extends BaseCronJob {
Util.verifyRequiredField(this);
List<Map<String, Object>> invoiceList = dzInvoiceMapper.queryOnChooseInvoices();
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(requestUnique);
Map<String,String> header = new HashMap<>(8);
header.put("Content-Type","application/json");
if(!invoiceList.isEmpty()){
for (Map<String, Object> invoice : invoiceList) {
logger.info("invoice query ==>"+ JSON.toJSONString(invoice));
Map<String, Object> requestParam = dealWithMapping.getRequestParam(invoice,requestMappingConfig);
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam);
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam,header);
if(responeVo.getCode() == 200){
Map<String,Object> result = responeVo.getResponseEntity(Map.class);
String code = Util.null2String(result.get("code"));
if("E0000".equals(code)){
List<Map<String,Object>> invoices = (List<Map<String, Object>>) result.get("data");
if(!invoices.isEmpty()){
Map<String,Object> res = (Map<String, Object>) result.get("result");
List<Map<String,Object>> invoices = (List<Map<String, Object>>) res.get("data");
if(Objects.nonNull(invoices) && !invoices.isEmpty()){
for (Map<String, Object> map : invoices) {
String checkStatus = Util.null2String(map.get("checkStatus"));
dzInvoiceMapper.updateInvoiceCheckStatus(Util.getIntValue(checkStatus),"id",invoice.get("id"));
@ -62,13 +71,12 @@ public class InvoiceQuerySchedule extends BaseCronJob {
}
}
}else {
throw new CustomerException("请求状态码不为 200");
logger.error(String.format("请求状态码不为200 发票 {%s} 查询失败!无法同步发票状态",invoice.get("invoiceNumber")));
}
}
}
}catch (Exception e){
logger.info("同步发生异常 ==>"+Util.getErrString(e));
logger.error("同步发生异常 ==>"+Util.getErrString(e));
}
}

View File

@ -50,8 +50,8 @@ public class ConfigMappingCMD {
String queryDetail1Sql = "";
switch (anEnum) {
case CUS_TABLE:
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext," +
" from " + configTableName + "_dt1 config ";
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext " +
" from " + configTableName + "_dt1 config where mainid = ?";
break;
case WORKFLOW:
queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,valueContext,relationWorkFlowField, " +

View File

@ -1,7 +1,9 @@
package weaver.xiao.commons.utils;
import aiyh.utils.excention.CustomerException;
import org.apache.log4j.Logger;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
@ -210,11 +212,11 @@ public class DocImageFileUtil {
try {
imageFileManager.setData(IOUtils.toBytes(content));
} catch (Exception ex) {
throw new CustomerException("创建文件失败,文件流转换失败", e);
throw new RuntimeException("创建文件失败,文件流转换失败", e);
}
imgFileId = imageFileManager.saveImageFile();
} catch (Exception e) {
throw new CustomerException("创建文件失败");
throw new RuntimeException("创建文件失败");
}
return imgFileId;
}
@ -324,16 +326,10 @@ public class DocImageFileUtil {
Iterator<XWPFParagraph> itPara = document.getParagraphsIterator();
while (itPara.hasNext()) {
XWPFParagraph paragraph = itPara.next();
List<XWPFRun> runs = paragraph.getRuns();
for (XWPFRun run : runs) {
String currentString = run.getText(run.getTextPosition()).trim();
for (Map.Entry<String, Object> entry : replaceMap.entrySet()) {
if (currentString.equals(entry.getKey())) {
currentString = currentString.replace(entry.getKey(), Util.null2String(entry.getValue()));
}
}
run.setText(currentString, 0);
DocImageFileUtil.replace(paragraph,entry.getKey(),entry.getValue());
}
}
try {
FileOutputStream outStream = null;
@ -346,4 +342,66 @@ public class DocImageFileUtil {
}
}
public static <V> void replace(XWPFParagraph paragraph, String searchText, V replacement) {
int firstPos = paragraph.getText().indexOf(searchText);
while (firstPos >= 0) {
int lastPos = firstPos + searchText.toString().length();
// 第一个和最后一个run要单独处理中间的run可以直接删除
int pos = 0;
boolean find = false;
for (int i = 0, ln = paragraph.getRuns().size(); i < ln; i++) {
XWPFRun run = (XWPFRun) paragraph.getRuns().get(i);
String runText = run.getText(run.getTextPosition());
if (runText == null) {
continue;
}
if (!find) {
if (pos + runText.length() > firstPos) {
// pos=0,替换run的子句; pos=1,在子句末端追加文字;
run.setText(runText.substring(0, firstPos - pos) + replacement.toString(), 0);
find = true;
}
pos += runText.length();
} else {
if (pos > lastPos) {
break;
} else if (pos <= lastPos - runText.length()) {
pos += runText.length();
// 不知道为啥,这个删除语句不起效,不过替换成空字符串也能起到删除效果
// paragraph.removeRun(i);
run.setText("", 0);
} else {
run.setText(runText.substring(lastPos - pos), 0);
break;
}
}
}
firstPos = paragraph.getText().indexOf(searchText);
}
}
//public static void replaceDocument(Map<String, Object> replaceMap, String docSourcePath, String targetPath) {
// HWPFDocument document = null;
// try {
// document = new HWPFDocument (Files.newInputStream(Paths.get(docSourcePath)));
// } catch (IOException e) {
// logger.error("模板文件位置错误:" + LogUtil.getExceptionStr(e));
// throw new RuntimeException("模板文件位置错误:" + docSourcePath);
// }
// Range range = document.getRange();
// for (Map.Entry<String, Object> entry : replaceMap.entrySet()) {
// String key = entry.getKey();
// range.replaceText(key,Util.null2String(entry.getValue()));
// }
// try {
// FileOutputStream outStream = null;
// outStream = new FileOutputStream(targetPath);
// document.write(outStream);
// outStream.close();
// } catch (IOException e) {
// logger.error("写入文件位置错误:" + LogUtil.getExceptionStr(e));
// throw new RuntimeException("写入文件位置错误:" + docSourcePath);
// }
//}
}

View File

@ -0,0 +1,31 @@
package bokang.xiao;
import lombok.Data;
/**
* @ClassName ConfigCache
* @Author
* @Date 2023/3/7 10:32
* @Description <h1></h1>
**/
@Data
public class ConfigCache {
private ConfigCache(){
if(CacheHolder.configCache != null){
throw new RuntimeException("不允许创建多个实例");
}
}
private final String string = "gjjg";
public static ConfigCache getInstance(){
return CacheHolder.configCache;
}
private static class CacheHolder{
private static final ConfigCache configCache = new ConfigCache();
private CacheHolder(){
}
}
}

View File

@ -13,6 +13,7 @@ import bokang.xiao.mapper.TestMapper;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.api.bokang.xiao.porsche_review.mapper.ReviewMapper;
import com.api.bokang.xiao.porsche_review.service.ReviewService;
import com.api.bokang.xiao.porsche_review.service.impl.ReviewServiceImpl;
import com.api.bokang.xiao.wx_report.entity.ReportEntityVO;
import com.api.bokang.xiao.wx_report.mapper.ReportMapper;
@ -30,12 +31,21 @@ import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.junit.Test;
import weaver.bokang.xiao.dz_invoice.action.InvoiceDeductionAction;
import weaver.bokang.xiao.dz_invoice.schedule.InvoiceQuerySchedule;
import weaver.general.StaticObj;
import weaver.hrm.User;
import weaver.interfaces.datasource.DataSource;
import weaver.workflow.workflow.WorkflowVersion;
import weaver.xiao.commons.config.entity.ResponseMapping;
import weaver.xiao.commons.utils.DocImageFileUtil;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
@ -50,15 +60,43 @@ public class NormalTest extends BaseTest {
@Test
public void testWord(){
//GenerateFileUtil.createActionDocument(InvoiceDeductionAction.class);
//GenerateFileUtil.createCronJobDocument(InvoiceQuerySchedule.class);
String s = "{uf_jxshttz:jxsqszt=1&qsfs=0:cjrq},{uf_htzzzs:dqjd=24&htlb is not null&yylx=0:sqrq}";
ReviewServiceImpl reviewService = new ReviewServiceImpl();
Map<String, Map<String, String>> modelTableSql = reviewService.getModelTableSql(s);
System.out.println(modelTableSql);
}
@Test
public void testQuery(){
TestMapper mapper = Util.getMapper(TestMapper.class);
List<Map<String, Object>> query = mapper.query();
System.out.println(query);
ReviewMapper reviewMapper = Util.getMapper(ReviewMapper.class);
Map<String,Object> param = new HashMap<>();
param.put("workflowIds","44,45,1");
param.put("type","1create");
param.put("startDate","2022-02-08");
param.put("endDate","2023-02-28");
Map<String, Object> map = reviewMapper.queryCreateTopDate(param, 1);
Logger sql_log = Util.getLogger("sql_log");
assert sql_log != null;
sql_log.info("我是傻狗");
System.out.println(map);
}
@Test
public void testDataSource(){
DataSource ds = (DataSource) StaticObj.getServiceByFullname(("datasource.a"),DataSource.class);
Connection conn = null ;
CallableStatement callableStatement = null; // CallableStatement对象
ResultSet resultSet = null; // 结果集对象
try{
conn = ds.getConnection();
callableStatement = conn.prepareCall("{CALL proc_search_user(?,?,?,?)}");
resultSet = callableStatement.executeQuery();
if(resultSet.next()){
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Test
@ -85,20 +123,26 @@ public class NormalTest extends BaseTest {
System.out.println(reportData);
}
@Test
public void testgg() throws IOException {
System.out.println(null instanceof Collections);
}
@Test
public void testPdf() throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("$name", "1231");
String s = DocImageFileUtil.replaceDocument(map, "E:\\test\\test.docx");
map.put("#{docNumber}", "1231");
map.put("#{title}", "我是一只傻狗");
String s = DocImageFileUtil.replaceDocument(map, "E:\\test\\template.docx");
System.out.println(s);
new Thread(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
DocImageFileUtil.deleteTempFile(s);
}).start();
//new Thread(() -> {
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
// DocImageFileUtil.deleteTempFile(s);
//}).start();
}
@Test
@ -169,4 +213,22 @@ public class NormalTest extends BaseTest {
}
@Test
public void testRef() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
ConfigCache instance = ConfigCache.getInstance();
System.out.println(instance);
Class<ConfigCache> configCacheClass = ConfigCache.class;
Constructor<ConfigCache> declaredConstructor = configCacheClass.getDeclaredConstructor();
declaredConstructor.setAccessible(true);
ConfigCache configCache = declaredConstructor.newInstance();
System.out.println(configCache);
}
@Test
public void testWorkflowBill(){
String versionStringByWfid = WorkflowVersion.getVersionStringByWfid("44");
System.out.println(versionStringByWfid);
GenerateFileUtil.createCronJobDocument();
}
}