功能迭代
This commit is contained in:
1 parent
ed890edb85
commit
d1844ce9a2
80 files changed
+1799
-75
No files matched your search
@@ -24,6 +24,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-core</artifactId>
|
<artifactId>flyway-core</artifactId>
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ package com.shoplix.admin.config;
|
|||||||
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
import com.shoplix.common.utils.BusinessCodeUtils;
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
||||||
|
import com.shoplix.modules.account.repository.entity.AdminUserSiteEntity;
|
||||||
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
||||||
|
import com.shoplix.modules.account.repository.service.AdminUserSiteRepositoryService;
|
||||||
|
import com.shoplix.modules.account.enums.AdminSiteMembershipStatusEnum;
|
||||||
|
import com.shoplix.modules.account.enums.AdminSiteRoleEnum;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
@@ -16,17 +20,19 @@ public class AdminAccountInitializer implements ApplicationRunner {
|
|||||||
private final AdminUserRepositoryService repository;
|
private final AdminUserRepositoryService repository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final BusinessCodeUtils codes;
|
private final BusinessCodeUtils codes;
|
||||||
|
private final AdminUserSiteRepositoryService membershipRepository;
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String password;
|
private final String password;
|
||||||
private final String siteCode;
|
private final String siteCode;
|
||||||
|
|
||||||
/** 注入初始化依赖与首次登录配置。 */
|
/** 注入初始化依赖与首次登录配置。 */
|
||||||
public AdminAccountInitializer(AdminUserRepositoryService repository, PasswordEncoder passwordEncoder,
|
public AdminAccountInitializer(AdminUserRepositoryService repository, PasswordEncoder passwordEncoder,
|
||||||
BusinessCodeUtils codes,
|
BusinessCodeUtils codes, AdminUserSiteRepositoryService membershipRepository,
|
||||||
@Value("${shoplix.admin.initial-username:admin}") String username,
|
@Value("${shoplix.admin.initial-username:admin}") String username,
|
||||||
@Value("${shoplix.admin.initial-password:Shoplix@2026}") String password,
|
@Value("${shoplix.admin.initial-password:Shoplix@2026}") String password,
|
||||||
@Value("${shoplix.admin.site-code:SIT0000000000001}") String siteCode) {
|
@Value("${shoplix.admin.site-code:SIT0000000000001}") String siteCode) {
|
||||||
this.repository = repository; this.passwordEncoder = passwordEncoder; this.codes = codes;
|
this.repository = repository; this.passwordEncoder = passwordEncoder; this.codes = codes;
|
||||||
|
this.membershipRepository = membershipRepository;
|
||||||
this.username = username; this.password = password; this.siteCode = siteCode;
|
this.username = username; this.password = password; this.siteCode = siteCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,5 +48,13 @@ public class AdminAccountInitializer implements ApplicationRunner {
|
|||||||
entity.setDisplayName("系统管理员");
|
entity.setDisplayName("系统管理员");
|
||||||
entity.setStatus("ENABLED");
|
entity.setStatus("ENABLED");
|
||||||
repository.insert(entity);
|
repository.insert(entity);
|
||||||
|
AdminUserSiteEntity membership = new AdminUserSiteEntity();
|
||||||
|
membership.setRelationCode(codes.generate(BusinessCodePrefixEnum.USER_SITE));
|
||||||
|
membership.setUserCode(entity.getUserCode());
|
||||||
|
membership.setSiteCode(siteCode);
|
||||||
|
membership.setSiteRole(AdminSiteRoleEnum.OWNER.getValue());
|
||||||
|
membership.setStatus(AdminSiteMembershipStatusEnum.ENABLED.getValue());
|
||||||
|
membership.setDeleted(0);
|
||||||
|
membershipRepository.insert(membership);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.shoplix.admin.config;
|
||||||
|
|
||||||
|
import com.shoplix.admin.service.AdminSiteAccessService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
/** 统一校验运营后台请求中的站点访问权限。 */
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class AdminSiteAccessAspect {
|
||||||
|
/** 站点访问权限业务。 */ private final AdminSiteAccessService accessService;
|
||||||
|
|
||||||
|
/** 注入站点访问权限业务。 */
|
||||||
|
public AdminSiteAccessAspect(AdminSiteAccessService accessService) { this.accessService = accessService; }
|
||||||
|
|
||||||
|
/** 校验除认证和站点管理接口外的 Controller 站点参数。 */
|
||||||
|
@Around("within(com.shoplix.admin.controller..*) && "
|
||||||
|
+ "!within(com.shoplix.admin.controller.AdminAuthController) && "
|
||||||
|
+ "!within(com.shoplix.admin.controller.AdminSiteController)")
|
||||||
|
public Object validate(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
Set<String> siteCodes = new LinkedHashSet<>();
|
||||||
|
HttpServletRequest request = currentRequest();
|
||||||
|
if (request != null && request.getParameter("siteCode") != null) {
|
||||||
|
siteCodes.add(request.getParameter("siteCode"));
|
||||||
|
}
|
||||||
|
for (Object argument : joinPoint.getArgs()) {
|
||||||
|
String siteCode = extractSiteCode(argument);
|
||||||
|
if (siteCode != null && !siteCode.isBlank()) siteCodes.add(siteCode);
|
||||||
|
}
|
||||||
|
if (!siteCodes.isEmpty()) {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
for (String siteCode : siteCodes) accessService.validateAccess(authentication.getName(), siteCode);
|
||||||
|
}
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从请求模型的 siteCode 方法读取站点编号。 */
|
||||||
|
private String extractSiteCode(Object argument) {
|
||||||
|
if (argument == null) return null;
|
||||||
|
try {
|
||||||
|
Method method = argument.getClass().getMethod("siteCode");
|
||||||
|
if (method.getParameterCount() == 0 && method.getReturnType() == String.class) {
|
||||||
|
return (String) method.invoke(argument);
|
||||||
|
}
|
||||||
|
} catch (ReflectiveOperationException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前 HTTP 请求。 */
|
||||||
|
private HttpServletRequest currentRequest() {
|
||||||
|
if (RequestContextHolder.getRequestAttributes() instanceof ServletRequestAttributes attributes) {
|
||||||
|
return attributes.getRequest();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.shoplix.admin.controller;
|
||||||
|
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
||||||
|
import com.shoplix.admin.modules.crm.req.*;
|
||||||
|
import com.shoplix.admin.modules.crm.res.CrmCustomerPageAdminRes;
|
||||||
|
import com.shoplix.admin.service.AdminCrmCustomerService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
/** 运营后台 CRM 客户接口。 */ @RestController @RequestMapping("/api/admin/v1/crm/customers") public class AdminCrmCustomerController { /** CRM客户业务。 */ private final AdminCrmCustomerService service; /** 注入 CRM 客户业务。 */ public AdminCrmCustomerController(AdminCrmCustomerService service){this.service=service;} /** 分页查询客户。 */ @PostMapping("/page") public CrmCustomerPageAdminRes page(@Valid @RequestBody CrmCustomerPageAdminReq request){return service.page(request);} /** 新增或编辑客户。 */ @PostMapping("/save") public CommonAdminRes save(@Valid @RequestBody SaveCrmCustomerAdminReq request){service.save(request);return CommonAdminRes.success();} /** 批量导入客户。 */ @PostMapping("/import") public CommonAdminRes importCustomers(@Valid @RequestBody ImportCrmCustomerAdminReq request){service.importCustomers(request);return CommonAdminRes.success();} /** 新增客户标签。 */ @PostMapping("/tags/create") public CommonAdminRes createTag(@Valid @RequestBody CreateCrmTagAdminReq request){service.createTag(request);return CommonAdminRes.success();} }
|
||||||
@@ -3,6 +3,7 @@ package com.shoplix.admin.controller;
|
|||||||
import com.shoplix.admin.facade.AdminMediaFacade;
|
import com.shoplix.admin.facade.AdminMediaFacade;
|
||||||
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
||||||
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
||||||
|
import com.shoplix.admin.modules.media.req.MediaBatchDeleteAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaListAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaListAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
||||||
@@ -71,4 +72,10 @@ public class AdminMediaController {
|
|||||||
public CommonAdminRes delete(@Valid @RequestBody MediaDeleteAdminReq request) {
|
public CommonAdminRes delete(@Valid @RequestBody MediaDeleteAdminReq request) {
|
||||||
return facade.delete(request);
|
return facade.delete(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除素材库中的指定素材。 */
|
||||||
|
@PostMapping("/batch-delete")
|
||||||
|
public CommonAdminRes deleteBatch(@Valid @RequestBody MediaBatchDeleteAdminReq request) {
|
||||||
|
return facade.deleteBatch(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.shoplix.admin.controller;
|
||||||
|
|
||||||
|
import com.shoplix.admin.modules.site.req.CreateSiteAdminReq;
|
||||||
|
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
||||||
|
import com.shoplix.admin.modules.site.res.SiteListAdminRes;
|
||||||
|
import com.shoplix.admin.service.AdminSiteService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/** 运营后台多站点管理接口。 */
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/admin/v1/sites")
|
||||||
|
public class AdminSiteController {
|
||||||
|
/** 多站点管理业务。 */ private final AdminSiteService service;
|
||||||
|
|
||||||
|
/** 注入多站点管理业务。 */
|
||||||
|
public AdminSiteController(AdminSiteService service) { this.service = service; }
|
||||||
|
|
||||||
|
/** 查询当前管理员可访问站点。 */
|
||||||
|
@PostMapping("/list")
|
||||||
|
public SiteListAdminRes list(Authentication authentication) { return service.list(authentication.getName()); }
|
||||||
|
|
||||||
|
/** 新建站点并将当前管理员设为所有者。 */
|
||||||
|
@PostMapping("/create")
|
||||||
|
public CommonAdminRes create(@Valid @RequestBody CreateSiteAdminReq request,
|
||||||
|
Authentication authentication) {
|
||||||
|
service.create(authentication.getName(), request);
|
||||||
|
return CommonAdminRes.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
package com.shoplix.admin.crm;
|
||||||
|
/** CRM 多语言消息键。 */ public final class CrmMessageKeys { /** 禁止实例化。 */ private CrmMessageKeys() { } /** 客户不存在。 */ public static final String CUSTOMER_NOT_FOUND="crm.customer.not-found"; /** 客户保存失败。 */ public static final String CUSTOMER_SAVE_FAILED="crm.customer.save-failed"; /** 标签保存失败。 */ public static final String TAG_SAVE_FAILED="crm.tag.save-failed"; }
|
||||||
@@ -2,6 +2,7 @@ package com.shoplix.admin.facade;
|
|||||||
|
|
||||||
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
import com.shoplix.admin.modules.common.res.CommonAdminRes;
|
||||||
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
||||||
|
import com.shoplix.admin.modules.media.req.MediaBatchDeleteAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
||||||
import com.shoplix.admin.modules.media.res.MediaListAdminRes;
|
import com.shoplix.admin.modules.media.res.MediaListAdminRes;
|
||||||
@@ -56,4 +57,10 @@ public class AdminMediaFacade {
|
|||||||
service.delete(request);
|
service.delete(request);
|
||||||
return CommonAdminRes.success();
|
return CommonAdminRes.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除素材库记录。 */
|
||||||
|
public CommonAdminRes deleteBatch(MediaBatchDeleteAdminReq request) {
|
||||||
|
service.deleteBatch(request);
|
||||||
|
return CommonAdminRes.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,12 @@
|
|||||||
package com.shoplix.admin.modules.account.res;
|
package com.shoplix.admin.modules.account.res;
|
||||||
|
|
||||||
|
import com.shoplix.admin.modules.site.res.SiteOptionAdminRes;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** 当前管理员账户响应。 */
|
/** 当前管理员账户响应。 */
|
||||||
public record AccountAdminRes(String userCode, String siteCode, String username, String displayName) {}
|
public record AccountAdminRes(
|
||||||
|
/** 管理员业务编号。 */ String userCode,
|
||||||
|
/** 兼容保留的默认站点业务编号。 */ String siteCode,
|
||||||
|
/** 登录账户名。 */ String username,
|
||||||
|
/** 管理员显示名称。 */ String displayName,
|
||||||
|
/** 当前管理员可访问站点。 */ List<SiteOptionAdminRes> sites) {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.req;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
/** 新增 CRM 客户标签请求。 */ public record CreateCrmTagAdminReq(/** 站点业务编号。 */ @NotBlank @Size(max=16) String siteCode, /** 标签名称。 */ @NotBlank @Size(max=50) String tagName, /** 标签颜色。 */ @NotBlank @Pattern(regexp="#[0-9a-fA-F]{6}") String color) { }
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.req;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
/** CRM 客户导入行。 */ public record CrmCustomerImportItemAdminReq(/** 公司名称,为空表示未填写。 */ @Size(max=200) String companyName, /** 联系人姓名。 */ @Size(max=100) String contactName, /** 公司网站。 */ @Size(max=500) String website, /** 联系邮箱。 */ @Email @Size(max=200) String email, /** 联系电话。 */ @Size(max=60) String phone, /** 国家或地区。 */ @Size(max=100) String country, /** Facebook主页。 */ @Size(max=500) String facebookUrl, /** Instagram主页。 */ @Size(max=500) String instagramUrl, /** LinkedIn主页。 */ @Size(max=500) String linkedinUrl, /** WhatsApp账号。 */ @Size(max=100) String whatsapp, /** 客户备注。 */ @Size(max=2000) String remark) { }
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.req;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
/** CRM客户分页请求。 */ public record CrmCustomerPageAdminReq(/** 站点业务编号。 */ @NotBlank @Size(max=16) String siteCode, /** 搜索关键词。 */ @Size(max=100) String keyword, /** 页码。 */ @NotNull @Min(1) Integer pageNo, /** 每页数量。 */ @NotNull @Min(1) @Max(100) Integer pageSize) { }
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.req;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import java.util.List;
|
||||||
|
/** 批量导入 CRM 客户请求。 */ public record ImportCrmCustomerAdminReq(/** 站点业务编号。 */ @NotBlank @Size(max=16) String siteCode, /** 导入客户,单次最多五百条。 */ @NotEmpty @Size(max=500) List<@Valid CrmCustomerImportItemAdminReq> items) { }
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.req;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import java.util.List;
|
||||||
|
/** 保存 CRM 客户请求。 */ public record SaveCrmCustomerAdminReq(/** 站点业务编号。 */ @NotBlank @Size(max=16) String siteCode, /** 客户业务编号,新增时为空。 */ @Size(max=16) String customerCode, /** 公司名称,为空表示未填写。 */ @Size(max=200) String companyName, /** 联系人姓名。 */ @Size(max=100) String contactName, /** 公司网站。 */ @Size(max=500) String website, /** 联系邮箱。 */ @Email @Size(max=200) String email, /** 联系电话。 */ @Size(max=60) String phone, /** 国家或地区。 */ @Size(max=100) String country, /** Facebook主页。 */ @Size(max=500) String facebookUrl, /** Instagram主页。 */ @Size(max=500) String instagramUrl, /** LinkedIn主页。 */ @Size(max=500) String linkedinUrl, /** WhatsApp账号。 */ @Size(max=100) String whatsapp, /** 客户备注。 */ @Size(max=2000) String remark, /** 客户标签业务编号。 */ @NotNull List<@Size(max=16) String> tagCodes) { }
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.res;
|
||||||
|
import java.util.List;
|
||||||
|
/** CRM 客户响应。 */ public record CrmCustomerAdminRes(/** 客户业务编号。 */ String customerCode, /** 公司名称。 */ String companyName, /** 联系人姓名。 */ String contactName, /** 公司网站。 */ String website, /** 联系邮箱。 */ String email, /** 联系电话。 */ String phone, /** 国家或地区。 */ String country, /** Facebook主页。 */ String facebookUrl, /** Instagram主页。 */ String instagramUrl, /** LinkedIn主页。 */ String linkedinUrl, /** WhatsApp账号。 */ String whatsapp, /** 客户备注。 */ String remark, /** 客户来源。 */ String source, /** 客户状态。 */ String status, /** 客户标签。 */ List<CrmTagAdminRes> tags, /** 创建时间。 */ java.time.LocalDateTime createTime) { }
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.res;
|
||||||
|
import java.util.List;
|
||||||
|
/** CRM 客户分页响应。 */ public record CrmCustomerPageAdminRes(/** 客户列表。 */ List<CrmCustomerAdminRes> items, /** 总数。 */ Long total, /** 总页数。 */ Integer totalPages, /** 可用标签。 */ List<CrmTagAdminRes> tags) { }
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
package com.shoplix.admin.modules.crm.res;
|
||||||
|
/** CRM 客户标签响应。 */ public record CrmTagAdminRes(/** 标签业务编号。 */ String tagCode, /** 标签名称。 */ String tagName, /** 标签颜色。 */ String color) { }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.shoplix.admin.modules.media.req;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 后台批量删除素材请求。 */
|
||||||
|
public record MediaBatchDeleteAdminReq(
|
||||||
|
/** 所属站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
||||||
|
/** 待删除素材业务编号,单次最多一百个。 */ @NotEmpty @Size(max = 100) List<@NotBlank @Size(max = 16) String> mediaCodes) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.shoplix.admin.modules.site.req;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
|
/** 创建站点请求。 */
|
||||||
|
public record CreateSiteAdminReq(
|
||||||
|
/** 站点名称。 */ @NotBlank @Size(max = 100) String siteName,
|
||||||
|
/** 所属行业。 */ @NotBlank @Size(max = 100) String industry,
|
||||||
|
/** 站点描述。 */ @Size(max = 1000) String description,
|
||||||
|
/** 站点展示时区,例如 Asia/Shanghai。 */ @NotBlank @Size(max = 50) String timezone) {}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.shoplix.admin.modules.site.res;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 管理员可访问站点列表响应。 */
|
||||||
|
public record SiteListAdminRes(
|
||||||
|
/** 可访问站点集合。 */ List<SiteOptionAdminRes> items) {}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.shoplix.admin.modules.site.res;
|
||||||
|
|
||||||
|
/** 管理员可访问站点选项响应。 */
|
||||||
|
public record SiteOptionAdminRes(
|
||||||
|
/** 站点业务编号。 */ String siteCode,
|
||||||
|
/** 站点名称。 */ String siteName,
|
||||||
|
/** 所属行业。 */ String industry,
|
||||||
|
/** 管理员在站点中的角色值。 */ String role,
|
||||||
|
/** 管理员在站点中的角色文案。 */ String roleLabel) {}
|
||||||
@@ -15,10 +15,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class AdminAccountService {
|
public class AdminAccountService {
|
||||||
private final AdminUserRepositoryService repository;
|
private final AdminUserRepositoryService repository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
private final AdminSiteService siteService;
|
||||||
|
|
||||||
/** 注入账户业务依赖。 */
|
/** 注入账户业务依赖。 */
|
||||||
public AdminAccountService(AdminUserRepositoryService repository, PasswordEncoder passwordEncoder) {
|
public AdminAccountService(AdminUserRepositoryService repository, PasswordEncoder passwordEncoder,
|
||||||
this.repository = repository; this.passwordEncoder = passwordEncoder;
|
AdminSiteService siteService) {
|
||||||
|
this.repository = repository; this.passwordEncoder = passwordEncoder; this.siteService = siteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 查询当前管理员账户。 */
|
/** 查询当前管理员账户。 */
|
||||||
@@ -67,6 +69,7 @@ public class AdminAccountService {
|
|||||||
|
|
||||||
/** 转换账户响应。 */
|
/** 转换账户响应。 */
|
||||||
private AccountAdminRes toResponse(AdminUserEntity entity) {
|
private AccountAdminRes toResponse(AdminUserEntity entity) {
|
||||||
return new AccountAdminRes(entity.getUserCode(), entity.getSiteCode(), entity.getUsername(), entity.getDisplayName());
|
return new AccountAdminRes(entity.getUserCode(), entity.getSiteCode(), entity.getUsername(),
|
||||||
|
entity.getDisplayName(), siteService.options(entity.getUserCode()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.shoplix.admin.service;
|
||||||
|
|
||||||
|
import com.shoplix.admin.crm.CrmMessageKeys;
|
||||||
|
import com.shoplix.admin.modules.crm.req.*;
|
||||||
|
import com.shoplix.admin.modules.crm.res.*;
|
||||||
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
|
import com.shoplix.common.exception.BusinessException;
|
||||||
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
|
import com.shoplix.modules.crm.enums.CrmCustomerSourceEnum;
|
||||||
|
import com.shoplix.modules.crm.enums.CrmCustomerStatusEnum;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.*;
|
||||||
|
import com.shoplix.modules.crm.repository.service.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/** 运营后台 CRM 客户业务。 */
|
||||||
|
@Service
|
||||||
|
public class AdminCrmCustomerService {
|
||||||
|
/** 客户数据源。 */ private final CrmCustomerRepositoryService customerRepository;
|
||||||
|
/** 客户标签数据源。 */ private final CrmCustomerTagRepositoryService tagRepository;
|
||||||
|
/** 业务编号生成器。 */ private final BusinessCodeUtils codes;
|
||||||
|
/** 多语言消息源。 */ private final MessageSource messageSource;
|
||||||
|
/** 注入 CRM 客户业务依赖。 */
|
||||||
|
public AdminCrmCustomerService(CrmCustomerRepositoryService customerRepository, CrmCustomerTagRepositoryService tagRepository, BusinessCodeUtils codes, MessageSource messageSource) { this.customerRepository=customerRepository; this.tagRepository=tagRepository; this.codes=codes; this.messageSource=messageSource; }
|
||||||
|
|
||||||
|
/** 分页查询客户及标签。 */
|
||||||
|
public CrmCustomerPageAdminRes page(CrmCustomerPageAdminReq request) {
|
||||||
|
var customers=customerRepository.page(request.siteCode(),request.keyword(),request.pageNo(),request.pageSize());
|
||||||
|
var tags=tagRepository.listTags(request.siteCode());
|
||||||
|
Map<String,CrmCustomerTagEntity> tagMap=tags.stream().collect(Collectors.toMap(CrmCustomerTagEntity::getTagCode,Function.identity()));
|
||||||
|
Map<String,List<CrmTagAdminRes>> customerTags=new HashMap<>();
|
||||||
|
for (var relation:tagRepository.listRelations(request.siteCode(),customers.stream().map(CrmCustomerEntity::getCustomerCode).toList())) {
|
||||||
|
var tag=tagMap.get(relation.getTagCode()); if(tag!=null) customerTags.computeIfAbsent(relation.getCustomerCode(),key->new ArrayList<>()).add(toTag(tag));
|
||||||
|
}
|
||||||
|
long total=customerRepository.count(request.siteCode(),request.keyword());
|
||||||
|
int pages=total==0?0:(int)((total+request.pageSize()-1)/request.pageSize());
|
||||||
|
return new CrmCustomerPageAdminRes(customers.stream().map(item->toResponse(item,customerTags.getOrDefault(item.getCustomerCode(),List.of()))).toList(),total,pages,tags.stream().map(this::toTag).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增或编辑客户并同步标签。 */
|
||||||
|
@Transactional
|
||||||
|
public void save(SaveCrmCustomerAdminReq request) {
|
||||||
|
boolean creating=request.customerCode()==null||request.customerCode().isBlank();
|
||||||
|
CrmCustomerEntity entity=creating?new CrmCustomerEntity():customerRepository.find(request.siteCode(),request.customerCode()).orElseThrow(()->exception("CRM_CUSTOMER_NOT_FOUND",CrmMessageKeys.CUSTOMER_NOT_FOUND));
|
||||||
|
if(creating){entity.setCustomerCode(codes.generate(BusinessCodePrefixEnum.CUSTOMER));entity.setSiteCode(request.siteCode());entity.setSource(CrmCustomerSourceEnum.MANUAL.name());entity.setStatus(CrmCustomerStatusEnum.ACTIVE.name());entity.setDeleted(0);}
|
||||||
|
fill(entity,request.companyName(),request.contactName(),request.website(),request.email(),request.phone(),request.country(),request.facebookUrl(),request.instagramUrl(),request.linkedinUrl(),request.whatsapp(),request.remark());
|
||||||
|
int rows=creating?customerRepository.insert(entity):customerRepository.update(entity);
|
||||||
|
if(rows!=1)throw exception("CRM_CUSTOMER_SAVE_FAILED",CrmMessageKeys.CUSTOMER_SAVE_FAILED);
|
||||||
|
replaceTags(request.siteCode(),entity.getCustomerCode(),request.tagCodes());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量导入客户。 */
|
||||||
|
@Transactional
|
||||||
|
public void importCustomers(ImportCrmCustomerAdminReq request) {
|
||||||
|
for(var item:request.items()){
|
||||||
|
CrmCustomerEntity entity=new CrmCustomerEntity(); entity.setCustomerCode(codes.generate(BusinessCodePrefixEnum.CUSTOMER)); entity.setSiteCode(request.siteCode()); entity.setSource(CrmCustomerSourceEnum.IMPORT.name()); entity.setStatus(CrmCustomerStatusEnum.ACTIVE.name()); entity.setDeleted(0);
|
||||||
|
fill(entity,item.companyName(),item.contactName(),item.website(),item.email(),item.phone(),item.country(),item.facebookUrl(),item.instagramUrl(),item.linkedinUrl(),item.whatsapp(),item.remark());
|
||||||
|
if(customerRepository.insert(entity)!=1)throw exception("CRM_CUSTOMER_SAVE_FAILED",CrmMessageKeys.CUSTOMER_SAVE_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增客户标签。 */
|
||||||
|
@Transactional
|
||||||
|
public void createTag(CreateCrmTagAdminReq request) {
|
||||||
|
CrmCustomerTagEntity entity=new CrmCustomerTagEntity(); entity.setTagCode(codes.generate(BusinessCodePrefixEnum.CRM_TAG)); entity.setSiteCode(request.siteCode()); entity.setTagName(request.tagName().trim()); entity.setColor(request.color()); entity.setDeleted(0);
|
||||||
|
if(tagRepository.insertTag(entity)!=1)throw exception("CRM_TAG_SAVE_FAILED",CrmMessageKeys.TAG_SAVE_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 替换客户标签关系。 */
|
||||||
|
private void replaceTags(String siteCode,String customerCode,List<String> tagCodes){
|
||||||
|
Set<String> allowed=tagRepository.listTags(siteCode).stream().map(CrmCustomerTagEntity::getTagCode).collect(Collectors.toSet());
|
||||||
|
var distinct=tagCodes.stream().filter(allowed::contains).distinct().toList();
|
||||||
|
tagRepository.deleteRelations(siteCode,customerCode);
|
||||||
|
for(String tagCode:distinct){CrmCustomerTagRelationEntity relation=new CrmCustomerTagRelationEntity();relation.setRelationCode(codes.generate(BusinessCodePrefixEnum.CRM_TAG_RELATION));relation.setSiteCode(siteCode);relation.setCustomerCode(customerCode);relation.setTagCode(tagCode);relation.setDeleted(0);if(tagRepository.insertRelation(relation)!=1)throw exception("CRM_TAG_SAVE_FAILED",CrmMessageKeys.TAG_SAVE_FAILED);}
|
||||||
|
}
|
||||||
|
/** 填充客户可编辑资料。 */
|
||||||
|
private void fill(CrmCustomerEntity entity,String companyName,String contactName,String website,String email,String phone,String country,String facebook,String instagram,String linkedin,String whatsapp,String remark){entity.setCompanyName(text(companyName));entity.setContactName(text(contactName));entity.setWebsite(text(website));entity.setEmail(text(email));entity.setPhone(text(phone));entity.setCountry(text(country));entity.setFacebookUrl(text(facebook));entity.setInstagramUrl(text(instagram));entity.setLinkedinUrl(text(linkedin));entity.setWhatsapp(text(whatsapp));entity.setRemark(text(remark));}
|
||||||
|
/** 将空值转换为空字符串。 */ private String text(String value){return value==null?"":value.trim();}
|
||||||
|
/** 转换标签响应。 */ private CrmTagAdminRes toTag(CrmCustomerTagEntity item){return new CrmTagAdminRes(item.getTagCode(),item.getTagName(),item.getColor());}
|
||||||
|
/** 转换客户响应。 */ private CrmCustomerAdminRes toResponse(CrmCustomerEntity item,List<CrmTagAdminRes> tags){return new CrmCustomerAdminRes(item.getCustomerCode(),item.getCompanyName(),item.getContactName(),item.getWebsite(),item.getEmail(),item.getPhone(),item.getCountry(),item.getFacebookUrl(),item.getInstagramUrl(),item.getLinkedinUrl(),item.getWhatsapp(),item.getRemark(),item.getSource(),item.getStatus(),tags,item.getCreateTime());}
|
||||||
|
/** 创建多语言业务异常。 */ private BusinessException exception(String code,String key){return new BusinessException(code,messageSource.getMessage(key,null,LocaleContextHolder.getLocale()));}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.shoplix.admin.service;
|
|||||||
|
|
||||||
import com.shoplix.admin.media.MediaMessageKeys;
|
import com.shoplix.admin.media.MediaMessageKeys;
|
||||||
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
||||||
|
import com.shoplix.admin.modules.media.req.MediaBatchDeleteAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
||||||
import com.shoplix.admin.modules.media.res.MediaItemAdminRes;
|
import com.shoplix.admin.modules.media.res.MediaItemAdminRes;
|
||||||
@@ -27,6 +28,7 @@ import java.util.Locale;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/** 运营后台媒体上传业务。 */
|
/** 运营后台媒体上传业务。 */
|
||||||
@Service
|
@Service
|
||||||
@@ -90,6 +92,19 @@ public class AdminMediaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量从素材库逻辑删除素材,保留对象以兼容已发布内容。 */
|
||||||
|
@Transactional
|
||||||
|
public void deleteBatch(MediaBatchDeleteAdminReq request) {
|
||||||
|
var mediaCodes = request.mediaCodes().stream().distinct().toList();
|
||||||
|
for (String mediaCode : mediaCodes) {
|
||||||
|
repository.find(request.siteCode(), mediaCode)
|
||||||
|
.orElseThrow(() -> mediaException("MEDIA_ASSET_NOT_FOUND", MediaMessageKeys.NOT_FOUND));
|
||||||
|
}
|
||||||
|
if (repository.deleteBatch(request.siteCode(), mediaCodes) != mediaCodes.size()) {
|
||||||
|
throw mediaException("MEDIA_ASSET_DELETE_FAILED", MediaMessageKeys.DELETE_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 转换素材列表响应。 */
|
/** 转换素材列表响应。 */
|
||||||
public MediaItemAdminRes toItemResponse(MediaAssetEntity entity) {
|
public MediaItemAdminRes toItemResponse(MediaAssetEntity entity) {
|
||||||
return new MediaItemAdminRes(entity.getMediaCode(), entity.getMediaType(), entity.getOriginalFileName(),
|
return new MediaItemAdminRes(entity.getMediaCode(), entity.getMediaType(), entity.getOriginalFileName(),
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.shoplix.admin.service;
|
||||||
|
|
||||||
|
import com.shoplix.admin.site.SiteMessageKeys;
|
||||||
|
import com.shoplix.common.exception.BusinessException;
|
||||||
|
import com.shoplix.modules.account.repository.service.AdminUserSiteRepositoryService;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/** 管理员站点访问权限业务。 */
|
||||||
|
@Service
|
||||||
|
public class AdminSiteAccessService {
|
||||||
|
/** 用户站点关系数据源。 */ private final AdminUserSiteRepositoryService repository;
|
||||||
|
/** 多语言消息源。 */ private final MessageSource messageSource;
|
||||||
|
|
||||||
|
/** 注入站点权限依赖。 */
|
||||||
|
public AdminSiteAccessService(AdminUserSiteRepositoryService repository, MessageSource messageSource) {
|
||||||
|
this.repository = repository; this.messageSource = messageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 判断管理员能否访问目标站点。 */
|
||||||
|
public boolean canAccess(String userCode, String siteCode) { return repository.canAccess(userCode, siteCode); }
|
||||||
|
|
||||||
|
/** 校验管理员可以访问目标站点。 */
|
||||||
|
public void validateAccess(String userCode, String siteCode) {
|
||||||
|
if (!canAccess(userCode, siteCode)) {
|
||||||
|
throw new BusinessException("SITE_ACCESS_DENIED",
|
||||||
|
messageSource.getMessage(SiteMessageKeys.ACCESS_DENIED, null, LocaleContextHolder.getLocale()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.shoplix.admin.service;
|
||||||
|
|
||||||
|
import com.shoplix.admin.modules.site.req.CreateSiteAdminReq;
|
||||||
|
import com.shoplix.admin.modules.site.res.SiteListAdminRes;
|
||||||
|
import com.shoplix.admin.modules.site.res.SiteOptionAdminRes;
|
||||||
|
import com.shoplix.admin.site.SiteMessageKeys;
|
||||||
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
|
import com.shoplix.common.exception.BusinessException;
|
||||||
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
|
import com.shoplix.modules.account.enums.AdminSiteMembershipStatusEnum;
|
||||||
|
import com.shoplix.modules.account.enums.AdminSiteRoleEnum;
|
||||||
|
import com.shoplix.modules.account.repository.entity.AdminUserSiteEntity;
|
||||||
|
import com.shoplix.modules.account.repository.service.AdminUserSiteRepositoryService;
|
||||||
|
import com.shoplix.modules.site.enums.SiteStatusEnum;
|
||||||
|
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
||||||
|
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/** 运营后台多站点管理业务。 */
|
||||||
|
@Service
|
||||||
|
public class AdminSiteService {
|
||||||
|
/** 站点数据源。 */ private final SiteRepositoryService siteRepository;
|
||||||
|
/** 用户站点关系数据源。 */ private final AdminUserSiteRepositoryService membershipRepository;
|
||||||
|
/** 业务编号生成器。 */ private final BusinessCodeUtils codeUtils;
|
||||||
|
/** 多语言消息源。 */ private final MessageSource messageSource;
|
||||||
|
|
||||||
|
/** 注入多站点管理依赖。 */
|
||||||
|
public AdminSiteService(SiteRepositoryService siteRepository,
|
||||||
|
AdminUserSiteRepositoryService membershipRepository,
|
||||||
|
BusinessCodeUtils codeUtils, MessageSource messageSource) {
|
||||||
|
this.siteRepository = siteRepository; this.membershipRepository = membershipRepository;
|
||||||
|
this.codeUtils = codeUtils; this.messageSource = messageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查询当前管理员可访问的全部站点。 */
|
||||||
|
public SiteListAdminRes list(String userCode) { return new SiteListAdminRes(options(userCode)); }
|
||||||
|
|
||||||
|
/** 查询当前管理员可访问站点选项。 */
|
||||||
|
public List<SiteOptionAdminRes> options(String userCode) {
|
||||||
|
List<AdminUserSiteEntity> memberships = membershipRepository.listEnabled(userCode);
|
||||||
|
Map<String, SiteEntity> sites = siteRepository.listByCodes(
|
||||||
|
memberships.stream().map(AdminUserSiteEntity::getSiteCode).toList()).stream()
|
||||||
|
.collect(Collectors.toMap(SiteEntity::getSiteCode, Function.identity()));
|
||||||
|
return memberships.stream().filter(item -> sites.containsKey(item.getSiteCode()))
|
||||||
|
.map(item -> toResponse(sites.get(item.getSiteCode()), item.getSiteRole())).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建站点并将当前管理员设为所有者。 */
|
||||||
|
@Transactional
|
||||||
|
public SiteOptionAdminRes create(String userCode, CreateSiteAdminReq request) {
|
||||||
|
SiteEntity site = new SiteEntity();
|
||||||
|
site.setSiteCode(codeUtils.generate(BusinessCodePrefixEnum.SITE));
|
||||||
|
site.setSiteName(request.siteName().trim());
|
||||||
|
site.setSiteDescription(request.description());
|
||||||
|
site.setIndustry(request.industry().trim());
|
||||||
|
site.setTimezone(request.timezone().trim());
|
||||||
|
site.setStatus(SiteStatusEnum.ENABLED.getValue());
|
||||||
|
site.setDeleted(0);
|
||||||
|
if (siteRepository.insert(site) != 1) throw businessException("SITE_CREATE_FAILED", SiteMessageKeys.CREATE_FAILED);
|
||||||
|
|
||||||
|
AdminUserSiteEntity membership = new AdminUserSiteEntity();
|
||||||
|
membership.setRelationCode(codeUtils.generate(BusinessCodePrefixEnum.USER_SITE));
|
||||||
|
membership.setUserCode(userCode);
|
||||||
|
membership.setSiteCode(site.getSiteCode());
|
||||||
|
membership.setSiteRole(AdminSiteRoleEnum.OWNER.getValue());
|
||||||
|
membership.setStatus(AdminSiteMembershipStatusEnum.ENABLED.getValue());
|
||||||
|
membership.setDeleted(0);
|
||||||
|
if (membershipRepository.insert(membership) != 1) {
|
||||||
|
throw businessException("SITE_MEMBERSHIP_CREATE_FAILED", SiteMessageKeys.MEMBERSHIP_CREATE_FAILED);
|
||||||
|
}
|
||||||
|
return toResponse(site, membership.getSiteRole());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 转换站点选项响应。 */
|
||||||
|
private SiteOptionAdminRes toResponse(SiteEntity site, String role) {
|
||||||
|
AdminSiteRoleEnum roleEnum = AdminSiteRoleEnum.valueOf(role);
|
||||||
|
return new SiteOptionAdminRes(site.getSiteCode(), site.getSiteName(), site.getIndustry(),
|
||||||
|
roleEnum.getValue(), roleEnum.getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建已完成多语言解析的业务异常。 */
|
||||||
|
private BusinessException businessException(String code, String key) {
|
||||||
|
return new BusinessException(code, messageSource.getMessage(key, null, LocaleContextHolder.getLocale()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import com.shoplix.admin.social.SocialMessageKeys;
|
|||||||
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
import com.shoplix.common.exception.BusinessException;
|
import com.shoplix.common.exception.BusinessException;
|
||||||
import com.shoplix.common.utils.BusinessCodeUtils;
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
|
||||||
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
||||||
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
@@ -22,17 +21,17 @@ import java.util.Set;
|
|||||||
@Service
|
@Service
|
||||||
public class AdminSocialChannelService {
|
public class AdminSocialChannelService {
|
||||||
private final SocialChannelRepositoryService repository;
|
private final SocialChannelRepositoryService repository;
|
||||||
private final AdminUserRepositoryService accountRepository;
|
private final AdminSiteAccessService accessService;
|
||||||
private final BusinessCodeUtils codeUtils;
|
private final BusinessCodeUtils codeUtils;
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
/** 注入社媒渠道配置依赖。 */
|
/** 注入社媒渠道配置依赖。 */
|
||||||
public AdminSocialChannelService(SocialChannelRepositoryService repository,
|
public AdminSocialChannelService(SocialChannelRepositoryService repository,
|
||||||
AdminUserRepositoryService accountRepository,
|
AdminSiteAccessService accessService,
|
||||||
BusinessCodeUtils codeUtils,
|
BusinessCodeUtils codeUtils,
|
||||||
MessageSource messageSource) {
|
MessageSource messageSource) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.accountRepository = accountRepository;
|
this.accessService = accessService;
|
||||||
this.codeUtils = codeUtils;
|
this.codeUtils = codeUtils;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
@@ -73,11 +72,7 @@ public class AdminSocialChannelService {
|
|||||||
|
|
||||||
/** 校验当前管理员是否归属目标站点。 */
|
/** 校验当前管理员是否归属目标站点。 */
|
||||||
private void validateSiteOwnership(String userCode, String siteCode) {
|
private void validateSiteOwnership(String userCode, String siteCode) {
|
||||||
var account = accountRepository.findByCode(userCode)
|
accessService.validateAccess(userCode, siteCode);
|
||||||
.orElseThrow(() -> businessException("ACCOUNT_NOT_FOUND", SocialMessageKeys.ACCOUNT_NOT_FOUND));
|
|
||||||
if (!siteCode.equals(account.getSiteCode())) {
|
|
||||||
throw businessException("SOCIAL_CHANNEL_ACCESS_DENIED", SocialMessageKeys.ACCESS_DENIED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建已完成多语言解析的业务异常。 */
|
/** 创建已完成多语言解析的业务异常。 */
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.shoplix.admin.modules.store.req.StoreProfileAdminReq;
|
|||||||
import com.shoplix.admin.modules.store.res.StoreProfileAdminRes;
|
import com.shoplix.admin.modules.store.res.StoreProfileAdminRes;
|
||||||
import com.shoplix.common.exception.BusinessException;
|
import com.shoplix.common.exception.BusinessException;
|
||||||
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
||||||
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
|
||||||
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
||||||
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -14,12 +13,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Service
|
@Service
|
||||||
public class AdminStoreService {
|
public class AdminStoreService {
|
||||||
private final SiteRepositoryService repository;
|
private final SiteRepositoryService repository;
|
||||||
private final AdminUserRepositoryService accountRepository;
|
private final AdminSiteAccessService accessService;
|
||||||
|
|
||||||
/** 注入站点数据源。 */
|
/** 注入站点数据源。 */
|
||||||
public AdminStoreService(SiteRepositoryService repository, AdminUserRepositoryService accountRepository) {
|
public AdminStoreService(SiteRepositoryService repository, AdminSiteAccessService accessService) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.accountRepository = accountRepository;
|
this.accessService = accessService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 查询店铺基本信息。 */
|
/** 查询店铺基本信息。 */
|
||||||
@@ -42,11 +41,7 @@ public class AdminStoreService {
|
|||||||
|
|
||||||
/** 校验当前管理员是否归属目标站点。 */
|
/** 校验当前管理员是否归属目标站点。 */
|
||||||
private void validateSiteOwnership(String userCode, String siteCode) {
|
private void validateSiteOwnership(String userCode, String siteCode) {
|
||||||
AdminUserEntity account = accountRepository.findByCode(userCode)
|
accessService.validateAccess(userCode, siteCode);
|
||||||
.orElseThrow(() -> new BusinessException("ACCOUNT_NOT_FOUND", "管理员账户不存在"));
|
|
||||||
if (!account.getSiteCode().equals(siteCode)) {
|
|
||||||
throw new BusinessException("STORE_ACCESS_DENIED", "无权访问该店铺");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取存在的站点。 */
|
/** 获取存在的站点。 */
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.shoplix.admin.site;
|
||||||
|
|
||||||
|
/** 站点管理多语言消息键。 */
|
||||||
|
public final class SiteMessageKeys {
|
||||||
|
/** 站点访问无权限。 */ public static final String ACCESS_DENIED = "site.access.denied";
|
||||||
|
/** 站点不存在。 */ public static final String NOT_FOUND = "site.not-found";
|
||||||
|
/** 站点创建失败。 */ public static final String CREATE_FAILED = "site.create-failed";
|
||||||
|
/** 站点关系创建失败。 */ public static final String MEMBERSHIP_CREATE_FAILED = "site.membership-create-failed";
|
||||||
|
|
||||||
|
/** 禁止实例化消息键类。 */ private SiteMessageKeys() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
CREATE TABLE admin_user_site (
|
||||||
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '数据库内部主键',
|
||||||
|
relation_code VARCHAR(16) NOT NULL COMMENT '用户站点关系业务编号',
|
||||||
|
user_code VARCHAR(16) NOT NULL COMMENT '管理员业务编号',
|
||||||
|
site_code VARCHAR(16) NOT NULL COMMENT '站点业务编号',
|
||||||
|
site_role VARCHAR(20) NOT NULL COMMENT '站点角色:OWNER所有者,ADMIN管理员',
|
||||||
|
status VARCHAR(20) NOT NULL COMMENT '关系状态:ENABLED启用,DISABLED停用',
|
||||||
|
deleted TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除状态:0未删除,1已删除',
|
||||||
|
create_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||||
|
update_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY uk_admin_user_site_relation_code (relation_code),
|
||||||
|
UNIQUE KEY uk_admin_user_site_user_site (user_code, site_code),
|
||||||
|
KEY idx_admin_user_site_site_status (site_code, status)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='管理员可访问站点关系';
|
||||||
|
|
||||||
|
INSERT INTO admin_user_site (relation_code, user_code, site_code, site_role, status, deleted)
|
||||||
|
SELECT CONCAT('UST', LPAD(id, 13, '0')), user_code, site_code, 'OWNER', 'ENABLED', 0
|
||||||
|
FROM admin_user
|
||||||
|
WHERE deleted = 0;
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
CREATE TABLE crm_customer (
|
||||||
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '数据库内部主键',
|
||||||
|
customer_code VARCHAR(16) NOT NULL COMMENT '客户业务编号',
|
||||||
|
site_code VARCHAR(16) NOT NULL COMMENT '所属站点业务编号',
|
||||||
|
company_name VARCHAR(200) NOT NULL DEFAULT '' COMMENT '公司名称,为空表示未填写',
|
||||||
|
contact_name VARCHAR(100) NOT NULL DEFAULT '' COMMENT '联系人姓名',
|
||||||
|
website VARCHAR(500) NOT NULL DEFAULT '' COMMENT '公司网站地址',
|
||||||
|
email VARCHAR(200) NOT NULL DEFAULT '' COMMENT '联系邮箱',
|
||||||
|
phone VARCHAR(60) NOT NULL DEFAULT '' COMMENT '联系电话',
|
||||||
|
country VARCHAR(100) NOT NULL DEFAULT '' COMMENT '所在国家或地区',
|
||||||
|
facebook_url VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'Facebook主页地址',
|
||||||
|
instagram_url VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'Instagram主页地址',
|
||||||
|
linkedin_url VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'LinkedIn主页地址',
|
||||||
|
whatsapp VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'WhatsApp账号或号码',
|
||||||
|
remark VARCHAR(2000) NOT NULL DEFAULT '' COMMENT '客户备注',
|
||||||
|
source VARCHAR(30) NOT NULL COMMENT '客户来源:MANUAL手工新增,IMPORT批量导入,INQUIRY询盘转化',
|
||||||
|
status VARCHAR(20) NOT NULL COMMENT '客户状态:ACTIVE有效,INACTIVE无效',
|
||||||
|
deleted TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除状态:0未删除,1已删除',
|
||||||
|
create_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||||
|
update_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY uk_crm_customer_code (customer_code),
|
||||||
|
KEY idx_crm_customer_site_status (site_code, status, deleted, id),
|
||||||
|
KEY idx_crm_customer_site_email (site_code, email, deleted)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='CRM客户';
|
||||||
|
|
||||||
|
CREATE TABLE crm_customer_tag (
|
||||||
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '数据库内部主键',
|
||||||
|
tag_code VARCHAR(16) NOT NULL COMMENT '客户标签业务编号',
|
||||||
|
site_code VARCHAR(16) NOT NULL COMMENT '所属站点业务编号',
|
||||||
|
tag_name VARCHAR(50) NOT NULL COMMENT '标签名称',
|
||||||
|
color VARCHAR(20) NOT NULL DEFAULT '#176b5b' COMMENT '标签展示颜色',
|
||||||
|
deleted TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除状态:0未删除,1已删除',
|
||||||
|
create_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||||
|
update_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY uk_crm_customer_tag_code (tag_code),
|
||||||
|
UNIQUE KEY uk_crm_customer_tag_site_name (site_code, tag_name),
|
||||||
|
KEY idx_crm_customer_tag_site (site_code, deleted, id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='CRM客户标签';
|
||||||
|
|
||||||
|
CREATE TABLE crm_customer_tag_relation (
|
||||||
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '数据库内部主键',
|
||||||
|
relation_code VARCHAR(16) NOT NULL COMMENT '客户标签关系业务编号',
|
||||||
|
site_code VARCHAR(16) NOT NULL COMMENT '所属站点业务编号',
|
||||||
|
customer_code VARCHAR(16) NOT NULL COMMENT '客户业务编号',
|
||||||
|
tag_code VARCHAR(16) NOT NULL COMMENT '客户标签业务编号',
|
||||||
|
deleted TINYINT NOT NULL DEFAULT 0 COMMENT '逻辑删除状态:0未删除,1已删除',
|
||||||
|
create_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||||
|
update_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY uk_crm_customer_tag_relation_code (relation_code),
|
||||||
|
UNIQUE KEY uk_crm_customer_tag_relation_customer_tag (site_code, customer_code, tag_code),
|
||||||
|
KEY idx_crm_customer_tag_relation_tag (site_code, tag_code, deleted)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='CRM客户标签关系';
|
||||||
@@ -10,3 +10,10 @@ product.template.unavailable=The selected product content template is unavailabl
|
|||||||
media.asset.not-found=The media asset was not found.
|
media.asset.not-found=The media asset was not found.
|
||||||
media.asset.tag-save-failed=Failed to save the media asset tag.
|
media.asset.tag-save-failed=Failed to save the media asset tag.
|
||||||
media.asset.delete-failed=Failed to delete the media asset.
|
media.asset.delete-failed=Failed to delete the media asset.
|
||||||
|
site.access.denied=You do not have access to this site.
|
||||||
|
site.not-found=The site was not found.
|
||||||
|
site.create-failed=Failed to create the site.
|
||||||
|
site.membership-create-failed=Failed to grant access to the new site.
|
||||||
|
crm.customer.not-found=Customer not found
|
||||||
|
crm.customer.save-failed=Failed to save customer
|
||||||
|
crm.tag.save-failed=Failed to save customer tag
|
||||||
@@ -10,3 +10,10 @@ product.template.unavailable=所选产品内容模板不可用。
|
|||||||
media.asset.not-found=素材不存在。
|
media.asset.not-found=素材不存在。
|
||||||
media.asset.tag-save-failed=素材标签保存失败。
|
media.asset.tag-save-failed=素材标签保存失败。
|
||||||
media.asset.delete-failed=素材删除失败。
|
media.asset.delete-failed=素材删除失败。
|
||||||
|
site.access.denied=无权访问该站点。
|
||||||
|
site.not-found=站点不存在。
|
||||||
|
site.create-failed=站点创建失败。
|
||||||
|
site.membership-create-failed=新站点访问权限创建失败。
|
||||||
|
crm.customer.not-found=客户不存在
|
||||||
|
crm.customer.save-failed=客户保存失败
|
||||||
|
crm.tag.save-failed=客户标签保存失败
|
||||||
@@ -10,3 +10,10 @@ product.template.unavailable=所選產品內容範本不可用。
|
|||||||
media.asset.not-found=素材不存在。
|
media.asset.not-found=素材不存在。
|
||||||
media.asset.tag-save-failed=素材標籤儲存失敗。
|
media.asset.tag-save-failed=素材標籤儲存失敗。
|
||||||
media.asset.delete-failed=素材刪除失敗。
|
media.asset.delete-failed=素材刪除失敗。
|
||||||
|
site.access.denied=無權存取該站點。
|
||||||
|
site.not-found=站點不存在。
|
||||||
|
site.create-failed=站點建立失敗。
|
||||||
|
site.membership-create-failed=新站點存取權限建立失敗。
|
||||||
|
crm.customer.not-found=客戶不存在
|
||||||
|
crm.customer.save-failed=客戶儲存失敗
|
||||||
|
crm.tag.save-failed=客戶標籤儲存失敗
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.shoplix.admin.service;
|
||||||
|
|
||||||
|
import com.shoplix.admin.modules.crm.req.SaveCrmCustomerAdminReq;
|
||||||
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerEntity;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerTagEntity;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerTagRelationEntity;
|
||||||
|
import com.shoplix.modules.crm.repository.service.CrmCustomerRepositoryService;
|
||||||
|
import com.shoplix.modules.crm.repository.service.CrmCustomerTagRepositoryService;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.context.support.StaticMessageSource;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/** 运营后台 CRM 客户业务测试。 */
|
||||||
|
class AdminCrmCustomerServiceTest {
|
||||||
|
/** 验证新增客户后会建立所选标签关系。 */
|
||||||
|
@Test
|
||||||
|
void shouldCreateCustomerWithSelectedTag() {
|
||||||
|
CrmCustomerRepositoryService customerRepository = mock(CrmCustomerRepositoryService.class);
|
||||||
|
CrmCustomerTagRepositoryService tagRepository = mock(CrmCustomerTagRepositoryService.class);
|
||||||
|
BusinessCodeUtils codes = mock(BusinessCodeUtils.class);
|
||||||
|
CrmCustomerTagEntity tag = new CrmCustomerTagEntity();
|
||||||
|
tag.setTagCode("CTG0000000000001");
|
||||||
|
when(tagRepository.listTags("site")).thenReturn(List.of(tag));
|
||||||
|
when(codes.generate(BusinessCodePrefixEnum.CUSTOMER)).thenReturn("CUS0000000000001");
|
||||||
|
when(codes.generate(BusinessCodePrefixEnum.CRM_TAG_RELATION)).thenReturn("CTR0000000000001");
|
||||||
|
when(customerRepository.insert(any(CrmCustomerEntity.class))).thenReturn(1);
|
||||||
|
when(tagRepository.insertRelation(any(CrmCustomerTagRelationEntity.class))).thenReturn(1);
|
||||||
|
AdminCrmCustomerService service = new AdminCrmCustomerService(
|
||||||
|
customerRepository, tagRepository, codes, new StaticMessageSource());
|
||||||
|
|
||||||
|
service.save(new SaveCrmCustomerAdminReq("site", "", "OpenAI", "张三",
|
||||||
|
"https://example.com", "sales@example.com", "13800000000", "中国",
|
||||||
|
"", "", "", "", "重点客户", List.of(tag.getTagCode())));
|
||||||
|
|
||||||
|
verify(customerRepository).insert(any(CrmCustomerEntity.class));
|
||||||
|
verify(tagRepository).insertRelation(any(CrmCustomerTagRelationEntity.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.shoplix.admin.service;
|
package com.shoplix.admin.service;
|
||||||
|
|
||||||
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaDeleteAdminReq;
|
||||||
|
import com.shoplix.admin.modules.media.req.MediaBatchDeleteAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaPageAdminReq;
|
||||||
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
import com.shoplix.admin.modules.media.req.MediaTagUpdateAdminReq;
|
||||||
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||||
@@ -127,4 +128,21 @@ class AdminMediaServiceTest {
|
|||||||
|
|
||||||
verify(repository).delete("site", entity.getMediaCode());
|
verify(repository).delete("site", entity.getMediaCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 验证批量删除会校验并删除当前站点的全部目标素材。 */
|
||||||
|
@Test
|
||||||
|
void shouldBatchDeleteMediaRecords() {
|
||||||
|
MediaAssetEntity first = new MediaAssetEntity();
|
||||||
|
first.setMediaCode("MED0000000000001");
|
||||||
|
MediaAssetEntity second = new MediaAssetEntity();
|
||||||
|
second.setMediaCode("MED0000000000002");
|
||||||
|
when(repository.find("site", first.getMediaCode())).thenReturn(Optional.of(first));
|
||||||
|
when(repository.find("site", second.getMediaCode())).thenReturn(Optional.of(second));
|
||||||
|
when(repository.deleteBatch("site", List.of(first.getMediaCode(), second.getMediaCode()))).thenReturn(2);
|
||||||
|
|
||||||
|
service.deleteBatch(new MediaBatchDeleteAdminReq(
|
||||||
|
"site", List.of(first.getMediaCode(), second.getMediaCode())));
|
||||||
|
|
||||||
|
verify(repository).deleteBatch("site", List.of(first.getMediaCode(), second.getMediaCode()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.shoplix.admin.service;
|
||||||
|
|
||||||
|
import com.shoplix.admin.modules.site.req.CreateSiteAdminReq;
|
||||||
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
|
import com.shoplix.modules.account.repository.entity.AdminUserSiteEntity;
|
||||||
|
import com.shoplix.modules.account.repository.service.AdminUserSiteRepositoryService;
|
||||||
|
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
||||||
|
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.springframework.context.support.StaticMessageSource;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/** 多站点管理业务测试。 */
|
||||||
|
class AdminSiteServiceTest {
|
||||||
|
/** 站点数据源模拟。 */ private SiteRepositoryService siteRepository;
|
||||||
|
/** 用户站点关系数据源模拟。 */ private AdminUserSiteRepositoryService membershipRepository;
|
||||||
|
/** 被测试多站点业务。 */ private AdminSiteService service;
|
||||||
|
|
||||||
|
/** 初始化多站点业务依赖。 */
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
siteRepository = mock(SiteRepositoryService.class);
|
||||||
|
membershipRepository = mock(AdminUserSiteRepositoryService.class);
|
||||||
|
when(siteRepository.insert(any())).thenReturn(1);
|
||||||
|
when(membershipRepository.insert(any())).thenReturn(1);
|
||||||
|
service = new AdminSiteService(siteRepository, membershipRepository,
|
||||||
|
new BusinessCodeUtils(1), new StaticMessageSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建站点时应同时授予当前管理员所有者权限。 */
|
||||||
|
@Test
|
||||||
|
void shouldCreateSiteAndOwnerMembership() {
|
||||||
|
var result = service.create("USR0000000000001",
|
||||||
|
new CreateSiteAdminReq("第二站点", "工业设备", "第二个独立站", "Asia/Shanghai"));
|
||||||
|
|
||||||
|
ArgumentCaptor<SiteEntity> siteCaptor = ArgumentCaptor.forClass(SiteEntity.class);
|
||||||
|
verify(siteRepository).insert(siteCaptor.capture());
|
||||||
|
assertThat(siteCaptor.getValue().getSiteName()).isEqualTo("第二站点");
|
||||||
|
assertThat(siteCaptor.getValue().getStatus()).isEqualTo("ENABLED");
|
||||||
|
|
||||||
|
ArgumentCaptor<AdminUserSiteEntity> membershipCaptor = ArgumentCaptor.forClass(AdminUserSiteEntity.class);
|
||||||
|
verify(membershipRepository).insert(membershipCaptor.capture());
|
||||||
|
assertThat(membershipCaptor.getValue().getSiteRole()).isEqualTo("OWNER");
|
||||||
|
assertThat(membershipCaptor.getValue().getSiteCode()).isEqualTo(result.siteCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,6 @@ package com.shoplix.admin.service;
|
|||||||
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
|
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
|
||||||
import com.shoplix.admin.modules.social.req.SocialChannelAdminReq;
|
import com.shoplix.admin.modules.social.req.SocialChannelAdminReq;
|
||||||
import com.shoplix.common.utils.BusinessCodeUtils;
|
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||||
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
|
||||||
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
|
|
||||||
import com.shoplix.modules.social.enums.SocialPlatformEnum;
|
import com.shoplix.modules.social.enums.SocialPlatformEnum;
|
||||||
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
|
||||||
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
|
||||||
@@ -15,7 +13,6 @@ import org.springframework.context.support.StaticMessageSource;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -35,14 +32,11 @@ class AdminSocialChannelServiceTest {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
repository = mock(SocialChannelRepositoryService.class);
|
repository = mock(SocialChannelRepositoryService.class);
|
||||||
AdminUserRepositoryService accountRepository = mock(AdminUserRepositoryService.class);
|
AdminSiteAccessService accessService = mock(AdminSiteAccessService.class);
|
||||||
AdminUserEntity account = new AdminUserEntity();
|
|
||||||
account.setSiteCode(SITE_CODE);
|
|
||||||
when(accountRepository.findByCode("USR001")).thenReturn(Optional.of(account));
|
|
||||||
StaticMessageSource messageSource = new StaticMessageSource();
|
StaticMessageSource messageSource = new StaticMessageSource();
|
||||||
messageSource.addMessage("social.channel.platform.duplicated", Locale.getDefault(), "duplicated");
|
messageSource.addMessage("social.channel.platform.duplicated", Locale.getDefault(), "duplicated");
|
||||||
messageSource.addMessage("social.channel.save.failed", Locale.getDefault(), "save failed");
|
messageSource.addMessage("social.channel.save.failed", Locale.getDefault(), "save failed");
|
||||||
service = new AdminSocialChannelService(repository, accountRepository, new BusinessCodeUtils(1), messageSource);
|
service = new AdminSocialChannelService(repository, accessService, new BusinessCodeUtils(1), messageSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 保存时应完整映射展示位置开关并物理替换旧配置。 */
|
/** 保存时应完整映射展示位置开关并物理替换旧配置。 */
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ public enum BusinessCodePrefixEnum {
|
|||||||
INQUIRY_SETTING("IST"), INQUIRY_FIELD_VALUE("IFV"), INQUIRY_ATTACHMENT("IAT"),
|
INQUIRY_SETTING("IST"), INQUIRY_FIELD_VALUE("IFV"), INQUIRY_ATTACHMENT("IAT"),
|
||||||
INQUIRY_LOG("ILG"), INQUIRY_RECEIVER("IRC"), MAIL_TASK("MLT"), CUSTOMER("CUS"),
|
INQUIRY_LOG("ILG"), INQUIRY_RECEIVER("IRC"), MAIL_TASK("MLT"), CUSTOMER("CUS"),
|
||||||
CONTACT("CON"), LEAD("LED"), FOLLOW_UP("FLW"), MEDIA("MED"), SEO("SEO"), SEO_HEADING("SEH"),
|
CONTACT("CON"), LEAD("LED"), FOLLOW_UP("FLW"), MEDIA("MED"), SEO("SEO"), SEO_HEADING("SEH"),
|
||||||
PUBLISH("PUB"), JOB("JOB"), USER("USR"), ROLE("ROL"), FLOW_LOG("FLO"), SOCIAL_CHANNEL("SOC");
|
PUBLISH("PUB"), JOB("JOB"), USER("USR"), USER_SITE("UST"), ROLE("ROL"), FLOW_LOG("FLO"), SOCIAL_CHANNEL("SOC"),
|
||||||
|
CRM_TAG("CTG"), CRM_TAG_RELATION("CTR");
|
||||||
|
|
||||||
/** 三位业务前缀。 */
|
/** 三位业务前缀。 */
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package com.shoplix.modules.account.enums;
|
||||||
|
|
||||||
|
/** 管理员站点关系状态。 */
|
||||||
|
public enum AdminSiteMembershipStatusEnum {
|
||||||
|
/** 启用。 */ ENABLED("ENABLED", "启用"),
|
||||||
|
/** 停用。 */ DISABLED("DISABLED", "停用");
|
||||||
|
|
||||||
|
/** 状态值。 */ private final String value;
|
||||||
|
/** 状态文案。 */ private final String label;
|
||||||
|
|
||||||
|
/** 创建关系状态。 */
|
||||||
|
AdminSiteMembershipStatusEnum(String value, String label) { this.value = value; this.label = label; }
|
||||||
|
|
||||||
|
/** 获取状态值。 */ public String getValue() { return value; }
|
||||||
|
/** 获取状态文案。 */ public String getLabel() { return label; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.shoplix.modules.account.enums;
|
||||||
|
|
||||||
|
/** 管理员在站点中的角色。 */
|
||||||
|
public enum AdminSiteRoleEnum {
|
||||||
|
/** 站点所有者。 */ OWNER("OWNER", "所有者"),
|
||||||
|
/** 站点管理员。 */ ADMIN("ADMIN", "管理员");
|
||||||
|
|
||||||
|
/** 角色值。 */ private final String value;
|
||||||
|
/** 角色文案。 */ private final String label;
|
||||||
|
|
||||||
|
/** 创建站点角色。 */
|
||||||
|
AdminSiteRoleEnum(String value, String label) { this.value = value; this.label = label; }
|
||||||
|
|
||||||
|
/** 获取角色值。 */ public String getValue() { return value; }
|
||||||
|
/** 获取角色文案。 */ public String getLabel() { return label; }
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package com.shoplix.modules.account.repository.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/** 管理员可访问站点关系持久化实体。 */
|
||||||
|
@Data
|
||||||
|
@TableName("admin_user_site")
|
||||||
|
public class AdminUserSiteEntity {
|
||||||
|
/** 数据库内部主键。 */ @TableId(type = IdType.AUTO) private Long id;
|
||||||
|
/** 用户站点关系业务编号。 */ private String relationCode;
|
||||||
|
/** 管理员业务编号。 */ private String userCode;
|
||||||
|
/** 站点业务编号。 */ private String siteCode;
|
||||||
|
/** 站点角色:OWNER所有者,ADMIN管理员。 */ private String siteRole;
|
||||||
|
/** 关系状态:ENABLED启用,DISABLED停用。 */ private String status;
|
||||||
|
/** 逻辑删除状态:0未删除,1已删除。 */ private Integer deleted;
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package com.shoplix.modules.account.repository.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shoplix.modules.account.repository.entity.AdminUserSiteEntity;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/** 管理员可访问站点关系 Mapper。 */
|
||||||
|
@Mapper
|
||||||
|
public interface AdminUserSiteMapper extends BaseMapper<AdminUserSiteEntity> {}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.shoplix.modules.account.repository.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.shoplix.modules.account.enums.AdminSiteMembershipStatusEnum;
|
||||||
|
import com.shoplix.modules.account.repository.entity.AdminUserSiteEntity;
|
||||||
|
import com.shoplix.modules.account.repository.mapper.AdminUserSiteMapper;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/** 管理员可访问站点关系单表数据源服务。 */
|
||||||
|
@Service
|
||||||
|
public class AdminUserSiteRepositoryService {
|
||||||
|
/** 用户站点关系 Mapper。 */ private final AdminUserSiteMapper mapper;
|
||||||
|
|
||||||
|
/** 注入用户站点关系 Mapper。 */
|
||||||
|
public AdminUserSiteRepositoryService(AdminUserSiteMapper mapper) { this.mapper = mapper; }
|
||||||
|
|
||||||
|
/** 查询管理员全部启用站点关系。 */
|
||||||
|
public List<AdminUserSiteEntity> listEnabled(String userCode) {
|
||||||
|
return mapper.selectList(Wrappers.<AdminUserSiteEntity>lambdaQuery()
|
||||||
|
.eq(AdminUserSiteEntity::getUserCode, userCode)
|
||||||
|
.eq(AdminUserSiteEntity::getStatus, AdminSiteMembershipStatusEnum.ENABLED.getValue())
|
||||||
|
.eq(AdminUserSiteEntity::getDeleted, 0)
|
||||||
|
.orderByAsc(AdminUserSiteEntity::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 判断管理员是否可以访问目标站点。 */
|
||||||
|
public boolean canAccess(String userCode, String siteCode) {
|
||||||
|
return mapper.selectCount(Wrappers.<AdminUserSiteEntity>lambdaQuery()
|
||||||
|
.eq(AdminUserSiteEntity::getUserCode, userCode)
|
||||||
|
.eq(AdminUserSiteEntity::getSiteCode, siteCode)
|
||||||
|
.eq(AdminUserSiteEntity::getStatus, AdminSiteMembershipStatusEnum.ENABLED.getValue())
|
||||||
|
.eq(AdminUserSiteEntity::getDeleted, 0)) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增管理员站点关系。 */
|
||||||
|
public int insert(AdminUserSiteEntity entity) { return mapper.insert(entity); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.shoplix.modules.crm.enums;
|
||||||
|
|
||||||
|
/** CRM客户来源。 */
|
||||||
|
public enum CrmCustomerSourceEnum {
|
||||||
|
/** 手工新增。 */ MANUAL,
|
||||||
|
/** 批量导入。 */ IMPORT,
|
||||||
|
/** 询盘转化。 */ INQUIRY
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.shoplix.modules.crm.enums;
|
||||||
|
|
||||||
|
/** CRM客户状态。 */
|
||||||
|
public enum CrmCustomerStatusEnum {
|
||||||
|
/** 有效客户。 */ ACTIVE,
|
||||||
|
/** 无效客户。 */ INACTIVE
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/** CRM客户持久化实体。 */
|
||||||
|
@Data
|
||||||
|
@TableName("crm_customer")
|
||||||
|
public class CrmCustomerEntity {
|
||||||
|
/** 数据库内部主键。 */ @TableId(type = IdType.AUTO) private Long id;
|
||||||
|
/** 客户业务编号。 */ private String customerCode;
|
||||||
|
/** 所属站点业务编号。 */ private String siteCode;
|
||||||
|
/** 公司名称。 */ private String companyName;
|
||||||
|
/** 联系人姓名。 */ private String contactName;
|
||||||
|
/** 公司网站。 */ private String website;
|
||||||
|
/** 联系邮箱。 */ private String email;
|
||||||
|
/** 联系电话。 */ private String phone;
|
||||||
|
/** 国家或地区。 */ private String country;
|
||||||
|
/** Facebook主页。 */ private String facebookUrl;
|
||||||
|
/** Instagram主页。 */ private String instagramUrl;
|
||||||
|
/** LinkedIn主页。 */ private String linkedinUrl;
|
||||||
|
/** WhatsApp账号。 */ private String whatsapp;
|
||||||
|
/** 客户备注。 */ private String remark;
|
||||||
|
/** 客户来源。 */ private String source;
|
||||||
|
/** 客户状态。 */ private String status;
|
||||||
|
/** 逻辑删除状态。 */ private Integer deleted;
|
||||||
|
/** 创建时间。 */ private java.time.LocalDateTime createTime;
|
||||||
|
/** 更新时间。 */ private java.time.LocalDateTime updateTime;
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/** CRM客户标签持久化实体。 */
|
||||||
|
@Data
|
||||||
|
@TableName("crm_customer_tag")
|
||||||
|
public class CrmCustomerTagEntity {
|
||||||
|
/** 数据库内部主键。 */ @TableId(type = IdType.AUTO) private Long id;
|
||||||
|
/** 标签业务编号。 */ private String tagCode;
|
||||||
|
/** 所属站点业务编号。 */ private String siteCode;
|
||||||
|
/** 标签名称。 */ private String tagName;
|
||||||
|
/** 标签颜色。 */ private String color;
|
||||||
|
/** 逻辑删除状态。 */ private Integer deleted;
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/** CRM客户标签关系持久化实体。 */
|
||||||
|
@Data
|
||||||
|
@TableName("crm_customer_tag_relation")
|
||||||
|
public class CrmCustomerTagRelationEntity {
|
||||||
|
/** 数据库内部主键。 */ @TableId(type = IdType.AUTO) private Long id;
|
||||||
|
/** 关系业务编号。 */ private String relationCode;
|
||||||
|
/** 所属站点业务编号。 */ private String siteCode;
|
||||||
|
/** 客户业务编号。 */ private String customerCode;
|
||||||
|
/** 标签业务编号。 */ private String tagCode;
|
||||||
|
/** 逻辑删除状态。 */ private Integer deleted;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.mapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerEntity;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
/** CRM客户 Mapper。 */ @Mapper public interface CrmCustomerMapper extends BaseMapper<CrmCustomerEntity> { }
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.mapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerTagEntity;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
/** CRM客户标签 Mapper。 */ @Mapper public interface CrmCustomerTagMapper extends BaseMapper<CrmCustomerTagEntity> { }
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.mapper;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerTagRelationEntity;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
/** CRM客户标签关系 Mapper。 */ @Mapper public interface CrmCustomerTagRelationMapper extends BaseMapper<CrmCustomerTagRelationEntity> { }
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerEntity;
|
||||||
|
import com.shoplix.modules.crm.repository.mapper.CrmCustomerMapper;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/** CRM客户单表数据源服务。 */
|
||||||
|
@Service
|
||||||
|
public class CrmCustomerRepositoryService {
|
||||||
|
/** CRM客户 Mapper。 */ private final CrmCustomerMapper mapper;
|
||||||
|
/** 注入 CRM 客户 Mapper。 */ public CrmCustomerRepositoryService(CrmCustomerMapper mapper) { this.mapper = mapper; }
|
||||||
|
/** 分页查询当前站点客户。 */
|
||||||
|
public List<CrmCustomerEntity> page(String siteCode, String keyword, int pageNo, int pageSize) {
|
||||||
|
var query = query(siteCode, keyword);
|
||||||
|
return mapper.selectList(query.orderByDesc(CrmCustomerEntity::getId)
|
||||||
|
.last("LIMIT " + pageSize + " OFFSET " + (long) (pageNo - 1) * pageSize));
|
||||||
|
}
|
||||||
|
/** 统计当前站点客户。 */ public long count(String siteCode, String keyword) { return mapper.selectCount(query(siteCode, keyword)); }
|
||||||
|
/** 按业务编号查询当前站点客户。 */
|
||||||
|
public Optional<CrmCustomerEntity> find(String siteCode, String customerCode) {
|
||||||
|
return Optional.ofNullable(mapper.selectOne(Wrappers.<CrmCustomerEntity>lambdaQuery()
|
||||||
|
.eq(CrmCustomerEntity::getSiteCode, siteCode).eq(CrmCustomerEntity::getCustomerCode, customerCode)
|
||||||
|
.eq(CrmCustomerEntity::getDeleted, 0)));
|
||||||
|
}
|
||||||
|
/** 新增客户。 */ public int insert(CrmCustomerEntity entity) { return mapper.insert(entity); }
|
||||||
|
/** 更新当前站点客户。 */
|
||||||
|
public int update(CrmCustomerEntity entity) { return mapper.update(entity, Wrappers.<CrmCustomerEntity>lambdaUpdate()
|
||||||
|
.eq(CrmCustomerEntity::getSiteCode, entity.getSiteCode()).eq(CrmCustomerEntity::getCustomerCode, entity.getCustomerCode())
|
||||||
|
.eq(CrmCustomerEntity::getDeleted, 0)); }
|
||||||
|
/** 构造客户搜索条件。 */
|
||||||
|
private com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<CrmCustomerEntity> query(String siteCode, String keyword) {
|
||||||
|
var query = Wrappers.<CrmCustomerEntity>lambdaQuery().eq(CrmCustomerEntity::getSiteCode, siteCode).eq(CrmCustomerEntity::getDeleted, 0);
|
||||||
|
if (keyword != null && !keyword.isBlank()) query.and(item -> item.like(CrmCustomerEntity::getCompanyName, keyword.trim())
|
||||||
|
.or().like(CrmCustomerEntity::getContactName, keyword.trim()).or().like(CrmCustomerEntity::getEmail, keyword.trim()));
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.shoplix.modules.crm.repository.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerTagEntity;
|
||||||
|
import com.shoplix.modules.crm.repository.entity.CrmCustomerTagRelationEntity;
|
||||||
|
import com.shoplix.modules.crm.repository.mapper.CrmCustomerTagMapper;
|
||||||
|
import com.shoplix.modules.crm.repository.mapper.CrmCustomerTagRelationMapper;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/** CRM客户标签单表数据源服务。 */
|
||||||
|
@Service
|
||||||
|
public class CrmCustomerTagRepositoryService {
|
||||||
|
/** 标签 Mapper。 */ private final CrmCustomerTagMapper tagMapper;
|
||||||
|
/** 标签关系 Mapper。 */ private final CrmCustomerTagRelationMapper relationMapper;
|
||||||
|
/** 注入 CRM 客户标签 Mapper。 */
|
||||||
|
public CrmCustomerTagRepositoryService(CrmCustomerTagMapper tagMapper, CrmCustomerTagRelationMapper relationMapper) { this.tagMapper = tagMapper; this.relationMapper = relationMapper; }
|
||||||
|
/** 查询站点全部标签。 */ public List<CrmCustomerTagEntity> listTags(String siteCode) { return tagMapper.selectList(Wrappers.<CrmCustomerTagEntity>lambdaQuery().eq(CrmCustomerTagEntity::getSiteCode, siteCode).eq(CrmCustomerTagEntity::getDeleted, 0).orderByAsc(CrmCustomerTagEntity::getId)); }
|
||||||
|
/** 查询客户标签关系。 */ public List<CrmCustomerTagRelationEntity> listRelations(String siteCode, List<String> customerCodes) { if (customerCodes.isEmpty()) return List.of(); return relationMapper.selectList(Wrappers.<CrmCustomerTagRelationEntity>lambdaQuery().eq(CrmCustomerTagRelationEntity::getSiteCode, siteCode).in(CrmCustomerTagRelationEntity::getCustomerCode, customerCodes).eq(CrmCustomerTagRelationEntity::getDeleted, 0)); }
|
||||||
|
/** 新增标签。 */ public int insertTag(CrmCustomerTagEntity entity) { return tagMapper.insert(entity); }
|
||||||
|
/** 新增客户标签关系。 */ public int insertRelation(CrmCustomerTagRelationEntity entity) { return relationMapper.insert(entity); }
|
||||||
|
/** 清除客户全部标签关系。 */ public void deleteRelations(String siteCode, String customerCode) { relationMapper.delete(Wrappers.<CrmCustomerTagRelationEntity>lambdaQuery().eq(CrmCustomerTagRelationEntity::getSiteCode, siteCode).eq(CrmCustomerTagRelationEntity::getCustomerCode, customerCode)); }
|
||||||
|
}
|
||||||
+9
@@ -84,6 +84,15 @@ public class MediaAssetRepositoryService {
|
|||||||
.eq(MediaAssetEntity::getDeleted, 0));
|
.eq(MediaAssetEntity::getDeleted, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 按业务编号批量逻辑删除素材。 */
|
||||||
|
public int deleteBatch(String siteCode, List<String> mediaCodes) {
|
||||||
|
return mapper.update(null, Wrappers.<MediaAssetEntity>lambdaUpdate()
|
||||||
|
.set(MediaAssetEntity::getDeleted, 1)
|
||||||
|
.eq(MediaAssetEntity::getSiteCode, siteCode)
|
||||||
|
.in(MediaAssetEntity::getMediaCode, mediaCodes)
|
||||||
|
.eq(MediaAssetEntity::getDeleted, 0));
|
||||||
|
}
|
||||||
|
|
||||||
/** 构造素材中心公共筛选条件。 */
|
/** 构造素材中心公共筛选条件。 */
|
||||||
private LambdaQueryWrapper<MediaAssetEntity> buildQuery(String siteCode, String mediaType,
|
private LambdaQueryWrapper<MediaAssetEntity> buildQuery(String siteCode, String mediaType,
|
||||||
String keyword, String tagName) {
|
String keyword, String tagName) {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.shoplix.modules.site.enums;
|
||||||
|
|
||||||
|
/** 站点启停状态。 */
|
||||||
|
public enum SiteStatusEnum {
|
||||||
|
/** 启用。 */ ENABLED("ENABLED", "启用"),
|
||||||
|
/** 停用。 */ DISABLED("DISABLED", "停用");
|
||||||
|
|
||||||
|
/** 状态值。 */ private final String value;
|
||||||
|
/** 状态文案。 */ private final String label;
|
||||||
|
|
||||||
|
/** 创建站点状态。 */
|
||||||
|
SiteStatusEnum(String value, String label) { this.value = value; this.label = label; }
|
||||||
|
|
||||||
|
/** 获取状态值。 */ public String getValue() { return value; }
|
||||||
|
/** 获取状态文案。 */ public String getLabel() { return label; }
|
||||||
|
}
|
||||||
+13
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||||||
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
||||||
import com.shoplix.modules.site.repository.mapper.SiteMapper;
|
import com.shoplix.modules.site.repository.mapper.SiteMapper;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.List;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/** 站点基本信息单表数据源服务。 */
|
/** 站点基本信息单表数据源服务。 */
|
||||||
@@ -20,6 +21,18 @@ public class SiteRepositoryService {
|
|||||||
.eq(SiteEntity::getSiteCode, siteCode)));
|
.eq(SiteEntity::getSiteCode, siteCode)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 按业务编号批量查询站点。 */
|
||||||
|
public List<SiteEntity> listByCodes(List<String> siteCodes) {
|
||||||
|
if (siteCodes.isEmpty()) return List.of();
|
||||||
|
return mapper.selectList(Wrappers.<SiteEntity>lambdaQuery()
|
||||||
|
.in(SiteEntity::getSiteCode, siteCodes)
|
||||||
|
.eq(SiteEntity::getDeleted, 0)
|
||||||
|
.orderByAsc(SiteEntity::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增站点。 */
|
||||||
|
public int insert(SiteEntity entity) { return mapper.insert(entity); }
|
||||||
|
|
||||||
/** 更新店铺基本信息。 */
|
/** 更新店铺基本信息。 */
|
||||||
public int updateProfile(SiteEntity entity) {
|
public int updateProfile(SiteEntity entity) {
|
||||||
return mapper.update(null, Wrappers.<SiteEntity>lambdaUpdate()
|
return mapper.update(null, Wrappers.<SiteEntity>lambdaUpdate()
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import PageEditor from "./PageEditor";
|
import PageEditor from "./PageEditor";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
|
|
||||||
/** 关于我们固定页面设置入口。 */
|
/** 关于我们固定页面设置入口。 */
|
||||||
export default function AboutUsSettingsPage() {
|
export default function AboutUsSettingsPage() {
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import { EditorContent, useEditor } from "@tiptap/react";
|
|||||||
import StarterKit from "@tiptap/starter-kit";
|
import StarterKit from "@tiptap/starter-kit";
|
||||||
import Link from "@tiptap/extension-link";
|
import Link from "@tiptap/extension-link";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
const AGREEMENT_PUBLISH_STATUS = "PUBLISHED";
|
const AGREEMENT_PUBLISH_STATUS = "PUBLISHED";
|
||||||
type AgreementKey = "COOKIE_POLICY" | "PRIVACY_POLICY" | "TERMS_OF_SERVICE";
|
type AgreementKey = "COOKIE_POLICY" | "PRIVACY_POLICY" | "TERMS_OF_SERVICE";
|
||||||
type AgreementTab = { key: AgreementKey; label: string; pageName: string; slug: string; seoDescription:string; robots:string };
|
type AgreementTab = { key: AgreementKey; label: string; pageName: string; slug: string; seoDescription:string; robots:string };
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ import {
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type ContentType = "NEWS" | "CASE" | "HELP";
|
type ContentType = "NEWS" | "CASE" | "HELP";
|
||||||
type Category = {
|
type Category = {
|
||||||
categoryCode: string;
|
categoryCode: string;
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ import {
|
|||||||
X,
|
X,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { API, assetUrl } from "./api";
|
import { API, assetUrl } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type ContentType = "NEWS" | "CASE" | "HELP";
|
type ContentType = "NEWS" | "CASE" | "HELP";
|
||||||
type Heading = { level: number; text: string; sortNo: number };
|
type Heading = { level: number; text: string; sortNo: number };
|
||||||
type MediaItem = {
|
type MediaItem = {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
.crm-page{max-width:1500px;margin:auto}.crm-actions{display:flex;gap:9px}.crm-actions .secondary,.crm-import{height:40px;border:1px solid #d5dce2;background:#fff;color:#34424d;border-radius:6px;padding:0 14px;display:inline-flex;align-items:center;gap:7px;font-weight:600;cursor:pointer}.crm-import input{display:none}.crm-toolbar{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}.crm-toolbar form{width:min(540px,60vw);height:42px;display:flex;align-items:center;gap:8px;border:1px solid #d9e0e5;background:#fff;border-radius:6px;padding-left:12px}.crm-toolbar input{min-width:0;flex:1;border:0;outline:0}.crm-toolbar button{height:100%;border:0;border-left:1px solid #e1e6e9;background:#f8faf9;padding:0 18px}.crm-toolbar>span{color:#718087}.crm-table{background:#fff;border:1px solid #dfe5e9;border-radius:6px;overflow:hidden}.crm-row{display:grid;grid-template-columns:1.35fr 1.35fr .7fr 1.2fr .5fr .6fr;gap:16px;align-items:center;min-height:72px;padding:12px 18px;border-bottom:1px solid #edf0f2}.crm-row:last-child{border:0}.crm-head{min-height:44px;background:#f8fafb;color:#6d7983;font-size:12px;font-weight:600}.crm-row>div{min-width:0;display:grid;gap:4px}.crm-row strong,.crm-row small,.crm-row span{overflow:hidden;text-overflow:ellipsis}.crm-row small{color:#839099}.crm-social{display:flex!important;grid-auto-flow:column;justify-content:start}.crm-social a{width:30px;height:30px;display:grid;place-items:center;border:1px solid #dce3e0;border-radius:4px;color:#176b5b}.crm-social svg{width:15px}.crm-tags{display:flex!important;flex-wrap:wrap;gap:5px}.crm-tags span{border:1px solid;border-radius:12px;padding:2px 7px;font-size:11px}.crm-empty{padding:70px;text-align:center;color:#839099}.crm-pages{display:flex;justify-content:center;align-items:center;gap:12px;margin-top:18px}.crm-pages button{border:1px solid #d5ddda;background:#fff;padding:8px 14px;border-radius:4px}.crm-dialog{width:min(850px,100%)}.crm-tag-dialog{width:min(520px,100%)}.crm-tag-options{border:1px solid #d9dee5;border-radius:5px;padding:12px;display:flex!important;flex-wrap:wrap;gap:12px!important}.crm-tag-options legend{font-size:13px;font-weight:600;padding:0 5px}.crm-tag-options label{display:flex!important;align-items:center;gap:6px}.crm-tag-options input{width:16px;height:16px}.crm-tag-options span{font-weight:500!important}@media(max-width:900px){.crm-row{grid-template-columns:1fr 1fr}.crm-head{display:none}.crm-actions{flex-wrap:wrap}.crm-toolbar{align-items:flex-start;gap:10px}.crm-toolbar form{width:100%}}
|
||||||
@@ -0,0 +1,490 @@
|
|||||||
|
import { FormEvent, useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
Facebook,
|
||||||
|
Globe2,
|
||||||
|
Instagram,
|
||||||
|
Linkedin,
|
||||||
|
Plus,
|
||||||
|
Search,
|
||||||
|
Tags,
|
||||||
|
Upload,
|
||||||
|
X,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { apiPost } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
import "./CrmCustomerPage.css";
|
||||||
|
|
||||||
|
type Tag = { tagCode: string; tagName: string; color: string };
|
||||||
|
type Customer = {
|
||||||
|
customerCode: string;
|
||||||
|
companyName: string;
|
||||||
|
contactName: string;
|
||||||
|
website: string;
|
||||||
|
email: string;
|
||||||
|
phone: string;
|
||||||
|
country: string;
|
||||||
|
facebookUrl: string;
|
||||||
|
instagramUrl: string;
|
||||||
|
linkedinUrl: string;
|
||||||
|
whatsapp: string;
|
||||||
|
remark: string;
|
||||||
|
source: string;
|
||||||
|
status: string;
|
||||||
|
tags: Tag[];
|
||||||
|
createTime: string;
|
||||||
|
};
|
||||||
|
const SITE = getCurrentSiteCode();
|
||||||
|
const emptyForm = {
|
||||||
|
customerCode: "",
|
||||||
|
companyName: "",
|
||||||
|
contactName: "",
|
||||||
|
website: "",
|
||||||
|
email: "",
|
||||||
|
phone: "",
|
||||||
|
country: "",
|
||||||
|
facebookUrl: "",
|
||||||
|
instagramUrl: "",
|
||||||
|
linkedinUrl: "",
|
||||||
|
whatsapp: "",
|
||||||
|
remark: "",
|
||||||
|
tagCodes: [] as string[],
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 解析支持引号转义的 CSV 文本。 */
|
||||||
|
function parseCsv(text: string): string[][] {
|
||||||
|
const rows: string[][] = [];
|
||||||
|
let row: string[] = [];
|
||||||
|
let value = "";
|
||||||
|
let quoted = false;
|
||||||
|
for (let index = 0; index < text.length; index += 1) {
|
||||||
|
const char = text[index];
|
||||||
|
if (char === '"' && quoted && text[index + 1] === '"') {
|
||||||
|
value += '"';
|
||||||
|
index += 1;
|
||||||
|
} else if (char === '"') quoted = !quoted;
|
||||||
|
else if (char === "," && !quoted) {
|
||||||
|
row.push(value.trim());
|
||||||
|
value = "";
|
||||||
|
} else if ((char === "\n" || char === "\r") && !quoted) {
|
||||||
|
if (char === "\r" && text[index + 1] === "\n") index += 1;
|
||||||
|
row.push(value.trim());
|
||||||
|
if (row.some(Boolean)) rows.push(row);
|
||||||
|
row = [];
|
||||||
|
value = "";
|
||||||
|
} else value += char;
|
||||||
|
}
|
||||||
|
row.push(value.trim());
|
||||||
|
if (row.some(Boolean)) rows.push(row);
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** CRM 客户管理页面。 */
|
||||||
|
export default function CrmCustomerPage() {
|
||||||
|
const [items, setItems] = useState<Customer[]>([]);
|
||||||
|
const [tags, setTags] = useState<Tag[]>([]);
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [pageNo, setPageNo] = useState(1);
|
||||||
|
const [total, setTotal] = useState(0);
|
||||||
|
const [totalPages, setTotalPages] = useState(0);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [dialog, setDialog] = useState(false);
|
||||||
|
const [form, setForm] = useState(emptyForm);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [tagDialog, setTagDialog] = useState(false);
|
||||||
|
const [tagForm, setTagForm] = useState({ tagName: "", color: "#176b5b" });
|
||||||
|
const [importing, setImporting] = useState(false);
|
||||||
|
/** 加载客户分页。 */ const load = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
setError("");
|
||||||
|
const data = await apiPost<{
|
||||||
|
items: Customer[];
|
||||||
|
total: number;
|
||||||
|
totalPages: number;
|
||||||
|
tags: Tag[];
|
||||||
|
}>("/crm/customers/page", {
|
||||||
|
siteCode: SITE,
|
||||||
|
keyword: query.trim(),
|
||||||
|
pageNo,
|
||||||
|
pageSize: 20,
|
||||||
|
});
|
||||||
|
setItems(data.items);
|
||||||
|
setTags(data.tags);
|
||||||
|
setTotal(data.total);
|
||||||
|
setTotalPages(data.totalPages);
|
||||||
|
} catch (reason) {
|
||||||
|
setError(reason instanceof Error ? reason.message : "客户加载失败");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [pageNo]);
|
||||||
|
/** 打开新增或编辑客户弹窗。 */ const edit = (customer?: Customer) => {
|
||||||
|
setForm(
|
||||||
|
customer
|
||||||
|
? { ...customer, tagCodes: customer.tags.map((tag) => tag.tagCode) }
|
||||||
|
: emptyForm,
|
||||||
|
);
|
||||||
|
setDialog(true);
|
||||||
|
};
|
||||||
|
/** 保存客户资料。 */ const save = async (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
try {
|
||||||
|
setSaving(true);
|
||||||
|
setError("");
|
||||||
|
await apiPost("/crm/customers/save", { siteCode: SITE, ...form });
|
||||||
|
setDialog(false);
|
||||||
|
await load();
|
||||||
|
} catch (reason) {
|
||||||
|
setError(reason instanceof Error ? reason.message : "客户保存失败");
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** 创建客户标签。 */ const createTag = async (event: FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
try {
|
||||||
|
await apiPost("/crm/customers/tags/create", {
|
||||||
|
siteCode: SITE,
|
||||||
|
...tagForm,
|
||||||
|
});
|
||||||
|
setTagDialog(false);
|
||||||
|
setTagForm({ tagName: "", color: "#176b5b" });
|
||||||
|
await load();
|
||||||
|
} catch (reason) {
|
||||||
|
setError(reason instanceof Error ? reason.message : "标签创建失败");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** 导入 CSV 客户文件。 */ const importCsv = async (file?: File) => {
|
||||||
|
if (!file) return;
|
||||||
|
try {
|
||||||
|
setImporting(true);
|
||||||
|
setError("");
|
||||||
|
const rows = parseCsv(await file.text());
|
||||||
|
if (rows.length < 2) throw new Error("CSV 文件没有客户数据");
|
||||||
|
const headers = rows[0].map((value) => value.toLowerCase());
|
||||||
|
const field = (row: string[], name: string) =>
|
||||||
|
row[headers.indexOf(name)] || "";
|
||||||
|
const imported = rows
|
||||||
|
.slice(1)
|
||||||
|
.map((row) => ({
|
||||||
|
companyName: field(row, "companyname"),
|
||||||
|
contactName: field(row, "contactname"),
|
||||||
|
website: field(row, "website"),
|
||||||
|
email: field(row, "email"),
|
||||||
|
phone: field(row, "phone"),
|
||||||
|
country: field(row, "country"),
|
||||||
|
facebookUrl: field(row, "facebookurl"),
|
||||||
|
instagramUrl: field(row, "instagramurl"),
|
||||||
|
linkedinUrl: field(row, "linkedinurl"),
|
||||||
|
whatsapp: field(row, "whatsapp"),
|
||||||
|
remark: field(row, "remark"),
|
||||||
|
}));
|
||||||
|
await apiPost("/crm/customers/import", {
|
||||||
|
siteCode: SITE,
|
||||||
|
items: imported,
|
||||||
|
});
|
||||||
|
setPageNo(1);
|
||||||
|
await load();
|
||||||
|
} catch (reason) {
|
||||||
|
setError(reason instanceof Error ? reason.message : "客户导入失败");
|
||||||
|
} finally {
|
||||||
|
setImporting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="crm-page">
|
||||||
|
<header>
|
||||||
|
<div>
|
||||||
|
<h1>客户列表</h1>
|
||||||
|
<p>集中管理公司资料、联系人、社媒账号和客户标签</p>
|
||||||
|
</div>
|
||||||
|
<div className="crm-actions">
|
||||||
|
<button className="secondary" onClick={() => setTagDialog(true)}>
|
||||||
|
<Tags size={16} />
|
||||||
|
新建标签
|
||||||
|
</button>
|
||||||
|
<label className="secondary crm-import">
|
||||||
|
<Upload size={16} />
|
||||||
|
{importing ? "导入中" : "导入客户"}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept=".csv,text/csv"
|
||||||
|
disabled={importing}
|
||||||
|
onChange={(event) => {
|
||||||
|
void importCsv(event.target.files?.[0]);
|
||||||
|
event.target.value = "";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button className="primary" onClick={() => edit()}>
|
||||||
|
<Plus size={16} />
|
||||||
|
新增客户
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div className="crm-toolbar">
|
||||||
|
<form
|
||||||
|
onSubmit={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
setPageNo(1);
|
||||||
|
void load();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Search size={17} />
|
||||||
|
<input
|
||||||
|
value={query}
|
||||||
|
onChange={(event) => setQuery(event.target.value)}
|
||||||
|
placeholder="搜索公司、联系人或邮箱"
|
||||||
|
/>
|
||||||
|
<button>搜索</button>
|
||||||
|
</form>
|
||||||
|
<span>共 {total} 个客户</span>
|
||||||
|
</div>
|
||||||
|
{error && <div className="notice">{error}</div>}
|
||||||
|
<section className="crm-table">
|
||||||
|
<div className="crm-row crm-head">
|
||||||
|
<span>客户</span>
|
||||||
|
<span>联系方式</span>
|
||||||
|
<span>社媒</span>
|
||||||
|
<span>标签</span>
|
||||||
|
<span>来源</span>
|
||||||
|
<span>操作</span>
|
||||||
|
</div>
|
||||||
|
{loading ? (
|
||||||
|
<div className="crm-empty">正在加载客户</div>
|
||||||
|
) : items.length === 0 ? (
|
||||||
|
<div className="crm-empty">暂无客户,可新增或导入 CSV</div>
|
||||||
|
) : (
|
||||||
|
items.map((item) => (
|
||||||
|
<div className="crm-row" key={item.customerCode}>
|
||||||
|
<div>
|
||||||
|
<strong>{item.companyName}</strong>
|
||||||
|
<small>
|
||||||
|
{item.contactName || item.country || item.customerCode}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>{item.email || "--"}</span>
|
||||||
|
<small>{item.phone || item.website || "未填写联系方式"}</small>
|
||||||
|
</div>
|
||||||
|
<div className="crm-social">
|
||||||
|
{item.website && (
|
||||||
|
<a href={item.website} target="_blank" title="网站">
|
||||||
|
<Globe2 />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{item.facebookUrl && (
|
||||||
|
<a href={item.facebookUrl} target="_blank" title="Facebook">
|
||||||
|
<Facebook />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{item.instagramUrl && (
|
||||||
|
<a href={item.instagramUrl} target="_blank" title="Instagram">
|
||||||
|
<Instagram />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{item.linkedinUrl && (
|
||||||
|
<a href={item.linkedinUrl} target="_blank" title="LinkedIn">
|
||||||
|
<Linkedin />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="crm-tags">
|
||||||
|
{item.tags.length ? (
|
||||||
|
item.tags.map((tag) => (
|
||||||
|
<span
|
||||||
|
key={tag.tagCode}
|
||||||
|
style={{ borderColor: tag.color, color: tag.color }}
|
||||||
|
>
|
||||||
|
{tag.tagName}
|
||||||
|
</span>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<small>未打标</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<span>{item.source === "IMPORT" ? "导入" : "手工新增"}</span>
|
||||||
|
<button className="link" onClick={() => edit(item)}>
|
||||||
|
查看 / 编辑
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
{totalPages > 1 && (
|
||||||
|
<div className="crm-pages">
|
||||||
|
<button disabled={pageNo === 1} onClick={() => setPageNo(pageNo - 1)}>
|
||||||
|
上一页
|
||||||
|
</button>
|
||||||
|
<span>
|
||||||
|
{pageNo} / {totalPages}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
disabled={pageNo === totalPages}
|
||||||
|
onClick={() => setPageNo(pageNo + 1)}
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{dialog && (
|
||||||
|
<div className="mask">
|
||||||
|
<form className="dialog crm-dialog" onSubmit={save}>
|
||||||
|
<div className="dialog-head">
|
||||||
|
<div>
|
||||||
|
<h2>{form.customerCode ? "编辑客户" : "新增客户"}</h2>
|
||||||
|
<p>维护公司、联系人和社媒触达信息</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="icon"
|
||||||
|
onClick={() => setDialog(false)}
|
||||||
|
>
|
||||||
|
<X />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="form-grid">
|
||||||
|
<label>
|
||||||
|
<span>公司名称</span>
|
||||||
|
<input
|
||||||
|
maxLength={200}
|
||||||
|
value={form.companyName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, companyName: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>联系人</span>
|
||||||
|
<input
|
||||||
|
maxLength={100}
|
||||||
|
value={form.contactName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, contactName: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
{(
|
||||||
|
[
|
||||||
|
["email", "邮箱"],
|
||||||
|
["phone", "电话"],
|
||||||
|
["country", "国家/地区"],
|
||||||
|
["website", "公司网站"],
|
||||||
|
["facebookUrl", "Facebook"],
|
||||||
|
["instagramUrl", "Instagram"],
|
||||||
|
["linkedinUrl", "LinkedIn"],
|
||||||
|
["whatsapp", "WhatsApp"],
|
||||||
|
] as const
|
||||||
|
).map(([key, label]) => (
|
||||||
|
<label key={key}>
|
||||||
|
<span>{label}</span>
|
||||||
|
<input
|
||||||
|
type={key === "email" ? "email" : "text"}
|
||||||
|
value={form[key]}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, [key]: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
<fieldset className="wide crm-tag-options">
|
||||||
|
<legend>客户标签</legend>
|
||||||
|
{tags.map((tag) => (
|
||||||
|
<label key={tag.tagCode}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={form.tagCodes.includes(tag.tagCode)}
|
||||||
|
onChange={() =>
|
||||||
|
setForm({
|
||||||
|
...form,
|
||||||
|
tagCodes: form.tagCodes.includes(tag.tagCode)
|
||||||
|
? form.tagCodes.filter(
|
||||||
|
(code) => code !== tag.tagCode,
|
||||||
|
)
|
||||||
|
: [...form.tagCodes, tag.tagCode],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span style={{ color: tag.color }}>{tag.tagName}</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</fieldset>
|
||||||
|
<label className="wide">
|
||||||
|
<span>备注</span>
|
||||||
|
<textarea
|
||||||
|
rows={4}
|
||||||
|
maxLength={2000}
|
||||||
|
value={form.remark}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm({ ...form, remark: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="dialog-actions">
|
||||||
|
<button type="button" onClick={() => setDialog(false)}>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
<button className="primary" disabled={saving}>
|
||||||
|
{saving ? "保存中" : "保存客户"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{tagDialog && (
|
||||||
|
<div className="mask">
|
||||||
|
<form className="dialog crm-tag-dialog" onSubmit={createTag}>
|
||||||
|
<div className="dialog-head">
|
||||||
|
<div>
|
||||||
|
<h2>新建客户标签</h2>
|
||||||
|
<p>标签创建后可用于客户分类</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="icon"
|
||||||
|
onClick={() => setTagDialog(false)}
|
||||||
|
>
|
||||||
|
<X />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="form-grid">
|
||||||
|
<label>
|
||||||
|
<span>标签名称</span>
|
||||||
|
<input
|
||||||
|
autoFocus
|
||||||
|
required
|
||||||
|
maxLength={50}
|
||||||
|
value={tagForm.tagName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setTagForm({ ...tagForm, tagName: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>标签颜色</span>
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
value={tagForm.color}
|
||||||
|
onChange={(event) =>
|
||||||
|
setTagForm({ ...tagForm, color: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="dialog-actions">
|
||||||
|
<button type="button" onClick={() => setTagDialog(false)}>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
<button className="primary">创建标签</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Code2, Pencil, Plus, Trash2 } from "lucide-react";
|
import { Code2, Pencil, Plus, Trash2 } from "lucide-react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type CodeItem = { code:string; siteCode:string; title:string; content:string; locale:string; device:string; position:string; enabled:boolean; sortNo:number };
|
type CodeItem = { code:string; siteCode:string; title:string; content:string; locale:string; device:string; position:string; enabled:boolean; sortNo:number };
|
||||||
async function post(path:string, body:unknown) { const r=await fetch(API+path,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}); if(!r.ok) throw new Error("请求失败"); return r.json(); }
|
async function post(path:string, body:unknown) { const r=await fetch(API+path,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}); if(!r.ok) throw new Error("请求失败"); return r.json(); }
|
||||||
/** 自定义代码管理页面。 */
|
/** 自定义代码管理页面。 */
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { Activity, ArrowUpRight, Clock3, Eye, FileCheck2, Mail, Monitor, RefreshCw, Users } from "lucide-react";
|
import { Activity, ArrowUpRight, Clock3, Eye, FileCheck2, Mail, Monitor, RefreshCw, Users } from "lucide-react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type Trend = { date: string; pageViews: number; visitors: number };
|
type Trend = { date: string; pageViews: number; visitors: number };
|
||||||
type ContentStat = { type: string; label: string; total: number; published: number };
|
type ContentStat = { type: string; label: string; total: number; published: number };
|
||||||
type TopPage = { path: string; title: string; pageViews: number; visitors: number };
|
type TopPage = { path: string; title: string; pageViews: number; visitors: number };
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type Viewport = "desktop" | "tablet" | "mobile";
|
type Viewport = "desktop" | "tablet" | "mobile";
|
||||||
type HeroHeight = "30" | "50" | "80" | "100";
|
type HeroHeight = "30" | "50" | "80" | "100";
|
||||||
type SectionType =
|
type SectionType =
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import React, { useEffect, useState } from "react";
|
|||||||
import { ArrowLeft, Edit3, Plus, Save, Trash2, X } from "lucide-react";
|
import { ArrowLeft, Edit3, Plus, Save, Trash2, X } from "lucide-react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type Field = {
|
type Field = {
|
||||||
fieldCode?: string;
|
fieldCode?: string;
|
||||||
fieldKey: string;
|
fieldKey: string;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { FormEvent, useState } from "react";
|
import { FormEvent, useState } from "react";
|
||||||
import { Eye, EyeOff, LockKeyhole, UserRound } from "lucide-react";
|
import { Eye, EyeOff, LockKeyhole, UserRound } from "lucide-react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import type { SiteOption } from "./siteContext";
|
||||||
|
|
||||||
export type Account = { userCode: string; siteCode: string; username: string; displayName: string };
|
export type Account = { userCode: string; siteCode: string; username: string; displayName: string; sites: SiteOption[] };
|
||||||
|
|
||||||
export default function LoginPage({ onLogin }: { onLogin: (account: Account) => void }) {
|
export default function LoginPage({ onLogin }: { onLogin: (account: Account) => void }) {
|
||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
|
|||||||
@@ -9,18 +9,84 @@
|
|||||||
min-height: 30px;
|
min-height: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.media-card {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-card.selected {
|
||||||
|
border-color: #176b5b;
|
||||||
|
box-shadow: 0 0 0 1px #176b5b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-card-selector {
|
||||||
|
position: absolute;
|
||||||
|
top: 18px;
|
||||||
|
left: 18px;
|
||||||
|
z-index: 2;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: rgba(255, 255, 255, 0.92);
|
||||||
|
box-shadow: 0 1px 5px rgba(20, 35, 32, 0.22);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-card-selector input,
|
||||||
|
.media-selection-tools input {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: 0;
|
||||||
|
accent-color: #176b5b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-selection-tools {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-selection-tools > label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 7px;
|
||||||
|
color: #34424d;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-batch-delete {
|
||||||
|
height: 34px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 0 11px;
|
||||||
|
border: 1px solid #d9a7a7;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #fff;
|
||||||
|
color: #a53b3b;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.media-delete {
|
.media-delete {
|
||||||
width: 30px;
|
min-width: 62px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
border: 1px solid #ead3d3;
|
border: 1px solid #ead3d3;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
color: #a53b3b;
|
color: #a53b3b;
|
||||||
display: grid;
|
display: inline-flex;
|
||||||
place-items: center;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 5px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 760px) {
|
||||||
|
.media-result-summary { gap: 12px; }
|
||||||
|
.media-selection-tools { flex-wrap: wrap; }
|
||||||
|
}
|
||||||
|
|
||||||
.media-delete:disabled {
|
.media-delete:disabled {
|
||||||
opacity: 0.45;
|
opacity: 0.45;
|
||||||
cursor: wait;
|
cursor: wait;
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { API, apiPost, assetUrl } from "./api";
|
import { API, apiPost, assetUrl } from "./api";
|
||||||
import "./MediaCenter.css";
|
import "./MediaCenter.css";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
|
|
||||||
type Media = {
|
type Media = {
|
||||||
/** 素材业务编号。 */ mediaCode: string;
|
/** 素材业务编号。 */ mediaCode: string;
|
||||||
@@ -53,6 +54,8 @@ export default function MediaCenter() {
|
|||||||
const [tagValue, setTagValue] = useState("");
|
const [tagValue, setTagValue] = useState("");
|
||||||
const [savingTag, setSavingTag] = useState(false);
|
const [savingTag, setSavingTag] = useState(false);
|
||||||
const [deletingCode, setDeletingCode] = useState("");
|
const [deletingCode, setDeletingCode] = useState("");
|
||||||
|
const [selectedCodes, setSelectedCodes] = useState<Set<string>>(new Set());
|
||||||
|
const [batchDeleting, setBatchDeleting] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = window.setTimeout(() => setDebouncedQuery(query.trim()), 300);
|
const timer = window.setTimeout(() => setDebouncedQuery(query.trim()), 300);
|
||||||
@@ -158,6 +161,11 @@ export default function MediaCenter() {
|
|||||||
siteCode: SITE,
|
siteCode: SITE,
|
||||||
mediaCode: item.mediaCode,
|
mediaCode: item.mediaCode,
|
||||||
});
|
});
|
||||||
|
setSelectedCodes((current) => {
|
||||||
|
const next = new Set(current);
|
||||||
|
next.delete(item.mediaCode);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
if (items.length === 1 && pageNo > 1) {
|
if (items.length === 1 && pageNo > 1) {
|
||||||
setPageNo((current) => current - 1);
|
setPageNo((current) => current - 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -170,6 +178,49 @@ export default function MediaCenter() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 选择或取消选择指定素材。 */
|
||||||
|
const toggleSelected = (mediaCode: string) => {
|
||||||
|
setSelectedCodes((current) => {
|
||||||
|
const next = new Set(current);
|
||||||
|
if (next.has(mediaCode)) next.delete(mediaCode);
|
||||||
|
else next.add(mediaCode);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 全选或取消选择当前页素材。 */
|
||||||
|
const toggleCurrentPage = () => {
|
||||||
|
const currentCodes = items.map((item) => item.mediaCode);
|
||||||
|
const allSelected = currentCodes.every((code) => selectedCodes.has(code));
|
||||||
|
setSelectedCodes((current) => {
|
||||||
|
const next = new Set(current);
|
||||||
|
currentCodes.forEach((code) => allSelected ? next.delete(code) : next.add(code));
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 批量删除已选择的素材。 */
|
||||||
|
const batchDeleteMedia = async () => {
|
||||||
|
const mediaCodes = Array.from(selectedCodes);
|
||||||
|
if (mediaCodes.length === 0) return;
|
||||||
|
if (!window.confirm(`确认删除已选择的 ${mediaCodes.length} 个素材吗?已发布页面中的文件仍会保留。`)) return;
|
||||||
|
try {
|
||||||
|
setBatchDeleting(true);
|
||||||
|
setError("");
|
||||||
|
await apiPost("/media/batch-delete", { siteCode: SITE, mediaCodes });
|
||||||
|
setSelectedCodes(new Set());
|
||||||
|
if (items.every((item) => selectedCodes.has(item.mediaCode)) && pageNo > 1) {
|
||||||
|
setPageNo((current) => current - 1);
|
||||||
|
} else {
|
||||||
|
await load();
|
||||||
|
}
|
||||||
|
} catch (reason) {
|
||||||
|
setError(reason instanceof Error ? reason.message : "素材批量删除失败");
|
||||||
|
} finally {
|
||||||
|
setBatchDeleting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const pages = pageNumbers(pageNo, totalPages);
|
const pages = pageNumbers(pageNo, totalPages);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -234,7 +285,18 @@ export default function MediaCenter() {
|
|||||||
{error && <div className="notice">{error}</div>}
|
{error && <div className="notice">{error}</div>}
|
||||||
<section className="media-panel">
|
<section className="media-panel">
|
||||||
<div className="media-result-summary">
|
<div className="media-result-summary">
|
||||||
<span>共 {total} 个素材</span>
|
<div className="media-selection-tools">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={items.length > 0 && items.every((item) => selectedCodes.has(item.mediaCode))}
|
||||||
|
onChange={toggleCurrentPage}
|
||||||
|
/>
|
||||||
|
全选当前页
|
||||||
|
</label>
|
||||||
|
<span>共 {total} 个素材{selectedCodes.size > 0 ? `,已选 ${selectedCodes.size} 个` : ""}</span>
|
||||||
|
{selectedCodes.size > 0 && <button type="button" className="media-batch-delete" disabled={batchDeleting} onClick={() => void batchDeleteMedia()}><Trash2 size={15}/>{batchDeleting ? "删除中" : "批量删除"}</button>}
|
||||||
|
</div>
|
||||||
<label>
|
<label>
|
||||||
每页
|
每页
|
||||||
<select
|
<select
|
||||||
@@ -269,7 +331,10 @@ export default function MediaCenter() {
|
|||||||
) : (
|
) : (
|
||||||
<div className="media-grid">
|
<div className="media-grid">
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<article className="media-card" key={item.mediaCode}>
|
<article className={`media-card${selectedCodes.has(item.mediaCode) ? " selected" : ""}`} key={item.mediaCode}>
|
||||||
|
<label className="media-card-selector" title="选择素材">
|
||||||
|
<input type="checkbox" checked={selectedCodes.has(item.mediaCode)} onChange={() => toggleSelected(item.mediaCode)} />
|
||||||
|
</label>
|
||||||
{item.mediaType === "VIDEO" ? (
|
{item.mediaType === "VIDEO" ? (
|
||||||
<video src={item.url} controls />
|
<video src={item.url} controls />
|
||||||
) : (
|
) : (
|
||||||
@@ -336,6 +401,7 @@ export default function MediaCenter() {
|
|||||||
onClick={() => void deleteMedia(item)}
|
onClick={() => void deleteMedia(item)}
|
||||||
>
|
>
|
||||||
<Trash2 size={15} />
|
<Trash2 size={15} />
|
||||||
|
<span>删除</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ import {
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE_CODE = "SIT0000000000001";
|
const SITE_CODE = getCurrentSiteCode();
|
||||||
|
|
||||||
type NavigationSummary = {
|
type NavigationSummary = {
|
||||||
navigationCode: string;
|
navigationCode: string;
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ import {
|
|||||||
Undo2,
|
Undo2,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { API } from "./api";
|
import { API } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type Heading = { level: number; text: string; sortNo: number };
|
type Heading = { level: number; text: string; sortNo: number };
|
||||||
type Props = {
|
type Props = {
|
||||||
pageCode?: string;
|
pageCode?: string;
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ import {
|
|||||||
X,
|
X,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { API, assetUrl } from "./api";
|
import { API, assetUrl } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
async function post(path: string, body: unknown) {
|
async function post(path: string, body: unknown) {
|
||||||
const r = await fetch(API + path, {
|
const r = await fetch(API + path, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { apiPost, assetUrl } from "./api";
|
import { apiPost, assetUrl } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
|
|
||||||
type ProductTemplate = {
|
type ProductTemplate = {
|
||||||
/** 模板业务编号。 */ templateCode: string;
|
/** 模板业务编号。 */ templateCode: string;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Save } from "lucide-react";
|
import { Save } from "lucide-react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
/** 当前后台维护的站点业务编号。 */
|
/** 当前后台维护的站点业务编号。 */
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
|
|
||||||
/** 固定页面 SEO 类型定义。 */
|
/** 固定页面 SEO 类型定义。 */
|
||||||
type SeoPageOption = {
|
type SeoPageOption = {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { FormEvent, useEffect, useState } from "react";
|
|||||||
import { KeyRound, LogOut, Plus, Save, Share2, Store, Trash2, UserRound } from "lucide-react";
|
import { KeyRound, LogOut, Plus, Save, Share2, Store, Trash2, UserRound } from "lucide-react";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
import type { Account } from "./LoginPage";
|
import type { Account } from "./LoginPage";
|
||||||
|
import { getCurrentSiteCode } from "./siteContext";
|
||||||
|
|
||||||
type StoreProfile = { siteCode: string; storeName: string; description: string; industry: string };
|
type StoreProfile = { siteCode: string; storeName: string; description: string; industry: string };
|
||||||
type SocialChannel = { platform: string; displayName: string; profileUrl: string; shareEnabled: boolean; floatingEnabled: boolean; enabled: boolean; sortNo: number };
|
type SocialChannel = { platform: string; displayName: string; profileUrl: string; shareEnabled: boolean; floatingEnabled: boolean; enabled: boolean; sortNo: number };
|
||||||
@@ -9,7 +10,8 @@ type SettingsTab = "store" | "account" | "social";
|
|||||||
const SOCIAL_PLATFORMS = ["FACEBOOK", "X", "LINKEDIN", "YOUTUBE", "INSTAGRAM", "WHATSAPP", "PINTEREST", "TIKTOK", "LINE", "TUMBLR", "EMAIL"];
|
const SOCIAL_PLATFORMS = ["FACEBOOK", "X", "LINKEDIN", "YOUTUBE", "INSTAGRAM", "WHATSAPP", "PINTEREST", "TIKTOK", "LINE", "TUMBLR", "EMAIL"];
|
||||||
|
|
||||||
export default function SettingsPage({ account, onAccount, onLogout, tab }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void; tab: SettingsTab }) {
|
export default function SettingsPage({ account, onAccount, onLogout, tab }: { account: Account; onAccount: (value: Account) => void; onLogout: () => void; tab: SettingsTab }) {
|
||||||
const [store, setStore] = useState<StoreProfile>({ siteCode: account.siteCode, storeName: "", description: "", industry: "" });
|
const siteCode = getCurrentSiteCode();
|
||||||
|
const [store, setStore] = useState<StoreProfile>({ siteCode, storeName: "", description: "", industry: "" });
|
||||||
const [profile, setProfile] = useState({ username: account.username, displayName: account.displayName });
|
const [profile, setProfile] = useState({ username: account.username, displayName: account.displayName });
|
||||||
const [password, setPassword] = useState({ currentPassword: "", newPassword: "", confirmPassword: "" });
|
const [password, setPassword] = useState({ currentPassword: "", newPassword: "", confirmPassword: "" });
|
||||||
const [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
|
const [socialChannels, setSocialChannels] = useState<SocialChannel[]>([]);
|
||||||
@@ -17,9 +19,9 @@ export default function SettingsPage({ account, onAccount, onLogout, tab }: { ac
|
|||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
apiPost<StoreProfile>("/store/detail", { siteCode: account.siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败"));
|
apiPost<StoreProfile>("/store/detail", { siteCode }).then(setStore).catch(cause => setError(cause instanceof Error ? cause.message : "加载失败"));
|
||||||
if (tab === "social") apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode: account.siteCode }).then(data => setSocialChannels(data.items || [])).catch(cause => setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"));
|
if (tab === "social") apiPost<{ items: SocialChannel[] }>("/social-channels/list", { siteCode }).then(data => setSocialChannels(data.items || [])).catch(cause => setError(cause instanceof Error ? cause.message : "社媒渠道加载失败"));
|
||||||
}, [account.siteCode, tab]);
|
}, [siteCode, tab]);
|
||||||
const run = async (operation: () => Promise<void>, success: string) => { try { setError(""); setMessage(""); await operation(); setMessage(success); } catch (cause) { setError(cause instanceof Error ? cause.message : "操作失败"); } };
|
const run = async (operation: () => Promise<void>, success: string) => { try { setError(""); setMessage(""); await operation(); setMessage(success); } catch (cause) { setError(cause instanceof Error ? cause.message : "操作失败"); } };
|
||||||
const saveStore = (event: FormEvent) => { event.preventDefault(); void run(async () => setStore(await apiPost("/store/save", store)), "店铺信息已保存"); };
|
const saveStore = (event: FormEvent) => { event.preventDefault(); void run(async () => setStore(await apiPost("/store/save", store)), "店铺信息已保存"); };
|
||||||
const saveProfile = (event: FormEvent) => { event.preventDefault(); void run(async () => onAccount(await apiPost("/auth/account", profile)), "账户资料已更新"); };
|
const saveProfile = (event: FormEvent) => { event.preventDefault(); void run(async () => onAccount(await apiPost("/auth/account", profile)), "账户资料已更新"); };
|
||||||
@@ -34,7 +36,7 @@ export default function SettingsPage({ account, onAccount, onLogout, tab }: { ac
|
|||||||
/** 更新指定社媒渠道。 */
|
/** 更新指定社媒渠道。 */
|
||||||
const updateSocialChannel = (index: number, patch: Partial<SocialChannel>) => setSocialChannels(current => current.map((item, itemIndex) => itemIndex === index ? { ...item, ...patch } : item));
|
const updateSocialChannel = (index: number, patch: Partial<SocialChannel>) => setSocialChannels(current => current.map((item, itemIndex) => itemIndex === index ? { ...item, ...patch } : item));
|
||||||
/** 保存整组社媒渠道配置。 */
|
/** 保存整组社媒渠道配置。 */
|
||||||
const saveSocialChannels = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/social-channels/save", { siteCode: account.siteCode, items: socialChannels }); }, "社媒渠道已保存"); };
|
const saveSocialChannels = (event: FormEvent) => { event.preventDefault(); void run(async () => { await apiPost("/social-channels/save", { siteCode, items: socialChannels }); }, "社媒渠道已保存"); };
|
||||||
|
|
||||||
const titles: Record<SettingsTab, [string, string]> = { store: ["店铺信息", "维护网站名称、行业和店铺介绍。"], account: ["账户与安全", "维护登录账户、显示名称和密码。"], social: ["社媒渠道", "配置产品分享入口和全站右侧悬浮联系渠道。"] };
|
const titles: Record<SettingsTab, [string, string]> = { store: ["店铺信息", "维护网站名称、行业和店铺介绍。"], account: ["账户与安全", "维护登录账户、显示名称和密码。"], social: ["社媒渠道", "配置产品分享入口和全站右侧悬浮联系渠道。"] };
|
||||||
return <div className="account-settings">
|
return <div className="account-settings">
|
||||||
|
|||||||
+114
-17
@@ -43,14 +43,16 @@ import NavigationManager from "./NavigationManager";
|
|||||||
import AgreementSettingsPage from "./AgreementSettingsPage";
|
import AgreementSettingsPage from "./AgreementSettingsPage";
|
||||||
import AboutUsSettingsPage from "./AboutUsSettingsPage";
|
import AboutUsSettingsPage from "./AboutUsSettingsPage";
|
||||||
import DashboardPage from "./DashboardPage";
|
import DashboardPage from "./DashboardPage";
|
||||||
|
import CrmCustomerPage from "./CrmCustomerPage";
|
||||||
import { apiPost } from "./api";
|
import { apiPost } from "./api";
|
||||||
import { statusLabel } from "./statusLabels";
|
import { statusLabel } from "./statusLabels";
|
||||||
|
import { ensureCurrentSiteCode, getCurrentSiteCode, setCurrentSiteCode, type SiteOption } from "./siteContext";
|
||||||
|
|
||||||
const SITE_WEB =
|
const SITE_WEB =
|
||||||
window.location.hostname === "admin.steliro.com"
|
window.location.hostname === "admin.steliro.com"
|
||||||
? "https://site.steliro.com"
|
? "https://site.steliro.com"
|
||||||
: "http://localhost:5174";
|
: "http://localhost:5174";
|
||||||
const SITE = "SIT0000000000001";
|
const SITE = getCurrentSiteCode();
|
||||||
type Section =
|
type Section =
|
||||||
| "dashboard"
|
| "dashboard"
|
||||||
| "products"
|
| "products"
|
||||||
@@ -74,7 +76,8 @@ type Section =
|
|||||||
| "inquiry-settings"
|
| "inquiry-settings"
|
||||||
| "settings-store"
|
| "settings-store"
|
||||||
| "settings-account"
|
| "settings-account"
|
||||||
| "settings-social";
|
| "settings-social"
|
||||||
|
| "crm-customers";
|
||||||
type EditorialSection = "NEWS" | "CASE" | "HELP";
|
type EditorialSection = "NEWS" | "CASE" | "HELP";
|
||||||
type ContentEditorState = {
|
type ContentEditorState = {
|
||||||
contentType: EditorialSection;
|
contentType: EditorialSection;
|
||||||
@@ -141,6 +144,7 @@ const systemSettingsMenus = [
|
|||||||
{ key: "settings-store" as Section, label: "店铺信息", icon: Store },
|
{ key: "settings-store" as Section, label: "店铺信息", icon: Store },
|
||||||
{ key: "settings-account" as Section, label: "账户与安全", icon: UserRound },
|
{ key: "settings-account" as Section, label: "账户与安全", icon: UserRound },
|
||||||
{ key: "settings-social" as Section, label: "社媒渠道", icon: Share2 },
|
{ key: "settings-social" as Section, label: "社媒渠道", icon: Share2 },
|
||||||
|
{ key: "inquiry-settings" as Section, label: "询盘设置", icon: Settings },
|
||||||
];
|
];
|
||||||
const sectionLabels: Record<Section, string> = {
|
const sectionLabels: Record<Section, string> = {
|
||||||
dashboard: "数据概览",
|
dashboard: "数据概览",
|
||||||
@@ -166,6 +170,7 @@ const sectionLabels: Record<Section, string> = {
|
|||||||
"settings-store": "店铺信息",
|
"settings-store": "店铺信息",
|
||||||
"settings-account": "账户与安全",
|
"settings-account": "账户与安全",
|
||||||
"settings-social": "社媒渠道",
|
"settings-social": "社媒渠道",
|
||||||
|
"crm-customers": "客户列表",
|
||||||
};
|
};
|
||||||
function App({
|
function App({
|
||||||
account,
|
account,
|
||||||
@@ -204,6 +209,40 @@ function App({
|
|||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [siteDialogOpen, setSiteDialogOpen] = useState(false);
|
||||||
|
const [siteCreating, setSiteCreating] = useState(false);
|
||||||
|
const [siteError, setSiteError] = useState("");
|
||||||
|
const [siteForm, setSiteForm] = useState({
|
||||||
|
siteName: "",
|
||||||
|
industry: "",
|
||||||
|
description: "",
|
||||||
|
timezone: "Asia/Shanghai",
|
||||||
|
});
|
||||||
|
const currentSiteCode = getCurrentSiteCode();
|
||||||
|
/** 切换当前站点并重新加载所有站点级数据。 */
|
||||||
|
const switchSite = (siteCode: string) => {
|
||||||
|
if (siteCode === currentSiteCode) return;
|
||||||
|
setCurrentSiteCode(siteCode);
|
||||||
|
window.location.assign("/");
|
||||||
|
};
|
||||||
|
/** 创建站点并自动切换到新站点。 */
|
||||||
|
const createSite = async () => {
|
||||||
|
try {
|
||||||
|
setSiteCreating(true);
|
||||||
|
setSiteError("");
|
||||||
|
const previousCodes = new Set(account.sites.map((site) => site.siteCode));
|
||||||
|
await apiPost("/sites/create", siteForm);
|
||||||
|
const result = await apiPost<{ items: SiteOption[] }>("/sites/list", {});
|
||||||
|
const site = result.items.find((item) => !previousCodes.has(item.siteCode));
|
||||||
|
if (!site) throw new Error("站点已创建,但未能读取新站点信息,请刷新后重试");
|
||||||
|
setCurrentSiteCode(site.siteCode);
|
||||||
|
window.location.assign("/");
|
||||||
|
} catch (cause) {
|
||||||
|
setSiteError(cause instanceof Error ? cause.message : "站点创建失败");
|
||||||
|
} finally {
|
||||||
|
setSiteCreating(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
const resolveProductRoute = () => {
|
const resolveProductRoute = () => {
|
||||||
if (window.location.pathname === "/products/new") return "";
|
if (window.location.pathname === "/products/new") return "";
|
||||||
const match = window.location.pathname.match(/^\/products\/([^/]+)\/edit$/);
|
const match = window.location.pathname.match(/^\/products\/([^/]+)\/edit$/);
|
||||||
@@ -226,6 +265,7 @@ function App({
|
|||||||
const [contentMenuOpen, setContentMenuOpen] = useState(true);
|
const [contentMenuOpen, setContentMenuOpen] = useState(true);
|
||||||
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
|
const [frontSiteMenuOpen, setFrontSiteMenuOpen] = useState(true);
|
||||||
const [systemSettingsOpen, setSystemSettingsOpen] = useState(true);
|
const [systemSettingsOpen, setSystemSettingsOpen] = useState(true);
|
||||||
|
const [crmMenuOpen, setCrmMenuOpen] = useState(true);
|
||||||
const navigateSection = (next: Section) => {
|
const navigateSection = (next: Section) => {
|
||||||
setEditingProduct(null);
|
setEditingProduct(null);
|
||||||
setEditingContent(null);
|
setEditingContent(null);
|
||||||
@@ -447,6 +487,30 @@ function App({
|
|||||||
Shoplix<small>运营中心</small>
|
Shoplix<small>运营中心</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="site-switcher">
|
||||||
|
<div>
|
||||||
|
<Globe2 size={15} />
|
||||||
|
<select
|
||||||
|
aria-label="当前站点"
|
||||||
|
value={currentSiteCode}
|
||||||
|
onChange={(event) => switchSite(event.target.value)}
|
||||||
|
>
|
||||||
|
{account.sites.map((site) => (
|
||||||
|
<option key={site.siteCode} value={site.siteCode}>
|
||||||
|
{site.siteName}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
title="新增站点"
|
||||||
|
aria-label="新增站点"
|
||||||
|
onClick={() => setSiteDialogOpen(true)}
|
||||||
|
>
|
||||||
|
<Plus size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<button className={section === "dashboard" ? "active" : ""} onClick={() => navigateSection("dashboard")}><LayoutDashboard size={18}/>数据概览</button>
|
<button className={section === "dashboard" ? "active" : ""} onClick={() => navigateSection("dashboard")}><LayoutDashboard size={18}/>数据概览</button>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
@@ -488,6 +552,16 @@ function App({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="nav-group">
|
||||||
|
<button className={section === "crm-customers" ? "group-active" : ""} onClick={() => setCrmMenuOpen(!crmMenuOpen)}>
|
||||||
|
<Users size={18} />
|
||||||
|
CRM 管理
|
||||||
|
<ChevronDown className={crmMenuOpen ? "expanded" : ""} size={16} />
|
||||||
|
</button>
|
||||||
|
{crmMenuOpen && <div className="nav-children">
|
||||||
|
<button className={section === "crm-customers" ? "active" : ""} onClick={() => navigateSection("crm-customers")}><Users size={15}/>客户列表</button>
|
||||||
|
</div>}
|
||||||
|
</div>
|
||||||
<div className="nav-group">
|
<div className="nav-group">
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
@@ -601,23 +675,12 @@ function App({
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</nav>
|
</nav>
|
||||||
<div className="aside-bottom">
|
|
||||||
<button>
|
|
||||||
<Users size={18} />
|
|
||||||
CRM 客户
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className={section === "inquiry-settings" ? "active" : ""}
|
|
||||||
onClick={() => navigateSection("inquiry-settings")}
|
|
||||||
>
|
|
||||||
<Settings size={18} />
|
|
||||||
询盘设置
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</aside>
|
</aside>
|
||||||
<main>
|
<main>
|
||||||
{section === "dashboard" ? (
|
{section === "dashboard" ? (
|
||||||
<DashboardPage onNavigate={(next) => navigateSection(next as Section)} />
|
<DashboardPage onNavigate={(next) => navigateSection(next as Section)} />
|
||||||
|
) : section === "crm-customers" ? (
|
||||||
|
<CrmCustomerPage />
|
||||||
) : section === "settings-store" ? (
|
) : section === "settings-store" ? (
|
||||||
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="store" />
|
<SettingsPage account={account} onAccount={onAccount} onLogout={onLogout} tab="store" />
|
||||||
) : section === "settings-account" ? (
|
) : section === "settings-account" ? (
|
||||||
@@ -1002,6 +1065,30 @@ function App({
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{siteDialogOpen && (
|
||||||
|
<div className="mask" onMouseDown={() => setSiteDialogOpen(false)}>
|
||||||
|
<section className="dialog site-dialog" onMouseDown={(event) => event.stopPropagation()}>
|
||||||
|
<div className="dialog-head">
|
||||||
|
<div>
|
||||||
|
<h2>新增站点</h2>
|
||||||
|
<p>创建后将自动切换到新站点。</p>
|
||||||
|
</div>
|
||||||
|
<button type="button" aria-label="关闭" onClick={() => setSiteDialogOpen(false)}><X size={19} /></button>
|
||||||
|
</div>
|
||||||
|
<div className="form-grid">
|
||||||
|
<label><span>站点名称</span><input autoFocus required maxLength={100} value={siteForm.siteName} onChange={(event) => setSiteForm({ ...siteForm, siteName: event.target.value })} placeholder="例如:Shoplix Global" /></label>
|
||||||
|
<label><span>所属行业</span><input required maxLength={100} value={siteForm.industry} onChange={(event) => setSiteForm({ ...siteForm, industry: event.target.value })} placeholder="例如:工业设备" /></label>
|
||||||
|
<label><span>站点时区</span><input required maxLength={50} value={siteForm.timezone} onChange={(event) => setSiteForm({ ...siteForm, timezone: event.target.value })} /></label>
|
||||||
|
<label className="wide"><span>站点描述</span><textarea rows={4} maxLength={1000} value={siteForm.description} onChange={(event) => setSiteForm({ ...siteForm, description: event.target.value })} /></label>
|
||||||
|
</div>
|
||||||
|
{siteError && <div className="site-dialog-error">{siteError}</div>}
|
||||||
|
<div className="dialog-actions">
|
||||||
|
<button type="button" onClick={() => setSiteDialogOpen(false)}>取消</button>
|
||||||
|
<button type="button" className="primary" disabled={siteCreating || !siteForm.siteName.trim() || !siteForm.industry.trim() || !siteForm.timezone.trim()} onClick={createSite}>{siteCreating ? "创建中..." : "创建并切换"}</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1009,12 +1096,22 @@ function App({
|
|||||||
function RootApp() {
|
function RootApp() {
|
||||||
const [account, setAccount] = useState<Account | null>(null);
|
const [account, setAccount] = useState<Account | null>(null);
|
||||||
const [checking, setChecking] = useState(true);
|
const [checking, setChecking] = useState(true);
|
||||||
|
/** 接收账户信息并保证模块级站点上下文与账户权限一致。 */
|
||||||
|
const acceptAccount = (value: Account) => {
|
||||||
|
const previousSiteCode = getCurrentSiteCode();
|
||||||
|
const currentSiteCode = ensureCurrentSiteCode(value.sites || [], value.siteCode);
|
||||||
|
if (previousSiteCode !== currentSiteCode) {
|
||||||
|
window.location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAccount(value);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unauthorized = () => setAccount(null);
|
const unauthorized = () => setAccount(null);
|
||||||
window.addEventListener("shoplix:unauthorized", unauthorized);
|
window.addEventListener("shoplix:unauthorized", unauthorized);
|
||||||
apiPost<Account>("/auth/me")
|
apiPost<Account>("/auth/me")
|
||||||
.then(setAccount)
|
.then(acceptAccount)
|
||||||
.catch(() => setAccount(null))
|
.catch(() => setAccount(null))
|
||||||
.finally(() => setChecking(false));
|
.finally(() => setChecking(false));
|
||||||
return () =>
|
return () =>
|
||||||
@@ -1028,7 +1125,7 @@ function RootApp() {
|
|||||||
<span>正在验证登录状态</span>
|
<span>正在验证登录状态</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
if (!account) return <LoginPage onLogin={setAccount} />;
|
if (!account) return <LoginPage onLogin={acceptAccount} />;
|
||||||
return (
|
return (
|
||||||
<App
|
<App
|
||||||
account={account}
|
account={account}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/** 后台可切换站点选项。 */
|
||||||
|
export type SiteOption = {
|
||||||
|
/** 站点业务编号。 */ siteCode: string;
|
||||||
|
/** 站点名称。 */ siteName: string;
|
||||||
|
/** 所属行业。 */ industry: string;
|
||||||
|
/** 当前账户的站点角色值。 */ role: string;
|
||||||
|
/** 当前账户的站点角色文案。 */ roleLabel: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 当前站点本地存储键。 */
|
||||||
|
const CURRENT_SITE_KEY = "shoplix.currentSiteCode";
|
||||||
|
/** 兼容历史版本的默认站点编号。 */
|
||||||
|
const DEFAULT_SITE_CODE = "SIT0000000000001";
|
||||||
|
|
||||||
|
/** 获取当前选中的站点业务编号。 */
|
||||||
|
export function getCurrentSiteCode(): string {
|
||||||
|
return window.localStorage.getItem(CURRENT_SITE_KEY) || DEFAULT_SITE_CODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 保存当前选中的站点业务编号。 */
|
||||||
|
export function setCurrentSiteCode(siteCode: string): void {
|
||||||
|
window.localStorage.setItem(CURRENT_SITE_KEY, siteCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 确保本地当前站点属于登录账户并返回最终站点。 */
|
||||||
|
export function ensureCurrentSiteCode(sites: SiteOption[], defaultSiteCode: string): string {
|
||||||
|
const current = getCurrentSiteCode();
|
||||||
|
if (sites.some((site) => site.siteCode === current)) return current;
|
||||||
|
const fallback = sites.find((site) => site.siteCode === defaultSiteCode)?.siteCode
|
||||||
|
|| sites[0]?.siteCode
|
||||||
|
|| defaultSiteCode;
|
||||||
|
setCurrentSiteCode(fallback);
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
@@ -70,6 +70,12 @@ select {
|
|||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
.site-switcher { display:grid; grid-template-columns:minmax(0,1fr) 36px; gap:6px; padding:0 4px 16px; }
|
||||||
|
.site-switcher > div { min-width:0; height:38px; display:flex; align-items:center; gap:7px; padding:0 8px; border:1px solid #344451; border-radius:6px; background:#111a22; color:#93a2ae; }
|
||||||
|
.site-switcher select { min-width:0; width:100%; border:0; outline:0; background:transparent; color:#f0f4f7; font-size:13px; cursor:pointer; }
|
||||||
|
.site-switcher select option { color:#17212b; background:#fff; }
|
||||||
|
.site-switcher > button { width:36px; height:38px; padding:0!important; justify-content:center; border:1px solid #344451!important; background:#111a22!important; }
|
||||||
|
.site-switcher > button:hover { border-color:#e9b949!important; color:#e9b949!important; }
|
||||||
nav {
|
nav {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
@@ -369,6 +375,8 @@ header p {
|
|||||||
background: #176b5b;
|
background: #176b5b;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
.site-dialog { width:min(620px,calc(100vw - 32px)); }
|
||||||
|
.site-dialog-error { margin:0 24px 14px; padding:10px 12px; border:1px solid #e5b7b7; border-radius:5px; background:#fff2f2; color:#a52f2f; font-size:13px; }
|
||||||
.primary:disabled {
|
.primary:disabled {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"root":["./src/aboutussettingspage.tsx","./src/agreementsettingspage.tsx","./src/categorymanager.tsx","./src/contenteditor.tsx","./src/customcodemanager.tsx","./src/dashboardpage.tsx","./src/decorationeditor.tsx","./src/inquirysettingspanel.tsx","./src/loginpage.tsx","./src/mediacenter.tsx","./src/navigationmanager.tsx","./src/pageeditor.tsx","./src/producteditor.tsx","./src/seosettingspage.tsx","./src/settingspage.tsx","./src/api.ts","./src/main.tsx","./src/statuslabels.ts","./src/vite-env.d.ts"],"version":"5.7.3"}
|
{"root":["./src/aboutussettingspage.tsx","./src/agreementsettingspage.tsx","./src/categorymanager.tsx","./src/contenteditor.tsx","./src/crmcustomerpage.tsx","./src/customcodemanager.tsx","./src/dashboardpage.tsx","./src/decorationeditor.tsx","./src/inquirysettingspanel.tsx","./src/loginpage.tsx","./src/mediacenter.tsx","./src/navigationmanager.tsx","./src/pageeditor.tsx","./src/producteditor.tsx","./src/producttemplatemanager.tsx","./src/seosettingspage.tsx","./src/settingspage.tsx","./src/api.ts","./src/main.tsx","./src/sitecontext.ts","./src/statuslabels.ts","./src/vite-env.d.ts"],"version":"5.7.3"}
|
||||||
Reference in new issue
Block a user