Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
haungxing 6 months ago
parent
commit
495af6306d
  1. 9
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestEntity.java
  2. 16
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailImgVO.java
  3. 15
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailStrVO.java
  4. 3
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java
  5. 8
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreSumVO.java
  6. 54
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java
  7. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java
  8. 18
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java
  9. 8
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java
  10. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java
  11. 3
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java
  12. 3
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java
  13. 3
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainPlanMapper.xml
  14. 6
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java
  15. 40
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java
  16. 3
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java
  17. 96
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java
  18. 4
      hzims-service/safeproduct/src/main/resources/db/2.0.1.sql
  19. BIN
      hzims-service/safeproduct/src/main/resources/template/演练记录表.docx

9
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TestEntity.java

@ -9,6 +9,8 @@ import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
@ -58,6 +60,12 @@ public class TestEntity extends BaseEntity {
@ApiModelProperty("考试结束时间")
private Date testEndTime;
// @NotNull
// @Min(value = 0, message = "及格分必须大于等于0")
// @Max(value = 100, message = "及格分必须小于等于100")
// @ApiModelProperty("及格分")
// private Integer passingScore;
@NotNull
@Size(max = 255, message = "考试地点字段长度不能超过255")
@ApiModelProperty("考试地点")
@ -77,7 +85,6 @@ public class TestEntity extends BaseEntity {
@ApiModelProperty("参考人员")
private String peopleName;
@Size(max = 1000, message = "考试图片字段长度不能超过1000")
@ApiModelProperty("考试图片")
private String imgPath;

16
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailImgVO.java

@ -0,0 +1,16 @@
package com.hnac.hzims.safeproduct.vo;
import cn.afterturn.easypoi.entity.ImageEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel(value = "演练记录表VO类")
public class RehearsalRecordDetailImgVO extends RehearsalRecordDetailVO{
@ApiModelProperty("图片列表")
private List<ImageEntity> images;
}

15
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailStrVO.java

@ -0,0 +1,15 @@
package com.hnac.hzims.safeproduct.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel(value = "演练记录表VO类")
public class RehearsalRecordDetailStrVO extends RehearsalRecordDetailVO{
@ApiModelProperty("图片列表")
private List<String> images;
}

3
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java

@ -55,9 +55,6 @@ public class RehearsalRecordDetailVO {
@ApiModelProperty("演练科目")
private String subject;
@ApiModelProperty("图片列表")
private List<ImageEntity> images;
@ApiModelProperty("年份")
private String year;

8
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreSumVO.java

@ -13,12 +13,14 @@ import lombok.Data;
public class TestScoreSumVO {
@ApiModelProperty("应考人数")
private Integer peopleNum=0;
private Integer peopleNum = 0;
@ApiModelProperty("实考人数")
private Integer actualPeopleNum=0;
private Integer actualPeopleNum = 0;
@ApiModelProperty("及格率")
private Double percentage=0.0;
private Double percentage = 0.0;
@ApiModelProperty("及格分")
private Integer passingScore;
}

54
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java

@ -6,6 +6,7 @@ import com.hnac.hzims.alarm.config.constants.AlarmConstants;
import com.hnac.hzims.alarm.config.service.AlarmConfigService;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService;
import com.hnac.hzims.alarm.show.service.AlarmHandleService;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo;
import com.hnac.hzims.message.entity.MessagePushRecordEntity;
@ -21,6 +22,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@ -35,6 +37,8 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
private final AlarmService alarmService;
private final AlarmHandleService handleService;
private final AlarmConfigService alarmConfigService;
private final IStationClient stationClient;
@ -49,41 +53,55 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
@Override
public Boolean save(List<AlarmEntity> alarms) {
// 步骤1.查询告警数据对应站点
R<List<StationEntity>> result = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList()));
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){
R<List<StationEntity>> stations = stationClient.querySatationByCodes(alarms.stream().map(AlarmEntity::getStationId).collect(Collectors.toList()));
if(!stations.isSuccess() || CollectionUtil.isEmpty(stations.getData())){
log.error("alarm_query_station_is_null : {}",alarms.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()));
return false;
}
// 步骤2.查询当天处理的告警
List<String> handlers = handleService.sameDayContent();
// 步骤3.查询延后未完成的告警
List<String> delays = handleService.incompleteContent();
// 步骤4.近5分钟内告警
Set<String> keys = stringRedisTemplate.keys("hzims:queue:filter:alarm" + "*");
// 步骤2.遍历保存告警数据
// 步骤5.遍历保存告警数据
alarms.forEach(alarm->{
List<StationEntity> stations = result.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(stations)){
// 未匹配到站点
Optional<StationEntity> optional = stations.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).findFirst();
if(!optional.isPresent()){
return;
}
// 告警已处理
if(handlers.contains(alarm.getAlarmContext())){
return;
}
// 告警已延后处理
if(delays.contains(alarm.getAlarmContext())){
return;
}
// 根据最近5分钟的数据,做去重
// 近5分钟内告警重复
for (String key : keys) {
String value = stringRedisTemplate.opsForValue().get(key);
if (value.equals(stations.get(0).getName()+alarm.getAlarmContext())){
if (value.equals(optional.get().getName()+alarm.getAlarmContext())){
return;
}
}
// fpd告警拼接
// fpd告警拼接站点名称
if(AlarmConstants.EARLY_WARNING.equals(alarm.getAlarmSource())){
alarm.setAlarmContext(stations.get(0).getName() + "." + alarm.getAlarmContext());
alarm.setAlarmContext(optional.get().getName() + "." + alarm.getAlarmContext());
}
// 步骤3.站点参数设置
alarm.setCreateDept(stations.get(0).getCreateDept());
alarm.setStationName(stations.get(0).getName());
alarm.setTenantId(stations.get(0).getTenantId());
// 站点参数设置
alarm.setCreateDept(optional.get().getCreateDept());
alarm.setStationName(optional.get().getName());
alarm.setTenantId(optional.get().getTenantId());
alarm.setStatus(0);
// 步骤4.根据站点查询配置标识
// 根据站点查询配置标识
AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType());
if(ObjectUtil.isEmpty(mark)){
log.error("alarm_obtain_mark_is_null : {}",alarm.getAlarmId());
return;
}
// 步骤5.告警处理标识赋值
// 告警处理标识赋值
alarm.setIsRightTabulation(mark.getIsRightTabulation());
alarm.setIsBroadcast(mark.getIsBroadcast());
alarm.setIsMask(mark.getIsMask());
@ -92,16 +110,16 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
alarm.setIsSmallBell(mark.getIsSmallBell());
alarm.setIsShortMessage(mark.getIsShortMessage());
alarm.setIsWxMessage(mark.getIsWxMessage());
// 步骤6.保存当日告警数据
// 保存告警
boolean isSave = alarmService.save(alarm);
if(!isSave){
log.error("alarm_save_fail : {}",alarm.getAlarmId());
return;
}
String key="hzims:queue:filter:alarm"+alarm.getAlarmId();
stringRedisTemplate.opsForValue().set(key,stations.get(0).getName()+alarm.getAlarmContext());
stringRedisTemplate.opsForValue().set(key,optional.get().getName()+alarm.getAlarmContext());
stringRedisTemplate.expire(key,5, TimeUnit.MINUTES);
// 步骤7.发生数据至redis告警队列
// 发送告警数据进行消息推送队列
stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm));
});
return true;

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java

