parent
1f646a6b18
commit
498335a9b8
@ -0,0 +1,28 @@ |
|||||||
|
package digital.laboratory.platform.entrustment.entity; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import digital.laboratory.platform.common.mybatis.base.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
@Data |
||||||
|
@TableName(value = "b_suspect", autoResultMap = true) |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value = "委托嫌疑人") |
||||||
|
public class Suspect extends BaseEntity { |
||||||
|
private String id; |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String idNumber; |
||||||
|
|
||||||
|
private String phoneNumber; |
||||||
|
|
||||||
|
private String sex; |
||||||
|
|
||||||
|
private int age; |
||||||
|
|
||||||
|
private String entrustId; |
||||||
|
|
||||||
|
private int orderNo; |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
package digital.laboratory.platform.entrustment.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import digital.laboratory.platform.entrustment.entity.Suspect; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 委托嫌疑人数据访问接口 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface SuspectMapper extends BaseMapper<Suspect> { |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
package digital.laboratory.platform.entrustment.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import digital.laboratory.platform.entrustment.entity.Suspect; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 委托嫌疑人业务逻辑接口 |
||||||
|
*/ |
||||||
|
public interface SuspectService extends IService<Suspect> { |
||||||
|
List<Suspect> addSuspectList(List<Suspect> suspectList, String entrustId); |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
package digital.laboratory.platform.entrustment.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.esotericsoftware.minlog.Log; |
||||||
|
import digital.laboratory.platform.entrustment.entity.Suspect; |
||||||
|
import digital.laboratory.platform.entrustment.mapper.SuspectMapper; |
||||||
|
import digital.laboratory.platform.entrustment.service.SuspectService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.time.format.DateTimeFormatter; |
||||||
|
import java.time.temporal.ChronoUnit; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 委托嫌疑人业务逻辑实现类 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class SuspectServiceImpl extends ServiceImpl<SuspectMapper, Suspect> implements SuspectService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 批量添加嫌疑人信息并关联到指定委托 |
||||||
|
* |
||||||
|
* @param suspectList 嫌疑人信息列表 |
||||||
|
* @param entrustId 委托ID,用于关联嫌疑人与委托关系 |
||||||
|
* @return 添加成功返回原嫌疑人列表,失败返回null |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public List<Suspect> addSuspectList(List<Suspect> suspectList, String entrustId) { |
||||||
|
// 遍历嫌疑人列表进行预处理
|
||||||
|
int orderNo = 1; |
||||||
|
for (Suspect suspect : suspectList) { |
||||||
|
// 生成全局唯一ID并设置(转为大写保证一致性)
|
||||||
|
suspect.setId(IdWorker.get32UUID().toUpperCase()); |
||||||
|
|
||||||
|
// 从身份证号码中提取并填充性别和年龄信息
|
||||||
|
String idNumber = suspect.getIdNumber(); |
||||||
|
if (!StringUtils.isNotBlank(idNumber) || idNumber.length() != 18){ |
||||||
|
throw new RuntimeException("身份证号码格式错误"); |
||||||
|
} |
||||||
|
this.fillIdentityInfo(suspect); |
||||||
|
|
||||||
|
// 关联委托ID,建立嫌疑人与委托的关系
|
||||||
|
suspect.setEntrustId(entrustId); |
||||||
|
suspect.setOrderNo(orderNo); |
||||||
|
orderNo++; |
||||||
|
} |
||||||
|
|
||||||
|
// 批量保存嫌疑人信息到数据库
|
||||||
|
boolean ret = this.saveBatch(suspectList); |
||||||
|
|
||||||
|
// 根据保存结果返回处理后的列表或null
|
||||||
|
return ret ? suspectList : null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 从身份证号码中提取并填充性别和年龄信息 |
||||||
|
*/ |
||||||
|
private void fillIdentityInfo(Suspect suspect) { |
||||||
|
String idNumber = suspect.getIdNumber(); |
||||||
|
|
||||||
|
// 去除空格并转换为大写
|
||||||
|
idNumber = idNumber.trim().toUpperCase(); |
||||||
|
|
||||||
|
// 校验身份证长度
|
||||||
|
if (idNumber.length() == 18) { |
||||||
|
try { |
||||||
|
// 提取性别
|
||||||
|
int genderCode = Integer.parseInt(idNumber.substring(16, 17)); |
||||||
|
suspect.setSex(genderCode % 2 == 0 ? "女" : "男"); |
||||||
|
|
||||||
|
// 提取出生日期并计算年龄
|
||||||
|
String birthDateStr = idNumber.substring(6, 14); |
||||||
|
LocalDate birthDate = LocalDate.parse(birthDateStr, DateTimeFormatter.BASIC_ISO_DATE); |
||||||
|
LocalDate currentDate = LocalDate.now(); |
||||||
|
long age = ChronoUnit.YEARS.between(birthDate, currentDate); |
||||||
|
suspect.setAge((int)age); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
// 身份证格式异常,记录日志但不中断业务
|
||||||
|
Log.info("身份证号码格式异常: {}", idNumber, e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue