万象报表开发

main
ic_excellent 2023-03-03 16:26:53 +08:00
parent 80d9200fdf
commit 0f54e90b33
19 changed files with 810 additions and 66 deletions

16
pom.xml
View File

@ -97,6 +97,22 @@
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>

View File

@ -20,7 +20,6 @@ import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;
/**
* @ClassName YearReviewController
* @Author
@ -36,8 +35,11 @@ public class YearReviewController {
/** 需要排除的流程id */
private final String workflowIds = new ToolUtil().getSystemParamValue("workflowIds");
/** 建模表表名及字段 */
private final String modelTables = new ToolUtil().getSystemParamValue("modelTables");
/** 合同表名及条件信息 */
private final String contractTable = new ToolUtil().getSystemParamValue("contractTable");
/** 用印表名及条件信息 */
private final String sealTable = new ToolUtil().getSystemParamValue("sealTable");
/**
* <h2></h2>
@ -63,6 +65,7 @@ public class YearReviewController {
}
}
/**
* <h2></h2>
* @param request
@ -86,20 +89,21 @@ public class YearReviewController {
}
/**
* <h2></h2>
* <h2></h2>
* @param request
* @param response
* @param param
* @return
*/
@Path("/getElectronicSealCount")
@Path("/getContractAndSealCount")
@POST
@Produces(MediaType.APPLICATION_JSON)
public String getElectronicSealCount(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
try{
param.put("modelTables",modelTables);
int count = reviewService.getElectronicSealCount(param);
return ApiResult.success(count);
param.put("contractTable",contractTable);
param.put("sealTable",sealTable);
Map<String, Object> electronicSealCount = reviewService.getElectronicSealCount(param);
return ApiResult.success(electronicSealCount);
}catch (Exception e){
log.error("获取电子章总数异常 ==> "+Util.getErrString(e));
return ApiResult.error(e.getMessage());
@ -113,14 +117,17 @@ public class YearReviewController {
* @param param
* @return
*/
@Path("/getWorkflowTop5")
@Path("/getWorkflowTop")
@POST
@Produces(MediaType.APPLICATION_JSON)
public String getWorkflowTop5(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
public String getWorkflowTop(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
try{
log.info("into getWorkflowTop5 success params ==> "+param);
log.info("into getWorkflowTop success params ==> "+param);
User loginUser = HrmUserVarify.getUser(request, response);
param.put("workflowIds",workflowIds);
if(!param.containsKey("limit")){
param.put("limit",3);
}
String type = Util.null2String(param.get("type"));
List<Map<String, Object>> data = "create".equals(type) ? reviewService.getCreateTop5(param, loginUser) : reviewService.getOperateTop5(param, loginUser);
return ApiResult.success(data);

View File

@ -112,7 +112,7 @@ public interface ReviewMapper {
" and workflowid not in (${param.workflowIds})" +
"group by workflowid " +
"ORDER BY wcount desc" +
"limit 5")
"limit ${param.limit}")
List<Map<String, Object>> queryCreateTop5(@ParamMapper("param") Map<String,Object> param,@ParamMapper("uid") int uid);
/**
@ -132,7 +132,7 @@ public interface ReviewMapper {
" and operatorid = #{uid} and workflowid not in (${param.workflowIds}) " +
"group by workflowid " +
"order by wcount desc " +
"limit 5")
"limit ${param.limit}")
List<Map<String, Object>> queryOperateTop5(@ParamMapper("param") Map<String, Object> param,@ParamMapper("uid") int uid);
/**
@ -171,12 +171,13 @@ public interface ReviewMapper {
/**
* <h2></h2>
* @param tableName
* @param fieldName
* @param fieldValue
* @param cusSql sql
* @return
*/
@Select("select count(*) from $t{tableName} where $t{fieldName} = #{fieldValue}")
@Select("select count(*) from $t{tableName} where $t{cusSql}")
int queryCountByParam(@ParamMapper("tableName") String tableName,
@ParamMapper("fieldName") String fieldName,
@ParamMapper("fieldValue") String fieldValue);
@ParamMapper("cusSql") String cusSql);
@Select("select tablename workflow_bill where id = #{tableId}")
String queryTableName(@ParamMapper("tableId")String tableId);
}

View File

@ -73,5 +73,5 @@ public interface ReviewService {
* @param param
* @return
*/
int getElectronicSealCount(Map<String, Object> param);
Map<String,Object> getElectronicSealCount(Map<String, Object> param);
}

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 org.apache.log4j.Logger;
import weaver.hrm.User;
import java.util.HashMap;
@ -21,6 +22,8 @@ public class ReviewServiceImpl implements ReviewService {
private final ReviewMapper reviewMapper = Util.getMapper(ReviewMapper.class);
private final Logger log = Util.getLogger();
private Integer resourceCount = 0;
@Override
@ -73,19 +76,33 @@ public class ReviewServiceImpl implements ReviewService {
}
@Override
public int getElectronicSealCount(Map<String, Object> param) {
String modelTables = Util.null2String(param.get("modelTables"));
int totalCount = 0;
Map<String, Map<String, Object>> modelTableMap = getModelTables(modelTables);
for (Map.Entry<String, Map<String, Object>> entry : modelTableMap.entrySet()) {
public Map<String, Object> getElectronicSealCount(Map<String, Object> param) {
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);
log.info("contractTable ==>"+contractTable);
log.info("sealTable ==>"+sealTable);
//计算合同总数
for (Map.Entry<String, String> entry : contractTable.entrySet()) {
String tableName = entry.getKey();
Map<String, Object> fieldMap = entry.getValue();
String fieldName = Util.null2String(fieldMap.get("fieldName"));
String fieldValue = Util.null2String(fieldMap.get("fieldValue"));
int count = reviewMapper.queryCountByParam(tableName, fieldName, fieldValue);
totalCount += count;
int count = reviewMapper.queryCountByParam(tableName,entry.getValue());
contractCount += count;
}
return totalCount;
//计算电子章总数
for (Map.Entry<String, String> entry : sealTable.entrySet()) {
String tableName = entry.getKey();
int count = reviewMapper.queryCountByParam(tableName,entry.getValue());
sealCount += count;
}
double exceed = 1.00*contractCount/sealCount;
result.put("contractCount",contractCount);
result.put("sealCount",sealCount);
result.put("exceed",exceed);
return result;
}
/**
@ -93,19 +110,16 @@ public class ReviewServiceImpl implements ReviewService {
* @param sourceStr
* @return
*/
public Map<String,Map<String,Object>> getModelTables(String sourceStr){
Map<String,Map<String,Object>> modelTableMap = new HashMap<>();
String regx = "\\{(?<tableName>\\S+):(?<fieldName>\\S+):(?<fieldValue>\\S+)}";
public Map<String,String> getModelTableSql(String sourceStr){
Map<String,String> modelTableMap = new HashMap<>();
String regx = "\\{(?<tableName>\\S+):(?<cusSql>\\S+)}";
Pattern compile = Pattern.compile(regx);
Matcher matcher = compile.matcher(sourceStr);
while (matcher.find()){
String tableName = matcher.group("tableName");
String fieldName = matcher.group("fieldName");
String fieldValue = matcher.group("fieldValue");
Map<String,Object> fieldMap = new HashMap<>();
fieldMap.put("fieldName",fieldName);
fieldMap.put("fieldValue",fieldValue);
modelTableMap.put(tableName,fieldMap);
String cusSql = matcher.group("cusSql");
cusSql = cusSql.replaceAll("&"," and ").replaceAll("/|"," or ");
modelTableMap.put(tableName,cusSql);
}
return modelTableMap;
}

View File

@ -4,17 +4,19 @@ 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 io.swagger.v3.oas.annotations.parameters.RequestBody;
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.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 ReportController
@ -37,14 +39,15 @@ public class ReportController {
* @return
*/
@Path("/getReportData")
@GET
@POST
@Produces(MediaType.APPLICATION_JSON)
public String getReportData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
public String getReportData(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map<String,Object> param) {
try{
log.info("====== into getCondition success =======");
log.info("====== into getReportData success =======");
log.info("param:"+param);
User loginUser = HrmUserVarify.getUser(request, response);
return ApiResult.success("");
Map<String,Object> reportData = reportService.getReportData(loginUser, param);
return ApiResult.success(reportData);
}catch (Exception e){
log.error("获取搜索组件信息 ==> "+Util.getErrString(e));
return ApiResult.error(e.getMessage());

View File

@ -0,0 +1,19 @@
package com.api.bokang.xiao.wx_report.entity;
import lombok.Builder;
import lombok.Data;
import java.util.List;
/**
* @ClassName KeyTypeEntity
* @Author
* @Date 2023/2/28 13:18
* @Description <h1></h1>
**/
@Data
@Builder
public class KeyTypeEntity {
private String key;
private List<String> typeList;
}

View File

@ -0,0 +1,18 @@
package com.api.bokang.xiao.wx_report.entity;
import lombok.Builder;
import lombok.Data;
/**
* @ClassName NetConfigItem
* @Author
* @Date 2023/2/28 16:01
* @Description <h1></h1>
**/
@Data
@Builder
public class NetConfigItem {
private String dataInConfig;
private String dataOutConfig;
}

View File

@ -0,0 +1,83 @@
package com.api.bokang.xiao.wx_report.entity;
import lombok.Data;
import java.util.List;
/**
* @ClassName ReportDataVO
* @Author
* @Date 2023/2/27 11:52
* @Description <h1></h1>
**/
@Data
public class ReportDataVO {
/** 经营性活动list */
private List<ReportEntityVO> businessActivityList;
/** 筹集资金list */
private List<ReportEntityVO> financingList;
/** 投资现金list */
private List<ReportEntityVO> investmentList;
/** 其他现金list */
private List<ReportEntityVO> otherList;
/** 经营性活动流入小计 */
private Double businessInTotal;
/** 经营性活动支出小计 */
private Double businessOutTotal;
/** 生产性经营支出小计 */
private Double productionOutTotal;
/** 固定支出小计 */
private Double fixOutTotal;
/** 经营性活动净额 */
private Double businessNetTotal;
/** 筹集资金流入小计 */
private Double financingInTotal;
/** 筹集资金流出小计 */
private Double financingOutTotal;
/** 筹集资金净额 */
private Double financingNetTotal;
/** 投资现金流入小计 */
private Double investmentInTotal;
/** 投资现金流出小计 */
private Double investmentOutTotal;
/** 投资现金净额 */
private Double investmentNetTotal;
/** 其他现金流入小计 */
private Double otherInTotal;
/** 其他现金流出小计 */
private Double otherOutTotal;
/** 其他现金净额 */
private Double otherNetTotal;
/** 收入小计 */
private Double inTotal;
/** 支出小计 */
private Double outTotal;
/** 本期净额 */
private Double netTotal;
/** 本期结余 */
private Double balanceTotal;
}

View File

@ -1,6 +1,13 @@
package com.api.bokang.xiao.wx_report.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
* @ClassName ReportEntity
@ -10,6 +17,9 @@ import lombok.Data;
**/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReportEntityVO {
/** 款项类别 */
@ -24,6 +34,15 @@ public class ReportEntityVO {
/** 月份 */
private Integer year;
/** 日 */
private Integer day;
/** 金额合计 */
private Double amount;
public void setAmount(Double amount) {
DecimalFormat format = new DecimalFormat("#.00");
String str = format.format(amount);
this.amount = Double.parseDouble(str);
}
}

View File

@ -77,7 +77,8 @@ public interface ReportMapper {
@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 ")
"group by sqrq " +
"order by category ")
List<ReportEntityVO> queryPettyCashList(@ParamMapper("queryStr") String queryStr,@ParamMapper("param") Map<String,Object> param);
/**

View File

@ -1,5 +1,11 @@
package com.api.bokang.xiao.wx_report.service;
import com.api.bokang.xiao.wx_report.entity.ReportEntityVO;
import weaver.hrm.User;
import java.util.List;
import java.util.Map;
/**
* @ClassName ReportService
* @Author
@ -7,4 +13,12 @@ package com.api.bokang.xiao.wx_report.service;
* @Description <h1></h1>
**/
public interface ReportService {
/**
* <h2></h2>
* @param user
* @param param
* @return
*/
Map<String, Object> getReportData(User user, Map<String,Object> param);
}

View File

@ -0,0 +1,16 @@
package com.api.bokang.xiao.wx_report.service.fun;
import lombok.Data;
/**
* @ClassName Entry
* @Author
* @Date 2023/2/28 12:33
* @Description <h1></h1>
**/
@Data
public class Entry<K,V> {
private K key;
private V value;
}

View File

@ -0,0 +1,18 @@
package com.api.bokang.xiao.wx_report.service.fun;
import java.util.List;
/**
* @ClassName GroupFunction
* @Author
* @Date 2023/2/28 12:32
* @Description <h1></h1>
**/
@FunctionalInterface
public interface GroupFunction<K,V,T> {
Entry<K,V> group(List<T> list);
}

View File

@ -1,6 +1,20 @@
package com.api.bokang.xiao.wx_report.service.impl;
import aiyh.utils.Util;
import com.api.bokang.xiao.wx_report.entity.KeyTypeEntity;
import com.api.bokang.xiao.wx_report.entity.NetConfigItem;
import com.api.bokang.xiao.wx_report.entity.ReportEntityVO;
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.fun.Entry;
import com.api.bokang.xiao.wx_report.service.fun.GroupFunction;
import weaver.hrm.User;
import java.text.DecimalFormat;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* @ClassName ReportServiceImpl
@ -9,4 +23,366 @@ import com.api.bokang.xiao.wx_report.service.ReportService;
* @Description <h1></h1>
**/
public class ReportServiceImpl implements ReportService {
private final ReportMapper reportMapper = Util.getMapper(ReportMapper.class);
private static final List<KeyTypeEntity> TYPE_IN_LIST = new ArrayList<>();
private static final List<KeyTypeEntity> TYPE_OUT_LIST = new ArrayList<>();
private static final Map<String, NetConfigItem> NET_MAP_CONFIG = new HashMap<>();
static {
//经营性活动现金流入 "0":销售回款; "1":电池租赁款; "2":国补"; "3":其他
TYPE_IN_LIST.add(KeyTypeEntity.builder().key("businessInTotal").typeList(Arrays.asList("0","1","2","3")).build());
//筹资活动现金流入 "4":贷款流入; "5":借款流入; "6":内部往来款
TYPE_IN_LIST.add(KeyTypeEntity.builder().key("financingInTotal").typeList(Arrays.asList("4","5","6")).build());
//投资活动资金流入 "7":收到投资款
TYPE_IN_LIST.add(KeyTypeEntity.builder().key("investmentInTotal").typeList(Collections.singletonList("7")).build());
//其他收入 "8"退保证金; "9"电池背靠背收; "10"其他收入-其他
TYPE_IN_LIST.add(KeyTypeEntity.builder().key("otherInTotal").typeList(Arrays.asList("8","9","10")).build());
}
static {
//生产经营支出 "1":水电、动力款; "8":采购货款(含零星); "4":广宣费; "2":运费(含快递费);
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("productionOutTotal").typeList(Arrays.asList("1","8","4","2")).build());
//固定支出 "7":税款; "3":社保/福利/奖金; "11":财务费用; "6":工资、劳务费; "0":费用报销
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("fixOutTotal").typeList(Arrays.asList("7","3","11","6","0")).build());
//经营活动支出小计 生产经营支出 + 固定支出
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("businessOutTotal").typeList(Arrays.asList("1","8","4","2","7","3","11","6","0")).build());
//固定支出 "7":税款; "3":社保/福利/奖金; "11":财务费用; "6":工资、劳务费; "0":费用报销
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("fixOutTotal").typeList(Arrays.asList("7","3","11","6","0")).build());
//筹资活动现金流出 "9":融资还款(贷款); "10":内部往来还款
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("financingOutTotal").typeList(Arrays.asList("9","10")).build());
//投资活动资金流出 "12":设备款; "13":基建工程款; "15":投资支付的现金; "14":资质准入; "5":研发款、检测款
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("investmentOutTotal").typeList(Arrays.asList("12","13","14","15","5")).build());
//其他支出 "16":保证金; "19":电池背靠背支出; "17":其他支出-其他; "18":暂借款
TYPE_OUT_LIST.add(KeyTypeEntity.builder().key("otherOutTotal").typeList(Arrays.asList("16","17","18","19")).build());
}
static {
NET_MAP_CONFIG.put("businessNetTotal",NetConfigItem.builder().dataInConfig("businessInTotal").dataOutConfig("businessOutTotal").build());
NET_MAP_CONFIG.put("financingNetTotal",NetConfigItem.builder().dataInConfig("financingInTotal").dataOutConfig("financingOutTotal").build());
NET_MAP_CONFIG.put("investmentNetTotal",NetConfigItem.builder().dataInConfig("investmentInTotal").dataOutConfig("investmentOutTotal").build());
NET_MAP_CONFIG.put("otherNetTotal",NetConfigItem.builder().dataInConfig("businessInTotal").dataOutConfig("businessOutTotal").build());
NET_MAP_CONFIG.put("netTotal",NetConfigItem.builder().dataInConfig("inTotal").dataOutConfig("outTotal").build());
}
@Override
public Map<String, Object> getReportData(User user, Map<String, Object> param) {
Map<String,Object> result = new HashMap<>();
Map<String, String> sqlMap = this.buildSql(param);
List<ReportEntityVO> reportEntityList = new ArrayList<>();
List<ReportEntityVO> dataInList = reportMapper.queryDataInList(sqlMap.get("dataInSql"), param);
List<ReportEntityVO> pettyCashList = reportMapper.queryPettyCashList(sqlMap.get("pettyCashSql"), param);
List<ReportEntityVO> publicPayList = reportMapper.queryPublicPayList(sqlMap.get("publicPaySql"), param);
List<ReportEntityVO> privatePayList = reportMapper.queryPrivatePayList(sqlMap.get("privatePaySql"), param);
List<ReportEntityVO> businessList = reportMapper.queryBusinessList(sqlMap.get("businessSql"), param);
reportEntityList.addAll(pettyCashList);
reportEntityList.addAll(publicPayList);
reportEntityList.addAll(privatePayList);
reportEntityList.addAll(businessList);
//分组求和 统计同一款项类别的数据集合,并计算统一款项类别,同一天的数据总和
Map<String, List<ReportEntityVO>> dataOutMap = this.groupList(reportEntityList);
//分组 统计同一款项类别的数据集合
Map<String, List<ReportEntityVO>> dataInMap = dataInList.stream().collect(Collectors.groupingBy(ReportEntityVO::getCategory));
List<ReportEntityVO> dataInAllList = this.statisticsSum(dataInMap);
List<ReportEntityVO> dataOutAllList = this.statisticsSum(dataOutMap);
//分组统计总和
Map<String, List<ReportEntityVO>> totalMap = this.getTotalMap(dataInAllList,1);
totalMap.putAll(this.getTotalMap(dataOutAllList,2));
totalMap.putAll(this.getNetMap(totalMap));
result.put("dataInMap",dataInMap);
result.put("dataOutMap",dataOutMap);
result.put("totalMap",totalMap);
result.put("currentCompanySpan",Util.null2String(param.get("currentCompanySpan")));
result.put("month",Util.null2String(param.get("month")));
return result;
}
/**
* <h2></h2>
* @param totalMap
* @return
*/
public Map<String,List<ReportEntityVO>> getNetMap(Map<String, List<ReportEntityVO>> totalMap){
return NET_MAP_CONFIG.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> {
NetConfigItem netConfigItem = e.getValue();
String dataInConfig = netConfigItem.getDataInConfig();
String dataOutConfig = netConfigItem.getDataOutConfig();
List<ReportEntityVO> dataInReportList = totalMap.get(dataInConfig);
List<ReportEntityVO> dataOutReportList = totalMap.get(dataOutConfig);
Map<Integer,Double> netTotalMap = new HashMap<>();
if(dataInReportList!= null && !dataInReportList.isEmpty()) {
for (ReportEntityVO inReport : dataInReportList) {
netTotalMap.put(inReport.getDay(), inReport.getAmount());
}
}
if(dataOutReportList!= null && !dataOutReportList.isEmpty()) {
for (ReportEntityVO outReport : dataOutReportList) {
if (netTotalMap.containsKey(outReport.getDay())) {
double inTotal = netTotalMap.get(outReport.getDay());
double outTotal = outReport.getAmount();
netTotalMap.put(outReport.getDay(), this.getTwoDouble(inTotal - outTotal));
}else {
netTotalMap.put(outReport.getDay(),this.getTwoDouble(-1*(outReport.getAmount())));
}
}
}
return netTotalMap.entrySet().stream().map(netEntry -> ReportEntityVO.builder()
.day(netEntry.getKey())
.amount(netEntry.getValue())
.build()).collect(Collectors.toList());
}));
}
/**
* <h2></h2>
* @param amount
* @return double
*/
public double getTwoDouble(double amount) {
DecimalFormat format = new DecimalFormat("#.00");
String str = format.format(amount);
return Double.parseDouble(str);
}
/**
* <h2>map</h2>
* @param dataList
* @param type 1: 2:
* @return
*/
public Map<String,List<ReportEntityVO>> getTotalMap(List<ReportEntityVO> dataList,int type){
List<KeyTypeEntity> typeList = type == 1 ? TYPE_IN_LIST : TYPE_OUT_LIST;
Map<String, List<ReportEntityVO>> totalMap = new HashMap<>();
List<ReportEntityVO> dataTotalList = new ArrayList<>();
Map<Integer, List<ReportEntityVO>> dayReportMap = dataList.stream().collect(Collectors.groupingBy(ReportEntityVO::getDay));
for (Map.Entry<Integer, List<ReportEntityVO>> dayReportEntry : dayReportMap.entrySet()) {
Integer day = dayReportEntry.getKey();
List<ReportEntityVO> dayReportList = dayReportEntry.getValue();
double sum = dayReportList.stream().mapToDouble(ReportEntityVO::getAmount).sum();
sum = this.getTwoDouble(sum);
dataTotalList.add(ReportEntityVO.builder()
.amount(sum)
.day(day)
.build()
);
Map<String, ReportEntityVO> reportEntityMap = this.sumParse(dayReportList,typeList);
for (Map.Entry<String, ReportEntityVO> entry : reportEntityMap.entrySet()) {
String key = entry.getKey();
ReportEntityVO value = entry.getValue();
if(totalMap.containsKey(key)){
totalMap.get(key).add(value);
}else {
List<ReportEntityVO> totalReportList = new ArrayList<>();
totalReportList.add(value);
totalMap.put(key,totalReportList);
}
}
}
String totalKey = type == 1 ? "inTotal" : "outTotal";
totalMap.put(totalKey,dataTotalList);
return totalMap;
}
/**
* <h2></h2>
* @param reportEntityList
* @param typeList
* @return
*/
private Map<String,ReportEntityVO> sumParse(List<ReportEntityVO> reportEntityList,List<KeyTypeEntity> typeList){
List<GroupFunction<String,List<ReportEntityVO>,ReportEntityVO>> groupFun = new ArrayList<>();
for (KeyTypeEntity keyTypeEntity : typeList) {
groupFun.add(list->parseGroup(reportEntityList,keyTypeEntity.getKey(),
item-> keyTypeEntity.getTypeList()
.contains(item),ReportEntityVO::getCategory));
}
Map<String, ReportEntityVO> result = new HashMap<>(16);
for (GroupFunction<String, List<ReportEntityVO>, ReportEntityVO> fun : groupFun) {
Entry<String, List<ReportEntityVO>> groupEntry = fun.group(reportEntityList);
if(Objects.isNull(groupEntry)){
continue;
}
double sum = groupEntry.getValue().stream().mapToDouble(ReportEntityVO::getAmount).sum();
sum = this.getTwoDouble(sum);
result.put(groupEntry.getKey(), ReportEntityVO.builder()
.amount(sum)
.day(groupEntry.getValue().get(0).getDay())
.build());
}
return result;
}
/**
* <h2></h2>
* @param list
* @param k
* @param compare
* @param compareValue
* @return
* @param <K>
* @param <T> list
* @param <R>
*/
private <K,T,R> Entry<K,List<T>> parseGroup(List<T> list, K k,
Predicate<R> compare,
Function<T,R> compareValue){
Entry<K,List<T>> entry = new Entry<>();
for (T t : list) {
if(compare.test(compareValue.apply(t))){
if(Objects.isNull(entry.getValue())){
entry.setValue(new ArrayList<>());
}
entry.getValue().add(t);
}
}
if(entry.getValue() == null || entry.getValue().isEmpty()){
return null;
}
entry.setKey(k);
return entry;
}
/**
* <h2>list</h2>
* @param reportEntityList
* @return map
*/
public Map<String, List<ReportEntityVO>> groupList(List<ReportEntityVO> reportEntityList){
return reportEntityList.stream()
.collect(Collectors.groupingBy(ReportEntityVO::getCategory))
.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().stream()
.collect(Collectors.groupingBy(ReportEntityVO::getDate))
.entrySet().stream()
.map(dateListEntry -> {
List<ReportEntityVO> dateList = dateListEntry.getValue();
ReportEntityVO reportEntity = dateList.get(0);
double amount = dateList.stream().mapToDouble(ReportEntityVO::getAmount).sum();
amount = this.getTwoDouble(amount);
return ReportEntityVO.builder()
.amount(amount)
.date(dateListEntry.getKey())
.day(reportEntity.getDay())
.year(reportEntity.getYear())
.category(reportEntity.getCategory())
.month(reportEntity.getMonth())
.build();
}).collect(Collectors.toList())
));
}
/**
* <h2></h2>
* @param dataMap
* @return list
*/
public List<ReportEntityVO> statisticsSum(Map<String, List<ReportEntityVO>> dataMap){
List<ReportEntityVO> allReportList = new ArrayList<>();
//计算每一行的总和并将结果加到list中
for (Map.Entry<String, List<ReportEntityVO>> entry : dataMap.entrySet()) {
String category = entry.getKey();
List<ReportEntityVO> reportList = entry.getValue();
ReportEntityVO reportEntityVO = reportList.get(0);
double cateGoryTotal = reportList.stream().mapToDouble(ReportEntityVO::getAmount).sum();
cateGoryTotal = this.getTwoDouble(cateGoryTotal);
ReportEntityVO totalEntity = ReportEntityVO.builder()
.amount(cateGoryTotal)
.day(-1)
.category(category)
.month(reportEntityVO.getMonth())
.year(reportEntityVO.getYear())
.build();
reportList.add(totalEntity);
allReportList.addAll(reportList);
}
return allReportList;
}
/**
* <h2>sql</h2>
* @param param
* @return sql
*/
public Map<String,String> buildSql(Map<String, Object> param){
Map<String,String> sqlMap = new HashMap<>();
StringBuilder pettyCashBuilder = new StringBuilder();
StringBuilder publicPayBuilder = new StringBuilder();
StringBuilder privatePayBuilder = new StringBuilder();
StringBuilder businessBuilder = new StringBuilder();
StringBuilder dataInBuilder = new StringBuilder();
String month = Util.null2String(param.get("month"));
String year = Util.null2String(param.get("year"));
String date = Util.null2String(param.get("date"));
String company = Util.null2String(param.get("company"));
String depart = Util.null2String(param.get("depart"));
if(!"".equals(month)){
dataInBuilder.append(" and ").append(" month(rq) = #{param.month}");
pettyCashBuilder.append(" and ").append(" month(sqrq) = #{param.month}");
publicPayBuilder.append(" and ").append(" month(main.qwfkrq) = #{param.month}");
privatePayBuilder.append(" and ").append(" month(main.sqrq) = #{param.month}");
businessBuilder.append(" and ").append(" month(main.sqrq) = #{param.month}");
}
if(!"".equals(year)){
dataInBuilder.append(" and ").append(" year(rq) = #{param.year}");
pettyCashBuilder.append(" and ").append(" year(sqrq) = #{param.year}");
publicPayBuilder.append(" and ").append(" year(main.qwfkrq) = #{param.year}");
privatePayBuilder.append(" and ").append(" year(main.sqrq) = #{param.year}");
businessBuilder.append(" and ").append(" year(main.sqrq) = #{param.year}");
}
if(!"".equals(date)){
dataInBuilder.append(" and ").append(" rq = #{param.date}");
pettyCashBuilder.append(" and ").append(" sqrq = #{param.date}");
publicPayBuilder.append(" and ").append(" main.qwfkrq = #{param.date}");
privatePayBuilder.append(" and ").append(" main.sqrq = #{param.date}");
businessBuilder.append(" and ").append(" main.sqrq = #{param.date}");
}
if(!"".equals(depart)){
dataInBuilder.append(" and ").append(" fycdbm = #{param.depart}");
pettyCashBuilder.append(" and ").append(" sqbm = #{param.depart}");
publicPayBuilder.append(" and ").append(" main.sqbm = #{param.depart}");
privatePayBuilder.append(" and ").append(" main.sqbm = #{param.depart}");
businessBuilder.append(" and ").append(" main.sqbm = #{param.depart}");
}
if(!"".equals(company)){
dataInBuilder.append(" and ").append(" fyzfgs = #{param.company}");
pettyCashBuilder.append(" and ").append(" dwmc = #{param.company}");
publicPayBuilder.append(" and ").append(" main.fycdgs = #{param.company}");
privatePayBuilder.append(" and ").append(" main.fycdgs = #{param.company}");
businessBuilder.append(" and ").append(" main.sqrq = #{param.company}");
}
sqlMap.put("dataInSql",dataInBuilder.toString());
sqlMap.put("pettyCashSql",pettyCashBuilder.toString());
sqlMap.put("publicPaySql",publicPayBuilder.toString());
sqlMap.put("privatePaySql",privatePayBuilder.toString());
sqlMap.put("businessSql",businessBuilder.toString());
return sqlMap;
}
}

