|
|
@ -7,6 +7,7 @@ import com.chenhai.common.core.page.TableDataInfo; |
|
|
import com.chenhai.common.enums.BusinessType; |
|
|
import com.chenhai.common.enums.BusinessType; |
|
|
import com.chenhai.common.exception.ServiceException; |
|
|
import com.chenhai.common.exception.ServiceException; |
|
|
import com.chenhai.common.utils.SecurityUtils; |
|
|
import com.chenhai.common.utils.SecurityUtils; |
|
|
|
|
|
import com.chenhai.common.utils.StringUtils; |
|
|
import com.chenhai.vet.domain.VetQualification; |
|
|
import com.chenhai.vet.domain.VetQualification; |
|
|
import com.chenhai.vet.service.IVetQualificationService; |
|
|
import com.chenhai.vet.service.IVetQualificationService; |
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
@ -176,6 +177,11 @@ public class VetQualificationController extends BaseController |
|
|
VetQualification query = new VetQualification(); |
|
|
VetQualification query = new VetQualification(); |
|
|
query.setQualificationId(qualificationId); |
|
|
query.setQualificationId(qualificationId); |
|
|
|
|
|
|
|
|
|
|
|
// 非管理员只能查询自己的资质 |
|
|
|
|
|
if (!SecurityUtils.isAdmin(userId)) { |
|
|
|
|
|
query.setUserId(userId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 查询指定资质 |
|
|
// 查询指定资质 |
|
|
List<VetQualification> qualifications = vetQualificationService.selectVetQualificationList(query); |
|
|
List<VetQualification> qualifications = vetQualificationService.selectVetQualificationList(query); |
|
|
if (qualifications == null || qualifications.isEmpty()) { |
|
|
if (qualifications == null || qualifications.isEmpty()) { |
|
|
@ -184,11 +190,6 @@ public class VetQualificationController extends BaseController |
|
|
|
|
|
|
|
|
VetQualification qualification = qualifications.get(0); |
|
|
VetQualification qualification = qualifications.get(0); |
|
|
|
|
|
|
|
|
// 权限验证:非管理员只能查看自己的资质 |
|
|
|
|
|
if (!SecurityUtils.isAdmin(userId) && !qualification.getUserId().equals(userId)) { |
|
|
|
|
|
throw new ServiceException("无权查看此资质的证书"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理分页 |
|
|
// 处理分页 |
|
|
startPage(); |
|
|
startPage(); |
|
|
|
|
|
|
|
|
@ -235,15 +236,21 @@ public class VetQualificationController extends BaseController |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
Long currentUserId = SecurityUtils.getUserId(); |
|
|
Long currentUserId = SecurityUtils.getUserId(); |
|
|
boolean isAdmin = SecurityUtils.isAdmin(currentUserId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 权限检查:只有管理员和证书所有者可以查看 |
|
|
Map<String, Object> certificateInfo = vetQualificationService |
|
|
Map<String, Object> certificateInfo = vetQualificationService |
|
|
.selectCertificateWithQualificationByCertId(certId, isAdmin ? null : currentUserId); |
|
|
|
|
|
|
|
|
.selectCertificateWithQualificationByCertId(certId, currentUserId); |
|
|
|
|
|
|
|
|
if (certificateInfo == null || certificateInfo.isEmpty()) { |
|
|
if (certificateInfo == null || certificateInfo.isEmpty()) { |
|
|
return AjaxResult.error("证书不存在或没有权限查看"); |
|
|
return AjaxResult.error("证书不存在或没有权限查看"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 再次权限验证(双重保险) |
|
|
|
|
|
Long certOwnerId = (Long) certificateInfo.get("userId"); |
|
|
|
|
|
if (!SecurityUtils.isAdmin(currentUserId) && !currentUserId.equals(certOwnerId)) { |
|
|
|
|
|
return AjaxResult.error("无权查看此证书"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Object expireDateObj = certificateInfo.get("expireDate"); |
|
|
Object expireDateObj = certificateInfo.get("expireDate"); |
|
|
if (expireDateObj instanceof Date) { |
|
|
if (expireDateObj instanceof Date) { |
|
|
Date expireDate = (Date) expireDateObj; |
|
|
Date expireDate = (Date) expireDateObj; |
|
|
@ -257,6 +264,7 @@ public class VetQualificationController extends BaseController |
|
|
return AjaxResult.success(certificateInfo); |
|
|
return AjaxResult.success(certificateInfo); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("查询证书失败,certId: {}", certId, e); |
|
|
return AjaxResult.error("查询证书失败:" + e.getMessage()); |
|
|
return AjaxResult.error("查询证书失败:" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -439,29 +447,536 @@ public class VetQualificationController extends BaseController |
|
|
/** |
|
|
/** |
|
|
* 提交审核 |
|
|
* 提交审核 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
/** |
|
|
|
|
|
* 提交审核(带完整校验,不改变原有逻辑) |
|
|
|
|
|
*/ |
|
|
@Log(title = "兽医资质", businessType = BusinessType.UPDATE) |
|
|
@Log(title = "兽医资质", businessType = BusinessType.UPDATE) |
|
|
@PostMapping("/submit") |
|
|
@PostMapping("/submit") |
|
|
public AjaxResult submitQualification(@RequestBody Object requestBody) { |
|
|
public AjaxResult submitQualification(@RequestBody Object requestBody) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
Long sysUserId = SecurityUtils.getUserId(); |
|
|
|
|
|
String username = SecurityUtils.getUsername(); |
|
|
|
|
|
|
|
|
|
|
|
if (sysUserId == null) { |
|
|
|
|
|
return error("用户未登录"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 1. 提取数据并进行校验(不改变原有数据结构) |
|
|
if (requestBody instanceof Map) { |
|
|
if (requestBody instanceof Map) { |
|
|
@SuppressWarnings("unchecked") |
|
|
@SuppressWarnings("unchecked") |
|
|
Map<String, Object> requestData = (Map<String, Object>) requestBody; |
|
|
Map<String, Object> requestData = (Map<String, Object>) requestBody; |
|
|
return processNewFormat(requestData); |
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 姓名校验 |
|
|
|
|
|
String realName = (String) requestData.get("realName"); |
|
|
|
|
|
if (realName == null || realName.trim().isEmpty()) { |
|
|
|
|
|
return error("真实姓名不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
realName = realName.trim(); |
|
|
|
|
|
if (!realName.matches("^[\\u4e00-\\u9fa5]{2,20}$")) { |
|
|
|
|
|
return error("姓名必须是2-20个汉字"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 身份证校验 |
|
|
|
|
|
String idCard = (String) requestData.get("idCard"); |
|
|
|
|
|
if (idCard == null || idCard.trim().isEmpty()) { |
|
|
|
|
|
return error("身份证号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
idCard = idCard.trim().toUpperCase(); |
|
|
|
|
|
if (!isValidIdCard(idCard)) { |
|
|
|
|
|
return error("身份证号格式不正确"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查身份证是否已被使用 |
|
|
|
|
|
VetQualification query = new VetQualification(); |
|
|
|
|
|
query.setIdCard(idCard); |
|
|
|
|
|
List<VetQualification> idCardUsers = vetQualificationService.selectVetQualificationList(query); |
|
|
|
|
|
if (!idCardUsers.isEmpty()) { |
|
|
|
|
|
for (VetQualification user : idCardUsers) { |
|
|
|
|
|
if (!user.getUserId().equals(sysUserId)) { |
|
|
|
|
|
return error("该身份证号已被其他用户使用"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 证书列表校验 |
|
|
|
|
|
Object certificatesObj = requestData.get("certificates"); |
|
|
|
|
|
if (certificatesObj == null) { |
|
|
|
|
|
return error("证书列表不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<?> certificatesList; |
|
|
|
|
|
if (certificatesObj instanceof List) { |
|
|
|
|
|
certificatesList = (List<?>) certificatesObj; |
|
|
|
|
|
} else { |
|
|
|
|
|
return error("证书列表格式不正确"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (certificatesList.isEmpty()) { |
|
|
|
|
|
return error("请至少添加一个证书"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
Map<String, Object> requestData = mapper.convertValue(requestBody, Map.class); |
|
|
|
|
|
|
|
|
for (int i = 0; i < certificatesList.size(); i++) { |
|
|
|
|
|
Object certObj = certificatesList.get(i); |
|
|
|
|
|
Map<String, Object> certMap; |
|
|
|
|
|
|
|
|
|
|
|
if (certObj instanceof Map) { |
|
|
|
|
|
certMap = (Map<String, Object>) certObj; |
|
|
|
|
|
} else { |
|
|
|
|
|
certMap = mapper.convertValue(certObj, Map.class); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String certName = (String) certMap.get("certName"); |
|
|
|
|
|
if (certName == null || certName.trim().isEmpty()) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的名称不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String certificateNo = (String) certMap.get("certificateNo"); |
|
|
|
|
|
if (certificateNo == null || certificateNo.trim().isEmpty()) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的编号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (requestData.containsKey("realName") && requestData.containsKey("certificates")) { |
|
|
|
|
|
return processNewFormat(requestData); |
|
|
|
|
|
|
|
|
String issueOrg = (String) certMap.get("issueOrg"); |
|
|
|
|
|
if (issueOrg == null || issueOrg.trim().isEmpty()) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的发证机关不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Object issueDateObj = certMap.get("issueDate"); |
|
|
|
|
|
if (issueDateObj == null) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的发证日期不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Object expireDateObj = certMap.get("expireDate"); |
|
|
|
|
|
if (expireDateObj == null) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的有效期不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 日期逻辑校验 |
|
|
|
|
|
try { |
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
|
Date issueDate; |
|
|
|
|
|
Date expireDate; |
|
|
|
|
|
|
|
|
|
|
|
if (issueDateObj instanceof Date) { |
|
|
|
|
|
issueDate = (Date) issueDateObj; |
|
|
|
|
|
} else { |
|
|
|
|
|
issueDate = sdf.parse(issueDateObj.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (expireDateObj instanceof Date) { |
|
|
|
|
|
expireDate = (Date) expireDateObj; |
|
|
|
|
|
} else { |
|
|
|
|
|
expireDate = sdf.parse(expireDateObj.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (expireDate.before(issueDate)) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的有效期不能早于发证日期"); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的日期格式不正确,请使用yyyy-MM-dd格式"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 证书编号唯一性检查 |
|
|
|
|
|
if (StringUtils.isNotEmpty(certificateNo)) { |
|
|
|
|
|
VetQualification certQuery = new VetQualification(); |
|
|
|
|
|
certQuery.setCertificateNo(certificateNo); |
|
|
|
|
|
List<VetQualification> existingCerts = vetQualificationService.selectVetQualificationList(certQuery); |
|
|
|
|
|
if (!existingCerts.isEmpty()) { |
|
|
|
|
|
for (VetQualification existing : existingCerts) { |
|
|
|
|
|
if (!existing.getUserId().equals(sysUserId)) { |
|
|
|
|
|
return error("证书编号 '" + certificateNo + "' 已被其他用户使用"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 经营范围校验 |
|
|
|
|
|
Object scopeIdsObj = requestData.get("scopeIds"); |
|
|
|
|
|
if (scopeIdsObj == null) { |
|
|
|
|
|
return error("请选择经营范围"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (scopeIdsObj instanceof List) { |
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
List<String> scopeIdsList = (List<String>) scopeIdsObj; |
|
|
|
|
|
if (scopeIdsList.isEmpty()) { |
|
|
|
|
|
return error("请选择经营范围"); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (scopeIdsObj instanceof String) { |
|
|
|
|
|
String scopeIds = (String) scopeIdsObj; |
|
|
|
|
|
if (StringUtils.isEmpty(scopeIds)) { |
|
|
|
|
|
return error("请选择经营范围"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 资质类型校验 |
|
|
|
|
|
String qualificationType = (String) requestData.get("qualificationType"); |
|
|
|
|
|
if (StringUtils.isEmpty(qualificationType)) { |
|
|
|
|
|
return error("请选择资质类型"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 校验通过,调用原有逻辑 |
|
|
|
|
|
return processNewFormat(requestData); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
// 旧格式处理 |
|
|
|
|
|
VetQualification vetQualification; |
|
|
|
|
|
if (requestBody instanceof VetQualification) { |
|
|
|
|
|
vetQualification = (VetQualification) requestBody; |
|
|
} else { |
|
|
} else { |
|
|
return processOldFormat(requestBody); |
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
|
vetQualification = mapper.convertValue(requestBody, VetQualification.class); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 姓名校验 |
|
|
|
|
|
String realName = vetQualification.getRealName(); |
|
|
|
|
|
if (realName == null || realName.trim().isEmpty()) { |
|
|
|
|
|
return error("真实姓名不能为空"); |
|
|
} |
|
|
} |
|
|
|
|
|
realName = realName.trim(); |
|
|
|
|
|
if (!realName.matches("^[\\u4e00-\\u9fa5]{2,20}$")) { |
|
|
|
|
|
return error("姓名必须是2-20个汉字"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 身份证校验 |
|
|
|
|
|
String idCard = vetQualification.getIdCard(); |
|
|
|
|
|
if (idCard == null || idCard.trim().isEmpty()) { |
|
|
|
|
|
return error("身份证号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
idCard = idCard.trim().toUpperCase(); |
|
|
|
|
|
if (!isValidIdCard(idCard)) { |
|
|
|
|
|
return error("身份证号格式不正确"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查身份证是否已被使用 |
|
|
|
|
|
VetQualification query = new VetQualification(); |
|
|
|
|
|
query.setIdCard(idCard); |
|
|
|
|
|
List<VetQualification> idCardUsers = vetQualificationService.selectVetQualificationList(query); |
|
|
|
|
|
if (!idCardUsers.isEmpty()) { |
|
|
|
|
|
for (VetQualification user : idCardUsers) { |
|
|
|
|
|
if (!user.getUserId().equals(sysUserId)) { |
|
|
|
|
|
return error("该身份证号已被其他用户使用"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 证书列表校验 |
|
|
|
|
|
List<VetQualification.CertificateInfo> certificateList = vetQualification.getCertificateList(); |
|
|
|
|
|
if (certificateList == null || certificateList.isEmpty()) { |
|
|
|
|
|
return error("请至少添加一个证书"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < certificateList.size(); i++) { |
|
|
|
|
|
VetQualification.CertificateInfo cert = certificateList.get(i); |
|
|
|
|
|
|
|
|
|
|
|
String certName = cert.getCertName(); |
|
|
|
|
|
if (certName == null || certName.trim().isEmpty()) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的名称不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String certificateNo = cert.getCertificateNo(); |
|
|
|
|
|
if (certificateNo == null || certificateNo.trim().isEmpty()) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的编号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String issueOrg = cert.getIssueOrg(); |
|
|
|
|
|
if (issueOrg == null || issueOrg.trim().isEmpty()) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的发证机关不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cert.getIssueDate() == null) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的发证日期不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cert.getExpireDate() == null) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的有效期不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cert.getExpireDate().before(cert.getIssueDate())) { |
|
|
|
|
|
return error("第" + (i + 1) + "个证书的有效期不能早于发证日期"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 证书编号唯一性检查 |
|
|
|
|
|
if (StringUtils.isNotEmpty(certificateNo)) { |
|
|
|
|
|
VetQualification certQuery = new VetQualification(); |
|
|
|
|
|
certQuery.setCertificateNo(certificateNo); |
|
|
|
|
|
List<VetQualification> existingCerts = vetQualificationService.selectVetQualificationList(certQuery); |
|
|
|
|
|
if (!existingCerts.isEmpty()) { |
|
|
|
|
|
for (VetQualification existing : existingCerts) { |
|
|
|
|
|
if (!existing.getUserId().equals(sysUserId)) { |
|
|
|
|
|
return error("证书编号 '" + certificateNo + "' 已被其他用户使用"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 经营范围校验 |
|
|
|
|
|
String scopeIds = vetQualification.getScopeIds(); |
|
|
|
|
|
if (StringUtils.isEmpty(scopeIds)) { |
|
|
|
|
|
return error("请选择经营范围"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 资质类型校验 |
|
|
|
|
|
String qualificationType = vetQualification.getQualificationType(); |
|
|
|
|
|
if (StringUtils.isEmpty(qualificationType)) { |
|
|
|
|
|
return error("请选择资质类型"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 校验通过,调用原有逻辑 |
|
|
|
|
|
return processOldFormat(requestBody); |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
return error(e.getMessage()); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("提交审核失败", e); |
|
|
return AjaxResult.error("提交失败:" + e.getMessage()); |
|
|
return AjaxResult.error("提交失败:" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 验证身份证号格式和合法性(18位) |
|
|
|
|
|
* 符合国家标准GB 11643-1999 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean isValidIdCard(String idCard) { |
|
|
|
|
|
if (StringUtils.isEmpty(idCard)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 清理输入 |
|
|
|
|
|
idCard = idCard.trim().toUpperCase(); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 基本格式校验(18位,最后一位可能是数字或X) |
|
|
|
|
|
String regex = "^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9X]$"; |
|
|
|
|
|
if (!idCard.matches(regex)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 校验码验证(必须) |
|
|
|
|
|
return validateIdCardCheckCode(idCard); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 验证身份证校验码 |
|
|
|
|
|
* 根据ISO 7064:1983.MOD 11-2算法 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean validateIdCardCheckCode(String idCard) { |
|
|
|
|
|
if (idCard == null || idCard.length() != 18) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 校验因子(加权因子) |
|
|
|
|
|
int[] factor = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; |
|
|
|
|
|
|
|
|
|
|
|
// 校验码对应值 |
|
|
|
|
|
char[] parityBit = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}; |
|
|
|
|
|
|
|
|
|
|
|
int sum = 0; |
|
|
|
|
|
try { |
|
|
|
|
|
for (int i = 0; i < 17; i++) { |
|
|
|
|
|
sum += Character.getNumericValue(idCard.charAt(i)) * factor[i]; |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int mod = sum % 11; |
|
|
|
|
|
char checkCode = parityBit[mod]; |
|
|
|
|
|
|
|
|
|
|
|
return checkCode == idCard.charAt(17); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 验证出生日期合法性 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean validateBirthDate(String idCard) { |
|
|
|
|
|
if (idCard == null || idCard.length() < 14) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 提取出生日期(第7-14位) |
|
|
|
|
|
String birthDateStr = idCard.substring(6, 14); |
|
|
|
|
|
int year = Integer.parseInt(birthDateStr.substring(0, 4)); |
|
|
|
|
|
int month = Integer.parseInt(birthDateStr.substring(4, 6)); |
|
|
|
|
|
int day = Integer.parseInt(birthDateStr.substring(6, 8)); |
|
|
|
|
|
|
|
|
|
|
|
// 年份范围校验(1900-当前年份) |
|
|
|
|
|
int currentYear = Calendar.getInstance().get(Calendar.YEAR); |
|
|
|
|
|
if (year < 1900 || year > currentYear) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 月份范围校验 |
|
|
|
|
|
if (month < 1 || month > 12) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 日期范围校验 |
|
|
|
|
|
if (day < 1 || day > 31) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 月份天数校验 |
|
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
|
|
cal.setLenient(false); |
|
|
|
|
|
cal.set(year, month - 1, day); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
cal.getTime(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 完整的身份证校验(包含所有验证) |
|
|
|
|
|
*/ |
|
|
|
|
|
private String validateIdCardFull(String idCard, Long currentUserId) { |
|
|
|
|
|
if (StringUtils.isEmpty(idCard)) { |
|
|
|
|
|
return "身份证号不能为空"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
idCard = idCard.trim().toUpperCase(); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 长度校验 |
|
|
|
|
|
if (idCard.length() != 18) { |
|
|
|
|
|
return "身份证号必须为18位"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 格式校验 |
|
|
|
|
|
if (!isValidIdCard(idCard)) { |
|
|
|
|
|
return "身份证号格式不正确"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 出生日期校验 |
|
|
|
|
|
if (!validateBirthDate(idCard)) { |
|
|
|
|
|
return "身份证号中的出生日期不合法"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 年龄校验(必须年满18岁) |
|
|
|
|
|
try { |
|
|
|
|
|
String birthDateStr = idCard.substring(6, 14); |
|
|
|
|
|
int year = Integer.parseInt(birthDateStr.substring(0, 4)); |
|
|
|
|
|
int month = Integer.parseInt(birthDateStr.substring(4, 6)); |
|
|
|
|
|
int day = Integer.parseInt(birthDateStr.substring(6, 8)); |
|
|
|
|
|
|
|
|
|
|
|
Calendar birthCal = Calendar.getInstance(); |
|
|
|
|
|
birthCal.set(year, month - 1, day); |
|
|
|
|
|
|
|
|
|
|
|
Calendar today = Calendar.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
int age = today.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR); |
|
|
|
|
|
if (today.get(Calendar.MONTH) < birthCal.get(Calendar.MONTH)) { |
|
|
|
|
|
age--; |
|
|
|
|
|
} else if (today.get(Calendar.MONTH) == birthCal.get(Calendar.MONTH) |
|
|
|
|
|
&& today.get(Calendar.DAY_OF_MONTH) < birthCal.get(Calendar.DAY_OF_MONTH)) { |
|
|
|
|
|
age--; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (age < 18) { |
|
|
|
|
|
return "必须年满18周岁"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (age > 100) { |
|
|
|
|
|
return "年龄超过100岁,请核实身份证号"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return "身份证号出生日期解析失败"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; // 校验通过 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 从身份证提取性别(0:男, 1:女) |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getGenderFromIdCard(String idCard) { |
|
|
|
|
|
if (!isValidIdCard(idCard)) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
// 第17位:奇数为男,偶数为女 |
|
|
|
|
|
int genderNum = Character.getNumericValue(idCard.charAt(16)); |
|
|
|
|
|
return genderNum % 2 == 1 ? "0" : "1"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 从身份证提取出生日期 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getBirthdayFromIdCard(String idCard) { |
|
|
|
|
|
if (!isValidIdCard(idCard)) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
String birthDateStr = idCard.substring(6, 14); |
|
|
|
|
|
return birthDateStr.substring(0, 4) + "-" + |
|
|
|
|
|
birthDateStr.substring(4, 6) + "-" + |
|
|
|
|
|
birthDateStr.substring(6, 8); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 从身份证提取年龄 |
|
|
|
|
|
*/ |
|
|
|
|
|
private int getAgeFromIdCard(String idCard) { |
|
|
|
|
|
if (!isValidIdCard(idCard)) { |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
String birthDateStr = idCard.substring(6, 14); |
|
|
|
|
|
int year = Integer.parseInt(birthDateStr.substring(0, 4)); |
|
|
|
|
|
int month = Integer.parseInt(birthDateStr.substring(4, 6)); |
|
|
|
|
|
int day = Integer.parseInt(birthDateStr.substring(6, 8)); |
|
|
|
|
|
|
|
|
|
|
|
Calendar birthCal = Calendar.getInstance(); |
|
|
|
|
|
birthCal.set(year, month - 1, day); |
|
|
|
|
|
|
|
|
|
|
|
Calendar today = Calendar.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
int age = today.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR); |
|
|
|
|
|
if (today.get(Calendar.MONTH) < birthCal.get(Calendar.MONTH)) { |
|
|
|
|
|
age--; |
|
|
|
|
|
} else if (today.get(Calendar.MONTH) == birthCal.get(Calendar.MONTH) |
|
|
|
|
|
&& today.get(Calendar.DAY_OF_MONTH) < birthCal.get(Calendar.DAY_OF_MONTH)) { |
|
|
|
|
|
age--; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return age; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
|
|
|
* 验证手机号格式 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean isValidPhone(String phone) { |
|
|
|
|
|
if (StringUtils.isEmpty(phone)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
// 手机号正则(11位) |
|
|
|
|
|
String regex = "^1[3-9]\\d{9}$"; |
|
|
|
|
|
return phone.matches(regex); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 验证邮箱格式 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean isValidEmail(String email) { |
|
|
|
|
|
if (StringUtils.isEmpty(email)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
String regex = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$"; |
|
|
|
|
|
return email.matches(regex); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private AjaxResult processNewFormat(Map<String, Object> requestData) { |
|
|
private AjaxResult processNewFormat(Map<String, Object> requestData) { |
|
|
Long userId = SecurityUtils.getUserId(); |
|
|
Long userId = SecurityUtils.getUserId(); |
|
|
int result = vetQualificationService.submitQualification(requestData); |
|
|
int result = vetQualificationService.submitQualification(requestData); |
|
|
@ -573,7 +1088,6 @@ public class VetQualificationController extends BaseController |
|
|
else return "未知"; |
|
|
else return "未知"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 修改单个证书信息并提交审核(根据证书ID修改单个证书) |
|
|
* 修改单个证书信息并提交审核(根据证书ID修改单个证书) |
|
|
*/ |
|
|
*/ |
|
|
@ -584,7 +1098,6 @@ public class VetQualificationController extends BaseController |
|
|
log.info("修改单个证书并提交审核请求数据: {}", requestData); |
|
|
log.info("修改单个证书并提交审核请求数据: {}", requestData); |
|
|
|
|
|
|
|
|
// 1. 获取证书ID(要修改的证书) |
|
|
// 1. 获取证书ID(要修改的证书) |
|
|
// 1. 获取字符串格式的ID |
|
|
|
|
|
String certIdStr = null; |
|
|
String certIdStr = null; |
|
|
Object certIdObj = requestData.get("certId"); |
|
|
Object certIdObj = requestData.get("certId"); |
|
|
if (certIdObj != null) { |
|
|
if (certIdObj != null) { |
|
|
@ -604,31 +1117,31 @@ public class VetQualificationController extends BaseController |
|
|
return AjaxResult.error("证书ID格式错误"); |
|
|
return AjaxResult.error("证书ID格式错误"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 3. 继续原有逻辑(使用Long类型的certId) |
|
|
|
|
|
|
|
|
// 3. 获取资质ID |
|
|
Long qualificationId = extractLongFromObject(requestData.get("qualificationId")); |
|
|
Long qualificationId = extractLongFromObject(requestData.get("qualificationId")); |
|
|
if (qualificationId == null) { |
|
|
if (qualificationId == null) { |
|
|
return AjaxResult.error("资质ID不能为空"); |
|
|
return AjaxResult.error("资质ID不能为空"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 3. 查询整个资质信息 |
|
|
|
|
|
|
|
|
// 4. 查询整个资质信息 |
|
|
VetQualification existingQualification = vetQualificationService.selectVetQualificationByQualificationId(qualificationId); |
|
|
VetQualification existingQualification = vetQualificationService.selectVetQualificationByQualificationId(qualificationId); |
|
|
if (existingQualification == null) { |
|
|
if (existingQualification == null) { |
|
|
return AjaxResult.error("资质信息不存在"); |
|
|
return AjaxResult.error("资质信息不存在"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 4. 权限检查 |
|
|
|
|
|
|
|
|
// 5. 权限检查 |
|
|
Long currentUserId = SecurityUtils.getUserId(); |
|
|
Long currentUserId = SecurityUtils.getUserId(); |
|
|
if (!SecurityUtils.isAdmin(currentUserId) && !existingQualification.getUserId().equals(currentUserId)) { |
|
|
if (!SecurityUtils.isAdmin(currentUserId) && !existingQualification.getUserId().equals(currentUserId)) { |
|
|
return AjaxResult.error("无权操作此证书"); |
|
|
return AjaxResult.error("无权操作此证书"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 5. 获取现有证书列表 |
|
|
|
|
|
|
|
|
// 6. 获取现有证书列表 |
|
|
List<VetQualification.CertificateInfo> certificateList = existingQualification.getCertificateList(); |
|
|
List<VetQualification.CertificateInfo> certificateList = existingQualification.getCertificateList(); |
|
|
if (certificateList == null || certificateList.isEmpty()) { |
|
|
if (certificateList == null || certificateList.isEmpty()) { |
|
|
return AjaxResult.error("该资质没有证书信息"); |
|
|
return AjaxResult.error("该资质没有证书信息"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 6. 查找并更新指定证书 |
|
|
|
|
|
|
|
|
// 7. 查找并更新指定证书 |
|
|
boolean certificateFound = false; |
|
|
boolean certificateFound = false; |
|
|
for (VetQualification.CertificateInfo cert : certificateList) { |
|
|
for (VetQualification.CertificateInfo cert : certificateList) { |
|
|
if (cert.getCertificateId() != null && cert.getCertificateId().equals(certId)) { |
|
|
if (cert.getCertificateId() != null && cert.getCertificateId().equals(certId)) { |
|
|
@ -643,17 +1156,17 @@ public class VetQualificationController extends BaseController |
|
|
return AjaxResult.error("未找到要修改的证书"); |
|
|
return AjaxResult.error("未找到要修改的证书"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 7. 创建更新对象 |
|
|
|
|
|
|
|
|
// 8. 创建更新对象 |
|
|
VetQualification updateQualification = new VetQualification(); |
|
|
VetQualification updateQualification = new VetQualification(); |
|
|
updateQualification.setQualificationId(qualificationId); |
|
|
updateQualification.setQualificationId(qualificationId); |
|
|
|
|
|
|
|
|
// 8. 更新基础信息(如果有的话) |
|
|
|
|
|
|
|
|
// 9. 更新基础信息(如果有的话) |
|
|
updateBasicInfo(requestData, updateQualification); |
|
|
updateBasicInfo(requestData, updateQualification); |
|
|
|
|
|
|
|
|
// 9. 更新证书列表到JSON |
|
|
|
|
|
|
|
|
// 10. 更新证书列表到JSON |
|
|
updateCertificatesToJson(certificateList, updateQualification); |
|
|
updateCertificatesToJson(certificateList, updateQualification); |
|
|
|
|
|
|
|
|
// 10. 更新主表字段(使用第一个证书的信息) |
|
|
|
|
|
|
|
|
// 11. 更新主表字段(使用第一个证书的信息) |
|
|
if (!certificateList.isEmpty()) { |
|
|
if (!certificateList.isEmpty()) { |
|
|
VetQualification.CertificateInfo firstCert = certificateList.get(0); |
|
|
VetQualification.CertificateInfo firstCert = certificateList.get(0); |
|
|
updateQualification.setCertName(firstCert.getCertName()); |
|
|
updateQualification.setCertName(firstCert.getCertName()); |
|
|
@ -664,16 +1177,16 @@ public class VetQualificationController extends BaseController |
|
|
updateQualification.setExpireDate(firstCert.getExpireDate()); |
|
|
updateQualification.setExpireDate(firstCert.getExpireDate()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 11. 设置审核状态为"待审核" |
|
|
|
|
|
|
|
|
// 12. 设置审核状态为"待审核" |
|
|
updateQualification.setAuditStatus("0"); |
|
|
updateQualification.setAuditStatus("0"); |
|
|
updateQualification.setAuditOpinion(null); |
|
|
updateQualification.setAuditOpinion(null); |
|
|
updateQualification.setApplyTime(new Date()); |
|
|
updateQualification.setApplyTime(new Date()); |
|
|
|
|
|
|
|
|
// 12. 设置更新人信息 |
|
|
|
|
|
|
|
|
// 13. 设置更新人信息 |
|
|
updateQualification.setUpdateBy(SecurityUtils.getUsername()); |
|
|
updateQualification.setUpdateBy(SecurityUtils.getUsername()); |
|
|
updateQualification.setUpdateTime(new Date()); |
|
|
updateQualification.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
|
// 13. 执行更新 |
|
|
|
|
|
|
|
|
// 14. 执行更新 |
|
|
int result = vetQualificationService.updateVetQualification(updateQualification); |
|
|
int result = vetQualificationService.updateVetQualification(updateQualification); |
|
|
|
|
|
|
|
|
if (result > 0) { |
|
|
if (result > 0) { |
|
|
|