|
|
@@ -3,6 +3,7 @@ package com.fs.hisStore.service.impl;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
+import com.fs.common.exception.base.BaseException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.his.param.FsStoreAuditParam;
|
|
|
@@ -102,10 +103,23 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
|
|
|
StoreMD5PasswordEncoder storeMD5PasswordEncoder = new StoreMD5PasswordEncoder();
|
|
|
fsStore.setPassword(storeMD5PasswordEncoder.encode("XyzAbc~12"));
|
|
|
fsStore.setCreateTime(DateUtils.getNowDate());
|
|
|
+ if (fsStore.getBusinessCode() != null && !fsStore.getBusinessCode().trim().isEmpty()) {
|
|
|
+ boolean exists = fsStoreMapper.existsByBusinessCode(fsStore.getBusinessCode());
|
|
|
+ if (exists) {
|
|
|
+ // 检查是否是同一个商家
|
|
|
+ String existingMerchantId = fsStoreMapper.findMerchantIdByBusinessCode(fsStore.getBusinessCode());
|
|
|
+ if (existingMerchantId != null) {
|
|
|
+ // 同一商家下检查店铺名称是否重复
|
|
|
+ if (fsStoreMapper.existsStoreNameInMerchant(existingMerchantId, fsStore.getStoreName())) {
|
|
|
+ throw new BaseException("该商家下已存在同名店铺");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//生成商家id
|
|
|
- String merchantId = generateMerchantId();
|
|
|
+ String merchantId = generateMerchantId(fsStore.getBusinessCode());
|
|
|
//生成店铺id
|
|
|
- String sequence = generateStoreSequence(merchantId);
|
|
|
+ String sequence = generateStoreSequence(merchantId,fsStore.getBusinessCode());
|
|
|
fsStore.setMerchantId(merchantId);
|
|
|
fsStore.setStoreSeq(sequence);
|
|
|
fsStoreMapper.insertFsStore(fsStore);
|
|
|
@@ -116,36 +130,57 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
|
|
|
* 生成商家ID:YJB202510180001
|
|
|
* 格式:前缀 + 年月日 + 4位序列号
|
|
|
*/
|
|
|
- public String generateMerchantId() {
|
|
|
- // 获取当天日期
|
|
|
- String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ @Transactional
|
|
|
+ public String generateMerchantId(String businessCode) {
|
|
|
+ // 如果营业执照已存在,返回已有的商家ID
|
|
|
+ if (businessCode != null && !businessCode.trim().isEmpty()) {
|
|
|
+ String existingMerchantId = fsStoreMapper.findMerchantIdByBusinessCode(businessCode);
|
|
|
+ if (existingMerchantId != null) {
|
|
|
+ return existingMerchantId;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 查询当天已生成的商家数量
|
|
|
- Long todayCount = fsStoreMapper.countMerchantsByDatePrefix(MERCHANT_PREFIX + datePart);
|
|
|
+ // 新营业执照,生成新的商家ID
|
|
|
+ String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ String prefix = MERCHANT_PREFIX + datePart;
|
|
|
|
|
|
- // 生成序号 (从0001开始)
|
|
|
- Long sequence = (todayCount == null) ? 1L : todayCount + 1;
|
|
|
- String sequencePart = String.format("%04d", sequence);
|
|
|
+ // 查询当天已生成的新商家数量(基于营业执照)
|
|
|
+ Long todayNewMerchantCount = fsStoreMapper.countNewMerchantsByDate(prefix);
|
|
|
+ Long sequence = (todayNewMerchantCount == null) ? 1L : todayNewMerchantCount + 1;
|
|
|
|
|
|
- return MERCHANT_PREFIX + datePart + sequencePart;
|
|
|
+ return prefix + String.format("%04d", sequence);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 生成店铺序号:年月日 + 当天第几家店
|
|
|
* 格式:202510180001
|
|
|
*/
|
|
|
- public String generateStoreSequence(String merchantId) {
|
|
|
- // 获取当天日期
|
|
|
+ @Transactional
|
|
|
+ public String generateStoreSequence(String merchantId, String businessCode) {
|
|
|
String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
|
|
|
- // 查询当天已生成的店铺数量
|
|
|
- Long todayCount = fsStoreMapper.countByStoreSeqPrefix(merchantId, datePart);
|
|
|
-
|
|
|
- // 生成序号 (从1开始)
|
|
|
- Long sequence = (todayCount == null) ? 1L : todayCount + 1;
|
|
|
- String sequencePart = String.format("%04d", sequence);
|
|
|
+ // 检查是否是新商家(根据营业执照是否已存在)
|
|
|
+ boolean isNewMerchant = false;
|
|
|
+ if (businessCode != null && !businessCode.trim().isEmpty()) {
|
|
|
+ String existingMerchantId = fsStoreMapper.findMerchantIdByBusinessCode(businessCode);
|
|
|
+ isNewMerchant = (existingMerchantId == null);
|
|
|
+ } else {
|
|
|
+ // 如果没有营业执照,检查商家ID是否已存在
|
|
|
+ Integer existingStoreCount = fsStoreMapper.countStoresByMerchant(merchantId);
|
|
|
+ isNewMerchant = (existingStoreCount == null || existingStoreCount == 0);
|
|
|
+ }
|
|
|
|
|
|
- return datePart + sequencePart;
|
|
|
+ if (isNewMerchant) {
|
|
|
+ // 新商家,店铺序列从1开始
|
|
|
+ return datePart + "0001";
|
|
|
+ } else {
|
|
|
+ // 现有商家,获取当前商家的店铺数量+1
|
|
|
+ Integer storeCount = fsStoreMapper.countStoresByMerchant(merchantId);
|
|
|
+ Long sequence = (storeCount == null) ? 1L : storeCount + 1L;
|
|
|
+ return datePart + String.format("%04d", sequence);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -185,13 +220,14 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService {
|
|
|
|
|
|
//验证资质日期是否正常
|
|
|
LocalDate today = LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
|
|
- if (fsStore.getBusinessLicenseExpireEnd().isBefore(today) || fsStore.getDrugLicenseExpiryEnd().isBefore(today)
|
|
|
- || fsStore.getMedicalDevice2ExpiryEnd().isBefore(today) || fsStore.getMedicalLicenseExpiryEnd().isBefore(today) || fsStore.getStatus() == 0) {
|
|
|
- fsStore.setStatus(0);
|
|
|
- } else {
|
|
|
- fsStore.setStatus(1);
|
|
|
+ if (Objects.equals(String.valueOf(fsStore.getIsBusinessLicensePermanent()), "0")) {
|
|
|
+ if (fsStore.getBusinessLicenseExpireEnd().isBefore(today) || fsStore.getDrugLicenseExpiryEnd().isBefore(today)
|
|
|
+ || fsStore.getMedicalDevice2ExpiryEnd().isBefore(today) || fsStore.getMedicalLicenseExpiryEnd().isBefore(today) || fsStore.getStatus() == 0) {
|
|
|
+ fsStore.setStatus(0);
|
|
|
+ } else {
|
|
|
+ fsStore.setStatus(1);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return fsStoreMapper.updateFsStore(fsStore);
|
|
|
}
|
|
|
|