@ -25,4 +25,8 @@ public interface AlarmHandleService extends BaseService<AlarmHandleEntity> {
List<User> handleUser();
List<String> handles();
List<String> sameDayContent();
List<String> incompleteContent();
}

18
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java

@ -170,4 +170,22 @@ public class AlarmHandleServiceImpl extends BaseServiceImpl<AlarmHandleMapper, A
String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME);
return this.baseMapper.handles(start,end);
}
/**
* 查询当天处理告警的内容
* @return
*/
@Override
public List<String> sameDayContent() {
return null;
}
/**
* 查询未到延后期限告警的内容
* @return
*/
@Override
public List<String> incompleteContent() {
return null;
}
}

8
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java

@ -3,15 +3,15 @@ package com.hnac.hzims.alarm.show.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hnac.hzims.alarm.config.service.AlarmConfigService;
import com.hnac.hzims.alarm.config.constants.AlarmConstants;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
import com.hnac.hzims.alarm.config.service.AlarmConfigService;
import com.hnac.hzims.alarm.config.vo.AlarmCountVo;
import com.hnac.hzims.alarm.config.vo.ChildAlarmCountVo;
import com.hnac.hzims.alarm.show.mapper.AlarmMapper;
import com.hnac.hzims.alarm.show.service.AlarmHandleService;
import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.alarm.source.service.MessageService;
import com.hnac.hzims.alarm.config.vo.AlarmCountVo;
import com.hnac.hzims.alarm.config.vo.ChildAlarmCountVo;
import com.hnac.hzims.equipment.entity.EmInfoEntity;
import com.hnac.hzims.equipment.entity.EmVideoBandingEntity;
import com.hnac.hzims.equipment.feign.IEmInfoClient;
@ -20,10 +20,8 @@ import com.hnac.hzims.message.dto.MailMessageDTO;
import com.hnac.hzims.message.fegin.IMessageClient;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient;
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient;
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceAttrVO;
import com.hnac.hzinfo.sdk.v5.project.ProjectClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java

