From 7d005de99a38a04e002648fd8eb59e9c85bf7622 Mon Sep 17 00:00:00 2001 From: ic_excellent Date: Mon, 27 Feb 2023 11:24:02 +0800 Subject: [PATCH] =?UTF-8?q?mapper=E6=94=AF=E6=8C=81Double?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/recordset/DoubleTypeHandler.java | 41 ++++++ .../aiyh/utils/recordset/ResultMapper.java | 6 +- .../dz_invoice/mapper/DzInvoiceMapper.java | 6 +- .../controller/ReportController.java | 53 ++++++++ .../xiao/wx_report/entity/ReportEntityVO.java | 29 ++++ .../xiao/wx_report/mapper/ReportMapper.java | 125 ++++++++++++++++++ .../xiao/wx_report/service/ReportService.java | 10 ++ .../service/impl/ReportServiceImpl.java | 12 ++ .../xiao/commons/utils/DocImageFileUtil.java | 61 ++++++++- src/test/java/bokang/xiao/NormalTest.java | 59 ++++++++- 10 files changed, 393 insertions(+), 9 deletions(-) create mode 100644 src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java create mode 100644 src/main/java/com/api/bokang/xiao/wx_report/controller/ReportController.java create mode 100644 src/main/java/com/api/bokang/xiao/wx_report/entity/ReportEntityVO.java create mode 100644 src/main/java/com/api/bokang/xiao/wx_report/mapper/ReportMapper.java create mode 100644 src/main/java/com/api/bokang/xiao/wx_report/service/ReportService.java create mode 100644 src/main/java/com/api/bokang/xiao/wx_report/service/impl/ReportServiceImpl.java diff --git a/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java b/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java new file mode 100644 index 0000000..6d9d9d0 --- /dev/null +++ b/src/main/java/aiyh/utils/recordset/DoubleTypeHandler.java @@ -0,0 +1,41 @@ +package aiyh.utils.recordset; + +import aiyh.utils.Util; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetTrans; + +import java.lang.reflect.Field; + +/** + *

float处理

+ *

create 2022/4/29 2:34 PM

+ * + * @author ayh + */ + +public class DoubleTypeHandler implements TypeHandler { + @Override + public Object getValue(RecordSet rs, String fieldName, Field declaredField) { + String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "0.0"); + return Double.parseDouble(string); + } + + @Override + public Object getValue(RecordSet rs, int index, Field declaredField) { + String string = Util.null2DefaultStr(rs.getString(index), "0.0"); + return Double.parseDouble(string); + } + + @Override + public Object getValue(RecordSetTrans rs, String fieldName, Field declaredField) { + String string = Util.null2DefaultStr(GetRsValueUtil.getRsValue(rs, fieldName, declaredField), "0.0"); + return Double.parseDouble(string); + } + + @Override + public Object getValue(RecordSetTrans rs, int index, Field declaredField) { + String string = Util.null2DefaultStr(rs.getString(index), "0.0"); + return Double.parseDouble(string); + } + +} diff --git a/src/main/java/aiyh/utils/recordset/ResultMapper.java b/src/main/java/aiyh/utils/recordset/ResultMapper.java index 80467bf..a4e89f8 100644 --- a/src/main/java/aiyh/utils/recordset/ResultMapper.java +++ b/src/main/java/aiyh/utils/recordset/ResultMapper.java @@ -41,7 +41,9 @@ public class ResultMapper { typeHandler.put(boolean.class, new BooleanTypeHandler()); typeHandler.put(Date.class, new DataTypeHandler()); typeHandler.put(Float.class, new FloatTypeHandler()); - typeHandler.put(float.class, new FloatTypeHandler()); + typeHandler.put(Float.class, new FloatTypeHandler()); + typeHandler.put(double.class, new DoubleTypeHandler()); + typeHandler.put(Double.class, new DoubleTypeHandler()); } static { @@ -55,6 +57,8 @@ public class ResultMapper { paramType.put(boolean.class, Boolean::parseBoolean); paramType.put(Float.class, Float::parseFloat); paramType.put(float.class, Float::parseFloat); + paramType.put(double.class, Double::parseDouble); + paramType.put(Double.class, Double::parseDouble); } public T mapperResult(RecordSet rs, Method method, Class tClass, RecordsetUtil recordsetUtil) { 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 e85d4b4..a318558 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 @@ -33,7 +33,7 @@ public interface DzInvoiceMapper { * @param fieldValue 字段值 * @return 操作结果 */ - @Update("update APInvoice set check_status = #{checkStatus} where $t{fieldId} = #{fieldValue}") + @Update("update fnaInvoiceLedger set check_status = #{checkStatus} where $t{fieldId} = #{fieldValue}") boolean updateInvoiceCheckStatus(@ParamMapper("check_status") int checkStatus, @ParamMapper("fieldId") String fieldId, @ParamMapper("fieldValue") Object fieldValue); @@ -45,7 +45,7 @@ public interface DzInvoiceMapper { * @param fieldValue 字段值 * @return 操作结果 */ - @Update("update APInvoice set check_status = #{checkStatus} where $t{fieldId} in ${fieldValue}") + @Update("update fnaInvoiceLedger set check_status = #{checkStatus} where $t{fieldId} in ${fieldValue}") boolean batchUpdateInvoiceCheckStatus(@ParamMapper("check_status") int checkStatus, @ParamMapper("fieldId") String fieldId, @ParamMapper("fieldValue") Object fieldValue); @@ -55,7 +55,7 @@ public interface DzInvoiceMapper { *

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

* @return 发票信息集合 */ - @Select("select * from APInvoice where check_status = 2 or check_status = 3") + @Select("select * from fnaInvoiceLedger where (check_status = 2 or check_status = 3) and hxjksflr = 'Y'") List> queryOnChooseInvoices(); } diff --git a/src/main/java/com/api/bokang/xiao/wx_report/controller/ReportController.java b/src/main/java/com/api/bokang/xiao/wx_report/controller/ReportController.java new file mode 100644 index 0000000..bead34e --- /dev/null +++ b/src/main/java/com/api/bokang/xiao/wx_report/controller/ReportController.java @@ -0,0 +1,53 @@ +package com.api.bokang.xiao.wx_report.controller; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import com.api.bokang.xiao.wx_report.service.ReportService; +import com.api.bokang.xiao.wx_report.service.impl.ReportServiceImpl; +import org.apache.log4j.Logger; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +/** + * @ClassName ReportController + * @Author 肖博亢 + * @Date 2023/2/21 12:45 + * @Description

+ **/ + +@Path("/xbk/wx_report") +public class ReportController { + + private final Logger log = Util.getLogger(); + + private final ReportService reportService = new ReportServiceImpl(); + + /** + *

获取搜索组件信息

+ * @param request 请求体 + * @param response 响应体 + * @return 请求结果 + */ + @Path("/getReportData") + @GET + @Produces(MediaType.APPLICATION_JSON) + public String getReportData(@Context HttpServletRequest request, @Context HttpServletResponse response) { + try{ + log.info("====== into getCondition success ======="); + User loginUser = HrmUserVarify.getUser(request, response); + + return ApiResult.success(""); + }catch (Exception e){ + log.error("获取搜索组件信息 ==> "+Util.getErrString(e)); + return ApiResult.error(e.getMessage()); + } + } +} diff --git a/src/main/java/com/api/bokang/xiao/wx_report/entity/ReportEntityVO.java b/src/main/java/com/api/bokang/xiao/wx_report/entity/ReportEntityVO.java new file mode 100644 index 0000000..d475606 --- /dev/null +++ b/src/main/java/com/api/bokang/xiao/wx_report/entity/ReportEntityVO.java @@ -0,0 +1,29 @@ +package com.api.bokang.xiao.wx_report.entity; + +import lombok.Data; + +/** + * @ClassName ReportEntity + * @Author 肖博亢 + * @Date 2023/2/26 21:06 + * @Description

+ **/ + +@Data +public class ReportEntityVO { + + /** 款项类别 */ + private String category; + + /** 日期 */ + private String date; + + /** 月份 */ + private Integer month; + + /** 月份 */ + private Integer year; + + /** 金额合计 */ + private Double amount; +} diff --git a/src/main/java/com/api/bokang/xiao/wx_report/mapper/ReportMapper.java b/src/main/java/com/api/bokang/xiao/wx_report/mapper/ReportMapper.java new file mode 100644 index 0000000..73c5805 --- /dev/null +++ b/src/main/java/com/api/bokang/xiao/wx_report/mapper/ReportMapper.java @@ -0,0 +1,125 @@ +package com.api.bokang.xiao.wx_report.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import com.api.bokang.xiao.wx_report.entity.ReportEntityVO; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName ReportMapper + * @Author 肖博亢 + * @Date 2023/2/26 21:04 + * @Description

+ **/ + +@SqlMapper +public interface ReportMapper { + + + /** + *

对公付款申请台账(报表)查询

+ * @param queryStr sql + * @param param 条件参数 + * @return 对公申请列表 + */ + @Select("select 90 category,sqrq date,sum(jkjey) amount,month(sqrq) month,year(sqrq) year,day(sqrq) day " + + "from uf_byjjksqtzbb " + + "where 1=1 $t{queryStr} " + + "group by sqrq " + + "union all " + + "select kxlb category,main.qwfkrq date,sum(fkjey) amount,month(main.qwfkrq) month,year(main.qwfkrq) year,day(main.qwfkrq) day " + + "from uf_dgfksqtzbb main " + + "inner join uf_dgfksqtzbb_dt1 dt on main.id = dt.mainid " + + "where kxlb is not null $t{queryStr}" + + "group by dt.kxlb,main.qwfkrq " + + "union all " + + "select kxlb category,main.sqrq date,sum(bxjey) amount,month(main.sqrq) month,year(main.sqrq) year,day(main.sqrq) day " + + "from uf_dsbxsqtzbb main " + + "inner join uf_dsbxsqtzbb_dt1 dt on main.id = dt.mainid " + + "where kxlb is not null $t{queryStr}" + + "group by dt.kxlb,main.sqrq " + + "union all " + + "select kxlb category,main.sqrq date,sum(bxjey) amount,month(main.sqrq) month,year(main.sqrq) year,day(main.sqrq) day " + + "from uf_dsbxsqtzclbb main " + + "inner join uf_dsbxsqtzclbb_dt1 dt on main.id = dt.mainid " + + "where kxlb is not null $t{queryStr}" + + "group by dt.kxlb,main.sqrq " + + "union all " + + "select kxlb category,rq date,sum(hsjey) amount,month(rq) month,year(rq) year,day(rq) day " + + "from uf_srmxb " + + "where kxlb is not null " + + "group by kxlb,rq " + + "order by category ") + List queryReportList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map param); + + /** + *

获取收入数据

+ * @param queryStr sql + * @param param 参数信息 + * @return 数据列表 + */ + @Select("select kxlb category,rq date,sum(hsjey) amount,month(rq) month,year(rq) year,day(rq) day " + + "from uf_srmxb " + + "where kxlb is not null $t{queryStr}" + + "group by kxlb,rq " + + "order by category ") + List queryDataInList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map param); + + /** + *

获取备用金数据

+ * @param queryStr sql + * @param param 参数信息 + * @return 数据列表 + */ + @Select("select 90 category,sqrq date,sum(jkjey) amount,month(sqrq) month,year(sqrq) year,day(sqrq) day " + + "from uf_byjjksqtzbb " + + "where 1=1 $t{queryStr} " + + "group by sqrq ") + List queryPettyCashList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map param); + + /** + *

获取对公付款数据

+ * @param queryStr sql + * @param param 参数信息 + * @return 数据列表 + */ + @Select("select kxlb category,main.qwfkrq date,sum(fkjey) amount,month(main.qwfkrq) month,year(main.qwfkrq) year,day(main.qwfkrq) day " + + "from uf_dgfksqtzbb main " + + "inner join uf_dgfksqtzbb_dt1 dt on main.id = dt.mainid " + + "where kxlb is not null $t{queryStr}" + + "group by dt.kxlb,main.qwfkrq " + + "order by category ") + List queryPublicPayList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map param); + + /** + *

获取对私报销申请数据

+ * @param queryStr sql + * @param param 参数信息 + * @return 数据列表 + */ + @Select("select kxlb category,main.sqrq date,sum(bxjey) amount,month(main.sqrq) month,year(main.sqrq) year,day(main.sqrq) day " + + "from uf_dsbxsqtzbb main " + + "inner join uf_dsbxsqtzbb_dt1 dt on main.id = dt.mainid " + + "where kxlb is not null $t{queryStr}" + + "group by dt.kxlb,main.sqrq " + + "order by category ") + List queryPrivatePayList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map param); + + /** + *

获取对私报销申请台账(差旅)数据

+ * @param queryStr sql + * @param param 参数信息 + * @return 数据列表 + */ + @Select("select kxlb category,main.sqrq date,sum(bxjey) amount,month(main.sqrq) month,year(main.sqrq) year,day(main.sqrq) day " + + "from uf_dsbxsqtzclbb main " + + "inner join uf_dsbxsqtzclbb_dt1 dt on main.id = dt.mainid " + + "where kxlb is not null $t{queryStr}" + + "group by dt.kxlb,main.sqrq " + + "order by category ") + List queryBusinessList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map param); + +} diff --git a/src/main/java/com/api/bokang/xiao/wx_report/service/ReportService.java b/src/main/java/com/api/bokang/xiao/wx_report/service/ReportService.java new file mode 100644 index 0000000..4efcb6c --- /dev/null +++ b/src/main/java/com/api/bokang/xiao/wx_report/service/ReportService.java @@ -0,0 +1,10 @@ +package com.api.bokang.xiao.wx_report.service; + +/** + * @ClassName ReportService + * @Author 肖博亢 + * @Date 2023/2/21 12:38 + * @Description

+ **/ +public interface ReportService { +} 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 new file mode 100644 index 0000000..3883bcb --- /dev/null +++ b/src/main/java/com/api/bokang/xiao/wx_report/service/impl/ReportServiceImpl.java @@ -0,0 +1,12 @@ +package com.api.bokang.xiao.wx_report.service.impl; + +import com.api.bokang.xiao.wx_report.service.ReportService; + +/** + * @ClassName ReportServiceImpl + * @Author 肖博亢 + * @Date 2023/2/21 12:38 + * @Description

+ **/ +public class ReportServiceImpl implements ReportService { +} diff --git a/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java b/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java index 9d2b53a..41983ad 100644 --- a/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java +++ b/src/main/java/weaver/xiao/commons/utils/DocImageFileUtil.java @@ -2,11 +2,16 @@ package weaver.xiao.commons.utils; import aiyh.utils.excention.CustomerException; import org.apache.log4j.Logger; +import org.apache.poi.ooxml.POIXMLDocument; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +import org.apache.poi.xwpf.usermodel.XWPFRun; import weaver.docs.docs.DocImageManager; import weaver.docs.webservices.DocInfo; import weaver.docs.webservices.DocServiceImpl; import weaver.file.ImageFileManager; import weaver.general.IOUtils; +import weaver.general.Util; import weaver.hrm.User; import weaver.xiao.commons.config.entity.WeaverFile; @@ -14,8 +19,7 @@ import java.io.*; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Enumeration; -import java.util.List; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -289,4 +293,57 @@ public class DocImageFileUtil { } } + /** + *

替换word文档的内容并输出为新的文档

+ * @param replaceMap 替换信息 + * @param docSourcePath 原文件路径 + * @return 新文档的路径 + */ + public static String replaceDocument(Map replaceMap, String docSourcePath) { + String sourcePath = docSourcePath.substring(0,docSourcePath.lastIndexOf(File.separator)); + String fileType = docSourcePath.substring(docSourcePath.lastIndexOf(".")); + String targetFileName = sourcePath + File.separator + UUID.randomUUID().toString().replace("-","") + fileType; + DocImageFileUtil.replaceDocument(replaceMap,docSourcePath,targetFileName); + return targetFileName; + } + + /** + *

替换word文档的内容并输出为新的文档

+ * @param replaceMap 替换信息 + * @param docSourcePath 原文件路径 + * @param targetPath 目标文件路径 + */ + public static void replaceDocument(Map replaceMap, String docSourcePath, String targetPath) { + XWPFDocument document = null; + try { + document = new XWPFDocument(POIXMLDocument.openPackage(docSourcePath)); + } catch (IOException e) { + logger.error("模板文件位置错误:" + LogUtil.getExceptionStr(e)); + throw new RuntimeException("模板文件位置错误:" + docSourcePath); + } + 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); + } + } + 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/NormalTest.java b/src/test/java/bokang/xiao/NormalTest.java index f19aa19..47eef00 100644 --- a/src/test/java/bokang/xiao/NormalTest.java +++ b/src/test/java/bokang/xiao/NormalTest.java @@ -8,12 +8,24 @@ import basetest.BaseTest; import bokang.xiao.mapper.TestMapper; import com.api.bokang.xiao.porsche_review.mapper.ReviewMapper; 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; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import org.apache.poi.POIXMLDocument; +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.usermodel.Range; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; +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.xiao.commons.config.entity.ResponseMapping; +import weaver.xiao.commons.utils.DocImageFileUtil; -import java.io.IOException; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; @@ -27,8 +39,8 @@ public class NormalTest extends BaseTest { @Test public void testWord(){ - GenerateFileUtil.createActionDocument(InvoiceDeductionAction.class); - GenerateFileUtil.createCronJobDocument(InvoiceQuerySchedule.class); + //GenerateFileUtil.createActionDocument(InvoiceDeductionAction.class); + //GenerateFileUtil.createCronJobDocument(InvoiceQuerySchedule.class); } @Test @@ -50,8 +62,49 @@ public class NormalTest extends BaseTest { } + @Test + public void testReport(){ + ReportMapper mapper = Util.getMapper(ReportMapper.class); + Map queryParam = new HashMap<>(); + queryParam.put("month","12"); + queryParam.put("year","2022"); + StringBuilder PettyCashBuilder = new StringBuilder(); + StringBuilder PublicPayBuilder = new StringBuilder(); + StringBuilder PrivatePayBuilder = new StringBuilder(); + StringBuilder BusinessBuilder = new StringBuilder(); + StringBuilder whereBuilder = new StringBuilder(); + String month = Util.null2String(queryParam.get("month")); + String year = Util.null2String(queryParam.get("year")); + String date = Util.null2String(queryParam.get("date")); + String company = Util.null2String(queryParam.get("company")); + String depart = Util.null2String(queryParam.get("depart")); + if(StringUtils.isNotBlank(month)){ + + } + List reportEntityVOS = mapper.queryReportList(whereBuilder.toString(),queryParam); + Map> groupMap = reportEntityVOS.stream().collect(Collectors.groupingBy(ReportEntityVO::getCategory)); + System.out.println(groupMap); + } + + @Test + public void testPdf() throws IOException { + Map map = new HashMap<>(); + map.put("$name", "1231"); + String s = DocImageFileUtil.replaceDocument(map, "E:\\test\\test.docx"); + System.out.println(s); + new Thread(() -> { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + DocImageFileUtil.deleteTempFile(s); + }).start(); + } + @Test public void testRequest() throws IOException { + HttpUtils httpUtils = new HttpUtils(); Map param = new HashMap<>(); param.put("grant_type","client_credentials");