From dd59c95e87ba585c4e3e2f059e218853784402e5 Mon Sep 17 00:00:00 2001
From: zhangfeng <1603559716@qq.com>
Date: Wed, 26 Jul 2023 11:17:31 +0800
Subject: [PATCH] 附件上传接口
---
src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java | 212 ++++++++++++++++++----------------------------------
1 files changed, 74 insertions(+), 138 deletions(-)
diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
index b8e40f0..eeab821 100644
--- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
+++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
@@ -53,9 +53,11 @@
private InspectionExpertService expertService;
@Autowired
private InspectionHiddenDangerService dangerService;
+ @Autowired
+ private AttachmentInfoService attachmentInfoService;
/**
- * @Description: 分页
+ * @Description: 自查分页
*/
@Override
public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
@@ -72,7 +74,7 @@
filter.put("city",user.getCity());
filter.put("area",user.getCounty());
}
- filter.put("flag",0);
+ filter.put("flag",(byte)2);
IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
List<SafetySelfInspection> records = res.getRecords();
@@ -97,7 +99,7 @@
}
/**
- * @Description: 分页
+ * @Description: 监管检查分页
*/
@Override
public IPage<SafetySelfInspection> selectSupervisePage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
@@ -114,7 +116,7 @@
filter.put("city",user.getCity());
filter.put("area",user.getCounty());
}
- filter.put("flag",1);
+ filter.put("flag",(byte)1);
IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
List<SafetySelfInspection> records = res.getRecords();
@@ -137,119 +139,7 @@
}
return res;
}
- /* @Override
- public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
- Integer type = user.getType();
- //普通用户
- if (type.equals(3)) {
- Long companyid = user.getCompanyid();
- filter.put("companyid",companyid);
- }
- //监管用户
- if (type.equals(2)) {
- Long companyid = user.getCompanyid();
- //获取企业信息
- CompanyInfo companyInfo = companyService.getById(companyid);
- filter.put("province",companyInfo.getProvince());
- filter.put("city",companyInfo.getCity());
- filter.put("area",companyInfo.getArea());
- }
- IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
- List<SafetySelfInspection> records = res.getRecords();
- if (CollectionUtils.isNotEmpty(records)){
- DecimalFormat df = new DecimalFormat("0.00%");
- records = records.stream().map((safetySelfInspection) -> {
- //总分
- Integer totalScore = 0;
- //扣分
- Integer delScore =0;
-
- Long id = safetySelfInspection.getId();
- SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id);
- safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem());
- if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) {
- BigDecimal rate = new BigDecimal(countDO.getQualifiedItem())
- .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP);
- String qualifiedRate = df.format(rate);
- safetySelfInspection.setQualifiedRate(qualifiedRate);
- safetySelfInspection.setItemSum(countDO.getItemSum());
- }
- //计算总分以及得分
- //获取要素
- List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id);
- //获取检查项
- List<SafetySelfInspectionItem> safetySelfInspectionItemList = safetySelfInspectionItemMapper.getBySafetySelfInspectionId2(id);
- //循环要素
- for(SafetyInspectionElementA elementA : inspectionElementAList){
- //获取该要素的树
- List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA());
- //二级要素
- if (CollectionUtils.isNotEmpty(elementTree)) {
- List<ElementTree> elementBList = elementTree.get(0).getChildren();
- for(ElementTree stree : elementBList){
- //三级要素为空
- if(CollectionUtils.isEmpty(stree.getChildren())){
- //总分累计
- totalScore += stree.getPoint();
- //无三级要素过滤出二级要素检查内容
- List<SafetySelfInspectionItem> sItemList = safetySelfInspectionItemList
- .stream()
- .filter(item -> item.getElementC() == null && item.getElementB().equals(stree.getValue()))
- .collect(Collectors.toList());
- //判断是否有否决项
- List<SafetySelfInspectionItem> rejectList = sItemList
- .stream()
- .filter(item -> item.getSafetyInspectionItemResult().equals(0))
- .collect(Collectors.toList());
-
- if(rejectList.size() > 0){
- delScore += stree.getPoint();
- }else {
- //计算出不合格扣分
- delScore += unqualifiedItemDelScore(sItemList);
- }
-
- } else {
- List<ElementTree> elementCList = stree.getChildren();
- for(ElementTree ttree : elementCList){
- //计算总分
- totalScore += ttree.getPoint();
- //过滤该三级要素检查项目
- List<SafetySelfInspectionItem> tItemList = safetySelfInspectionItemList
- .stream()
- .filter(item -> item.getElementC() != null && item.getElementC().equals(ttree.getValue()))
- .collect(Collectors.toList());
- //判断是否有被否决
- List<SafetySelfInspectionItem> rejectList = tItemList
- .stream()
- .filter(item -> item.getSafetyInspectionItemResult().equals(0))
- .collect(Collectors.toList());
- if(rejectList.size() > 0){
- delScore += ttree.getPoint();
- }else {
- //计算出不合格扣分
- totalScore += unqualifiedItemDelScore(tItemList);
- }
- }
-
- }
- }
-
- }
-
-
- }
- //得分
- Integer score = totalScore - delScore;
- safetySelfInspection.setTotalScore(totalScore.toString());
- safetySelfInspection.setScore(score.toString());
- return safetySelfInspection;
- }).collect(Collectors.toList());
- res.setRecords(records);
- }
- return res;
- }*/
//累计过出不合格扣分
private Integer unqualifiedItemDelScore(List<SafetySelfInspectionItem> itemList){
int delScore = 0;
@@ -283,7 +173,7 @@
Date date = new Date();
String username = user.getRealname();
param.setValidFlag(Boolean.TRUE);
- param.setFlag((byte) 0);
+ param.setFlag((byte) 2);
param.setUpdateBy(username);
param.setCreateBy(username);
param.setUpdateTime(date);
@@ -521,25 +411,23 @@
BeanUtils.copyProperties(safetySelfInspection,safetySelfInspectionRespDTO);
//获取所有检查项
List<SafetySelfInspectionItem> itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id,unqualified);
- //获取关联要素
- List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id);
+ //获取要素树
+ List<ElementTree> elementTreeList = elementManagementService.getMenuType1Tree();
List<SafetySelfInspectionElementRespDTO> arespDTOList = new ArrayList<>();
- if (CollectionUtils.isNotEmpty(inspectionElementAList)) {
- for (SafetyInspectionElementA elementA : inspectionElementAList) {
- //获取该要素的树
- List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA());
- if (CollectionUtils.isNotEmpty(elementTree)) {
- //一级要素
- ElementTree otree = elementTree.get(0);
+ if (CollectionUtils.isNotEmpty(elementTreeList)) {
+ for (ElementTree elementA : elementTreeList) {
+
+ List<SafetySelfInspectionItem> selectElementList = itemList.stream().filter(item -> item.getElementA().equals(elementA.getValue())).collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(selectElementList)) {
SafetySelfInspectionElementRespDTO elementARespDTO = new SafetySelfInspectionElementRespDTO();
- elementARespDTO.setElementId(otree.getValue());
- elementARespDTO.setElementName(otree.getLabel());
- elementARespDTO.setType(otree.getType());
+ elementARespDTO.setElementId(elementA.getValue());
+ elementARespDTO.setElementName(elementA.getLabel());
+ elementARespDTO.setType(elementA.getType());
List<SafetySelfInspectionElementRespDTO> brespDTOList = new ArrayList<>();
//二级要素
- List<ElementTree> elementBList = otree.getChildren();
+ List<ElementTree> elementBList = elementA.getChildren();
if(CollectionUtils.isNotEmpty(elementBList)){
for (ElementTree stree : elementBList) {
SafetySelfInspectionElementRespDTO elementBRespDTO = new SafetySelfInspectionElementRespDTO();
@@ -669,6 +557,7 @@
SafetySelfInspectionItem safetySelfInspectionItem = safetySelfInspectionItemMapper.getDetailById(id);
List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId());
List<InspectionHiddenDanger> inspectionHiddenDangerList = dangerService.getBySafetySelfInspectionItemId(id);
+ List<AttachmentInfo> byBusinessId = attachmentInfoService.findByBusinessId(id);
if (CollectionUtils.isNotEmpty(selfDeductionList)){
safetySelfInspectionItem.setSelfDeductionList(selfDeductionList);
@@ -689,6 +578,20 @@
safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>());
}
}
+ for (InspectionHiddenDanger inspectionHiddenDanger : inspectionHiddenDangerList) {
+ if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){
+ List<Long> attachmentIds = new ArrayList<>();
+ String[] split = inspectionHiddenDanger.getUrl().split(",");
+ for (String s : split) {
+ attachmentIds.add(Long.valueOf(s));
+ }
+
+ List<AttachmentInfo> dangerAttachList = attachmentInfoService.findByIds(attachmentIds);
+ inspectionHiddenDanger.setAttachmentList(dangerAttachList);
+ }
+
+ }
+ safetySelfInspectionItem.setAttachmentList(byBusinessId);
safetySelfInspectionItem.setDangerList(inspectionHiddenDangerList);
return safetySelfInspectionItem;
}
@@ -705,6 +608,15 @@
param.setUpdateTime(date);
param.setUpdateBy(username);
safetySelfInspectionItemMapper.updateById(param);
+ //附件
+ List<AttachmentInfo> attachmentInfoList = new ArrayList<>();
+ if(CollectionUtils.isNotEmpty(param.getAttachmentList())){
+ for (AttachmentInfo attachmentInfo : param.getAttachmentList()) {
+ attachmentInfo.setBusinessId(param.getId());
+ attachmentInfoList.add(attachmentInfo);
+ }
+ }
+
if (param.getSafetyInspectionItemResult()==0 || param.getSafetyInspectionItemResult() == 2){
//否决 合格--删除扣分记录
safetySelfInspectionItemDeductionMapper.delBySafetySelfInspectionItemId(param.getId(),username,date);
@@ -747,6 +659,15 @@
dangerService.delByIds(idList);
}
for (InspectionHiddenDanger inspectionHiddenDanger : param.getDangerList()) {
+ StringBuffer stringBuffer = new StringBuffer();
+ //附件
+ if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){
+ for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) {
+ stringBuffer.append(attachmentInfo.getId().toString()).append(",");
+ }
+ stringBuffer = stringBuffer.deleteCharAt(stringBuffer.length()-1);
+ }
+
if(inspectionHiddenDanger.getId() == null){
inspectionHiddenDanger.setCreateBy(user.getRealname());
inspectionHiddenDanger.setCreateTime(new Date());
@@ -756,14 +677,35 @@
inspectionHiddenDanger.setValidFlag(true);
inspectionHiddenDanger.setSelfInspectionId(param.getSafetySelfInspectionId());
inspectionHiddenDanger.setSelfInspectionItemId(param.getId());
+ inspectionHiddenDanger.setUrl(stringBuffer.toString());
dangerService.save(inspectionHiddenDanger);
+ //附件
+ if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){
+ for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) {
+ attachmentInfo.setBusinessId(inspectionHiddenDanger.getId());
+ attachmentInfoList.add(attachmentInfo);
+ }
+ }
}else {
inspectionHiddenDanger.setUpdateBy(user.getRealname());
inspectionHiddenDanger.setUpdateTime(new Date());
+ inspectionHiddenDanger.setUrl(stringBuffer.toString());
dangerService.updateById(inspectionHiddenDanger);
+ //附件
+ if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){
+ for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) {
+ attachmentInfo.setBusinessId(inspectionHiddenDanger.getId());
+ attachmentInfoList.add(attachmentInfo);
+ }
+ }
}
}
}
+
+ }
+ //附件信息更新
+ if(CollectionUtils.isNotEmpty(attachmentInfoList)){
+ attachmentInfoService.updateBusinessIdBatch(attachmentInfoList);
}
}
@@ -844,13 +786,7 @@
if (param.getCheckedCompanyId() == null){
throw new BusinessException("请选择被检查公司");
}
- if(CollectionUtils.isEmpty(param.getElementAList())){
- throw new BusinessException("请选择A检查要素");
- }
- for(SafetyInspectionElementA elementA : param.getElementAList()){
- if(elementA.getElementA() == null){
- throw new BusinessException("请选择A检查要素");
- }
- }
}
+
+
}
--
Gitblit v1.9.2