请求济南拓兴获取高支模数据-合并

This commit is contained in:
guoshengxiong 2025-11-04 09:06:34 +08:00
parent 1804b4f80b
commit de1a4cc585
9 changed files with 701 additions and 490 deletions

View File

@ -5,15 +5,19 @@ import com.zhgd.netty.tcp.constant.HighFormworkSupport;
import com.zhgd.xmgl.modules.highformwork.entity.*;
import com.zhgd.xmgl.modules.highformwork.entity.vo.HighFormworkMeasureCurrentDataAlarmStateEnum;
import com.zhgd.xmgl.modules.highformwork.mapper.*;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkAlarmDataService;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkMeasureCurrentDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -36,6 +40,9 @@ public class HighFormworkSupportService {
private HighFormworkAlarmDataMapper highFormworkAlarmDataMapper;
@Autowired
private HighFormworkMeasurePointThresholdMapper highFormworkMeasurePointThresholdMapper;
@Lazy
@Autowired
private IHighFormworkAlarmDataService highFormworkAlarmDataService;
public void saveTcpData(String msg) throws ParseException {
/*
@ -214,7 +221,7 @@ public class HighFormworkSupportService {
HighFormworkMeasureCurrentData currentData = getAndSaveHighFormworkMeasureCurrentData(dataMap, no, no2, no3, no4, no5, no6, point);
//插入报警/预警数据
addAlarmData(point, currentData);
highFormworkAlarmDataService.addAlarmData(point, currentData);
}
@ -310,97 +317,6 @@ public class HighFormworkSupportService {
currentData.setAlarmState(alarmState);
}
/**
* 插入报警/预警数据
*
* @param point
* @param currentData
*/
private void addAlarmData(HighFormworkMeasurePoint point, HighFormworkMeasureCurrentData currentData) {
boolean isAlarm = false;
boolean isWarn = false;
List<HighFormworkMeasurePointThreshold> thresholds = highFormworkMeasurePointThresholdMapper.selectList(new LambdaQueryWrapper<HighFormworkMeasurePointThreshold>()
.eq(HighFormworkMeasurePointThreshold::getMeasurePointId, point.getId()));
if (CollectionUtils.isNotEmpty(thresholds)) {
for (HighFormworkMeasurePointThreshold threshold : thresholds) {
Integer type = threshold.getType();
Double alarmValue = StringUtils.isNotBlank(threshold.getAlarmValue()) ? Double.valueOf(threshold.getAlarmValue()) : null;
Double warningValue = StringUtils.isNotBlank(threshold.getWarningValue()) ? Double.valueOf(threshold.getWarningValue()) : null;
//类型1立杆轴力2水平位移3模板沉降4立杆倾斜5地基沉降
if (type == 1) {
Double subside = StringUtils.isNotBlank(currentData.getPoleAxialForce()) ? Double.valueOf(currentData.getPoleAxialForce()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 1, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 1, 2);
isWarn = true;
}
} else if (type == 2) {
Double subside = StringUtils.isNotBlank(currentData.getHorizontalDisplacement()) ? Double.valueOf(currentData.getHorizontalDisplacement()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 2, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 2, 2);
isWarn = true;
}
} else if (type == 3) {
Double subside = StringUtils.isNotBlank(currentData.getFormworkSettlement()) ? Double.valueOf(currentData.getFormworkSettlement()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 3, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 3, 2);
isWarn = true;
}
} else if (type == 4) {
Double subside = StringUtils.isNotBlank(currentData.getPoleTilt()) ? Double.valueOf(currentData.getPoleTilt()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 4, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 4, 2);
isWarn = true;
}
} else if (type == 5) {
Double subside = StringUtils.isNotBlank(currentData.getFoundationSettlement()) ? Double.valueOf(currentData.getFoundationSettlement()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 5, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 5, 2);
isWarn = true;
}
}
}
}
HighFormworkMeasurePoint tempHighFormworkMeasurePoint = new HighFormworkMeasurePoint();
tempHighFormworkMeasurePoint.setId(point.getId());
tempHighFormworkMeasurePoint.setRealTime(new Date());
tempHighFormworkMeasurePoint.setAlarmState(isAlarm ? 3 : (isWarn ? 2 : 1));
highFormworkMeasurePointMapper.updateById(tempHighFormworkMeasurePoint);
}
private void insertHighFormworkAlarmData(HighFormworkMeasurePoint point, Double electricPower, Integer type, Integer warningValue) {
HighFormworkAlarmData highFormworkAlarmData = new HighFormworkAlarmData();
highFormworkAlarmData.setType(type);
highFormworkAlarmData.setMeasurePointId(point.getId());
highFormworkAlarmData.setAlarmValue(String.valueOf(electricPower));
highFormworkAlarmData.setAlarmType(warningValue);
highFormworkAlarmData.setProjectSn(point.getProjectSn());
highFormworkAlarmDataMapper.insert(highFormworkAlarmData);
}
/**
* 获取测点状态

View File

@ -2,12 +2,10 @@ package com.zhgd.xmgl.modules.highformwork.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasureCurrentData;
import com.zhgd.xmgl.modules.highformwork.entity.vo.BigScreenHighFormworkVo;
import com.zhgd.xmgl.modules.highformwork.entity.vo.DataPerHourForTheLastDayVo;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkMeasureCurrentDataService;
import com.zhgd.xmgl.modules.taskprogress.entity.TaskProgressMaterialRel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -46,7 +44,7 @@ public class HighFormworkMeasureCurrentDataController {
@ApiOperation(value = "分页列表查询高支模-测量点实时数据信息", notes = "分页列表查询高支模-测量点实时数据信息", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "measurePointNumber", value = "监测点编号", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "acquisitionInstrumentNumber", value = "采集仪编号(联瑞科-终端编号)", paramType = "query", required = true, dataType = "String"),
@ApiImplicitParam(name = "acquisitionInstrumentNumber", value = "采集仪编号(联瑞科-终端编号)", paramType = "query", required = false, dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间格式2021-05-08", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间格式2021-05-08", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "alarmState", value = "报警状态1正常2预警3报警", paramType = "body", required = false, dataType = "String"),

View File

@ -31,10 +31,10 @@
and hfmcd.collect_time &lt;= CONCAT(DATE_FORMAT(#{param.endTime}, "%Y-%m-%d"), ' 23:59:59')
</if>
<if test="param.measurePointNumber != null and param.measurePointNumber != ''">
and hfmcd.measure_point_number like CONCAT(CONCAT('%', #{param.measurePointNumber}), '%')
and hfmcd.measure_point_number like #{param.measurePointNumber}
</if>
<if test="param.acquisitionInstrumentNumber != null and param.acquisitionInstrumentNumber != ''">
and hfmcd.acquisition_instrument_number like CONCAT(CONCAT('%', #{param.acquisitionInstrumentNumber}), '%')
and hfmcd.acquisition_instrument_number like #{param.acquisitionInstrumentNumber}
</if>
<if test="param.alarmState != null and param.alarmState != ''">
and hfmcd.alarm_state = #{param.alarmState}

View File

@ -5,6 +5,8 @@ import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkAlarmData;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasureCurrentData;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasurePoint;
import com.zhgd.xmgl.modules.highformwork.entity.vo.NumberDifferentTypesAlarmsRadarChartOneMonthVo;
import javax.servlet.http.HttpServletRequest;
@ -24,4 +26,11 @@ public interface IHighFormworkAlarmDataService extends IService<HighFormworkAlar
List<NumberDifferentTypesAlarmsRadarChartOneMonthVo> getNumberDifferentTypesAlarmsRadarChartOneMonth(Map<String, Object> map);
List<EntityMap> getAlarmCycleTrendGraph(Map<String, Object> map);
/**
* 插入报警/预警数据
* @param point
* @param currentData
*/
void addAlarmData(HighFormworkMeasurePoint point, HighFormworkMeasureCurrentData currentData);
}