View File

@ -1,32 +1,43 @@
package bokang.xiao;
import aiyh.utils.GenerateFileUtil;
import aiyh.utils.ThreadPoolConfig;
import aiyh.utils.Util;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import basetest.BaseTest;
import bokang.xiao.entity.CourseEntity;
import bokang.xiao.entity.StudentEntity;
import bokang.xiao.entity.TeacherEntity;
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.impl.ReviewServiceImpl;
import com.api.bokang.xiao.wx_report.entity.ReportEntityVO;
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 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.ss.usermodel.Workbook;
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.hrm.User;
import weaver.xiao.commons.config.entity.ResponseMapping;
import weaver.xiao.commons.utils.DocImageFileUtil;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
/**
@ -68,22 +79,10 @@ public class NormalTest extends BaseTest {
Map<String,Object> 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<ReportEntityVO> reportEntityVOS = mapper.queryReportList(whereBuilder.toString(),queryParam);
Map<String, List<ReportEntityVO>> groupMap = reportEntityVOS.stream().collect(Collectors.groupingBy(ReportEntityVO::getCategory));
System.out.println(groupMap);
//queryParam.put("date","2022-12-01");
ReportService reportService = new ReportServiceImpl();
Map<String, Object> reportData = reportService.getReportData(new User(1), queryParam);
System.out.println(reportData);
}
@Test
@ -129,6 +128,45 @@ public class NormalTest extends BaseTest {
Map responseEntity = responeVo1.getResponseEntity(Map.class);
System.out.println(responseEntity);
}
@Test
public void testExportExcel() throws Exception {
List<CourseEntity> courseEntityList = new ArrayList<>();
CourseEntity courseEntity = new CourseEntity();
courseEntity.setId("1");
courseEntity.setName("测试课程");
TeacherEntity teacherEntity = new TeacherEntity();
teacherEntity.setName("张老师");
teacherEntity.setSex(1);
courseEntity.setMathTeacher(teacherEntity);
courseEntity.setStingList(Arrays.asList("姜凯","加几个","hih"));
List<StudentEntity> studentEntities = new ArrayList<>();
for (int i = 1; i <= 2; i++) {
StudentEntity studentEntity = new StudentEntity();
studentEntity.setName("学生" + i);
studentEntity.setSex(i);
studentEntity.setBirthday(new Date());
studentEntities.add(studentEntity);
}
courseEntity.setStudents(studentEntities);
courseEntityList.add(courseEntity);
Date start = new Date();
Workbook workbook = ExcelExportUtil.exportExcel( new ExportParams("导出测试", null, "测试"),
CourseEntity.class, courseEntityList);
System.out.println(new Date().getTime() - start.getTime());
File savefile = new File("D:/excel/");
if (!savefile.exists()) {
savefile.mkdirs();
}
FileOutputStream fos = new FileOutputStream("D:/excel/教师课程学生导出测试.xls");
workbook.write(fos);
fos.close();
}
}

View File

@ -0,0 +1,38 @@
package bokang.xiao.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import lombok.Data;
import java.util.List;
/**
* @ClassName CourseEntity
* @Author
* @Date 2023/3/3 13:35
* @Description <h1></h1>
**/
@Data
public class CourseEntity implements java.io.Serializable {
/** 主键 */
private String id;
/** 课程名称 */
@Excel(name = "课程名称", orderNum = "1", width = 25,needMerge = true)
private String name;
/** 老师主键 */
//@ExcelEntity(id = "major")
private TeacherEntity chineseTeacher;
/** 老师主键 */
@ExcelEntity(id = "absent")
private TeacherEntity mathTeacher;
@ExcelCollection(name = "学生", orderNum = "4")
private List<StudentEntity> students;
@ExcelCollection(name = "kkl", orderNum = "4")
private List<String> StingList;
}

