diff --git a/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java b/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java index bf5abcc10..05937aee7 100644 --- a/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java +++ b/src/main/java/com/zhgd/netty/tcp/service/HighFormworkSupportService.java @@ -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 thresholds = highFormworkMeasurePointThresholdMapper.selectList(new LambdaQueryWrapper() - .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); - } /** * 获取测点状态 diff --git a/src/main/java/com/zhgd/xmgl/modules/highformwork/controller/HighFormworkMeasureCurrentDataController.java b/src/main/java/com/zhgd/xmgl/modules/highformwork/controller/HighFormworkMeasureCurrentDataController.java index b17957c3f..6591a6dc7 100644 --- a/src/main/java/com/zhgd/xmgl/modules/highformwork/controller/HighFormworkMeasureCurrentDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/highformwork/controller/HighFormworkMeasureCurrentDataController.java @@ -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"), diff --git a/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasureCurrentDataMapper.xml b/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasureCurrentDataMapper.xml index 469b749e6..5e3fe8793 100644 --- a/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasureCurrentDataMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/highformwork/mapper/xml/HighFormworkMeasureCurrentDataMapper.xml @@ -31,10 +31,10 @@ and hfmcd.collect_time <= CONCAT(DATE_FORMAT(#{param.endTime}, "%Y-%m-%d"), ' 23:59:59') - and hfmcd.measure_point_number like CONCAT(CONCAT('%', #{param.measurePointNumber}), '%') + and hfmcd.measure_point_number like #{param.measurePointNumber} - and hfmcd.acquisition_instrument_number like CONCAT(CONCAT('%', #{param.acquisitionInstrumentNumber}), '%') + and hfmcd.acquisition_instrument_number like #{param.acquisitionInstrumentNumber} and hfmcd.alarm_state = #{param.alarmState} diff --git a/src/main/java/com/zhgd/xmgl/modules/highformwork/service/IHighFormworkAlarmDataService.java b/src/main/java/com/zhgd/xmgl/modules/highformwork/service/IHighFormworkAlarmDataService.java index ae6e6d97e..6b984452d 100644 --- a/src/main/java/com/zhgd/xmgl/modules/highformwork/service/IHighFormworkAlarmDataService.java +++ b/src/main/java/com/zhgd/xmgl/modules/highformwork/service/IHighFormworkAlarmDataService.java @@ -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 getNumberDifferentTypesAlarmsRadarChartOneMonth(Map map); List getAlarmCycleTrendGraph(Map map); + + /** + * 插入报警/预警数据 + * @param point + * @param currentData + */ + void addAlarmData(HighFormworkMeasurePoint point, HighFormworkMeasureCurrentData currentData); } diff --git a/src/main/java/com/zhgd/xmgl/modules/highformwork/service/impl/HighFormworkAlarmDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/highformwork/service/impl/HighFormworkAlarmDataServiceImpl.java index fe647468c..b0258a8e7 100644 --- a/src/main/java/com/zhgd/xmgl/modules/highformwork/service/impl/HighFormworkAlarmDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/highformwork/service/impl/HighFormworkAlarmDataServiceImpl.java @@ -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> queryPageList(HighFormworkAlarmData highFormworkAlarmData, Integer pageNo, Integer pageSize, HttpServletRequest req) { @@ -57,6 +73,93 @@ public class HighFormworkAlarmDataServiceImpl extends ServiceImpl thresholds = highFormworkMeasurePointThresholdMapper.selectList(new LambdaQueryWrapper() + .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); + } + /** * 补全数据 * diff --git a/src/main/java/com/zhgd/xmgl/modules/project/entity/Project.java b/src/main/java/com/zhgd/xmgl/modules/project/entity/Project.java index 9bdc56d38..571ba4c11 100644 --- a/src/main/java/com/zhgd/xmgl/modules/project/entity/Project.java +++ b/src/main/java/com/zhgd/xmgl/modules/project/entity/Project.java @@ -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 */ diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java b/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java index 4f25a0be0..cafdea892 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java @@ -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 param) { - String templateUrl = null; + AtomicReference templateUrl = new AtomicReference<>(); try { - ArrayList delColIndexes = new ArrayList<>(); String projectSn = MapUtils.getString(param, "projectSn"); - Project project = projectService.getOne(new LambdaQueryWrapper() - .eq(Project::getProjectSn, projectSn)); + Project project = projectService.getOne(new LambdaQueryWrapper().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 dateTimes = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR); - Map> root = new HashMap<>(); - int sheetIndex = 0; - List 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 voList = this.doCountDailyAttendanceByDateRange(param).getRecords(); - Map> deptNameMap = voList.stream().collect(Collectors.groupingBy(StatisticsListVo::getDeptName)); - Map>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper() - .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> entry : deptNameMap.entrySet()) { - BigDecimal totalAttendanceDay = BigDecimal.ZERO; - Map sheetMap = new HashMap<>(); - List> listMap = new ArrayList<>(); - List vos = entry.getValue(); - int index = 0; - for (StatisticsListVo vo : vos) { - Map 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 list = workerDailyAttendanceStatisticsV2Service.countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(param); - Map>> date2Type2IdMap = list.stream() - .collect(Collectors.groupingBy( - ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDate, // 第一层按日期分组 - Collectors.groupingBy( - ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getPersonType, // 第二层按类型分组 - Collectors.toMap( - ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDeptId, // 第三层按ID映射 - Function.identity(), - (existing, replacement) -> existing // 处理键冲突,保留现有值 - ) - ) - )); - Map sheetMap1 = new HashMap<>(); - List> colList = new ArrayList>(); - List> listMap1 = new ArrayList<>(); - Integer totalGlNum = 0; - Integer totalSgNum = 0; - Map deptKeyMap = new HashMap<>(); - int index = 0; - String enterpriseId = MapUtils.getString(param, "enterpriseId"); - List departmentInfos = departmentInfoService.list(new LambdaQueryWrapper() - .eq(DepartmentInfo::getEnterpriseId, enterpriseId)); - List teamInfos = teamInfoService.list(new LambdaQueryWrapper() - .eq(TeamInfo::getEnterpriseId, enterpriseId)); - for (int z = 0; z < dateTimes.size(); z++) { - DateTime dateTime = dateTimes.get(z); - Map 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 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 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 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 voList = this.doCountDailyAttendanceByDateRange(param).getRecords(); - Map sheetMap2 = new HashMap<>(); - index = 0; - List> listMap2 = new ArrayList<>(); - for (StatisticsListVo vo : voList) { - Map 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 voList = this.doCountDailyAttendanceByDateRange(param).getRecords(); - Map>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper() - .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 sheetMap = new HashMap<>(); - sheetMap.put("startDate", startDate); - sheetMap.put("endDate", endDate); - List> listMap = new ArrayList<>(); - for (int z = 0; z < dateTimes.size(); z++) { - Map 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 vos = this.doCountDailyAttendanceByDateRange(param).getRecords(); - Map>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper() - .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 sheetMap = new HashMap<>(); - List> listMap = new ArrayList<>(); - int index = 0; - for (StatisticsListVo vo : vos) { - Map 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 param, String projectSn, Project project, String startDate, String endDate, Integer downloadType, AtomicReference templateUrl) throws IOException { + //按项目 + String tempSheetName = "考勤月报-按项目.xlsx"; + param.put("startTime", startDate); + param.put("endTime", endDate); + param.put("pageSize", -1); + List vos = this.doCountDailyAttendanceByDateRange(param).getRecords(); + Map>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper() + .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 sheetMap = new HashMap<>(); + List> listMap = new ArrayList<>(); + int index = 0; + for (StatisticsListVo vo : vos) { + Map 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().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>) new HashMap>()).put(0, sheetMap); + ((List) new ArrayList()).add(project.getProjectName()); + templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath()); + TemplateExportParams params = new TemplateExportParams(templateUrl.get(), true); + params.setSheetName(((List) new ArrayList()).toArray(new String[]{})); + try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap>(), params);) { + if (CollUtil.isNotEmpty(new ArrayList())) { + ExcelUtils.removeColumns(((XSSFWorkbook) workbook), 0, new ArrayList()); + } + ExcelUtils.downLoadExcel(tempSheetName, response, workbook); + } + } + + private void downloadByWorker(HttpServletResponse response, HashMap param, String projectSn, Project project, String startDate, String endDate, AtomicReference templateUrl) throws IOException { + int sheetIndex = 0; + //按人员 + param.put("startTime", startDate); + param.put("endTime", endDate); + param.put("pageSize", -1); + String tempSheetName = "单个人员考勤出入明细报表.xlsx"; + List voList = this.doCountDailyAttendanceByDateRange(param).getRecords(); + Map>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper() + .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 sheetMap = new HashMap<>(); + sheetMap.put("startDate", startDate); + sheetMap.put("endDate", endDate); + List> listMap = new ArrayList<>(); + for (int z = 0; z < DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR).size(); z++) { + Map 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>) new HashMap>()).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) new ArrayList()).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) new ArrayList()).size() - 1); + TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true); + params.setSheetName(ListUtils.renameDuplicates(new ArrayList()).toArray(new String[]{})); + try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap>(), params);) { + ExcelUtils.downLoadExcel(tempSheetName, response, workbook); + } + } + + private void downloadByEnterprise(HttpServletResponse response, HashMap param, Project project, String startDate, String endDate, AtomicReference templateUrl) throws IOException { + //按参建单位 + String tempSheetName = "考勤月报-按单位-出勤人数与考勤报表.xlsx"; + //导出sheet1上海振南出勤人数 + List list = workerDailyAttendanceStatisticsV2Service.countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(param); + Map>> date2Type2IdMap = list.stream() + .collect(Collectors.groupingBy( + ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDate, // 第一层按日期分组 + Collectors.groupingBy( + ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getPersonType, // 第二层按类型分组 + Collectors.toMap( + ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDeptId, // 第三层按ID映射 + Function.identity(), + (existing, replacement) -> existing // 处理键冲突,保留现有值 + ) + ) + )); + Map sheetMap1 = new HashMap<>(); + List> colList = new ArrayList>(); + List> listMap1 = new ArrayList<>(); + Integer totalGlNum = 0; + Integer totalSgNum = 0; + Map deptKeyMap = new HashMap<>(); + int index = 0; + String enterpriseId = MapUtils.getString(param, "enterpriseId"); + List departmentInfos = departmentInfoService.list(new LambdaQueryWrapper() + .eq(DepartmentInfo::getEnterpriseId, enterpriseId)); + List teamInfos = teamInfoService.list(new LambdaQueryWrapper() + .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 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 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 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 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>) new HashMap>()).put(0, sheetMap1); + ((List) new ArrayList()).add(enterpriseName + "出勤人数"); + param.put("startTime", startDate); + param.put("endTime", endDate); + //导出sheet2上海振南考勤报表 + List voList = this.doCountDailyAttendanceByDateRange(param).getRecords(); + Map sheetMap2 = new HashMap<>(); + index = 0; + List> listMap2 = new ArrayList<>(); + for (StatisticsListVo vo : voList) { + Map 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>) new HashMap>()).put(1, sheetMap2); + ((List) new ArrayList()).add(enterpriseName + "考勤报表"); + templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath()); + TemplateExportParams params = new TemplateExportParams(templateUrl.get(), true); + params.setColForEach(true); + params.setSheetName(((List) new ArrayList()).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().add(i); + } + try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap>(), params);) { + if (CollUtil.isNotEmpty(new ArrayList())) { + ExcelUtils.removeColumns(((XSSFWorkbook) workbook), 1, new ArrayList()); + } + ExcelUtils.mergeRows(workbook, 0, 0, 0, 0, 4 + colList.size() * 2); + ExcelUtils.downLoadExcel(tempSheetName, response, workbook); + } + } + + private void downloadByTeam(HttpServletResponse response, HashMap param, String projectSn, Project project, String startDate, String endDate, Integer downloadType, AtomicReference templateUrl) throws IOException { + //按班组/部门 + int sheetIndex = 0; + String tempSheetName = "考勤月报-按班组.xlsx"; + //考勤月报-按班组.xlsx + param.put("startTime", startDate); + param.put("endTime", endDate); + param.put("pageSize", -1); + List voList = this.doCountDailyAttendanceByDateRange(param).getRecords(); + Map> deptNameMap = voList.stream().collect(Collectors.groupingBy(StatisticsListVo::getDeptName)); + Map>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper() + .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> entry : deptNameMap.entrySet()) { + BigDecimal totalAttendanceDay = BigDecimal.ZERO; + Map sheetMap = new HashMap<>(); + List> listMap = new ArrayList<>(); + List vos = entry.getValue(); + int index = 0; + for (StatisticsListVo vo : vos) { + Map 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>) new HashMap>()).put(sheetIndex++, sheetMap); + ((List) new ArrayList()).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().add(i); + } + templateUrl.set(FileUtils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath()); + if (CollUtil.isNotEmpty(new ArrayList())) { + ExcelUtils.removeColumns(templateUrl.get(), 0, new ArrayList()); + } + String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx"; + ExcelUtils.cloneSheetMultipleTimes(templateUrl.get(), outputTemplateFilePath, "1", ((List) new ArrayList()).size() - 1); + TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true); + params.setSheetName(((List) new ArrayList()).toArray(new String[]{})); + try (Workbook workbook = ExcelExportUtil.exportExcel(new HashMap>(), params);) { + ExcelUtils.downLoadExcel(tempSheetName, response, workbook); + } + } + /** * 获取一天上下午/进出场打卡,格式: * 07:19入场; diff --git a/src/main/java/com/zhgd/xmgl/task/HighFormworkTask.java b/src/main/java/com/zhgd/xmgl/task/HighFormworkTask.java index fe596859b..8f9c397fa 100644 --- a/src/main/java/com/zhgd/xmgl/task/HighFormworkTask.java +++ b/src/main/java/com/zhgd/xmgl/task/HighFormworkTask.java @@ -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 queryWrapper=new QueryWrapper<>(); - List list=highFormworkMeasurePointMapper.selectList(queryWrapper); - if(list!=null&&list.size()>0){ - for(HighFormworkMeasurePoint point:list){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + List 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 projectList = projectService.list(new LambdaQueryWrapper().isNotNull(Project::getJntxAppKey).isNotNull(Project::getJntxAppSecret).ne(Project::getJntxAppKey, "").ne(Project::getJntxAppSecret, "")); + for (Project project : projectList) { + List measurePoints = highFormworkMeasurePointService.list(new LambdaQueryWrapper() + .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 measurePoints, JSONObject data, String no) { + Optional 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); + } + } } diff --git a/src/main/java/com/zhgd/xmgl/util/JntxUtil.java b/src/main/java/com/zhgd/xmgl/util/JntxUtil.java new file mode 100644 index 000000000..7630d1a6b --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/util/JntxUtil.java @@ -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; + } +}