|
|
@@ -19,9 +19,12 @@ import shop.alien.entity.store.LawFirm;
|
|
|
import shop.alien.entity.store.LawFirmPayment;
|
|
|
import shop.alien.entity.store.excelVo.LawFirmExcelVo;
|
|
|
import shop.alien.entity.store.excelVo.util.ExcelHeader;
|
|
|
+import shop.alien.entity.store.vo.LawFirmPaymentVO;
|
|
|
import shop.alien.lawyer.service.LawFirmPaymentService;
|
|
|
import shop.alien.lawyer.service.LawFirmService;
|
|
|
import shop.alien.mapper.LawFirmMapper;
|
|
|
+import shop.alien.mapper.LawFirmPaymentMapper;
|
|
|
+import shop.alien.util.excel.EasyExcelUtil;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.DateUtil;
|
|
|
|
|
|
@@ -50,6 +53,7 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
|
|
|
private final LawFirmMapper lawFirmMapper;
|
|
|
private final LawFirmPaymentService lawFirmPaymentService;
|
|
|
+ private final LawFirmPaymentMapper lawFirmPaymentMapper;
|
|
|
|
|
|
@Override
|
|
|
public R<IPage<LawFirm>> getLawFirmList(int pageNum, int pageSize, String firmName, Integer status) {
|
|
|
@@ -70,106 +74,214 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
|
|
|
@Override
|
|
|
public R<LawFirm> addLawFirm(LawFirm lawFirm) {
|
|
|
- log.info("LawFirmServiceImpl.addLawFirm?lawFirm={}", lawFirm);
|
|
|
-
|
|
|
- // 校验收款账号唯一性
|
|
|
+ log.info("LawFirmServiceImpl.addLawFirm?lawFirm={}, platformCommissionRatio={}", lawFirm, lawFirm.getPlatformCommissionRatio());
|
|
|
+
|
|
|
+ // 第一步:先校验收款账号,如果 paymentAccount 在数据库中存在,不让新增
|
|
|
if (lawFirm.getPaymentList() != null && !lawFirm.getPaymentList().isEmpty()) {
|
|
|
for (LawFirmPayment payment : lawFirm.getPaymentList()) {
|
|
|
if (StringUtils.hasText(payment.getPaymentAccount())) {
|
|
|
- // 检查收款账号是否已存在
|
|
|
+ String paymentAccount = payment.getPaymentAccount().trim();
|
|
|
+
|
|
|
+ // 检查收款账号是否在数据库中存在
|
|
|
LambdaQueryWrapper<LawFirmPayment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LawFirmPayment::getPaymentAccount, payment.getPaymentAccount());
|
|
|
+ queryWrapper.eq(LawFirmPayment::getPaymentAccount, paymentAccount);
|
|
|
queryWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
long count = lawFirmPaymentService.count(queryWrapper);
|
|
|
if (count > 0) {
|
|
|
- return R.fail("收款账号[" + payment.getPaymentAccount() + "]已存在,不能重复添加");
|
|
|
+ return R.fail("收款账号[" + paymentAccount + "]在数据库中已存在,不能添加");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 保存主表
|
|
|
- boolean result = this.save(lawFirm);
|
|
|
- if (!result) {
|
|
|
- return R.fail("新增失败");
|
|
|
+
|
|
|
+ // 第二步:paymentAccount 校验通过后,检查统一社会信用代码是否已存在
|
|
|
+ LawFirm existingLawFirm = null;
|
|
|
+ if (StringUtils.hasText(lawFirm.getCreditCode())) {
|
|
|
+ LambdaQueryWrapper<LawFirm> creditCodeWrapper = new LambdaQueryWrapper<>();
|
|
|
+ creditCodeWrapper.eq(LawFirm::getCreditCode, lawFirm.getCreditCode());
|
|
|
+ creditCodeWrapper.eq(LawFirm::getDeleteFlag, 0);
|
|
|
+ existingLawFirm = this.getOne(creditCodeWrapper);
|
|
|
}
|
|
|
-
|
|
|
- // 保存子表数据
|
|
|
- if (lawFirm.getPaymentList() != null && !lawFirm.getPaymentList().isEmpty()) {
|
|
|
- for (LawFirmPayment payment : lawFirm.getPaymentList()) {
|
|
|
- try {
|
|
|
+
|
|
|
+ // existingLawFirm 不为空执行更新子表,否则执行新增主子表操作
|
|
|
+ if (existingLawFirm != null) {
|
|
|
+ // 更新子表操作:只更新子表数据,不更新主表
|
|
|
+ Integer firmId = existingLawFirm.getId();
|
|
|
+ log.info("统一社会信用代码[{}]已存在,只更新子表数据,律所ID={}", lawFirm.getCreditCode(), firmId);
|
|
|
+
|
|
|
+ // 保存子表数据
|
|
|
+ if (lawFirm.getPaymentList() != null && !lawFirm.getPaymentList().isEmpty()) {
|
|
|
+ for (LawFirmPayment payment : lawFirm.getPaymentList()) {
|
|
|
+ if (!StringUtils.hasText(payment.getPaymentAccount())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String paymentAccount = payment.getPaymentAccount().trim();
|
|
|
+
|
|
|
+ // 再次检查账号是否已存在(防止并发问题)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
+ checkWrapper.eq(LawFirmPayment::getPaymentAccount, paymentAccount);
|
|
|
+ checkWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ long checkCount = lawFirmPaymentService.count(checkWrapper);
|
|
|
+ if (checkCount > 0) {
|
|
|
+ return R.fail("收款账号[" + paymentAccount + "]在数据库中已存在,不能添加");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增收款账号
|
|
|
+ LawFirmPayment newPayment = new LawFirmPayment();
|
|
|
+ newPayment.setFirmId(firmId);
|
|
|
+ newPayment.setPaymentAccount(paymentAccount);
|
|
|
+ if (StringUtils.hasText(payment.getAddress())) {
|
|
|
+ newPayment.setAddress(payment.getAddress().trim());
|
|
|
+ }
|
|
|
+ newPayment.setDeleteFlag(0);
|
|
|
+
|
|
|
+ boolean saveResult = lawFirmPaymentService.save(newPayment);
|
|
|
+ if (!saveResult) {
|
|
|
+ log.error("保存收款账号失败,firmId={}, paymentAccount={}", firmId, paymentAccount);
|
|
|
+ return R.fail("保存收款账号失败:" + paymentAccount);
|
|
|
+ }
|
|
|
+ log.info("保存收款账号成功,firmId={}, paymentAccount={}, id={}",
|
|
|
+ firmId, paymentAccount, newPayment.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.data(existingLawFirm, "统一社会信用代码已存在,已更新收款账号列表");
|
|
|
+ } else {
|
|
|
+ // 新增主子表操作
|
|
|
+ // 保存主表
|
|
|
+ log.info("新增律所,platformCommissionRatio={}", lawFirm.getPlatformCommissionRatio());
|
|
|
+ boolean result = this.save(lawFirm);
|
|
|
+ if (!result) {
|
|
|
+ return R.fail("新增失败");
|
|
|
+ }
|
|
|
+ Integer firmId = lawFirm.getId();
|
|
|
+
|
|
|
+ // 验证 platformCommissionRatio 是否保存成功
|
|
|
+ LawFirm savedLawFirm = this.getById(firmId);
|
|
|
+ if (savedLawFirm != null) {
|
|
|
+ log.info("保存后的律所,platformCommissionRatio={}", savedLawFirm.getPlatformCommissionRatio());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存子表数据
|
|
|
+ if (lawFirm.getPaymentList() != null && !lawFirm.getPaymentList().isEmpty()) {
|
|
|
+ for (LawFirmPayment payment : lawFirm.getPaymentList()) {
|
|
|
+ if (!StringUtils.hasText(payment.getPaymentAccount())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String paymentAccount = payment.getPaymentAccount().trim();
|
|
|
+
|
|
|
+ // 再次检查账号是否已存在(防止并发问题)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
+ checkWrapper.eq(LawFirmPayment::getPaymentAccount, paymentAccount);
|
|
|
+ checkWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ long checkCount = lawFirmPaymentService.count(checkWrapper);
|
|
|
+ if (checkCount > 0) {
|
|
|
+ return R.fail("收款账号[" + paymentAccount + "]在数据库中已存在,不能添加");
|
|
|
+ }
|
|
|
+
|
|
|
// 创建新的对象,避免污染原对象
|
|
|
LawFirmPayment newPayment = new LawFirmPayment();
|
|
|
- newPayment.setFirmId(lawFirm.getId());
|
|
|
- newPayment.setPaymentAccount(payment.getPaymentAccount().trim());
|
|
|
+ newPayment.setFirmId(firmId);
|
|
|
+ newPayment.setPaymentAccount(paymentAccount);
|
|
|
if (StringUtils.hasText(payment.getAddress())) {
|
|
|
newPayment.setAddress(payment.getAddress().trim());
|
|
|
}
|
|
|
+ newPayment.setDeleteFlag(0);
|
|
|
|
|
|
boolean saveResult = lawFirmPaymentService.save(newPayment);
|
|
|
if (!saveResult) {
|
|
|
- log.error("保存收款账号失败,firmId={}, paymentAccount={}", lawFirm.getId(), payment.getPaymentAccount());
|
|
|
- return R.fail("保存收款账号失败:" + payment.getPaymentAccount());
|
|
|
+ log.error("保存收款账号失败,firmId={}, paymentAccount={}", firmId, paymentAccount);
|
|
|
+ return R.fail("保存收款账号失败:" + paymentAccount);
|
|
|
}
|
|
|
- log.info("保存收款账号成功,firmId={}, paymentAccount={}, id={}", lawFirm.getId(), payment.getPaymentAccount(), newPayment.getId());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("保存收款账号异常,firmId={}, paymentAccount={}", lawFirm.getId(), payment.getPaymentAccount(), e);
|
|
|
- return R.fail("保存收款账号异常:" + e.getMessage());
|
|
|
+ log.info("保存收款账号成功,firmId={}, paymentAccount={}, id={}",
|
|
|
+ firmId, paymentAccount, newPayment.getId());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return R.data(lawFirm);
|
|
|
}
|
|
|
- return R.data(lawFirm);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public R<LawFirm> editLawFirm(LawFirm lawFirm) {
|
|
|
log.info("LawFirmServiceImpl.editLawFirm?lawFirm={}", lawFirm);
|
|
|
-
|
|
|
+
|
|
|
+ // 校验律所ID
|
|
|
if (lawFirm.getId() == null) {
|
|
|
return R.fail("律所ID不能为空");
|
|
|
}
|
|
|
-
|
|
|
- // 校验收款账号唯一性(排除当前律所的账号)
|
|
|
+
|
|
|
+ // 检查律所是否存在
|
|
|
+ LawFirm existingLawFirm = this.getById(lawFirm.getId());
|
|
|
+ if (existingLawFirm == null || existingLawFirm.getDeleteFlag() == 1) {
|
|
|
+ return R.fail("律所不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第一步:先校验收款账号,如果 paymentAccount 在数据库中存在,不让新增或修改
|
|
|
if (lawFirm.getPaymentList() != null && !lawFirm.getPaymentList().isEmpty()) {
|
|
|
+ // 查询当前律所下现有的收款账号记录(用于判断是新增还是更新)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> existingWrapper = new LambdaQueryWrapper<>();
|
|
|
+ existingWrapper.eq(LawFirmPayment::getFirmId, lawFirm.getId());
|
|
|
+ existingWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ List<LawFirmPayment> existingPayments = lawFirmPaymentService.list(existingWrapper);
|
|
|
+ Map<Integer, String> existingPaymentMap = existingPayments.stream()
|
|
|
+ .collect(Collectors.toMap(LawFirmPayment::getId, LawFirmPayment::getPaymentAccount));
|
|
|
+
|
|
|
for (LawFirmPayment payment : lawFirm.getPaymentList()) {
|
|
|
if (StringUtils.hasText(payment.getPaymentAccount())) {
|
|
|
- // 检查收款账号是否已存在(排除当前律所和当前记录)
|
|
|
- LambdaQueryWrapper<LawFirmPayment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LawFirmPayment::getPaymentAccount, payment.getPaymentAccount());
|
|
|
- queryWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
- queryWrapper.ne(LawFirmPayment::getFirmId, lawFirm.getId());
|
|
|
- // 如果是更新操作,排除当前记录
|
|
|
+ String paymentAccount = payment.getPaymentAccount().trim();
|
|
|
+
|
|
|
+ // 如果是更新操作,检查账号是否被修改
|
|
|
if (payment.getId() != null) {
|
|
|
- queryWrapper.ne(LawFirmPayment::getId, payment.getId());
|
|
|
- }
|
|
|
- long count = lawFirmPaymentService.count(queryWrapper);
|
|
|
- if (count > 0) {
|
|
|
- return R.fail("收款账号[" + payment.getPaymentAccount() + "]已存在,不能重复添加");
|
|
|
+ String originalAccount = existingPaymentMap.get(payment.getId());
|
|
|
+ // 如果账号被修改了,需要检查新账号是否已存在
|
|
|
+ if (originalAccount != null && !originalAccount.equals(paymentAccount)) {
|
|
|
+ // 检查新账号是否在数据库中存在(排除当前记录)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LawFirmPayment::getPaymentAccount, paymentAccount);
|
|
|
+ queryWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ queryWrapper.ne(LawFirmPayment::getId, payment.getId());
|
|
|
+ long count = lawFirmPaymentService.count(queryWrapper);
|
|
|
+ if (count > 0) {
|
|
|
+ return R.fail("新收款账号数据库已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 新增操作:检查账号是否在数据库中存在
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LawFirmPayment::getPaymentAccount, paymentAccount);
|
|
|
+ queryWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ long count = lawFirmPaymentService.count(queryWrapper);
|
|
|
+ if (count > 0) {
|
|
|
+ return R.fail("收款账号[" + paymentAccount + "]在数据库中已存在,不能添加");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 更新主表
|
|
|
+
|
|
|
+ // 第二步:更新主表
|
|
|
boolean result = this.updateById(lawFirm);
|
|
|
if (!result) {
|
|
|
- return R.fail("修改失败");
|
|
|
+ return R.fail("修改失败");
|
|
|
}
|
|
|
-
|
|
|
- // 处理子表数据
|
|
|
+
|
|
|
+ // 第三步:处理子表数据
|
|
|
if (lawFirm.getPaymentList() != null) {
|
|
|
// 查询现有的收款账号记录
|
|
|
LambdaQueryWrapper<LawFirmPayment> existingWrapper = new LambdaQueryWrapper<>();
|
|
|
existingWrapper.eq(LawFirmPayment::getFirmId, lawFirm.getId());
|
|
|
existingWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
List<LawFirmPayment> existingPayments = lawFirmPaymentService.list(existingWrapper);
|
|
|
-
|
|
|
+
|
|
|
// 收集前端传来的收款账号ID
|
|
|
Set<Integer> incomingIds = lawFirm.getPaymentList().stream()
|
|
|
.filter(p -> p.getId() != null)
|
|
|
.map(LawFirmPayment::getId)
|
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
+
|
|
|
// 删除不在前端列表中的记录(逻辑删除)
|
|
|
for (LawFirmPayment existing : existingPayments) {
|
|
|
if (!incomingIds.contains(existing.getId())) {
|
|
|
@@ -177,33 +289,133 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
lawFirmPaymentService.updateById(existing);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 新增或更新收款账号记录
|
|
|
for (LawFirmPayment payment : lawFirm.getPaymentList()) {
|
|
|
- payment.setFirmId(lawFirm.getId());
|
|
|
- if (payment.getId() != null) {
|
|
|
- // 更新
|
|
|
- payment.setDeleteFlag(0);
|
|
|
- lawFirmPaymentService.updateById(payment);
|
|
|
- } else {
|
|
|
- // 新增
|
|
|
- payment.setDeleteFlag(0);
|
|
|
- lawFirmPaymentService.save(payment);
|
|
|
+ if (!StringUtils.hasText(payment.getPaymentAccount())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String paymentAccount = payment.getPaymentAccount().trim();
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (payment.getId() != null) {
|
|
|
+ // 更新:获取原始记录
|
|
|
+ LawFirmPayment existingPayment = existingPayments.stream()
|
|
|
+ .filter(p -> p.getId().equals(payment.getId()))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ if (existingPayment != null) {
|
|
|
+ String originalAccount = existingPayment.getPaymentAccount();
|
|
|
+
|
|
|
+ // 如果 paymentAccount 被修改了,不更新 paymentAccount 字段,保持原值
|
|
|
+ LawFirmPayment updatePayment = new LawFirmPayment();
|
|
|
+ updatePayment.setId(payment.getId());
|
|
|
+ updatePayment.setFirmId(lawFirm.getId());
|
|
|
+
|
|
|
+ // 如果账号被修改了,保持原值;否则使用新值
|
|
|
+ if (!originalAccount.equals(paymentAccount)) {
|
|
|
+ updatePayment.setPaymentAccount(originalAccount); // 保持原值
|
|
|
+ } else {
|
|
|
+ updatePayment.setPaymentAccount(paymentAccount);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新其他字段
|
|
|
+ if (StringUtils.hasText(payment.getAddress())) {
|
|
|
+ updatePayment.setAddress(payment.getAddress().trim());
|
|
|
+ } else {
|
|
|
+ updatePayment.setAddress(existingPayment.getAddress());
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean updateResult = lawFirmPaymentService.updateById(updatePayment);
|
|
|
+ if (!updateResult) {
|
|
|
+ log.error("更新收款账号失败,firmId={}, paymentAccount={}, id={}",
|
|
|
+ lawFirm.getId(), paymentAccount, payment.getId());
|
|
|
+ return R.fail("更新收款账号失败:" + paymentAccount);
|
|
|
+ }
|
|
|
+ log.info("更新收款账号成功,firmId={}, paymentAccount={}, id={}",
|
|
|
+ lawFirm.getId(), existingPayment.getPaymentAccount(), updatePayment.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 新增:再次检查账号是否已存在(防止并发问题)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
+ checkWrapper.eq(LawFirmPayment::getPaymentAccount, paymentAccount);
|
|
|
+ checkWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ long checkCount = lawFirmPaymentService.count(checkWrapper);
|
|
|
+ if (checkCount > 0) {
|
|
|
+ return R.fail("收款账号[" + paymentAccount + "]在数据库中已存在,不能添加");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增收款账号
|
|
|
+ LawFirmPayment newPayment = new LawFirmPayment();
|
|
|
+ newPayment.setFirmId(lawFirm.getId());
|
|
|
+ newPayment.setPaymentAccount(paymentAccount);
|
|
|
+ if (StringUtils.hasText(payment.getAddress())) {
|
|
|
+ newPayment.setAddress(payment.getAddress().trim());
|
|
|
+ }
|
|
|
+ newPayment.setDeleteFlag(0);
|
|
|
+
|
|
|
+ boolean saveResult = lawFirmPaymentService.save(newPayment);
|
|
|
+ if (!saveResult) {
|
|
|
+ log.error("保存收款账号失败,firmId={}, paymentAccount={}", lawFirm.getId(), paymentAccount);
|
|
|
+ return R.fail("保存收款账号失败:" + paymentAccount);
|
|
|
+ }
|
|
|
+ log.info("保存收款账号成功,firmId={}, paymentAccount={}, id={}",
|
|
|
+ lawFirm.getId(), paymentAccount, newPayment.getId());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理收款账号异常,firmId={}, paymentAccount={}", lawFirm.getId(), paymentAccount, e);
|
|
|
+ return R.fail("处理收款账号异常:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return R.data(lawFirm);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public R<Boolean> deleteLawFirm(Integer id) {
|
|
|
- log.info("LawFirmServiceImpl.deleteLawFirm?id={}", id);
|
|
|
- boolean result = this.removeById(id);
|
|
|
- if (result) {
|
|
|
+ log.info("LawFirmServiceImpl.deleteLawFirm?paymentId={}", id);
|
|
|
+
|
|
|
+ // 1. 根据律所子表id查询子表记录
|
|
|
+ LawFirmPayment payment = lawFirmPaymentService.getById(id);
|
|
|
+ if (payment == null || payment.getDeleteFlag() == 1) {
|
|
|
+ return R.fail("收款账号记录不存在或已被删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer firmId = payment.getFirmId();
|
|
|
+ if (firmId == null) {
|
|
|
+ return R.fail("律所ID为空,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 删除子表记录(逻辑删除)
|
|
|
+ boolean deletePaymentResult = lawFirmPaymentService.removeById(id);
|
|
|
+ if (!deletePaymentResult) {
|
|
|
+ return R.fail("删除收款账号失败");
|
|
|
+ }
|
|
|
+ log.info("删除收款账号成功,paymentId={}, firmId={}", id, firmId);
|
|
|
+
|
|
|
+ // 3. 查询该律所是否还有关联的子表(未删除的)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> paymentWrapper = new LambdaQueryWrapper<>();
|
|
|
+ paymentWrapper.eq(LawFirmPayment::getFirmId, firmId);
|
|
|
+ paymentWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ long remainingPaymentCount = lawFirmPaymentService.count(paymentWrapper);
|
|
|
+
|
|
|
+ // 4. 如果没有子表了,继续删除主表(逻辑删除)
|
|
|
+ if (remainingPaymentCount == 0) {
|
|
|
+ log.info("律所[{}]没有关联的收款账号了,删除主表", firmId);
|
|
|
+ boolean deleteFirmResult = this.removeById(firmId);
|
|
|
+ if (!deleteFirmResult) {
|
|
|
+ log.warn("删除律所主表失败,firmId={}", firmId);
|
|
|
+ return R.success("收款账号删除成功,但删除律所主表失败");
|
|
|
+ }
|
|
|
+ log.info("删除律所主表成功,firmId={}", firmId);
|
|
|
+ return R.success("删除成功,已同时删除律所主表");
|
|
|
+ } else {
|
|
|
+ log.info("律所[{}]还有{}个收款账号,保留主表", firmId, remainingPaymentCount);
|
|
|
return R.success("删除成功");
|
|
|
}
|
|
|
- return R.fail("删除失败");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -290,76 +502,33 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<String> exportLawFirm(HttpServletResponse response) {
|
|
|
+ public void exportLawFirm(HttpServletResponse response) throws IOException {
|
|
|
log.info("LawFirmServiceImpl.exportLawFirm");
|
|
|
try {
|
|
|
- // 查询所有未删除的律所
|
|
|
- LambdaQueryWrapper<LawFirm> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LawFirm::getDeleteFlag, 0);
|
|
|
- queryWrapper.orderByDesc(LawFirm::getCreatedTime);
|
|
|
- List<LawFirm> lawFirmList = this.list(queryWrapper);
|
|
|
-
|
|
|
- if (lawFirmList.isEmpty()) {
|
|
|
- return R.fail("暂无数据可导出");
|
|
|
- }
|
|
|
-
|
|
|
- // 按律所名称分组
|
|
|
- Map<String, List<LawFirm>> firmNameMap = lawFirmList.stream()
|
|
|
- .collect(Collectors.groupingBy(LawFirm::getFirmName));
|
|
|
-
|
|
|
- // 转换为ExcelVo,相同律所名称的每个账号一行
|
|
|
- List<LawFirmExcelVo> excelVoList = new ArrayList<>();
|
|
|
- int serialNumber = 0;
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-
|
|
|
- for (Map.Entry<String, List<LawFirm>> entry : firmNameMap.entrySet()) {
|
|
|
- List<LawFirm> firms = entry.getValue();
|
|
|
- // 合并所有账号(从子表获取)
|
|
|
- Set<String> accountSet = new HashSet<>();
|
|
|
- for (LawFirm firm : firms) {
|
|
|
- LambdaQueryWrapper<LawFirmPayment> paymentWrapper = new LambdaQueryWrapper<>();
|
|
|
- paymentWrapper.eq(LawFirmPayment::getFirmId, firm.getId());
|
|
|
- paymentWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
- List<LawFirmPayment> payments = lawFirmPaymentService.list(paymentWrapper);
|
|
|
- for (LawFirmPayment payment : payments) {
|
|
|
- if (StringUtils.hasText(payment.getPaymentAccount())) {
|
|
|
- accountSet.add(payment.getPaymentAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- String allPaymentAccounts = String.join(",", accountSet);
|
|
|
-
|
|
|
- // 为每个账号创建一行(如果账号为空,至少创建一行)
|
|
|
- if (firms.isEmpty()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 如果账号为空或只有一个账号,创建一行
|
|
|
- if (allPaymentAccounts.isEmpty() || !allPaymentAccounts.contains(",")) {
|
|
|
- LawFirm firstFirm = firms.get(0);
|
|
|
- LawFirmExcelVo excelVo = convertToExcelVo(firstFirm, ++serialNumber, dateFormat, dateTimeFormat);
|
|
|
- excelVo.setPaymentAccount(allPaymentAccounts);
|
|
|
- excelVoList.add(excelVo);
|
|
|
- } else {
|
|
|
- // 多个账号,每个账号一行
|
|
|
- String[] accounts = allPaymentAccounts.split(",");
|
|
|
- for (int i = 0; i < accounts.length; i++) {
|
|
|
- LawFirm firstFirm = firms.get(0);
|
|
|
- LawFirmExcelVo excelVo = convertToExcelVo(firstFirm, ++serialNumber, dateFormat, dateTimeFormat);
|
|
|
- excelVo.setPaymentAccount(accounts[i].trim());
|
|
|
- excelVoList.add(excelVo);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 使用 getPaymentPageWithFirm 的方式查询所有数据(不分页)
|
|
|
+ // 设置一个很大的页面大小来获取所有数据
|
|
|
+ Page<LawFirmPaymentVO> page = new Page<>(1, Integer.MAX_VALUE);
|
|
|
+ IPage<LawFirmPaymentVO> pageResult = lawFirmPaymentMapper.selectPaymentPageWithFirm(
|
|
|
+ page, null, null, null, null, null, null, null, null, null
|
|
|
+ );
|
|
|
+
|
|
|
+ List<LawFirmPaymentVO> paymentList = pageResult.getRecords();
|
|
|
+
|
|
|
+ if (paymentList == null || paymentList.isEmpty()) {
|
|
|
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
|
|
+ response.getWriter().write("暂无数据可导出");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- // 生成Excel
|
|
|
- generateExcelWithMerge(response, excelVoList, firmNameMap);
|
|
|
-
|
|
|
- return R.success("导出成功");
|
|
|
+ // 使用 EasyExcelUtil 导出
|
|
|
+ EasyExcelUtil.exportExcel(response, paymentList, LawFirmPaymentVO.class, "律所列表", "律所列表");
|
|
|
} catch (Exception e) {
|
|
|
log.error("导出律所数据失败", e);
|
|
|
- return R.fail("导出失败:" + e.getMessage());
|
|
|
+ if (!response.isCommitted()) {
|
|
|
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
+ response.getWriter().write("导出失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ throw new IOException("导出失败:" + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -483,24 +652,20 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
Set<String> allImportAccounts = new HashSet<>();
|
|
|
Map<String, String> accountToFirmNameMap = new HashMap<>(); // 账号 -> 律所名称,用于错误提示
|
|
|
|
|
|
- // 先收集所有账号,检查导入数据中的重复
|
|
|
+ // 先收集所有账号,检查导入数据中的重复(不允许逗号分隔)
|
|
|
for (LawFirmExcelVo excelVo : excelVoList) {
|
|
|
String paymentAccount = excelVo.getPaymentAccount();
|
|
|
if (StringUtils.hasText(paymentAccount)) {
|
|
|
- // 账号可能包含多个,用逗号分隔
|
|
|
- String[] accounts = paymentAccount.split(",");
|
|
|
- for (String account : accounts) {
|
|
|
- String trimmedAccount = account.trim();
|
|
|
- if (!trimmedAccount.isEmpty()) {
|
|
|
- if (allImportAccounts.contains(trimmedAccount)) {
|
|
|
- // 发现重复账号
|
|
|
- String existingFirmName = accountToFirmNameMap.get(trimmedAccount);
|
|
|
- return R.fail(String.format("导入数据中存在重复的收款账号[%s],律所[%s]和律所[%s]使用了相同的账号,无法导入",
|
|
|
- trimmedAccount, existingFirmName, excelVo.getFirmName()));
|
|
|
- }
|
|
|
- allImportAccounts.add(trimmedAccount);
|
|
|
- accountToFirmNameMap.put(trimmedAccount, excelVo.getFirmName());
|
|
|
+ String trimmedAccount = paymentAccount.trim();
|
|
|
+ if (!trimmedAccount.isEmpty()) {
|
|
|
+ if (allImportAccounts.contains(trimmedAccount)) {
|
|
|
+ // 发现重复账号
|
|
|
+ String existingFirmName = accountToFirmNameMap.get(trimmedAccount);
|
|
|
+ return R.fail(String.format("导入数据中存在重复的收款账号[%s],律所[%s]和律所[%s]使用了相同的账号,无法导入",
|
|
|
+ trimmedAccount, existingFirmName, excelVo.getFirmName()));
|
|
|
}
|
|
|
+ allImportAccounts.add(trimmedAccount);
|
|
|
+ accountToFirmNameMap.put(trimmedAccount, excelVo.getFirmName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -537,77 +702,183 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 按律所名称分组,合并账号
|
|
|
- Map<String, List<LawFirmExcelVo>> firmNameMap = excelVoList.stream()
|
|
|
- .collect(Collectors.groupingBy(LawFirmExcelVo::getFirmName));
|
|
|
+ // 按统一社会信用代码分组,合并数据
|
|
|
+ // 先检查是否有空的信用代码
|
|
|
+ for (LawFirmExcelVo excelVo : excelVoList) {
|
|
|
+ if (!StringUtils.hasText(excelVo.getCreditCode())) {
|
|
|
+ return R.fail("导入数据中存在空的统一社会信用代码,请检查第" + (excelVoList.indexOf(excelVo) + 2) + "行数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按统一社会信用代码分组
|
|
|
+ Map<String, List<LawFirmExcelVo>> creditCodeMap = excelVoList.stream()
|
|
|
+ .filter(vo -> StringUtils.hasText(vo.getCreditCode()))
|
|
|
+ .collect(Collectors.groupingBy(LawFirmExcelVo::getCreditCode));
|
|
|
|
|
|
int successCount = 0;
|
|
|
int failCount = 0;
|
|
|
+ int updateCount = 0;
|
|
|
List<String> importErrors = new ArrayList<>();
|
|
|
|
|
|
- for (Map.Entry<String, List<LawFirmExcelVo>> entry : firmNameMap.entrySet()) {
|
|
|
- String firmName = entry.getKey();
|
|
|
+ for (Map.Entry<String, List<LawFirmExcelVo>> entry : creditCodeMap.entrySet()) {
|
|
|
+ String creditCode = entry.getKey();
|
|
|
List<LawFirmExcelVo> voList = entry.getValue();
|
|
|
|
|
|
- // 合并账号
|
|
|
- String paymentAccounts = voList.stream()
|
|
|
- .map(LawFirmExcelVo::getPaymentAccount)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .filter(acc -> !acc.trim().isEmpty())
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.joining(","));
|
|
|
+ // 合并收款账号,并维护账号和地址的对应关系(不允许逗号分隔)
|
|
|
+ // 使用LinkedHashMap保持顺序,后出现的账号地址会覆盖先出现的(如果地址不为空)
|
|
|
+ Map<String, String> accountAddressMap = new LinkedHashMap<>();
|
|
|
+ for (LawFirmExcelVo vo : voList) {
|
|
|
+ String paymentAccount = vo.getPaymentAccount();
|
|
|
+ String address = vo.getAddress();
|
|
|
+ if (StringUtils.hasText(paymentAccount)) {
|
|
|
+ String trimmedAccount = paymentAccount.trim();
|
|
|
+ if (!trimmedAccount.isEmpty()) {
|
|
|
+ // 如果账号已存在但地址为空,且当前地址不为空,则更新地址
|
|
|
+ // 如果账号不存在,直接添加
|
|
|
+ if (!accountAddressMap.containsKey(trimmedAccount) ||
|
|
|
+ (StringUtils.hasText(address) && !StringUtils.hasText(accountAddressMap.get(trimmedAccount)))) {
|
|
|
+ accountAddressMap.put(trimmedAccount, address != null ? address.trim() : "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 使用第一个数据作为主数据
|
|
|
+ // 使用第一个数据作为主数据,其他数据补充缺失字段
|
|
|
LawFirmExcelVo firstVo = voList.get(0);
|
|
|
LawFirm lawFirm = convertToLawFirm(firstVo);
|
|
|
-
|
|
|
- // 保存主表
|
|
|
- boolean saveResult = this.save(lawFirm);
|
|
|
- if (!saveResult) {
|
|
|
- importErrors.add("律所[" + firmName + "]保存失败");
|
|
|
- failCount++;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 保存子表收款账号
|
|
|
- if (StringUtils.hasText(paymentAccounts)) {
|
|
|
- String[] accounts = paymentAccounts.split(",");
|
|
|
- for (String account : accounts) {
|
|
|
- String trimmedAccount = account.trim();
|
|
|
- if (!trimmedAccount.isEmpty()) {
|
|
|
- LawFirmPayment payment = new LawFirmPayment();
|
|
|
- payment.setFirmId(lawFirm.getId());
|
|
|
- payment.setPaymentAccount(trimmedAccount);
|
|
|
- payment.setDeleteFlag(0);
|
|
|
- lawFirmPaymentService.save(payment);
|
|
|
+
|
|
|
+ // 如果第一个数据缺少某些字段,尝试从其他数据中获取
|
|
|
+ for (int i = 1; i < voList.size(); i++) {
|
|
|
+ LawFirmExcelVo otherVo = voList.get(i);
|
|
|
+ // 补充缺失的字段(这里可以根据需要补充其他字段)
|
|
|
+ if (!StringUtils.hasText(lawFirm.getFirmName()) && StringUtils.hasText(otherVo.getFirmName())) {
|
|
|
+ lawFirm.setFirmName(otherVo.getFirmName());
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(lawFirm.getPhone()) && StringUtils.hasText(otherVo.getPhone())) {
|
|
|
+ lawFirm.setPhone(otherVo.getPhone());
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(lawFirm.getDirectorName()) && StringUtils.hasText(otherVo.getDirectorName())) {
|
|
|
+ lawFirm.setDirectorName(otherVo.getDirectorName());
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(lawFirm.getDirectorPhone()) && StringUtils.hasText(otherVo.getDirectorPhone())) {
|
|
|
+ lawFirm.setDirectorPhone(otherVo.getDirectorPhone());
|
|
|
+ }
|
|
|
+ // 补充平台佣金比例(只支持纯数字格式,不支持百分号)
|
|
|
+ if (lawFirm.getPlatformCommissionRatio() == null && StringUtils.hasText(otherVo.getPlatformCommissionRatio())) {
|
|
|
+ try {
|
|
|
+ String ratioStr = otherVo.getPlatformCommissionRatio().trim();
|
|
|
+ // 解析为整数(必须是纯数字)
|
|
|
+ Integer ratio = Integer.parseInt(ratioStr);
|
|
|
+ lawFirm.setPlatformCommissionRatio(ratio);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析佣金比例失败:{},必须是纯数字格式", otherVo.getPlatformCommissionRatio(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 校验统一社会信用代码是否已存在
|
|
|
-// LambdaQueryWrapper<LawFirm> creditCodeWrapper = new LambdaQueryWrapper<>();
|
|
|
-// creditCodeWrapper.eq(LawFirm::getCreditCode, lawFirm.getCreditCode());
|
|
|
-// creditCodeWrapper.eq(LawFirm::getDeleteFlag, 0);
|
|
|
-// long creditCodeCount = this.count(creditCodeWrapper);
|
|
|
-// if (creditCodeCount > 0) {
|
|
|
-// importErrors.add("律所[" + firmName + "]的统一社会信用代码[" + lawFirm.getCreditCode() + "]已存在");
|
|
|
-// failCount++;
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-
|
|
|
- // 设置默认值
|
|
|
+ // 检查统一社会信用代码是否已存在
|
|
|
+ LambdaQueryWrapper<LawFirm> creditCodeWrapper = new LambdaQueryWrapper<>();
|
|
|
+ creditCodeWrapper.eq(LawFirm::getCreditCode, creditCode);
|
|
|
+ creditCodeWrapper.eq(LawFirm::getDeleteFlag, 0);
|
|
|
+ LawFirm existingLawFirm = this.getOne(creditCodeWrapper);
|
|
|
+
|
|
|
+ boolean isUpdate = false;
|
|
|
+ if (existingLawFirm != null) {
|
|
|
+ // 如果已存在,更新现有记录
|
|
|
+ isUpdate = true;
|
|
|
+ lawFirm.setId(existingLawFirm.getId());
|
|
|
+ // 保留原有的一些字段(如果新数据没有提供)
|
|
|
+ if (!StringUtils.hasText(lawFirm.getFirmName())) {
|
|
|
+ lawFirm.setFirmName(existingLawFirm.getFirmName());
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(lawFirm.getPhone())) {
|
|
|
+ lawFirm.setPhone(existingLawFirm.getPhone());
|
|
|
+ }
|
|
|
+ if (lawFirm.getStatus() == null) {
|
|
|
+ lawFirm.setStatus(existingLawFirm.getStatus());
|
|
|
+ }
|
|
|
+ // 如果新数据没有提供平台佣金比例,保留原有值
|
|
|
+ if (lawFirm.getPlatformCommissionRatio() == null) {
|
|
|
+ lawFirm.setPlatformCommissionRatio(existingLawFirm.getPlatformCommissionRatio());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 设置默认值(新增时)
|
|
|
if (lawFirm.getStatus() == null) {
|
|
|
lawFirm.setStatus(1);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
if (lawFirm.getDeleteFlag() == null) {
|
|
|
lawFirm.setDeleteFlag(0);
|
|
|
}
|
|
|
+
|
|
|
+ // 保存或更新主表
|
|
|
+ boolean saveResult;
|
|
|
+ if (isUpdate) {
|
|
|
+ saveResult = this.updateById(lawFirm);
|
|
|
+ } else {
|
|
|
+ saveResult = this.save(lawFirm);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!saveResult) {
|
|
|
+ importErrors.add("统一社会信用代码[" + creditCode + "]" + (isUpdate ? "更新" : "保存") + "失败");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理子表收款账号
|
|
|
+ if (!accountAddressMap.isEmpty()) {
|
|
|
+ // 查询现有的收款账号
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> existingPaymentWrapper = new LambdaQueryWrapper<>();
|
|
|
+ existingPaymentWrapper.eq(LawFirmPayment::getFirmId, lawFirm.getId());
|
|
|
+ existingPaymentWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ List<LawFirmPayment> existingPayments = lawFirmPaymentService.list(existingPaymentWrapper);
|
|
|
+
|
|
|
+ // 收集现有的收款账号
|
|
|
+ Set<String> existingAccountSet = existingPayments.stream()
|
|
|
+ .map(LawFirmPayment::getPaymentAccount)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(acc -> !acc.trim().isEmpty())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 添加新的收款账号(排除已存在的),每个账号使用其对应的地址
|
|
|
+ for (Map.Entry<String, String> accountEntry : accountAddressMap.entrySet()) {
|
|
|
+ String trimmedAccount = accountEntry.getKey();
|
|
|
+ String address = accountEntry.getValue();
|
|
|
+
|
|
|
+ if (!trimmedAccount.isEmpty() && !existingAccountSet.contains(trimmedAccount)) {
|
|
|
+ // 检查账号是否已存在(全局唯一性校验)
|
|
|
+ LambdaQueryWrapper<LawFirmPayment> accountWrapper = new LambdaQueryWrapper<>();
|
|
|
+ accountWrapper.eq(LawFirmPayment::getPaymentAccount, trimmedAccount);
|
|
|
+ accountWrapper.eq(LawFirmPayment::getDeleteFlag, 0);
|
|
|
+ long accountCount = lawFirmPaymentService.count(accountWrapper);
|
|
|
+ if (accountCount == 0) {
|
|
|
+ // 账号不存在,可以添加
|
|
|
+ LawFirmPayment payment = new LawFirmPayment();
|
|
|
+ payment.setFirmId(lawFirm.getId());
|
|
|
+ payment.setPaymentAccount(trimmedAccount);
|
|
|
+ // 设置详细地址(使用该账号对应的地址)
|
|
|
+ if (StringUtils.hasText(address)) {
|
|
|
+ payment.setAddress(address.trim());
|
|
|
+ }
|
|
|
+ payment.setDeleteFlag(0);
|
|
|
+ lawFirmPaymentService.save(payment);
|
|
|
+ } else {
|
|
|
+ // 账号已存在,记录警告但不阻止导入
|
|
|
+ log.warn("收款账号[{}]已存在,跳过添加", trimmedAccount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 保存主表(已在上面保存)
|
|
|
- successCount++;
|
|
|
+ if (isUpdate) {
|
|
|
+ updateCount++;
|
|
|
+ } else {
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- String resultMsg = String.format("导入完成:成功%d条,失败%d条", successCount, failCount);
|
|
|
+ String resultMsg = String.format("导入完成:新增%d条,更新%d条,失败%d条", successCount, updateCount, failCount);
|
|
|
if (!importErrors.isEmpty()) {
|
|
|
resultMsg += "\n失败详情:\n" + String.join("\n", importErrors);
|
|
|
}
|
|
|
@@ -742,11 +1013,11 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
String fileName = URLEncoder.encode("律所列表", "UTF-8").replaceAll("\\+", "%20");
|
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
|
|
|
- // 输出
|
|
|
+ // 输出(不要关闭 response 的输出流,由容器管理)
|
|
|
OutputStream outputStream = response.getOutputStream();
|
|
|
workbook.write(outputStream);
|
|
|
+ outputStream.flush();
|
|
|
workbook.close();
|
|
|
- outputStream.close();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -834,9 +1105,9 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
if (!StringUtils.hasText(excelVo.getFirmName())) {
|
|
|
return "第" + rowIndex + "行:律所名称不能为空";
|
|
|
}
|
|
|
-// if (!StringUtils.hasText(excelVo.getCreditCode())) {
|
|
|
-// return "第" + rowIndex + "行:统一社会信用代码不能为空";
|
|
|
-// }
|
|
|
+ if (!StringUtils.hasText(excelVo.getCreditCode())) {
|
|
|
+ return "第" + rowIndex + "行:统一社会信用代码不能为空";
|
|
|
+ }
|
|
|
// if (!StringUtils.hasText(excelVo.getPhone())) {
|
|
|
// return "第" + rowIndex + "行:联系电话不能为空";
|
|
|
// }
|
|
|
@@ -847,6 +1118,20 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
// return "第" + rowIndex + "行:负责人电话不能为空";
|
|
|
// }
|
|
|
|
|
|
+ // 校验收款账号(不允许逗号分隔,必须是单个16位或19位账号)
|
|
|
+ if (StringUtils.hasText(excelVo.getPaymentAccount())) {
|
|
|
+ String paymentAccount = excelVo.getPaymentAccount().trim();
|
|
|
+ // 不允许包含逗号
|
|
|
+ if (paymentAccount.contains(",")) {
|
|
|
+ return "第" + rowIndex + "行:收款账号不允许包含逗号,每行只能填写一个账号";
|
|
|
+ }
|
|
|
+ // 校验长度(必须是16位或19位)
|
|
|
+ int length = paymentAccount.length();
|
|
|
+ if (length != 16 && length != 19) {
|
|
|
+ return "第" + rowIndex + "行:收款账号[" + paymentAccount + "]长度不正确,必须是16位或19位,当前为" + length + "位";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 校验邮箱格式
|
|
|
// if (StringUtils.hasText(excelVo.getEmail())) {
|
|
|
// if (!excelVo.getEmail().matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) {
|
|
|
@@ -930,13 +1215,15 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 解析佣金比例
|
|
|
+ // 解析佣金比例(只支持纯数字格式,不支持百分号)
|
|
|
if (StringUtils.hasText(excelVo.getPlatformCommissionRatio())) {
|
|
|
try {
|
|
|
- String ratio = excelVo.getPlatformCommissionRatio().replace("%", "").trim();
|
|
|
- lawFirm.setPlatformCommissionRatio(new BigDecimal(ratio));
|
|
|
+ String ratioStr = excelVo.getPlatformCommissionRatio().trim();
|
|
|
+ // 解析为整数(必须是纯数字)
|
|
|
+ Integer ratio = Integer.parseInt(ratioStr);
|
|
|
+ lawFirm.setPlatformCommissionRatio(ratio);
|
|
|
} catch (Exception e) {
|
|
|
- log.warn("解析佣金比例失败:{}", excelVo.getPlatformCommissionRatio());
|
|
|
+ log.warn("解析佣金比例失败:{},必须是纯数字格式", excelVo.getPlatformCommissionRatio(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1097,6 +1384,22 @@ public class LawFirmServiceImpl extends ServiceImpl<LawFirmMapper, LawFirm> impl
|
|
|
lawFirm.setPaymentList(paymentList);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<IPage<LawFirmPaymentVO>> getPaymentPageWithFirm(
|
|
|
+ int pageNum, int pageSize,
|
|
|
+ Integer firmId, String paymentAccount, String firmName, String creditCode,
|
|
|
+ Integer status, Integer certificationStatus, String directorName,
|
|
|
+ String createdTimeStart, String createdTimeEnd) {
|
|
|
+ log.info("LawFirmServiceImpl.getPaymentPageWithFirm?pageNum={},pageSize={},firmId={},paymentAccount={},firmName={},creditCode={},status={},certificationStatus={},directorName={},createdTimeStart={},createdTimeEnd={}",
|
|
|
+ pageNum, pageSize, firmId, paymentAccount, firmName, creditCode, status, certificationStatus, directorName, createdTimeStart, createdTimeEnd);
|
|
|
+
|
|
|
+ Page<LawFirmPaymentVO> page = new Page<>(pageNum, pageSize);
|
|
|
+ IPage<LawFirmPaymentVO> pageResult = lawFirmPaymentMapper.selectPaymentPageWithFirm(
|
|
|
+ page, firmId, paymentAccount, firmName, creditCode, status, certificationStatus, directorName, createdTimeStart, createdTimeEnd
|
|
|
+ );
|
|
|
+ return R.data(pageResult);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|