View File

@ -1,5 +1,6 @@
package com.zhgd.xmgl.modules.highformwork.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -7,14 +8,23 @@ import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.discharging.service.impl.DischargingPlatformAlarmServiceImpl;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkAlarmData;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasureCurrentData;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasurePoint;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasurePointThreshold;
import com.zhgd.xmgl.modules.highformwork.entity.vo.NumberDifferentTypesAlarmsRadarChartOneMonthVo;
import com.zhgd.xmgl.modules.highformwork.mapper.HighFormworkAlarmDataMapper;
import com.zhgd.xmgl.modules.highformwork.mapper.HighFormworkMeasurePointMapper;
import com.zhgd.xmgl.modules.highformwork.mapper.HighFormworkMeasurePointThresholdMapper;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkAlarmDataService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -31,6 +41,12 @@ public class HighFormworkAlarmDataServiceImpl extends ServiceImpl<HighFormworkAl
private DischargingPlatformAlarmServiceImpl dischargingPlatformAlarmService;
@Autowired
private HighFormworkAlarmDataMapper highFormworkAlarmDataMapper;
@Lazy
@Autowired
private HighFormworkMeasurePointMapper highFormworkMeasurePointMapper;
@Lazy
@Autowired
private HighFormworkMeasurePointThresholdMapper highFormworkMeasurePointThresholdMapper;
@Override
public Result<IPage<HighFormworkAlarmData>> queryPageList(HighFormworkAlarmData highFormworkAlarmData, Integer pageNo, Integer pageSize, HttpServletRequest req) {
@ -57,6 +73,93 @@ public class HighFormworkAlarmDataServiceImpl extends ServiceImpl<HighFormworkAl
return list;
}
@Override
public void addAlarmData(HighFormworkMeasurePoint point, HighFormworkMeasureCurrentData currentData) {
boolean isAlarm = false;
boolean isWarn = false;
List<HighFormworkMeasurePointThreshold> thresholds = highFormworkMeasurePointThresholdMapper.selectList(new LambdaQueryWrapper<HighFormworkMeasurePointThreshold>()
.eq(HighFormworkMeasurePointThreshold::getMeasurePointId, point.getId()));
if (CollectionUtils.isNotEmpty(thresholds)) {
for (HighFormworkMeasurePointThreshold threshold : thresholds) {
Integer type = threshold.getType();
Double alarmValue = StringUtils.isNotBlank(threshold.getAlarmValue()) ? Double.valueOf(threshold.getAlarmValue()) : null;
Double warningValue = StringUtils.isNotBlank(threshold.getWarningValue()) ? Double.valueOf(threshold.getWarningValue()) : null;
//类型1立杆轴力2水平位移3模板沉降4立杆倾斜5地基沉降
if (type == 1) {
Double subside = StringUtils.isNotBlank(currentData.getPoleAxialForce()) ? Double.valueOf(currentData.getPoleAxialForce()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 1, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 1, 2);
isWarn = true;
}
} else if (type == 2) {
Double subside = StringUtils.isNotBlank(currentData.getHorizontalDisplacement()) ? Double.valueOf(currentData.getHorizontalDisplacement()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 2, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 2, 2);
isWarn = true;
}
} else if (type == 3) {
Double subside = StringUtils.isNotBlank(currentData.getFormworkSettlement()) ? Double.valueOf(currentData.getFormworkSettlement()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 3, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 3, 2);
isWarn = true;
}
} else if (type == 4) {
Double subside = StringUtils.isNotBlank(currentData.getPoleTilt()) ? Double.valueOf(currentData.getPoleTilt()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 4, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 4, 2);
isWarn = true;
}
} else if (type == 5) {
Double subside = StringUtils.isNotBlank(currentData.getFoundationSettlement()) ? Double.valueOf(currentData.getFoundationSettlement()) : null;
if (subside != null && alarmValue != null && alarmValue < subside) {
//报警
insertHighFormworkAlarmData(point, subside, 5, 1);
isAlarm = true;
} else if (subside != null && warningValue != null && warningValue < subside) {
//预警
insertHighFormworkAlarmData(point, subside, 5, 2);
isWarn = true;
}
}
}
}
HighFormworkMeasurePoint tempHighFormworkMeasurePoint = new HighFormworkMeasurePoint();
tempHighFormworkMeasurePoint.setId(point.getId());
tempHighFormworkMeasurePoint.setRealTime(new Date());
tempHighFormworkMeasurePoint.setAlarmState(isAlarm ? 3 : (isWarn ? 2 : 1));
highFormworkMeasurePointMapper.updateById(tempHighFormworkMeasurePoint);
}
private void insertHighFormworkAlarmData(HighFormworkMeasurePoint point, Double electricPower, Integer type, Integer warningValue) {
HighFormworkAlarmData highFormworkAlarmData = new HighFormworkAlarmData();
highFormworkAlarmData.setType(type);
highFormworkAlarmData.setMeasurePointId(point.getId());
highFormworkAlarmData.setAlarmValue(String.valueOf(electricPower));
highFormworkAlarmData.setAlarmType(warningValue);
highFormworkAlarmData.setProjectSn(point.getProjectSn());
baseMapper.insert(highFormworkAlarmData);
}
/**
* 补全数据
*

View File

@ -348,13 +348,21 @@ public class Project implements Serializable {
private String xiaosaAppSecret;
@ApiModelProperty(value="icc同步id")
private java.lang.Long iccId ;
@ApiModelProperty(value = "项目图标")
private String projectIcon;
/**位置json*/
@ApiModelProperty(value="位置json")
private java.lang.String positionJson ;
@ApiModelProperty(value = "济南拓兴appKey")
private String jntxAppKey;
@ApiModelProperty(value = "济南拓兴appSecret")
private String jntxAppSecret;
/**
* 桥梁长度(m)
*/
@Excel(name = "桥梁长度(m)", width = 15)
@ApiModelProperty(value = "桥梁长度(m)")
private java.lang.String bridgeLength;
/**
* runde平台token
*/

View File

