|
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.google.zxing.BarcodeFormat; |
|
|
|
import com.google.zxing.BarcodeFormat; |
|
|
|
|
|
|
|
import com.hnac.hzims.message.dto.PlanMsgRecordDto; |
|
|
|
import com.hnac.hzims.safeproduct.dto.SafetyToolBatchRecheckDTO; |
|
|
|
import com.hnac.hzims.safeproduct.dto.SafetyToolBatchRecheckDTO; |
|
|
|
import com.hnac.hzims.safeproduct.dto.SafetyToolDTO; |
|
|
|
import com.hnac.hzims.safeproduct.dto.SafetyToolDTO; |
|
|
|
import com.hnac.hzims.safeproduct.entity.SafeProductPdf; |
|
|
|
import com.hnac.hzims.safeproduct.entity.SafeProductPdf; |
|
|
@ -20,6 +21,7 @@ import com.hnac.hzims.safeproduct.mapper.SafetyToolMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.SafetyToolRecheckMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.SafetyToolRecheckMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.SafetyToolTypeMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.SafetyToolTypeMapper; |
|
|
|
import com.hnac.hzims.safeproduct.service.ISafetyToolService; |
|
|
|
import com.hnac.hzims.safeproduct.service.ISafetyToolService; |
|
|
|
|
|
|
|
import com.hnac.hzims.safeproduct.template.service.TemplateService; |
|
|
|
import com.hnac.hzims.safeproduct.utils.ExcelToolListener; |
|
|
|
import com.hnac.hzims.safeproduct.utils.ExcelToolListener; |
|
|
|
import com.hnac.hzims.safeproduct.utils.HtmlModule; |
|
|
|
import com.hnac.hzims.safeproduct.utils.HtmlModule; |
|
|
|
import com.hnac.hzims.safeproduct.utils.HtmltoPdf; |
|
|
|
import com.hnac.hzims.safeproduct.utils.HtmltoPdf; |
|
|
@ -53,10 +55,7 @@ import java.io.BufferedInputStream; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.time.Instant; |
|
|
|
import java.time.*; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
|
|
|
import java.time.ZoneOffset; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -79,6 +78,8 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
private final IUserClient userClient; |
|
|
|
private final IUserClient userClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<TemplateService> templateService; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${hzims.safeProduct.safeTool.sadeToolKey}") |
|
|
|
@Value("${hzims.safeProduct.safeTool.sadeToolKey}") |
|
|
|
private String sadeToolKey; |
|
|
|
private String sadeToolKey; |
|
|
|
@Value("${hzims.tenantId}") |
|
|
|
@Value("${hzims.tenantId}") |
|
|
@ -95,7 +96,7 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
String toolCode = req.getToolCode(); |
|
|
|
String toolCode = req.getToolCode(); |
|
|
|
List<SafetyToolEntity> list = this.list(new LambdaQueryWrapper<SafetyToolEntity>().eq(SafetyToolEntity::getToolCode, toolCode)); |
|
|
|
List<SafetyToolEntity> list = this.list(new LambdaQueryWrapper<SafetyToolEntity>().eq(SafetyToolEntity::getToolCode, toolCode)); |
|
|
|
if (CollectionUtil.isNotEmpty(list)) { |
|
|
|
if (CollectionUtil.isNotEmpty(list)) { |
|
|
|
return R.fail(400,String.format("编号[%s]已经被使用!", toolCode)); |
|
|
|
return R.fail(400, String.format("编号[%s]已经被使用!", toolCode)); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.status(super.save(req)); |
|
|
|
return R.status(super.save(req)); |
|
|
|
} |
|
|
|
} |
|
|
@ -105,7 +106,7 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
String toolCode = req.getToolCode(); |
|
|
|
String toolCode = req.getToolCode(); |
|
|
|
SafetyToolEntity entity = safetyToolMapper.selectOne(new LambdaQueryWrapper<SafetyToolEntity>().eq(SafetyToolEntity::getToolCode, toolCode)); |
|
|
|
SafetyToolEntity entity = safetyToolMapper.selectOne(new LambdaQueryWrapper<SafetyToolEntity>().eq(SafetyToolEntity::getToolCode, toolCode)); |
|
|
|
if (entity != null && !entity.getId().equals(req.getId())) { |
|
|
|
if (entity != null && !entity.getId().equals(req.getId())) { |
|
|
|
return R.fail(400,String.format("编号[%s]已经被使用!", toolCode)); |
|
|
|
return R.fail(400, String.format("编号[%s]已经被使用!", toolCode)); |
|
|
|
} |
|
|
|
} |
|
|
|
return R.status(super.updateById(req)); |
|
|
|
return R.status(super.updateById(req)); |
|
|
|
} |
|
|
|
} |
|
|
@ -133,6 +134,27 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
for (SafetyToolEntity item : safetyTools) { |
|
|
|
for (SafetyToolEntity item : safetyTools) { |
|
|
|
item.setLastCheckTime(currentTime); |
|
|
|
item.setLastCheckTime(currentTime); |
|
|
|
item.setNextCheckTime(DateUtil.plusDays(currentTime, Long.valueOf(item.getSafeTime().toString()))); |
|
|
|
item.setNextCheckTime(DateUtil.plusDays(currentTime, Long.valueOf(item.getSafeTime().toString()))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String noticeUsers = item.getNoticeUsers(); |
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(noticeUsers)) { |
|
|
|
|
|
|
|
String[] split = noticeUsers.split(","); |
|
|
|
|
|
|
|
for (String s : split) { |
|
|
|
|
|
|
|
PlanMsgRecordDto planMsgRecordDtoDto = new PlanMsgRecordDto(); |
|
|
|
|
|
|
|
planMsgRecordDtoDto.setTemplateId(item.getMessageTemplateId()); |
|
|
|
|
|
|
|
planMsgRecordDtoDto.setTaskId(item.getId()); |
|
|
|
|
|
|
|
planMsgRecordDtoDto.setDeptId(item.getCurSts()); |
|
|
|
|
|
|
|
planMsgRecordDtoDto.setCreateUser(item.getCreateUser()); |
|
|
|
|
|
|
|
planMsgRecordDtoDto.setReceiver(Long.valueOf(s)); |
|
|
|
|
|
|
|
ZoneId zoneId = ZoneId.systemDefault(); |
|
|
|
|
|
|
|
Date nextCheckTime = item.getNextCheckTime(); |
|
|
|
|
|
|
|
planMsgRecordDtoDto.setPlanTime(nextCheckTime.toInstant().atZone(zoneId).toLocalDateTime()); |
|
|
|
|
|
|
|
TemplateService templateService1 = |
|
|
|
|
|
|
|
templateService.stream().filter(item1 -> item1.isTemplateStatus(1)).findFirst().orElse(null); |
|
|
|
|
|
|
|
templateService1.execute(planMsgRecordDtoDto); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!super.updateBatchById(safetyTools)) { |
|
|
|
if (!super.updateBatchById(safetyTools)) { |
|
|
|
throw new RuntimeException("数据库update操作失败!"); |
|
|
|
throw new RuntimeException("数据库update操作失败!"); |
|
|
@ -152,6 +174,8 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
if (safetyToolRecheckMapper.insertBatch(safetyToolRechecks) == 0) { |
|
|
|
if (safetyToolRecheckMapper.insertBatch(safetyToolRechecks) == 0) { |
|
|
|
throw new RuntimeException("数据库insert操作失败!"); |
|
|
|
throw new RuntimeException("数据库insert操作失败!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -163,7 +187,7 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void importExcel(MultipartFile file,Long createDept) { |
|
|
|
public void importExcel(MultipartFile file, Long createDept) { |
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
ExcelToolListener excelToolListener = new ExcelToolListener(); |
|
|
|
ExcelToolListener excelToolListener = new ExcelToolListener(); |
|
|
|
if (StringUtils.isEmpty(filename)) { |
|
|
|
if (StringUtils.isEmpty(filename)) { |
|
|
@ -173,25 +197,25 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
try { |
|
|
|
try { |
|
|
|
InputStream inputStream = new BufferedInputStream(file.getInputStream()); |
|
|
|
InputStream inputStream = new BufferedInputStream(file.getInputStream()); |
|
|
|
com.hnac.hzims.safeproduct.utils.ExcelUtil.asyncReadModel(inputStream, excelToolListener,SafetyToolSaveExcel.class,0,1); |
|
|
|
com.hnac.hzims.safeproduct.utils.ExcelUtil.asyncReadModel(inputStream, excelToolListener, SafetyToolSaveExcel.class, 0, 1); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List dataList = excelToolListener.getDataList(); |
|
|
|
List dataList = excelToolListener.getDataList(); |
|
|
|
if(CollectionUtil.isNotEmpty(dataList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(dataList)) { |
|
|
|
List<SafetyToolEntity> entityList = new ArrayList<>(); |
|
|
|
List<SafetyToolEntity> entityList = new ArrayList<>(); |
|
|
|
Map<String,List<SafetyToolEntity>> map = JSONArray.parseArray(JSON.toJSONString(dataList),SafetyToolEntity.class).stream() |
|
|
|
Map<String, List<SafetyToolEntity>> map = JSONArray.parseArray(JSON.toJSONString(dataList), SafetyToolEntity.class).stream() |
|
|
|
.filter(entity -> Func.isNotEmpty(entity.getToolCode())).collect(Collectors.groupingBy(SafetyToolEntity::getToolCode)); |
|
|
|
.filter(entity -> Func.isNotEmpty(entity.getToolCode())).collect(Collectors.groupingBy(SafetyToolEntity::getToolCode)); |
|
|
|
Assert.isTrue(CollectionUtil.isNotEmpty(map),()->{ |
|
|
|
Assert.isTrue(CollectionUtil.isNotEmpty(map), () -> { |
|
|
|
throw new ServiceException("填入工器具编码不能为空"); |
|
|
|
throw new ServiceException("填入工器具编码不能为空"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
IntStream.iterate(0,index->index+1).limit(dataList.size()).forEachOrdered(index->{ |
|
|
|
IntStream.iterate(0, index -> index + 1).limit(dataList.size()).forEachOrdered(index -> { |
|
|
|
SafetyToolEntity entity = BeanUtil.copy(dataList.get(index),SafetyToolEntity.class); |
|
|
|
SafetyToolEntity entity = BeanUtil.copy(dataList.get(index), SafetyToolEntity.class); |
|
|
|
SafetyToolSaveExcel safetyToolSaveExcel = JSONObject.parseObject(JSON.toJSONString(dataList.get(index)),SafetyToolSaveExcel.class); |
|
|
|
SafetyToolSaveExcel safetyToolSaveExcel = JSONObject.parseObject(JSON.toJSONString(dataList.get(index)), SafetyToolSaveExcel.class); |
|
|
|
Assert.isTrue(Func.isNotEmpty(entity.getToolCode()) && Func.isNotEmpty(entity.getToolName()) |
|
|
|
Assert.isTrue(Func.isNotEmpty(entity.getToolCode()) && Func.isNotEmpty(entity.getToolName()) |
|
|
|
&& Func.isNotEmpty(entity.getSafeTime()) && Func.isNotEmpty(safetyToolSaveExcel.getTypeName()),()->{ |
|
|
|
&& Func.isNotEmpty(entity.getSafeTime()) && Func.isNotEmpty(safetyToolSaveExcel.getTypeName()), () -> { |
|
|
|
throw new ServiceException("第"+ index+"填入数据部分缺失,请修改后重新导入"); |
|
|
|
throw new ServiceException("第" + index + "填入数据部分缺失,请修改后重新导入"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
List<SafetyToolEntity> list = this.list(new LambdaQueryWrapper<SafetyToolEntity>().eq(SafetyToolEntity::getToolCode, entity.getToolCode())); |
|
|
|
List<SafetyToolEntity> list = this.list(new LambdaQueryWrapper<SafetyToolEntity>().eq(SafetyToolEntity::getToolCode, entity.getToolCode())); |
|
|
|
if (CollectionUtil.isNotEmpty(list) || (CollectionUtil.isNotEmpty(map.get(entity.getToolCode())) && map.get(entity.getToolCode()).size() > 1)) { |
|
|
|
if (CollectionUtil.isNotEmpty(list) || (CollectionUtil.isNotEmpty(map.get(entity.getToolCode())) && map.get(entity.getToolCode()).size() > 1)) { |
|
|
@ -199,8 +223,8 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
} |
|
|
|
} |
|
|
|
List<SafetyToolTypeEntity> safetyToolTypeEntityList = safetyToolTypeService.list(Wrappers.<SafetyToolTypeEntity>lambdaQuery() |
|
|
|
List<SafetyToolTypeEntity> safetyToolTypeEntityList = safetyToolTypeService.list(Wrappers.<SafetyToolTypeEntity>lambdaQuery() |
|
|
|
.eq(SafetyToolTypeEntity::getTypeName, safetyToolSaveExcel.getTypeName())); |
|
|
|
.eq(SafetyToolTypeEntity::getTypeName, safetyToolSaveExcel.getTypeName())); |
|
|
|
Assert.isTrue(safetyToolTypeEntityList.size() > 0,()->{ |
|
|
|
Assert.isTrue(safetyToolTypeEntityList.size() > 0, () -> { |
|
|
|
throw new ServiceException("第"+ index+"行填入类型未找到相关记录,请修改后重新导入"); |
|
|
|
throw new ServiceException("第" + index + "行填入类型未找到相关记录,请修改后重新导入"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
//验证账户
|
|
|
|
//验证账户
|
|
|
|
String userIds = Arrays.stream(safetyToolSaveExcel.getAccounts().split(",")).map(account -> { |
|
|
|
String userIds = Arrays.stream(safetyToolSaveExcel.getAccounts().split(",")).map(account -> { |
|
|
@ -222,24 +246,24 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 安全工器具二维码导出 |
|
|
|
* 安全工器具二维码导出 |
|
|
|
|
|
|
|
* |
|
|
|
* @param idList |
|
|
|
* @param idList |
|
|
|
* @return 文件路径 |
|
|
|
* @return 文件路径 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String safetyToolRQExport(List idList){ |
|
|
|
public String safetyToolRQExport(List idList) { |
|
|
|
List<SafetyToolEntity> entityList = null; |
|
|
|
List<SafetyToolEntity> entityList = null; |
|
|
|
if(CollectionUtil.isNotEmpty(idList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(idList)) { |
|
|
|
entityList = list(new LambdaQueryWrapper<SafetyToolEntity>(){{ |
|
|
|
entityList = list(new LambdaQueryWrapper<SafetyToolEntity>() {{ |
|
|
|
in(SafetyToolEntity::getId,idList); |
|
|
|
in(SafetyToolEntity::getId, idList); |
|
|
|
orderByDesc(SafetyToolEntity::getCreateTime); |
|
|
|
orderByDesc(SafetyToolEntity::getCreateTime); |
|
|
|
}}); |
|
|
|
}}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
entityList = page(Condition.getPage(new Query()), new LambdaQueryWrapper<SafetyToolEntity>()).getRecords(); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
if (CollectionUtil.isNotEmpty(entityList)) { |
|
|
|
entityList = page(Condition.getPage(new Query()),new LambdaQueryWrapper<SafetyToolEntity>()).getRecords(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(entityList)){ |
|
|
|
|
|
|
|
List<SafeProductPdf> pdfList = new ArrayList<>(entityList.size()); |
|
|
|
List<SafeProductPdf> pdfList = new ArrayList<>(entityList.size()); |
|
|
|
entityList.forEach(entity->{ |
|
|
|
entityList.forEach(entity -> { |
|
|
|
String imgPath = uploadPath + "/" + entity.getTenantId() + entity.getToolCode() + UPLOAD_IMG_SUFFIX; |
|
|
|
String imgPath = uploadPath + "/" + entity.getTenantId() + entity.getToolCode() + UPLOAD_IMG_SUFFIX; |
|
|
|
File file = new File(imgPath); |
|
|
|
File file = new File(imgPath); |
|
|
|
if (!file.exists()) { |
|
|
|
if (!file.exists()) { |
|
|
@ -249,32 +273,30 @@ public class SafetyToolServiceImpl extends BaseServiceImpl<SafetyToolMapper, Saf |
|
|
|
|
|
|
|
|
|
|
|
SafeProductPdf safeProductPdf = new SafeProductPdf(); |
|
|
|
SafeProductPdf safeProductPdf = new SafeProductPdf(); |
|
|
|
safeProductPdf.setData_1(entity.getToolName()); |
|
|
|
safeProductPdf.setData_1(entity.getToolName()); |
|
|
|
safeProductPdf.setData_2(DateUtil.format(entity.getCreateTime(),"yyyy年MM月dd日")); |
|
|
|
safeProductPdf.setData_2(DateUtil.format(entity.getCreateTime(), "yyyy年MM月dd日")); |
|
|
|
safeProductPdf.setData_3(imgPath); |
|
|
|
safeProductPdf.setData_3(imgPath); |
|
|
|
pdfList.add(safeProductPdf); |
|
|
|
pdfList.add(safeProductPdf); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/**二维码写入html文件中成功后生成pdf文件地址**/ |
|
|
|
/**二维码写入html文件中成功后生成pdf文件地址**/ |
|
|
|
String pdfPath = uploadPath + "/" + UUID.randomUUID().toString() + ".pdf"; |
|
|
|
String pdfPath = uploadPath + "/" + UUID.randomUUID().toString() + ".pdf"; |
|
|
|
try{ |
|
|
|
try { |
|
|
|
/**将生成二维码写入html文件内**/ |
|
|
|
/**将生成二维码写入html文件内**/ |
|
|
|
String html = HtmlModule.buildHtml(pdfList, modulePath); |
|
|
|
String html = HtmlModule.buildHtml(pdfList, modulePath); |
|
|
|
HtmltoPdf.htmlToPdf(html, pdfPath); |
|
|
|
HtmltoPdf.htmlToPdf(html, pdfPath); |
|
|
|
return pdfPath; |
|
|
|
return pdfPath; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
throw new ServiceException("导出pdf发生异常:" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e){ |
|
|
|
} else { |
|
|
|
throw new ServiceException("导出pdf发生异常:"+e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else{ |
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R remove(List<Long> idList) { |
|
|
|
public R remove(List<Long> idList) { |
|
|
|
List<SafetyToolEntity> toolEntityList = list(new LambdaQueryWrapper<SafetyToolEntity>(){{ |
|
|
|
List<SafetyToolEntity> toolEntityList = list(new LambdaQueryWrapper<SafetyToolEntity>() {{ |
|
|
|
in(SafetyToolEntity::getId,idList); |
|
|
|
in(SafetyToolEntity::getId, idList); |
|
|
|
isNotNull(SafetyToolEntity::getNextCheckTime); |
|
|
|
isNotNull(SafetyToolEntity::getNextCheckTime); |
|
|
|
orderByDesc(SafetyToolEntity::getNextCheckTime); |
|
|
|
orderByDesc(SafetyToolEntity::getNextCheckTime); |
|
|
|
}}); |
|
|
|
}}); |
|
|
|