6 changed files with 109 additions and 50 deletions
@ -0,0 +1,50 @@ |
|||||||
|
package com.biutag.supervision.service; |
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||||
|
import com.biutag.supervision.mapper.SupRiskPersonalSupRecordMapper; |
||||||
|
import com.biutag.supervision.pojo.entity.SupRiskPersonalSupRecord; |
||||||
|
import com.biutag.supervision.pojo.vo.FileVo; |
||||||
|
import com.biutag.supervision.util.JSON; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import org.springframework.scheduling.annotation.Async; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream; |
||||||
|
import java.util.Base64; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@RequiredArgsConstructor |
||||||
|
@Service |
||||||
|
public class SupRiskPersonalSupRecordAsyncService { |
||||||
|
|
||||||
|
private final FileService fileService; |
||||||
|
|
||||||
|
private final SupRiskPersonalSupRecordMapper baseMapper; |
||||||
|
|
||||||
|
@Async |
||||||
|
public void uploadFile(List<FileVo> files, Integer id) { |
||||||
|
if (!files.isEmpty()) { |
||||||
|
for (FileVo file : files) { |
||||||
|
if (StrUtil.isNotBlank(file.getFilePath())) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
String base64 = file.getBase64(); |
||||||
|
if (base64.contains(",")) { |
||||||
|
base64 = base64.substring(base64.indexOf(",") + 1); |
||||||
|
} |
||||||
|
byte[] decodedBytes = Base64.getDecoder().decode(base64); |
||||||
|
ByteArrayInputStream is = new ByteArrayInputStream(decodedBytes); |
||||||
|
String filePath = fileService.upload(is, is.available(), FileUtil.extName(file.getFileName())); |
||||||
|
file.setFilePath(filePath); |
||||||
|
file.setBase64(null); |
||||||
|
} |
||||||
|
LambdaUpdateWrapper<SupRiskPersonalSupRecord> updateWrapper = new LambdaUpdateWrapper<>(); |
||||||
|
updateWrapper.eq(SupRiskPersonalSupRecord::getId, id) |
||||||
|
.set(SupRiskPersonalSupRecord::getFiles, JSON.toJSONString(files)); |
||||||
|
baseMapper.update(updateWrapper); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,12 +1,61 @@ |
|||||||
package com.biutag.supervision.service; |
package com.biutag.supervision.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
import com.biutag.supervision.mapper.SupRiskPersonalSupMapper; |
import com.biutag.supervision.common.UserContextHolder; |
||||||
|
import com.biutag.supervision.constants.AppConstants; |
||||||
|
import com.biutag.supervision.constants.enums.WorkStatusEnum; |
||||||
import com.biutag.supervision.mapper.SupRiskPersonalSupRecordMapper; |
import com.biutag.supervision.mapper.SupRiskPersonalSupRecordMapper; |
||||||
import com.biutag.supervision.pojo.entity.SupRiskPersonalSup; |
import com.biutag.supervision.pojo.dto.SupRiskPersonalSupRecordDto; |
||||||
|
import com.biutag.supervision.pojo.entity.SupRiskPersonal; |
||||||
import com.biutag.supervision.pojo.entity.SupRiskPersonalSupRecord; |
import com.biutag.supervision.pojo.entity.SupRiskPersonalSupRecord; |
||||||
|
import com.biutag.supervision.pojo.entity.SupTask; |
||||||
|
import com.biutag.supervision.pojo.model.UserAuth; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.time.LocalDateTime; |
||||||
|
|
||||||
|
@RequiredArgsConstructor |
||||||
@Service |
@Service |
||||||
public class SupRiskPersonalSupRecordService extends ServiceImpl<SupRiskPersonalSupRecordMapper, SupRiskPersonalSupRecord> { |
public class SupRiskPersonalSupRecordService extends ServiceImpl<SupRiskPersonalSupRecordMapper, SupRiskPersonalSupRecord> { |
||||||
|
|
||||||
|
private final SupTaskService taskService; |
||||||
|
|
||||||
|
private final SupRiskPersonalService riskPersonalService; |
||||||
|
|
||||||
|
private final SupRiskPersonalSupRecordAsyncService riskPersonalSupRecordAsyncService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 录入督察记录数据 |
||||||
|
* */ |
||||||
|
public Boolean saveSupRecord(SupRiskPersonalSupRecordDto supRecordDto){ |
||||||
|
SupRiskPersonalSupRecord supRecord = new SupRiskPersonalSupRecord(); |
||||||
|
BeanUtils.copyProperties(supRecordDto,supRecord); |
||||||
|
supRecord.setCreateTime(LocalDateTime.now()); |
||||||
|
UserAuth user = UserContextHolder.getCurrentUser(); |
||||||
|
if (!AppConstants.USER_TYPE_SUPER.equals(user.getUserType())) { |
||||||
|
supRecord.setCreateEmpNo(user.getEmpNo()); |
||||||
|
supRecord.setCreateName(user.getUserName()); |
||||||
|
} |
||||||
|
//补充file
|
||||||
|
// supRecord.setFiles(JSON.toJSONString(supRecordDto.getFiles()));
|
||||||
|
boolean b = saveOrUpdate(supRecord); |
||||||
|
if (b) { |
||||||
|
|
||||||
|
riskPersonalService.update(new LambdaUpdateWrapper<SupRiskPersonal>().eq(SupRiskPersonal::getIdCode, supRecordDto.getIdCode()) |
||||||
|
.set(SupRiskPersonal::getWorkStatus, WorkStatusEnum.done.name()) |
||||||
|
.set(SupRiskPersonal::getSupStatus, supRecordDto.getSupStatus())); |
||||||
|
if (!riskPersonalService.exists(new LambdaUpdateWrapper<SupRiskPersonal>() |
||||||
|
.eq(SupRiskPersonal::getTaskId, supRecordDto.getTaskId()) |
||||||
|
.eq(SupRiskPersonal::getWorkStatus, WorkStatusEnum.todo.name()))) { |
||||||
|
taskService.update(new LambdaUpdateWrapper<SupTask>().eq(SupTask::getId, supRecordDto.getTaskId()) |
||||||
|
.set(SupTask::getTaskStatus, WorkStatusEnum.done.name())); |
||||||
|
} |
||||||
|
riskPersonalSupRecordAsyncService.uploadFile(supRecordDto.getFiles(), supRecord.getId()); |
||||||
|
} |
||||||
|
|
||||||
|
return b; |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue