|
@@ -1,6 +1,7 @@
|
|
|
package com.usky.fire.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
@@ -18,6 +19,7 @@ import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.fire.service.vo.CompanyDataVo;
|
|
|
import com.usky.fire.service.vo.DemReportInfoIdVo;
|
|
|
import com.usky.fire.service.vo.DemReportInfoVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -33,6 +35,7 @@ import java.util.*;
|
|
|
* @author han
|
|
|
* @since 2023-03-02
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DemReportInfoServiceImpl extends AbstractCrudService<DemReportInfoMapper, DemReportInfo> implements DemReportInfoService {
|
|
|
|
|
@@ -43,7 +46,13 @@ public class DemReportInfoServiceImpl extends AbstractCrudService<DemReportInfoM
|
|
|
public CommonPage<DemReportInfo> reportInfoList(String companyId, String sourceType, Integer pageNum, Integer pageSize) {
|
|
|
IPage<DemReportInfo> page = new Page<>(pageNum, pageSize);
|
|
|
|
|
|
- String organization = SecurityUtils.getLoginUser().getSysUser().getRemark();
|
|
|
+ String organization = null;
|
|
|
+ try {
|
|
|
+ organization = SecurityUtils.getLoginUser().getSysUser().getRemark();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取remake失败", e);
|
|
|
+ return ToCommonPage(page);
|
|
|
+ }
|
|
|
|
|
|
if (StringUtils.isBlank(organization)) {
|
|
|
throw new BusinessException("当前登录账号非消防重点单位,请联系管理员!");
|
|
@@ -52,7 +61,12 @@ public class DemReportInfoServiceImpl extends AbstractCrudService<DemReportInfoM
|
|
|
LambdaQueryWrapper<BaseCompany> queryWrapper3 = Wrappers.lambdaQuery();
|
|
|
queryWrapper3.select(BaseCompany::getCompanyId)
|
|
|
.eq(BaseCompany::getOrganization, organization);
|
|
|
- String companyId1 = baseCompanyMapper.selectOne(queryWrapper3).getCompanyId();
|
|
|
+ String companyId1 = null;
|
|
|
+ try {
|
|
|
+ companyId1 = baseCompanyMapper.selectOne(queryWrapper3).getCompanyId();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return ToCommonPage(page);
|
|
|
+ }
|
|
|
|
|
|
if (StringUtils.isBlank(companyId)) {
|
|
|
companyId = companyId1;
|
|
@@ -67,9 +81,7 @@ public class DemReportInfoServiceImpl extends AbstractCrudService<DemReportInfoM
|
|
|
queryWrapper.orderByDesc(DemReportInfo::getId);
|
|
|
}
|
|
|
page = this.page(page, queryWrapper);
|
|
|
- if (page.getRecords().isEmpty()) {
|
|
|
- throw new BusinessException("当前单位暂未生成消防报告,请联系管理员!");
|
|
|
- }
|
|
|
+
|
|
|
return ToCommonPage(page);
|
|
|
}
|
|
|
|
|
@@ -127,4 +139,50 @@ public class DemReportInfoServiceImpl extends AbstractCrudService<DemReportInfoM
|
|
|
List<DemReportInfo> list2 = this.list(queryWrapper1);
|
|
|
return list2;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateReadStatus(String id) {
|
|
|
+ String remark = null;
|
|
|
+ try {
|
|
|
+ remark = SecurityUtils.getLoginUser().getSysUser().getRemark();
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ log.error("获取remake失败", e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String companyId = null;
|
|
|
+ LambdaQueryWrapper<BaseCompany> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(BaseCompany::getCompanyId)
|
|
|
+ .eq(BaseCompany::getOrganization, remark);
|
|
|
+ BaseCompany baseCompany = baseCompanyMapper.selectOne(queryWrapper);
|
|
|
+ if (baseCompany != null) {
|
|
|
+ companyId = baseCompany.getCompanyId();
|
|
|
+ } else {
|
|
|
+ log.warn("未查询到与组织[{}]匹配的公司信息", remark);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DemReportInfo report = this.getOne(Wrappers.<DemReportInfo>lambdaQuery()
|
|
|
+ .eq(DemReportInfo::getId, id));
|
|
|
+ if (report == null) {
|
|
|
+ log.warn("报告ID[{}]不存在,无法更新已读状态", id);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String reportCompanyId = report.getCompanyId();
|
|
|
+ if (!Objects.equals(reportCompanyId, companyId)) {
|
|
|
+ log.warn("报告ID[{}]所属公司[{}]与当前用户公司[{}]不匹配,无权限更新",
|
|
|
+ id, reportCompanyId, companyId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (report.getIsRead() == 0) {
|
|
|
+ report.setReadTime(LocalDateTime.now());
|
|
|
+ report.setIsRead(1);
|
|
|
+ this.updateById(report);
|
|
|
+ log.info("报告ID[{}]已更新为已读状态", id);
|
|
|
+ } else {
|
|
|
+ log.info("报告ID[{}]非第一次阅读,无需更新", id);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|