@ -51,9 +51,11 @@ import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -845,392 +847,403 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
})
@PostMapping(value = "/exportWorkerDailyAttendancesStaticsByMonthXls")
public void exportWorkerDailyAttendancesStaticsByMonthXls(HttpServletResponse response, @RequestBody HashMap<String, Object> param) {
String templateUrl = null;
AtomicReference<String> templateUrl = new AtomicReference<>();
try {
ArrayList<Integer> delColIndexes = new ArrayList<>();
String projectSn = MapUtils.getString(param, "projectSn");
Project project = projectService.getOne(new LambdaQueryWrapper<Project>()
.eq(Project::getProjectSn, projectSn));
Project project = projectService.getOne(new LambdaQueryWrapper<Project>().eq(Project::getProjectSn, projectSn));
String startDate = MapUtils.getString(param, "startDate");
String endDate = MapUtils.getString(param, "endDate");
Integer downloadType = MapUtils.getInteger(param, "downloadType");
Integer groupByType = MapUtils.getInteger(param, "groupByType");
List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR);
Map<Integer, Map<String, Object>> root = new HashMap<>();
int sheetIndex = 0;
List<String> sheetNames = new ArrayList<>();
String tempSheetName;
if (Objects.equals(groupByType, 3)) {
//按班组/部门
tempSheetName = "考勤月报-按班组.xlsx";
//考勤月报-按班组.xlsx
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, List<StatisticsListVo>> deptNameMap = voList.stream().collect(Collectors.groupingBy(StatisticsListVo::getDeptName));
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
BigDecimal totalHour = BigDecimal.ZERO;
for (Map.Entry<String, List<StatisticsListVo>> entry : deptNameMap.entrySet()) {
BigDecimal totalAttendanceDay = BigDecimal.ZERO;
Map<String, Object> sheetMap = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
List<StatisticsListVo> vos = entry.getValue();
int index = 0;
for (StatisticsListVo vo : vos) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", Objects.equals(vo.getPersonType(), 1) ? "施工人员" : "管理人员");
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
sheetMap.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
String value;
if (Objects.equals(downloadType, 1) || Objects.equals(downloadType, 2)) {
value = getExcelAmPmAttendanceByDate(personSn2Date2AttendancesMap, vo, dateTime, downloadType);
} else if (Objects.equals(downloadType, 3)) {
//每日工时
value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(BigDecimal::toString).orElse("0.0");
} else {
//每日明细
value = Optional.ofNullable(vo.getDailyAttendanceMap().get(DateUtil.formatDate(dateTime))).map(integer -> Objects.equals(integer, 1) ? "" : "×").orElse("x");
}
map.put("attendanceByDate" + (z + 1), value);
}
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
totalAttendanceDay = NumberUtil.add(vo.getTotalAttendanceDay(), totalAttendanceDay);
totalHour = NumberUtil.add(vo.getTotalHour(), totalHour);
listMap.add(map);
}
sheetMap.put("listMap", listMap);
sheetMap.put("projectName", project.getProjectName());
StatisticsListVo vo = CollUtil.getFirst(vos);
sheetMap.put("title", StrUtil.format("项目名称:{} 参建单位名称:{} {}名称:{} 总人数:{} 时间:({} - {}",
project.getProjectName(), vo.getEnterpriseName(), vo.getPersonType() == 1 ? "班组" : "部门", vo.getDeptName(), vos.size(), startDate, endDate));
sheetMap.put("totalAttendanceDay", totalAttendanceDay);
sheetMap.put("totalHour", totalHour);
root.put(sheetIndex++, sheetMap);
sheetNames.add(entry.getKey());
}
for (int i = 11 + dateTimes.size(); i < 11 + 31; i++) {
delColIndexes.add(i);
}
templateUrl = FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
if (CollUtil.isNotEmpty(delColIndexes)) {
ExcelUtils.removeColumns(templateUrl, 0, delColIndexes);
}
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
ExcelUtils.cloneSheetMultipleTimes(templateUrl, outputTemplateFilePath, "1", sheetNames.size() - 1);
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(sheetNames.toArray(new String[]{}));
try (Workbook workbook = ExcelExportUtil.exportExcel(root, params);) {
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
downloadByTeam(response, param, projectSn, project, startDate, endDate, downloadType, templateUrl);
} else if (Objects.equals(groupByType, 2)) {
//按参建单位
tempSheetName = "考勤月报-按单位-出勤人数与考勤报表.xlsx";
//导出sheet1上海振南出勤人数
List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo> list = workerDailyAttendanceStatisticsV2Service.countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(param);
Map<String, Map<Integer, Map<Long, ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo>>> date2Type2IdMap = list.stream()
.collect(Collectors.groupingBy(
ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDate, // 第一层按日期分组
Collectors.groupingBy(
ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getPersonType, // 第二层按类型分组
Collectors.toMap(
ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDeptId, // 第三层按ID映射
Function.identity(),
(existing, replacement) -> existing // 处理键冲突保留现有值
)
)
));
Map<String, Object> sheetMap1 = new HashMap<>();
List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> listMap1 = new ArrayList<>();
Integer totalGlNum = 0;
Integer totalSgNum = 0;
Map<String, Integer> deptKeyMap = new HashMap<>();
int index = 0;
String enterpriseId = MapUtils.getString(param, "enterpriseId");
List<DepartmentInfo> departmentInfos = departmentInfoService.list(new LambdaQueryWrapper<DepartmentInfo>()
.eq(DepartmentInfo::getEnterpriseId, enterpriseId));
List<TeamInfo> teamInfos = teamInfoService.list(new LambdaQueryWrapper<TeamInfo>()
.eq(TeamInfo::getEnterpriseId, enterpriseId));
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("date", DateUtil.format(dateTime, "yyyy年MM月dd日"));
Integer glNum = 0;
Integer sgNum = 0;
for (DepartmentInfo departmentInfo : departmentInfos) {
Map<String, Object> e = new HashMap<>();
String deptName = departmentInfo.getDepartmentName();
e.put("name", deptName + "(部门)");
e.put("glName", "管理人数");
e.put("sgName", "施工人数");
String glKey = "gl" + deptName;
String sgKey = "sg" + deptName;
e.put("glNum", "t." + glKey);
e.put("sgNum", "t." + sgKey);
e.put("totalNumKey", deptName);
colList.add(e);
Integer glKeyVal = Optional.ofNullable(date2Type2IdMap.get(DateUtil.format(dateTime, "yyyy-MM-dd"))).map(m -> m.get(2)).map(m -> m.get(departmentInfo.getId())).map(m -> m.getWorkerNum()).orElse(0);
glNum += glKeyVal;
Integer sgKeyVal = 0;
map.put(glKey, glKeyVal);
map.put(sgKey, sgKeyVal);
deptKeyMap.merge(glKey, glKeyVal, (o, n) -> o + n);
deptKeyMap.merge(sgKey, sgKeyVal, (o, n) -> o + n);
}
for (TeamInfo teamInfo : teamInfos) {
Map<String, Object> e = new HashMap<>();
String deptName = teamInfo.getTeamName();
e.put("name", deptName + "(班组)");
e.put("glName", "管理人数");
e.put("sgName", "施工人数");
String glKey = "gl" + deptName;
String sgKey = "sg" + deptName;
e.put("glNum", "t." + glKey);
e.put("sgNum", "t." + sgKey);
e.put("totalNumKey", deptName);
colList.add(e);
Integer sgKeyVal = Optional.ofNullable(date2Type2IdMap.get(DateUtil.format(dateTime, "yyyy-MM-dd"))).map(m -> m.get(1)).map(m -> m.get(teamInfo.getId())).map(m -> m.getWorkerNum()).orElse(0);
sgNum += sgKeyVal;
Integer glKeyVal = 0;
map.put(glKey, glKeyVal);
map.put(sgKey, sgKeyVal);
deptKeyMap.merge(glKey, glKeyVal, (o, n) -> o + n);
deptKeyMap.merge(sgKey, sgKeyVal, (o, n) -> o + n);
}
map.put("glNum", glNum);
map.put("sgNum", sgNum);
map.put("totalNum", glNum + sgNum);
listMap1.add(map);
totalGlNum += glNum;
totalSgNum += sgNum;
}
for (Map<String, Object> map : colList) {
map.put("glTotalNum", deptKeyMap.get("gl" + MapUtils.getString(map, "totalNumKey")));
map.put("sgTotalNum", deptKeyMap.get("sg" + MapUtils.getString(map, "totalNumKey")));
}
sheetMap1.put("listMap", listMap1);
sheetMap1.put("totalGlNum", totalGlNum);
sheetMap1.put("totalSgNum", totalSgNum);
sheetMap1.put("totalNum", totalGlNum + totalSgNum);
sheetMap1.put("projectName", project.getProjectName());
sheetMap1.put("hourValBegin", MapUtils.getInteger(param, "hourValBegin"));
EnterpriseInfo enterpriseInfo = enterpriseInfoService.getById(enterpriseId);
String enterpriseName = enterpriseInfo.getEnterpriseName();
sheetMap1.put("enterpriseName", enterpriseName);
sheetMap1.put("colList", colList);
root.put(0, sheetMap1);
sheetNames.add(enterpriseName + "出勤人数");
param.put("startTime", startDate);
param.put("endTime", endDate);
//导出sheet2上海振南考勤报表
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Object> sheetMap2 = new HashMap<>();
index = 0;
List<Map<String, Object>> listMap2 = new ArrayList<>();
for (StatisticsListVo vo : voList) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", Objects.equals(vo.getPersonType(), 1) ? "施工人员" : "管理人员");
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
sheetMap2.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
//每日工时
String value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("0.0");
map.put("attendanceByDate" + (z + 1), value);
}
listMap2.add(map);
}
sheetMap2.put("listMap", listMap2);
sheetMap2.put("projectName", project.getProjectName());
sheetMap2.put("title", StrUtil.format("项目名称:{} 参建单位名称:{} 班组名称:全部 总人数:{} 时间:({} - {}",
project.getProjectName(), enterpriseName, voList.size(), startDate, endDate));
sheetMap2.put("enterpriseName", enterpriseName);
root.put(1, sheetMap2);
sheetNames.add(enterpriseName + "考勤报表");
templateUrl = FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
TemplateExportParams params = new TemplateExportParams(templateUrl, true);
params.setColForEach(true);
params.setSheetName(sheetNames.toArray(new String[]{}));
for (int i = 10 + dateTimes.size(); i < 10 + 41; i++) {
delColIndexes.add(i);
}
try (Workbook workbook = ExcelExportUtil.exportExcel(root, params);) {
if (CollUtil.isNotEmpty(delColIndexes)) {
ExcelUtils.removeColumns(((XSSFWorkbook) workbook), 1, delColIndexes);
}
ExcelUtils.mergeRows(workbook, 0, 0, 0, 0, 4 + colList.size() * 2);
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
downloadByEnterprise(response, param, project, startDate, endDate, templateUrl);
} else if (Objects.equals(groupByType, 4)) {
//按人员
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
tempSheetName = "单个人员考勤出入明细报表.xlsx";
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
for (StatisticsListVo vo : voList) {
Map<String, Object> sheetMap = new HashMap<>();
sheetMap.put("startDate", startDate);
sheetMap.put("endDate", endDate);
List<Map<String, Object>> listMap = new ArrayList<>();
for (int z = 0; z < dateTimes.size(); z++) {
Map<String, Object> map = new HashMap<>();
DateTime date = dateTimes.get(z);
map.put("date", DateUtil.formatDate(date));
map.put("week", DateUtil.dayOfWeekEnum(date).toChinese());
map.put("detail", Optional.ofNullable(personSn2Date2AttendancesMap.get(vo.getPersonSn())).map(m -> m.get(DateUtil.formatDate(date)))
.map(attendances -> attendances.stream().sorted(Comparator.comparing(WorkerAttendance::getCreateTime))
.map(att -> DateUtil.format(DateUtil.parseDateTime(att.getCreateTime()), "HH:mm") + (att.getPassType() == 1 ? "入场" : "出场")).collect(Collectors.joining("\n"))).orElse(""));
listMap.add(map);
}
root.put(sheetIndex++, sheetMap);
sheetMap.put("listMap", listMap);
sheetMap.put("projectName", project.getProjectName());
sheetMap.put("personType", vo.getPersonType() == 1 ? "班组" : "部门");
sheetMap.put("enterpriseName", vo.getEnterpriseName());
sheetMap.put("workerName", vo.getWorkerName());
sheetMap.put("deptName", vo.getDeptName());
sheetMap.put("workerTypeName", vo.getWorkerTypeName());
sheetMap.put("totalAttendanceDay", vo.getTotalAttendanceDay());
sheetNames.add(vo.getWorkerName());
}
templateUrl = FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
ExcelUtils.cloneSheetMultipleTimes(templateUrl, outputTemplateFilePath, "1", sheetNames.size() - 1);
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(ListUtils.renameDuplicates(sheetNames).toArray(new String[]{}));
try (Workbook workbook = ExcelExportUtil.exportExcel(root, params);) {
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
downloadByWorker(response, param, projectSn, project, startDate, endDate, templateUrl);
} else if (Objects.equals(groupByType, 1)) {
//按项目
tempSheetName = "考勤月报-按项目.xlsx";
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
List<StatisticsListVo> vos = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
BigDecimal totalAttendanceDay = BigDecimal.ZERO;
BigDecimal totalHour = BigDecimal.ZERO;
Map<String, Object> sheetMap = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
int index = 0;
for (StatisticsListVo vo : vos) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", Objects.equals(vo.getPersonType(), 1) ? "施工人员" : "管理人员");
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
sheetMap.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
String value;
if (Objects.equals(downloadType, 1) || Objects.equals(downloadType, 2)) {
value = getExcelAmPmAttendanceByDate(personSn2Date2AttendancesMap, vo, dateTime, downloadType);
} else if (Objects.equals(downloadType, 3)) {
//每日工时
value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("");
} else {
//每日明细
value = Optional.ofNullable(vo.getDailyAttendanceMap().get(DateUtil.formatDate(dateTime))).map(integer -> Objects.equals(integer, 1) ? "" : "×").orElse("x");
}
map.put("attendanceByDate" + (z + 1), value);
}
map.put("totalHour", Objects.nonNull(vo.getTotalHour()) && !NumberUtil.equals(vo.getTotalHour(), BigDecimal.ZERO) ? vo.getTotalHour() : "0.0");
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
totalAttendanceDay = NumberUtil.add(vo.getTotalAttendanceDay(), totalAttendanceDay);
totalHour = NumberUtil.add(vo.getTotalHour(), totalHour);
listMap.add(map);
}
for (int i = 11 + dateTimes.size(); i < 11 + 31; i++) {
delColIndexes.add(i);
}
sheetMap.put("listMap", listMap);
sheetMap.put("totalAttendanceDay", totalAttendanceDay);
sheetMap.put("totalWorkerNum", vos.size());
sheetMap.put("totalHour", totalHour);
sheetMap.put("startDate", startDate);
sheetMap.put("endDate", endDate);
sheetMap.put("projectName", project.getProjectName());
root.put(0, sheetMap);
sheetNames.add(project.getProjectName());
templateUrl = FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
TemplateExportParams params = new TemplateExportParams(templateUrl, true);
params.setSheetName(sheetNames.toArray(new String[]{}));
try (Workbook workbook = ExcelExportUtil.exportExcel(root, params);) {
if (CollUtil.isNotEmpty(delColIndexes)) {
ExcelUtils.removeColumns(((XSSFWorkbook) workbook), 0, delColIndexes);
}
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
downloadByProject(response, param, projectSn, project, startDate, endDate, downloadType, templateUrl);
}
} catch (Exception e) {
throw new OpenAlertException("系统错误", e);
} finally {
if (templateUrl != null) {
FileUtil.deleteFile(templateUrl);
if (templateUrl.get() != null) {
FileUtil.deleteFile(templateUrl.get());
}
}
}
private void downloadByProject(HttpServletResponse response, HashMap<String, Object> param, String projectSn, Project project, String startDate, String endDate, Integer downloadType, AtomicReference<String> templateUrl) throws IOException {
//按项目
String tempSheetName = "考勤月报-按项目.xlsx";
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
List<StatisticsListVo> vos = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
BigDecimal totalAttendanceDay = BigDecimal.ZERO;
BigDecimal totalHour = BigDecimal.ZERO;
Map<String, Object> sheetMap = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
int index = 0;
for (StatisticsListVo vo : vos) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", Objects.equals(vo.getPersonType(), 1) ? "施工人员" : "管理人员");
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
for (int z = 0; z < DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); z++) {
DateTime dateTime = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).get(z);
sheetMap.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
String value;
if (Objects.equals(downloadType, 1) || Objects.equals(downloadType, 2)) {
value = getExcelAmPmAttendanceByDate(personSn2Date2AttendancesMap, vo, dateTime, downloadType);
} else if (Objects.equals(downloadType, 3)) {
//每日工时
value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("");
} else {
//每日明细
value = Optional.ofNullable(vo.getDailyAttendanceMap().get(DateUtil.formatDate(dateTime))).map(integer -> Objects.equals(integer, 1) ? "" : "×").orElse("x");
}
map.put("attendanceByDate" + (z + 1), value);
}
map.put("totalHour", Objects.nonNull(vo.getTotalHour()) && !NumberUtil.equals(vo.getTotalHour(), BigDecimal.ZERO) ? vo.getTotalHour() : "0.0");
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
totalAttendanceDay = NumberUtil.add(vo.getTotalAttendanceDay(), totalAttendanceDay);
totalHour = NumberUtil.add(vo.getTotalHour(), totalHour);
listMap.add(map);
}
for (int i = 11 + DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); i < 11 + 31; i++) {
new ArrayList<Integer>().add(i);
}
sheetMap.put("listMap", listMap);
sheetMap.put("totalAttendanceDay", totalAttendanceDay);
sheetMap.put("totalWorkerNum", vos.size());
sheetMap.put("totalHour", totalHour);
sheetMap.put("startDate", startDate);
sheetMap.put("endDate", endDate);
sheetMap.put("projectName", project.getProjectName());
((Map<Integer, Map<String, Object>>) new HashMap<Integer, Map<String, Object>>()).put(0, sheetMap);
((List<String>) new ArrayList<String>()).add(project.getProjectName());
templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath());
TemplateExportParams params = new TemplateExportParams(templateUrl.get(), true);
params.setSheetName(((List<String>) new ArrayList<String>()).toArray(new String[]{}));
try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap<Integer, Map<String, Object>>(), params);) {
if (CollUtil.isNotEmpty(new ArrayList<Integer>())) {
ExcelUtils.removeColumns(((XSSFWorkbook) workbook), 0, new ArrayList<Integer>());
}
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
}
private void downloadByWorker(HttpServletResponse response, HashMap<String, Object> param, String projectSn, Project project, String startDate, String endDate, AtomicReference<String> templateUrl) throws IOException {
int sheetIndex = 0;
//按人员
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
String tempSheetName = "单个人员考勤出入明细报表.xlsx";
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
for (StatisticsListVo vo : voList) {
Map<String, Object> sheetMap = new HashMap<>();
sheetMap.put("startDate", startDate);
sheetMap.put("endDate", endDate);
List<Map<String, Object>> listMap = new ArrayList<>();
for (int z = 0; z < DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); z++) {
Map<String, Object> map = new HashMap<>();
DateTime date = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).get(z);
map.put("date", DateUtil.formatDate(date));
map.put("week", DateUtil.dayOfWeekEnum(date).toChinese());
map.put("detail", Optional.ofNullable(personSn2Date2AttendancesMap.get(vo.getPersonSn())).map(m -> m.get(DateUtil.formatDate(date)))
.map(attendances -> attendances.stream().sorted(Comparator.comparing(WorkerAttendance::getCreateTime))
.map(att -> DateUtil.format(DateUtil.parseDateTime(att.getCreateTime()), "HH:mm") + (att.getPassType() == 1 ? "入场" : "出场")).collect(Collectors.joining("\n"))).orElse(""));
listMap.add(map);
}
((Map<Integer, Map<String, Object>>) new HashMap<Integer, Map<String, Object>>()).put(sheetIndex++, sheetMap);
sheetMap.put("listMap", listMap);
sheetMap.put("projectName", project.getProjectName());
sheetMap.put("personType", vo.getPersonType() == 1 ? "班组" : "部门");
sheetMap.put("enterpriseName", vo.getEnterpriseName());
sheetMap.put("workerName", vo.getWorkerName());
sheetMap.put("deptName", vo.getDeptName());
sheetMap.put("workerTypeName", vo.getWorkerTypeName());
sheetMap.put("totalAttendanceDay", vo.getTotalAttendanceDay());
((List<String>) new ArrayList<String>()).add(vo.getWorkerName());
}
templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath());
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
ExcelUtils.cloneSheetMultipleTimes(templateUrl.get(), outputTemplateFilePath, "1", ((List<String>) new ArrayList<String>()).size() - 1);
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(ListUtils.renameDuplicates(new ArrayList<String>()).toArray(new String[]{}));
try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap<Integer, Map<String, Object>>(), params);) {
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
}
private void downloadByEnterprise(HttpServletResponse response, HashMap<String, Object> param, Project project, String startDate, String endDate, AtomicReference<String> templateUrl) throws IOException {
//按参建单位
String tempSheetName = "考勤月报-按单位-出勤人数与考勤报表.xlsx";
//导出sheet1上海振南出勤人数
List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo> list = workerDailyAttendanceStatisticsV2Service.countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(param);
Map<String, Map<Integer, Map<Long, ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo>>> date2Type2IdMap = list.stream()
.collect(Collectors.groupingBy(
ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDate, // 第一层按日期分组
Collectors.groupingBy(
ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getPersonType, // 第二层按类型分组
Collectors.toMap(
ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDeptId, // 第三层按ID映射
Function.identity(),
(existing, replacement) -> existing // 处理键冲突保留现有值
)
)
));
Map<String, Object> sheetMap1 = new HashMap<>();
List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> listMap1 = new ArrayList<>();
Integer totalGlNum = 0;
Integer totalSgNum = 0;
Map<String, Integer> deptKeyMap = new HashMap<>();
int index = 0;
String enterpriseId = MapUtils.getString(param, "enterpriseId");
List<DepartmentInfo> departmentInfos = departmentInfoService.list(new LambdaQueryWrapper<DepartmentInfo>()
.eq(DepartmentInfo::getEnterpriseId, enterpriseId));
List<TeamInfo> teamInfos = teamInfoService.list(new LambdaQueryWrapper<TeamInfo>()
.eq(TeamInfo::getEnterpriseId, enterpriseId));
for (int z = 0; z < DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); z++) {
DateTime dateTime = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).get(z);
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("date", DateUtil.format(dateTime, "yyyy年MM月dd日"));
Integer glNum = 0;
Integer sgNum = 0;
for (DepartmentInfo departmentInfo : departmentInfos) {
Map<String, Object> e = new HashMap<>();
String deptName = departmentInfo.getDepartmentName();
e.put("name", deptName + "(部门)");
e.put("glName", "管理人数");
e.put("sgName", "施工人数");
String glKey = "gl" + deptName;
String sgKey = "sg" + deptName;
e.put("glNum", "t." + glKey);
e.put("sgNum", "t." + sgKey);
e.put("totalNumKey", deptName);
colList.add(e);
Integer glKeyVal = Optional.ofNullable(date2Type2IdMap.get(DateUtil.format(dateTime, "yyyy-MM-dd"))).map(m -> m.get(2)).map(m -> m.get(departmentInfo.getId())).map(m -> m.getWorkerNum()).orElse(0);
glNum += glKeyVal;
Integer sgKeyVal = 0;
map.put(glKey, glKeyVal);
map.put(sgKey, sgKeyVal);
deptKeyMap.merge(glKey, glKeyVal, (o, n) -> o + n);
deptKeyMap.merge(sgKey, sgKeyVal, (o, n) -> o + n);
}
for (TeamInfo teamInfo : teamInfos) {
Map<String, Object> e = new HashMap<>();
String deptName = teamInfo.getTeamName();
e.put("name", deptName + "(班组)");
e.put("glName", "管理人数");
e.put("sgName", "施工人数");
String glKey = "gl" + deptName;
String sgKey = "sg" + deptName;
e.put("glNum", "t." + glKey);
e.put("sgNum", "t." + sgKey);
e.put("totalNumKey", deptName);
colList.add(e);
Integer sgKeyVal = Optional.ofNullable(date2Type2IdMap.get(DateUtil.format(dateTime, "yyyy-MM-dd"))).map(m -> m.get(1)).map(m -> m.get(teamInfo.getId())).map(m -> m.getWorkerNum()).orElse(0);
sgNum += sgKeyVal;
Integer glKeyVal = 0;
map.put(glKey, glKeyVal);
map.put(sgKey, sgKeyVal);
deptKeyMap.merge(glKey, glKeyVal, (o, n) -> o + n);
deptKeyMap.merge(sgKey, sgKeyVal, (o, n) -> o + n);
}
map.put("glNum", glNum);
map.put("sgNum", sgNum);
map.put("totalNum", glNum + sgNum);
listMap1.add(map);
totalGlNum += glNum;
totalSgNum += sgNum;
}
for (Map<String, Object> map : colList) {
map.put("glTotalNum", deptKeyMap.get("gl" + MapUtils.getString(map, "totalNumKey")));
map.put("sgTotalNum", deptKeyMap.get("sg" + MapUtils.getString(map, "totalNumKey")));
}
sheetMap1.put("listMap", listMap1);
sheetMap1.put("totalGlNum", totalGlNum);
sheetMap1.put("totalSgNum", totalSgNum);
sheetMap1.put("totalNum", totalGlNum + totalSgNum);
sheetMap1.put("projectName", project.getProjectName());
sheetMap1.put("hourValBegin", MapUtils.getInteger(param, "hourValBegin"));
EnterpriseInfo enterpriseInfo = enterpriseInfoService.getById(enterpriseId);
String enterpriseName = enterpriseInfo.getEnterpriseName();
sheetMap1.put("enterpriseName", enterpriseName);
sheetMap1.put("colList", colList);
((Map<Integer, Map<String, Object>>) new HashMap<Integer, Map<String, Object>>()).put(0, sheetMap1);
((List<String>) new ArrayList<String>()).add(enterpriseName + "出勤人数");
param.put("startTime", startDate);
param.put("endTime", endDate);
//导出sheet2上海振南考勤报表
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Object> sheetMap2 = new HashMap<>();
index = 0;
List<Map<String, Object>> listMap2 = new ArrayList<>();
for (StatisticsListVo vo : voList) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", Objects.equals(vo.getPersonType(), 1) ? "施工人员" : "管理人员");
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
for (int z = 0; z < DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); z++) {
DateTime dateTime = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).get(z);
sheetMap2.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
//每日工时
String value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("0.0");
map.put("attendanceByDate" + (z + 1), value);
}
listMap2.add(map);
}
sheetMap2.put("listMap", listMap2);
sheetMap2.put("projectName", project.getProjectName());
sheetMap2.put("title", StrUtil.format("项目名称:{} 参建单位名称:{} 班组名称:全部 总人数:{} 时间:({} - {}",
project.getProjectName(), enterpriseName, voList.size(), startDate, endDate));
sheetMap2.put("enterpriseName", enterpriseName);
((Map<Integer, Map<String, Object>>) new HashMap<Integer, Map<String, Object>>()).put(1, sheetMap2);
((List<String>) new ArrayList<String>()).add(enterpriseName + "考勤报表");
templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath());
TemplateExportParams params = new TemplateExportParams(templateUrl.get(), true);
params.setColForEach(true);
params.setSheetName(((List<String>) new ArrayList<String>()).toArray(new String[]{}));
for (int i = 10 + DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); i < 10 + 41; i++) {
new ArrayList<Integer>().add(i);
}
try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap<Integer, Map<String, Object>>(), params);) {
if (CollUtil.isNotEmpty(new ArrayList<Integer>())) {
ExcelUtils.removeColumns(((XSSFWorkbook) workbook), 1, new ArrayList<Integer>());
}
ExcelUtils.mergeRows(workbook, 0, 0, 0, 0, 4 + colList.size() * 2);
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
}
private void downloadByTeam(HttpServletResponse response, HashMap<String, Object> param, String projectSn, Project project, String startDate, String endDate, Integer downloadType, AtomicReference<String> templateUrl) throws IOException {
//按班组/部门
int sheetIndex = 0;
String tempSheetName = "考勤月报-按班组.xlsx";
//考勤月报-按班组.xlsx
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, List<StatisticsListVo>> deptNameMap = voList.stream().collect(Collectors.groupingBy(StatisticsListVo::getDeptName));
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
BigDecimal totalHour = BigDecimal.ZERO;
for (Map.Entry<String, List<StatisticsListVo>> entry : deptNameMap.entrySet()) {
BigDecimal totalAttendanceDay = BigDecimal.ZERO;
Map<String, Object> sheetMap = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
List<StatisticsListVo> vos = entry.getValue();
int index = 0;
for (StatisticsListVo vo : vos) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", Objects.equals(vo.getPersonType(), 1) ? "施工人员" : "管理人员");
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
for (int z = 0; z < DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); z++) {
DateTime dateTime = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).get(z);
sheetMap.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
String value;
if (Objects.equals(downloadType, 1) || Objects.equals(downloadType, 2)) {
value = getExcelAmPmAttendanceByDate(personSn2Date2AttendancesMap, vo, dateTime, downloadType);
} else if (Objects.equals(downloadType, 3)) {
//每日工时
value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(BigDecimal::toString).orElse("0.0");
} else {
//每日明细
value = Optional.ofNullable(vo.getDailyAttendanceMap().get(DateUtil.formatDate(dateTime))).map(integer -> Objects.equals(integer, 1) ? "" : "×").orElse("x");
}
map.put("attendanceByDate" + (z + 1), value);
}
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
totalAttendanceDay = NumberUtil.add(vo.getTotalAttendanceDay(), totalAttendanceDay);
totalHour = NumberUtil.add(vo.getTotalHour(), totalHour);
listMap.add(map);
}
sheetMap.put("listMap", listMap);
sheetMap.put("projectName", project.getProjectName());
StatisticsListVo vo = CollUtil.getFirst(vos);
sheetMap.put("title", StrUtil.format("项目名称:{} 参建单位名称:{} {}名称:{} 总人数:{} 时间:({} - {}",
project.getProjectName(), vo.getEnterpriseName(), vo.getPersonType() == 1 ? "班组" : "部门", vo.getDeptName(), vos.size(), startDate, endDate));
sheetMap.put("totalAttendanceDay", totalAttendanceDay);
sheetMap.put("totalHour", totalHour);
((Map<Integer, Map<String, Object>>) new HashMap<Integer, Map<String, Object>>()).put(sheetIndex++, sheetMap);
((List<String>) new ArrayList<String>()).add(entry.getKey());
}
for (int i = 11 + DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); i < 11 + 31; i++) {
new ArrayList<Integer>().add(i);
}
templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath());
if (CollUtil.isNotEmpty(new ArrayList<Integer>())) {
ExcelUtils.removeColumns(templateUrl.get(), 0, new ArrayList<Integer>());
}
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
ExcelUtils.cloneSheetMultipleTimes(templateUrl.get(), outputTemplateFilePath, "1", ((List<String>) new ArrayList<String>()).size() - 1);
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(((List<String>) new ArrayList<String>()).toArray(new String[]{}));
try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap<Integer, Map<String, Object>>(), params);) {
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
}
/**
* 获取一天上下午/进出场打卡格式
* 07:19入场;

View File

@ -1,20 +1,36 @@
package com.zhgd.xmgl.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.base.Objects;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkDeviceCurrentData;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasureCurrentData;
import com.zhgd.xmgl.modules.highformwork.entity.HighFormworkMeasurePoint;
import com.zhgd.xmgl.modules.highformwork.mapper.HighFormworkDeviceCurrentDataMapper;
import com.zhgd.xmgl.modules.highformwork.mapper.HighFormworkMeasureCurrentDataMapper;
import com.zhgd.xmgl.modules.highformwork.mapper.HighFormworkMeasurePointMapper;
import lombok.extern.log4j.Log4j;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkAlarmDataService;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkMeasureCurrentDataService;
import com.zhgd.xmgl.modules.highformwork.service.IHighFormworkMeasurePointService;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.service.IProjectService;
import com.zhgd.xmgl.util.JntxUtil;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @program: wisdomSite
@ -25,53 +41,64 @@ import java.util.List;
@Slf4j
@Component
public class HighFormworkTask {
@Lazy
@Autowired
IProjectService projectService;
@Autowired
private HighFormworkMeasureCurrentDataMapper highFormworkMeasureCurrentDataMapper;
@Autowired
private HighFormworkDeviceCurrentDataMapper highFormworkDeviceCurrentDataMapper;
@Autowired
private HighFormworkMeasurePointMapper highFormworkMeasurePointMapper;
@Lazy
@Autowired
private IHighFormworkMeasurePointService highFormworkMeasurePointService;
@Lazy
@Autowired
private IHighFormworkAlarmDataService highFormworkAlarmDataService;
@Autowired
private IHighFormworkMeasureCurrentDataService dataService;
/**
* 1小时报警推送
*/
@Scheduled(cron = "0 0 */5 * * ?")
@SchedulerLock(name = "measureCurrentDataTask", lockAtMostFor = 1000*60*30, lockAtLeastFor = 1000*60*5)
@SchedulerLock(name = "measureCurrentDataTask", lockAtMostFor = 1000 * 60 * 30, lockAtLeastFor = 1000 * 60 * 5)
public void measureCurrentDataTask() {
try {
QueryWrapper<HighFormworkMeasurePoint> queryWrapper=new QueryWrapper<>();
List<HighFormworkMeasurePoint> list=highFormworkMeasurePointMapper.selectList(queryWrapper);
if(list!=null&&list.size()>0){
for(HighFormworkMeasurePoint point:list){
QueryWrapper<HighFormworkMeasurePoint> queryWrapper = new QueryWrapper<>();
List<HighFormworkMeasurePoint> list = highFormworkMeasurePointMapper.selectList(queryWrapper);
if (list != null && list.size() > 0) {
for (HighFormworkMeasurePoint point : list) {
//倾角
HighFormworkDeviceCurrentData data1=highFormworkDeviceCurrentDataMapper.getNewMeasureCurrentDataByType(point.getId(),1);
HighFormworkDeviceCurrentData data1 = highFormworkDeviceCurrentDataMapper.getNewMeasureCurrentDataByType(point.getId(), 1);
//压力
HighFormworkDeviceCurrentData data2=highFormworkDeviceCurrentDataMapper.getNewMeasureCurrentDataByType(point.getId(),2);
HighFormworkDeviceCurrentData data2 = highFormworkDeviceCurrentDataMapper.getNewMeasureCurrentDataByType(point.getId(), 2);
//沉降
HighFormworkDeviceCurrentData data3=highFormworkDeviceCurrentDataMapper.getNewMeasureCurrentDataByType(point.getId(),3);
if(data1!=null||data2!=null||data3!=null){
HighFormworkMeasureCurrentData highFormworkMeasureCurrentData=new HighFormworkMeasureCurrentData();
HighFormworkDeviceCurrentData data3 = highFormworkDeviceCurrentDataMapper.getNewMeasureCurrentDataByType(point.getId(), 3);
if (data1 != null || data2 != null || data3 != null) {
HighFormworkMeasureCurrentData highFormworkMeasureCurrentData = new HighFormworkMeasureCurrentData();
highFormworkMeasureCurrentData.setProjectSn(point.getProjectSn());
highFormworkMeasureCurrentData.setMeasurePointNumber(point.getMeasurePointNumber());
highFormworkMeasureCurrentData.setAcquisitionInstrumentNumber(point.getAcquisitionInstrumentNumber());
Integer alarmState=1;
if(data1!=null){
Integer alarmState = 1;
if (data1 != null) {
highFormworkMeasureCurrentData.setAngleXAxis(data1.getDataValue());
alarmState=data1.getAlarmState();
alarmState = data1.getAlarmState();
}
if(data2!=null){
if (data2 != null) {
highFormworkMeasureCurrentData.setPressure(data2.getDataValue());
if(alarmState!=3){
if(data2.getAlarmState()!=1){
alarmState=data2.getAlarmState();
if (alarmState != 3) {
if (data2.getAlarmState() != 1) {
alarmState = data2.getAlarmState();
}
}
}
if(data3!=null){
if (data3 != null) {
highFormworkMeasureCurrentData.setSubside(data3.getDataValue());
if(alarmState!=3){
if(data3.getAlarmState()!=1){
alarmState=data3.getAlarmState();
if (alarmState != 3) {
if (data3.getAlarmState() != 1) {
alarmState = data3.getAlarmState();
}
}
}
@ -85,4 +112,63 @@ public class HighFormworkTask {
}
}
/**
* 济南拓兴获取高支模数据
*/
@Scheduled(cron = "* */5 * * * ?")
@SchedulerLock(name = "getHighFormworkDatas", lockAtMostFor = 1000 * 60, lockAtLeastFor = 1000 * 60)
public void getHighFormworkDatas() {
List<Project> projectList = projectService.list(new LambdaQueryWrapper<Project>().isNotNull(Project::getJntxAppKey).isNotNull(Project::getJntxAppSecret).ne(Project::getJntxAppKey, "").ne(Project::getJntxAppSecret, ""));
for (Project project : projectList) {
List<HighFormworkMeasurePoint> measurePoints = highFormworkMeasurePointService.list(new LambdaQueryWrapper<HighFormworkMeasurePoint>()
.eq(HighFormworkMeasurePoint::getProjectSn, project.getProjectSn()));
if (CollUtil.isNotEmpty(measurePoints)) {
String devsns = measurePoints.stream().map(HighFormworkMeasurePoint::getAcquisitionInstrumentNumber).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
if (StrUtil.isBlank(devsns)) {
continue;
}
JSONObject jo = JntxUtil.sendHttpToGetHighFormworkDatas(project.getJntxAppKey(), project.getJntxAppSecret(), devsns);
if (!Objects.equal(jo.getInteger("code"), 0)) {
log.error("济南拓兴获取高支模数据错误:项目:{},错误:{}", project.getProjectName(), JSONArray.toJSONString(jo));
continue;
}
JSONArray datas = jo.getJSONArray("data");
for (int i = 0; i < datas.size(); i++) {
JSONObject data = datas.getJSONObject(i);
addHighFormworkData(measurePoints, data, "1");
addHighFormworkData(measurePoints, data, "2");
}
}
}
}
/**
* 添加高支模数据
*
* @param measurePoints
* @param data
* @param no 1路或2路
*/
private void addHighFormworkData(List<HighFormworkMeasurePoint> measurePoints, JSONObject data, String no) {
Optional<HighFormworkMeasurePoint> op1 = measurePoints.stream().filter(h -> Objects.equal(h.getAcquisitionInstrumentNumber(), data.getString("sn")) && Objects.equal(h.getMeasurePointNumber(), no)).findFirst();
if (op1.isPresent()) {
HighFormworkMeasureCurrentData currentData = new HighFormworkMeasureCurrentData();
HighFormworkMeasurePoint point = op1.get();
currentData.setMeasurePointNumber(point.getMeasurePointNumber());
currentData.setProjectSn(point.getProjectSn());
currentData.setCollectTime(DateUtil.parseDateTime(data.getString("updateTime")));
currentData.setAngleXAxis(data.getString("dipX" + no));
currentData.setAngleYAxis(data.getString("dipY" + no));
Double poleAxialForce = data.getDouble("weight" + no);
if (poleAxialForce != null) {
poleAxialForce = poleAxialForce * 1000;
}
currentData.setPoleAxialForce(Convert.toStr(poleAxialForce));
currentData.setHorizontalDisplacement(data.getString("spanX" + no));
currentData.setFormworkSettlement(data.getString("down" + no));
currentData.setAcquisitionInstrumentNumber(point.getAcquisitionInstrumentNumber());
dataService.save(currentData);
highFormworkAlarmDataService.addAlarmData(point, currentData);
}
}
}

View File

@ -0,0 +1,78 @@
package com.zhgd.xmgl.util;
import com.alibaba.fastjson.JSONObject;
import com.zhgd.jeecg.common.util.pass.HttpUtils;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* 济南拓兴工具类
*/
public class JntxUtil {
/**
* 生成签名
*
* @param appSecret 应用密钥
* @param deviceCode 设备编号
* @param timestamp 时间戳
* @return 32位MD5签名
*/
public static String getSignature(String appSecret, String deviceCode, long timestamp) {
try {
// 拼接字符串AppSecret + 设备编号 + 时间戳
String signStr = appSecret + deviceCode + timestamp;
// 生成MD5签名
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(signStr.getBytes(StandardCharsets.UTF_8));
// 转换为32位十六进制字符串
StringBuilder hexString = new StringBuilder();
for (byte b : digest) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5算法不支持", e);
}
}
/**
* 重载方法使用当前时间戳
*/
public static String getSignature(String appSecret, String deviceCode) {
return getSignature(appSecret, deviceCode, System.currentTimeMillis());
}
public static void main(String[] args) {
long l = System.currentTimeMillis();
System.out.println("timestamp:" + l);
System.out.println(getSignature("84D462DE6D624031B17CA671AE00EF05", "7000021", l));
}
/**
* 发送http获取高支模数据
*
* @param jntxAppKey
* @param jntxAppSecret
* @param devsns
* @return
*/
public static JSONObject sendHttpToGetHighFormworkDatas(String jntxAppKey, String jntxAppSecret, String devsns) {
long l = System.currentTimeMillis();
JSONObject body = new JSONObject();
body.put("appKey", jntxAppKey);
body.put("devSns", devsns);
body.put("signature", getSignature(jntxAppSecret, devsns, l));
body.put("timeStemp", l);
JSONObject jsonObject = HttpUtils.sendPostBodyRtJo("请求济南拓兴获取高支模数据", "http://api.tuoxing888.com/api/v1/gaozhimo/realdata", body, 1000 * 10, null);
return jsonObject;
}
}