From 950b68a79608398c1149c9413833c580a71adeff Mon Sep 17 00:00:00 2001 From: ic_excellent Date: Wed, 15 Mar 2023 16:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=85=8D=E7=BD=AE-=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89=E8=A1=A8=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/InvoiceSelectController.java | 1 + .../dz_invoice/mapper/DzInvoiceMapper.java | 11 +- .../service/impl/DzInvoiceServiceImpl.java | 14 ++- .../porsche_review/mapper/ReviewMapper.java | 39 ++++--- .../service/impl/ReviewServiceImpl.java | 109 ++++++++++++++---- .../service/impl/ReportServiceImpl.java | 2 + .../action/InvoiceDeductionAction.java | 7 +- .../schedule/InvoiceQuerySchedule.java | 20 +++- .../commons/config/dao/ConfigMappingCMD.java | 4 +- .../xiao/commons/utils/DocImageFileUtil.java | 82 +++++++++++-- src/test/java/bokang/xiao/ConfigCache.java | 31 +++++ src/test/java/bokang/xiao/NormalTest.java | 92 ++++++++++++--- 12 files changed, 328 insertions(+), 84 deletions(-) create mode 100644 src/test/java/bokang/xiao/ConfigCache.java diff --git a/src/main/java/com/api/bokang/xiao/dz_invoice/controller/InvoiceSelectController.java b/src/main/java/com/api/bokang/xiao/dz_invoice/controller/InvoiceSelectController.java index d44ec32..01e7755 100644 --- a/src/main/java/com/api/bokang/xiao/dz_invoice/controller/InvoiceSelectController.java +++ b/src/main/java/com/api/bokang/xiao/dz_invoice/controller/InvoiceSelectController.java @@ -40,6 +40,7 @@ public class InvoiceSelectController { @Produces(MediaType.APPLICATION_JSON) public String checkInvoice(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map param) { try{ + request.getParameter(""); log.info("into checkInvoice success params ==> "+param); List> maps = dzInvoiceService.checkInvoice(param); return ApiResult.success(maps); diff --git a/src/main/java/com/api/bokang/xiao/dz_invoice/mapper/DzInvoiceMapper.java b/src/main/java/com/api/bokang/xiao/dz_invoice/mapper/DzInvoiceMapper.java index a318558..602351a 100644 --- a/src/main/java/com/api/bokang/xiao/dz_invoice/mapper/DzInvoiceMapper.java +++ b/src/main/java/com/api/bokang/xiao/dz_invoice/mapper/DzInvoiceMapper.java @@ -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> 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); /** *

查询已经勾选过的发票信息

diff --git a/src/main/java/com/api/bokang/xiao/dz_invoice/service/impl/DzInvoiceServiceImpl.java b/src/main/java/com/api/bokang/xiao/dz_invoice/service/impl/DzInvoiceServiceImpl.java index 514d07e..753db86 100644 --- a/src/main/java/com/api/bokang/xiao/dz_invoice/service/impl/DzInvoiceServiceImpl.java +++ b/src/main/java/com/api/bokang/xiao/dz_invoice/service/impl/DzInvoiceServiceImpl.java @@ -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> invoiceList = dzInvoiceMapper.queryInvoiceList(ids); RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(reqUniqueCode); + Map header = new HashMap<>(); + header.put("Content-Type","application/json"); for (Map invoice : invoiceList) { Map result = new HashMap<>(); Map 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; - dzInvoiceMapper.updateInvoiceCheckStatus(checkStatus,"id",invoiceId); + if(reqStatus) { + dzInvoiceMapper.updateInvoiceCheckStatus(checkStatus, "id", invoiceId); + } }else { + log.info("调用勾选接口失败 ==>"+responeVo); result.put("reqFlag",false); } results.add(result); diff --git a/src/main/java/com/api/bokang/xiao/porsche_review/mapper/ReviewMapper.java b/src/main/java/com/api/bokang/xiao/porsche_review/mapper/ReviewMapper.java index 4fba8ed..66e1c99 100644 --- a/src/main/java/com/api/bokang/xiao/porsche_review/mapper/ReviewMapper.java +++ b/src/main/java/com/api/bokang/xiao/porsche_review/mapper/ReviewMapper.java @@ -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 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 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 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 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 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 param); + /** + *

通过表单id获取表单名

+ * @param tableId 表单id + * @return 表单名 + */ @Select("select tablename workflow_bill where id = #{tableId}") String queryTableName(@ParamMapper("tableId")String tableId); } diff --git a/src/main/java/com/api/bokang/xiao/porsche_review/service/impl/ReviewServiceImpl.java b/src/main/java/com/api/bokang/xiao/porsche_review/service/impl/ReviewServiceImpl.java index e1a4966..ca2a769 100644 --- a/src/main/java/com/api/bokang/xiao/porsche_review/service/impl/ReviewServiceImpl.java +++ b/src/main/java/com/api/bokang/xiao/porsche_review/service/impl/ReviewServiceImpl.java @@ -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 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 contractTable = getModelTableSql(contractTableStr); - Map sealTable = getModelTableSql(sealTableStr); + Map> contractTable = getModelTableSql(contractTableStr); + Map> sealTable = getModelTableSql(sealTableStr); log.info("contractTable ==>"+contractTable); log.info("sealTable ==>"+sealTable); //计算合同总数 - for (Map.Entry entry : contractTable.entrySet()) { - String tableName = entry.getKey(); - int count = reviewMapper.queryCountByParam(tableName,entry.getValue()); - contractCount += count; - } + Map contractMap = this.getTotalCountByMap(contractTable, param); + int contractCount = Math.max(contractMap.get("totalCount"),0); //计算电子章总数 - for (Map.Entry entry : sealTable.entrySet()) { - String tableName = entry.getKey(); - int count = reviewMapper.queryCountByParam(tableName,entry.getValue()); - sealCount += count; + Map 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; } /** - *

获取建模表及其唯一字段

+ *

通过配置信息获取总数

+ * @param queryMap 表名及条件信息 + * @param param 请求参数 + * @return 总数 + */ + private Map getTotalCountByMap(Map> queryMap,Map param){ + int totalCount = 0; + Map result = new HashMap<>(); + for (Map.Entry> entry : queryMap.entrySet()) { + String tableName = entry.getKey(); + Map 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; + } + + /** + *

获取建模表及条件sql

* @param sourceStr 原有表名字符串 * @return 表名集合 */ - public Map getModelTableSql(String sourceStr){ - Map modelTableMap = new HashMap<>(); - String regx = "\\{(?\\S+):(?\\S+)}"; + public Map> getModelTableSql(String sourceStr){ + Map> modelTableMap = new HashMap<>(); + sourceStr = toDbc(sourceStr); + String[] split = sourceStr.split(","); + String regx = "\\{(?\\S+):(?[\\S\\s]+):(?\\S+):(?\\S+)}"; Pattern compile = Pattern.compile(regx); - Matcher matcher = compile.matcher(sourceStr); - while (matcher.find()){ - String tableName = matcher.group("tableName"); - String cusSql = matcher.group("cusSql"); - cusSql = cusSql.replaceAll("&"," and ").replaceAll("/|"," or "); - modelTableMap.put(tableName,cusSql); + for (String str : split) { + Matcher matcher = compile.matcher(str); + while (matcher.find()){ + Map cusMap = new HashMap<>(); + String tableName = matcher.group("tableName"); + String cusSql = matcher.group("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; } + /** + *

全角转半角

+ * @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); + } + } diff --git a/src/main/java/com/api/bokang/xiao/wx_report/service/impl/ReportServiceImpl.java b/src/main/java/com/api/bokang/xiao/wx_report/service/impl/ReportServiceImpl.java index 28667c7..ec49bbd 100644 --- a/src/main/java/com/api/bokang/xiao/wx_report/service/impl/ReportServiceImpl.java +++ b/src/main/java/com/api/bokang/xiao/wx_report/service/impl/ReportServiceImpl.java @@ -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; diff --git a/src/main/java/weaver/bokang/xiao/dz_invoice/action/InvoiceDeductionAction.java b/src/main/java/weaver/bokang/xiao/dz_invoice/action/InvoiceDeductionAction.java index 576b6be..a285a97 100644 --- a/src/main/java/weaver/bokang/xiao/dz_invoice/action/InvoiceDeductionAction.java +++ b/src/main/java/weaver/bokang/xiao/dz_invoice/action/InvoiceDeductionAction.java @@ -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 workflowMessage = workflowMapper.queryWorkflowByRequestId(requestId, billTable); + dealWithMapping.setMainTable(billTable); RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(requestUnique); Map requestParam = dealWithMapping.getRequestParam(workflowMessage, requestMappingConfig); - dealWithMapping.setMainTable(billTable); try { - ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam); + Map 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")); diff --git a/src/main/java/weaver/bokang/xiao/dz_invoice/schedule/InvoiceQuerySchedule.java b/src/main/java/weaver/bokang/xiao/dz_invoice/schedule/InvoiceQuerySchedule.java index a96888e..ef32907 100644 --- a/src/main/java/weaver/bokang/xiao/dz_invoice/schedule/InvoiceQuerySchedule.java +++ b/src/main/java/weaver/bokang/xiao/dz_invoice/schedule/InvoiceQuerySchedule.java @@ -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> invoiceList = dzInvoiceMapper.queryOnChooseInvoices(); RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(requestUnique); + Map header = new HashMap<>(8); + header.put("Content-Type","application/json"); if(!invoiceList.isEmpty()){ for (Map invoice : invoiceList) { + logger.info("invoice query ==>"+ JSON.toJSONString(invoice)); Map 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 result = responeVo.getResponseEntity(Map.class); String code = Util.null2String(result.get("code")); if("E0000".equals(code)){ - List> invoices = (List>) result.get("data"); - if(!invoices.isEmpty()){ + Map res = (Map) result.get("result"); + List> invoices = (List>) res.get("data"); + if(Objects.nonNull(invoices) && !invoices.isEmpty()){ for (Map 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)); } } diff --git a/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java b/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java index 9feef2a..5c11d89 100644 --- a/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java +++ b/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java @@ -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, " + diff --git a/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java b/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java index 41983ad..038b015 100644 --- a/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java +++ b/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java @@ -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 itPara = document.getParagraphsIterator(); while (itPara.hasNext()) { XWPFParagraph paragraph = itPara.next(); - List runs = paragraph.getRuns(); - for (XWPFRun run : runs) { - String currentString = run.getText(run.getTextPosition()).trim(); - for (Map.Entry entry : replaceMap.entrySet()) { - if (currentString.equals(entry.getKey())) { - currentString = currentString.replace(entry.getKey(), Util.null2String(entry.getValue())); - } - } - run.setText(currentString, 0); + for (Map.Entry entry : replaceMap.entrySet()) { + DocImageFileUtil.replace(paragraph,entry.getKey(),entry.getValue()); } + } try { FileOutputStream outStream = null; @@ -346,4 +342,66 @@ public class DocImageFileUtil { } } + public static 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 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 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); + // } + //} + } diff --git a/src/test/java/bokang/xiao/ConfigCache.java b/src/test/java/bokang/xiao/ConfigCache.java new file mode 100644 index 0000000..05eceb8 --- /dev/null +++ b/src/test/java/bokang/xiao/ConfigCache.java @@ -0,0 +1,31 @@ +package bokang.xiao; + +import lombok.Data; + +/** + * @ClassName ConfigCache + * @Author 肖博亢 + * @Date 2023/3/7 10:32 + * @Description

+ **/ +@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(){ + + } + } +} diff --git a/src/test/java/bokang/xiao/NormalTest.java b/src/test/java/bokang/xiao/NormalTest.java index d12497a..5224d02 100644 --- a/src/test/java/bokang/xiao/NormalTest.java +++ b/src/test/java/bokang/xiao/NormalTest.java @@ -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> modelTableSql = reviewService.getModelTableSql(s); + System.out.println(modelTableSql); } @Test public void testQuery(){ - TestMapper mapper = Util.getMapper(TestMapper.class); - List> query = mapper.query(); - System.out.println(query); + ReviewMapper reviewMapper = Util.getMapper(ReviewMapper.class); + Map 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 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 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 configCacheClass = ConfigCache.class; + Constructor 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(); + } + }