refactor(property): 优化授权逻辑
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2025-08-01 14:45:28 +08:00
parent 389ba82659
commit c366a30488
6 changed files with 177 additions and 118 deletions

View File

@@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.excel.core.ExcelResult;
import org.dromara.property.domain.vo.ResidentPersonImportVo;
import org.dromara.property.listener.ResidentPersonImportListener;
@@ -38,6 +39,7 @@ import org.springframework.web.multipart.MultipartFile;
* @author mocheng
* @since 2025-06-19
*/
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@@ -126,17 +128,17 @@ public class ResidentPersonController extends BaseController {
@SaCheckPermission("property:person:import")
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport, Long unitId) throws Exception {
ExcelResult<ResidentPersonImportVo> result = ExcelUtil.importExcel(file.getInputStream(), ResidentPersonImportVo.class, new ResidentPersonImportListener(updateSupport, unitId));
return R.ok(result.getAnalysis());
asyncImportExcel(StpUtil.getTokenValue(), file, updateSupport, unitId);
return R.ok("文件上传成功,请等待处理!");
}
@Async
public void asyncImportExcel(String tokenValue, MultipartFile file, Boolean updateSupport, Long unitId) {
try {
StpUtil.setTokenValueToStorage(tokenValue);
ExcelResult<ResidentPersonImportVo> result = ExcelUtil.importExcel(file.getInputStream(), ResidentPersonImportVo.class, new ResidentPersonImportListener(updateSupport, unitId));
ExcelUtil.importExcel(file.getInputStream(), ResidentPersonImportVo.class, new ResidentPersonImportListener(updateSupport, unitId));
} catch (Exception e) {
throw new RuntimeException(e);
log.info("处理导入入驻员工Excel文件时出错");
}
}
@@ -156,7 +158,17 @@ public class ResidentPersonController extends BaseController {
*/
@PostMapping(value = "/importFace", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<Void> importFace(@RequestPart("file") MultipartFile file, Long unitId) {
uploadFaceUtil.processFaceZip(file, unitId);
return R.ok();
asyncImportFace(StpUtil.getTokenValue(), file, unitId);
return R.ok("文件上传成功,请等待处理!");
}
@Async
public void asyncImportFace(String tokenValue, MultipartFile file, Long unitId) {
try {
StpUtil.setTokenValueToStorage(tokenValue);
uploadFaceUtil.processFaceZip(file, unitId);
} catch (Exception e) {
log.info("处理人脸压缩包时出错");
}
}
}

View File

@@ -126,30 +126,8 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
add.setAuthGroupId(ruVo.getAuthGroupId());
add.setAuthBegDate(ruVo.getAuthBegDate());
add.setAuthEndDate(ruVo.getAuthEndDate());
boolean flag = baseMapper.insert(add) > 0;
Assert.isTrue(flag, "员工入驻失败!");
// 存在图片时,才同步授权
if (flag && add.getImg() != null) {
log.info("开始写入授权记录, {}", bo.getUserName());
RemotePersonAuth personAuth = new RemotePersonAuth();
personAuth.setId(add.getId());
personAuth.setName(bo.getUserName());
personAuth.setSex(bo.getGender().intValue());
personAuth.setPhone(bo.getPhone());
personAuth.setEmail(bo.getEmail());
personAuth.setIdCardNumber(bo.getIdCard());
personAuth.setOssId(bo.getImg());
personAuth.setCarNumber(bo.getCarNumber());
// 使用公司权限组
personAuth.setAuthBegDate(ruVo.getAuthBegDate());
personAuth.setAuthEndDate(ruVo.getAuthEndDate());
personAuth.setAuthGroupId(ruVo.getAuthGroupId());
Boolean auth = remoteSisAuth.personAuth(personAuth);
Assert.isTrue(auth, "新增授权记录失败");
}
return flag;
}
@@ -180,22 +158,8 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
if (flag && e8Id != null) {
log.info("开始修改授权记录, {}", bo.getUserName());
RemotePersonAuth personAuth = new RemotePersonAuth();
personAuth.setId(update.getId());
personAuth.setName(update.getUserName());
personAuth.setSex(update.getGender().intValue());
personAuth.setPhone(update.getPhone());
personAuth.setEmail(update.getEmail());
personAuth.setIdCardNumber(update.getIdCard());
personAuth.setOssId(update.getImg());
personAuth.setCarNumber(update.getCarNumber());
personAuth.setE8Id(e8Id);
personAuth.setAuthGroupId(update.getAuthGroupId());
personAuth.setAuthBegDate(update.getAuthBegDate());
personAuth.setAuthEndDate(update.getAuthEndDate());
Boolean auth = remoteSisAuth.updatePersonAuth(personAuth);
// 先删除,定时任务增加
Boolean auth = remoteSisAuth.deletePersonAuth(List.of(update.getId()), List.of(e8Id));
Assert.isTrue(auth, "修改授权记录失败!");
}
@@ -256,7 +220,6 @@ public class ResidentPersonServiceImpl implements IResidentPersonService {
boolean auth = remoteSisAuth.deletePersonAuth(ids, e8Ids);
Assert.isTrue(auth, "删除授权记录失败!");
}
}
return baseMapper.deleteByIds(ids) > 0;
}