@ -21,7 +21,7 @@ public class RemoteParamVO implements Serializable {
private String remoteName;
@JSONField(name = "device_id")
private String deviceCode;
private String deviceId;
@JSONField(name = "device_name")
private String deviceName;

3
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java

@ -82,7 +82,8 @@ public class RehearsalController extends BladeController {
@ApiImplicitParams({
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "rehearsalStatus", value = "演练状态", dataType = "query", paramType = "string")
})
@ApiOperation(value = "演练计划分页")
@ApiOperationSupport(order = 5)

3
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java

@ -91,7 +91,8 @@ public class TrainController extends BladeController {
@ApiImplicitParams({
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "trainStatus", value = "培训计划状态", dataType = "query", paramType = "string")
})
@ApiOperation(value = "培训计划分页")
@ApiOperationSupport(order = 5)

3
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainPlanMapper.xml

@ -87,6 +87,9 @@
<if test="param.endTime != null and param.endTime != ''">
AND scheduled_end_time &lt;= #{param.endTime}
</if>
<if test="param.trainStatus != null and param.trainStatus != ''">
AND train_status = #{param.trainStatus}
</if>
ORDER BY
create_time DESC
</select>

6
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java

@ -275,7 +275,8 @@ public class RehearsalPlanServiceImpl extends ServiceImpl<RehearsalPlanMapper, R
QueryWrapper<RehearsalPlanEntity> queryWrapper = new QueryWrapper<>();
String unit = String.valueOf(param.get("unit"));
String startTime = String.valueOf(param.get("scheduledStartTime"));
String endTime = String.valueOf((param.get("scheduledEndTime")));
String endTime = String.valueOf(param.get("scheduledEndTime"));
String rehearsalStatus = String.valueOf(param.get("rehearsalStatus"));
if (!unit.equals("null") && !unit.equals("")) {
queryWrapper.lambda().like(RehearsalPlanEntity::getUnit, unit);
}
@ -285,6 +286,9 @@ public class RehearsalPlanServiceImpl extends ServiceImpl<RehearsalPlanMapper, R
if (!endTime.equals("null") && !endTime.equals("")) {
queryWrapper.lambda().le(RehearsalPlanEntity::getScheduledEndTime, endTime);
}
if (!rehearsalStatus.equals("null") && !rehearsalStatus.equals("")) {
queryWrapper.lambda().eq(RehearsalPlanEntity::getRehearsalStatus, rehearsalStatus);
}
queryWrapper.lambda().orderByDesc(RehearsalPlanEntity::getCreateTime);
return this.page(Condition.getPage(query), queryWrapper);
}

40
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

@ -19,10 +19,13 @@ import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper;
import com.hnac.hzims.safeproduct.service.IRehearsalRecordService;
import com.hnac.hzims.safeproduct.utils.BaseUtil;
import com.hnac.hzims.safeproduct.utils.TimeUtils;
import com.hnac.hzims.safeproduct.vo.RehearsalRecordDetailImgVO;
import com.hnac.hzims.safeproduct.vo.RehearsalRecordDetailStrVO;
import com.hnac.hzims.safeproduct.vo.RehearsalRecordDetailVO;
import com.hnac.hzims.safeproduct.vo.RehearsalRecordlVO;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Query;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -150,20 +153,6 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
if (StringUtils.isNotEmpty(rehearsalRecordDetailVO.getActualEndTime())){
rehearsalRecordDetailVO.setActualEndTime(TimeUtils.format(rehearsalRecordDetailVO.getActualEndTime()));
}
// 图片
List<ImageEntity> list = new ArrayList<>();
if (StringUtils.isNotEmpty(rehearsalRecordDetailVO.getImgPath())) {
String[] imgArr = rehearsalRecordDetailVO.getImgPath().split(",");
for (String img : imgArr) {
ImageEntity imageEntity = new ImageEntity(BaseUtil.imgToByte(savePath +
BaseUtil.downloadFileByUrl(img, savePath)), 180, 150);
list.add(imageEntity);
}
} else {
// 添加空的ImageEntity,防止数据填入时显示"{{"
list.add(new ImageEntity());
}
rehearsalRecordDetailVO.setImages(list);
// 记录:换行符使用\r\n
String standardRecord = rehearsalRecordDetailVO.getRecord().replaceAll("\n", "\r\n");
rehearsalRecordDetailVO.setRecord(standardRecord);
@ -183,7 +172,28 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
} else {
rehearsalRecordDetailVO.setRehearsalMethod(RehearsalMethodEnum.OFFLINE.getDesc());
}
Map<String, Object> params = BaseUtil.obj2Map(rehearsalRecordDetailVO);
// 图片
Map<String, Object> params;
if (StringUtils.isNotEmpty(rehearsalRecordDetailVO.getImgPath())) {
List<ImageEntity> list = new ArrayList<>();
RehearsalRecordDetailImgVO imgVO = new RehearsalRecordDetailImgVO();
BeanUtils.copyProperties(rehearsalRecordDetailVO, imgVO);
String[] imgArr = rehearsalRecordDetailVO.getImgPath().split(",");
for (String img : imgArr) {
ImageEntity imageEntity = new ImageEntity(BaseUtil.imgToByte(savePath +
BaseUtil.downloadFileByUrl(img, savePath)), 180, 150);
list.add(imageEntity);
}
imgVO.setImages(list);
params = BaseUtil.obj2Map(imgVO);
} else {
List<String> list = new ArrayList<>();
list.add("");
RehearsalRecordDetailStrVO strVO = new RehearsalRecordDetailStrVO();
BeanUtils.copyProperties(rehearsalRecordDetailVO, strVO);
strVO.setImages(list);
params = BaseUtil.obj2Map(strVO);
}
String templateFile = "template/演练记录表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/演练记录表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/演练记录表" + SafeProductConstant.PDF_SUFFIX;

3
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java