View File

@ -0,0 +1,38 @@
package bokang.xiao.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* @ClassName StudentEntity
* @Author
* @Date 2023/3/3 13:36
* @Description <h1></h1>
**/
@Data
public class StudentEntity {
/**
* id
*/
private String id;
/**
*
*/
@Excel(name = "学生姓名", height = 20, width = 30, isImportField = "true_st")
private String name;
/**
*
*/
@Excel(name = "学生性别", replace = { "男_1", "女_2" }, suffix = "生", isImportField = "true_st")
private int sex;
@Excel(name = "出生日期", exportFormat = "yyyyMMddHHmmss", format = "yyyy-MM-dd", isImportField = "true_st", width = 20)
private Date birthday;
@Excel(name = "进校日期", exportFormat = "yyyyMMddHHmmss", format = "yyyy-MM-dd")
private Date registrationDate;
}

View File

@ -0,0 +1,25 @@
package bokang.xiao.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
/**
* @ClassName TeacherEntity
* @Author
* @Date 2023/3/3 13:35
* @Description <h1></h1>
**/
@Data
public class TeacherEntity {
/**
*
*/
@Excel(name = "教师姓名", height = 20, width = 30, isImportField = "true_st")
private String name;
/**
*
*/
@Excel(name = "教师性别", replace = {"男_1", "女_2"}, suffix = "生", isImportField = "true_st")
private int sex;
}