@ -126,6 +126,7 @@ public class TestScoreServiceImpl extends ServiceImpl<TestScoreMapper, TestScore
public TestScoreSumVO testScoreSum(Long testId, String name) {
TestScoreSumVO testScoreSumVO = new TestScoreSumVO();
TestEntity testEntity = testMapper.selectById(testId);
// testScoreSumVO.setPassingScore(testEntity.getPassingScore());
String peopleName = testEntity.getPeopleName();
if (StringUtils.isNotBlank(peopleName)) {
String[] split = peopleName.split(",");
@ -141,7 +142,7 @@ public class TestScoreServiceImpl extends ServiceImpl<TestScoreMapper, TestScore
if (CollectionUtils.isNotEmpty(list)&&CollectionUtils.isNotEmpty(passCollect)) {
double result = BigDecimal.valueOf(passCollect.size()).divide(BigDecimal.valueOf(list.size()),2, RoundingMode.UP).doubleValue();
testScoreSumVO.setPercentage(result);
}else {
} else {
testScoreSumVO.setPercentage(0.0);
}
}

96
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -119,39 +119,22 @@ public class BaseUtil {
XWPFDocument xwpfDocument = null;
try {
xwpfDocument = WordExportUtil.exportWord07(templatePath, params);
if (StringUtils.isNotEmpty(findName)) {
// 超链接处理
if (findName != null && !findName.isEmpty()) {
String findText = params.get(findName).toString();
if (StringUtils.isNotEmpty(findText)) {
if (findText != null && !findText.isEmpty()) {
JSONArray jsonArray = new JSONArray(findText);
for (XWPFTable table : xwpfDocument.getTables()) {
for (int row = 0; row < table.getNumberOfRows(); row++) {
for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
XWPFTableCell cell = table.getRow(row).getCell(col);
for (XWPFTableRow row : table.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
Iterator<XWPFRun> iterator = p.getRuns().iterator();
while (iterator.hasNext()) {
XWPFRun r = iterator.next();
String text = r.getText(0);
for (int index = 0; index < p.getRuns().size(); index++) {
XWPFRun run = p.getRuns().get(index);
String text = run.getText(0);
if (findText.equals(text)) {
r.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = r.getParagraph();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String url = jsonObject.getString("url");
url = URLEncoder.encode(url, "UTF-8");
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id);
CTText ctText = CTText.Factory.newInstance();
ctText.setStringValue(name);
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{ctText});
cLink.setRArray(new CTR[]{ctr});
if (i<jsonArray.length()-1) {
paragraph.createRun().addBreak();
}
}
run.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = run.getParagraph();
insertJsonArrayIntoParagraph(jsonArray, paragraph);
}
}
}
@ -160,17 +143,72 @@ public class BaseUtil {
}
}
}
// 表格处理
if (templatePath.equals("template/卫生自查表.docx")) {
formatHygieneRecordTable(xwpfDocument);
}
} catch (Exception e) {
log.error("数据写入异常: {}",e.getCause().toString()+ e.getStackTrace());
e.printStackTrace();
}
return xwpfDocument;
}
/**
* 车辆检查表格式处理
* @param xwpfDocument word文件类
*/
private static void formatCarCheckRecordTable(XWPFDocument xwpfDocument) {
// 获取文档中所有的表格
List<XWPFTable> tableList = xwpfDocument.getTables();
if (tableList.size() > 0) {
// 循环表格
for (XWPFTable table : tableList) {
// 获取表格所有行数
List<XWPFTableRow> rows = table.getRows();
// 第五行到倒数第三行为需合并区域
for (int row = 5; row < rows.size() - 2;) {
XWPFTableCell startCell = rows.get(row).getCell(0);
String startText = startCell.getText();
int index = row + 1;
for (; index < rows.size(); index++) {
XWPFTableCell endCell = rows.get(index).getCell(0);
String endText = endCell.getText();
if (!startText.equals(endText)) {
break;
}
}
mergeCellsVertically(table, 0, row, index - 1);
row = index;
}
}
}
}
private static void insertJsonArrayIntoParagraph(JSONArray jsonArray, XWPFParagraph paragraph) throws IOException {
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String url = jsonObject.getString("url");
// URL编码格式化
String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20");
String prefixString = url.substring(0, url.lastIndexOf("/") + 1);
String encodeUrl = prefixString + encodeName;
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl,
XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id);
CTText ctText = CTText.Factory.newInstance();
ctText.setStringValue(name);
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{ctText});
cLink.setRArray(new CTR[]{ctr});
if (i < jsonArray.length() - 1) {
paragraph.createRun().addBreak();
}
}
}
/**
* 卫生自查表格式处理
* @param xwpfDocument word文件类
*/

4
hzims-service/safeproduct/src/main/resources/db/2.0.1.sql

@ -41,3 +41,7 @@ CREATE TABLE IF NOT EXISTS `hzims_hygiene_template_detail` (
`is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='卫生自查模板详情表';
-- 添加考试及格分字段
ALTER TABLE hzims_test
ADD COLUMN passing_score int(10) NOT NULL DEFAULT 60 COMMENT '考试及格分';

BIN
hzims-service/safeproduct/src/main/resources/template/演练记录表.docx

Binary file not shown.
Loading…
Cancel
Save