Merge remote-tracking branch 'origin/dev/dev' into dev/dev

This commit is contained in:
shahaibo
2025-05-20 10:29:30 +08:00
22 changed files with 389 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.DesignMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.Organization;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.PaymentInfoVO;
@@ -206,4 +207,17 @@ public class ConvenientInquiryController {
return Response.success(convenientInquiryService.getAllGenerateFuncName());
}
@ApiOperation("添加组织机构")
@GetMapping("/addOrganization")
public Response<String> addOrganization(@ApiParam(value = "机构名") @RequestParam String name, @ApiParam(value = "Enterprise || Education") @RequestParam String type){
convenientInquiryService.addOrganization(name, type);
return Response.success();
}
@ApiOperation("查询所有企业或教育机构")
@GetMapping("/queryOrganization")
public Response<List<Organization>> queryOrganization(@ApiParam(value = "Enterprise || Education") @RequestParam String type){
return Response.success(convenientInquiryService.queryOrganization(type));
}
}

View File

@@ -27,10 +27,7 @@ import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.File;
import java.text.ParseException;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.*;
@Api(tags = "library模块")
@@ -210,4 +207,39 @@ public class LibraryController {
return Response.success(libraryService.addSysModelToLib(sysModelId));
}
@ApiOperation(value = "将个人library元素添加到公共库")
@GetMapping("addToPublicLibrary")
public Response<String> addToPublicLibrary(@ApiParam("元素的libraryId") @RequestParam("libraryId") Long libraryId){
boolean b = libraryService.saveToOrganizationLibrary(libraryId);
if (b){
return Response.success("success");
}else {
return Response.success("fail");
}
}
@ApiOperation(value = "将个人library元素从公共库中删除")
@GetMapping("deleteFromPublicLib")
public Response<String> deleteFromPublicLib(@ApiParam("元素的libraryId") @RequestParam("libraryId") Long libraryId){
libraryService.deleteFromPublicLib(libraryId);
return Response.success("success");
}
@ApiOperation(value = "获取公共库")
@GetMapping("getPublicLib")
public Response<PageBaseResponse<Library>> getPublicLib(@ApiParam("排序" ) @RequestParam(value = "order", defaultValue = "DESC", required = false) String order,
@ApiParam("page") @RequestParam(value = "page", defaultValue = "1", required = false) Long page,
@ApiParam("size") @RequestParam(value = "size", defaultValue = "20", required = false) Long size){
return Response.success(libraryService.getPublicLib(order, page, size));
}
@ApiOperation(value = "管理员获取所有子账号lib元素")
@GetMapping("getAllSubAccLib")
public Response<PageBaseResponse<Library>> getAllSubAccLib(@ApiParam("排序") @RequestParam(value = "order", defaultValue = "DESC", required = false) String order,
@ApiParam("page") @RequestParam(value = "page", defaultValue = "1", required = false) Long page,
@ApiParam("size") @RequestParam(value = "size", defaultValue = "20", required = false) Long size){
return Response.success(libraryService.getAllSubAccLib(order, page, size));
}
}

View File

@@ -154,4 +154,11 @@ public class PortfolioController {
@RequestParam(value = "tagId", required = false) Long tagId) {
return Response.success(portfolioService.queryPortfolioByTag(tagName, tagId));
}*/
@ApiOperation(value = "将企业或教育版中的作品发布到公共gallery")
@GetMapping("/toPublic")
public Response<String> setPortfolioToPublic(@RequestParam("portfolioId") Long portfolioId) {
portfolioService.setPortfolioToPublic(portfolioId);
return Response.success("success");
}
}

View File

@@ -0,0 +1,8 @@
package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.EducationLibrary;
public interface EductionLibraryMapper extends CommonMapper<EducationLibrary> {
}

View File

@@ -0,0 +1,7 @@
package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.EnterpriseLibrary;
public interface EnterpriseLibraryMapper extends CommonMapper<EnterpriseLibrary> {
}

View File

@@ -3,6 +3,8 @@ package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Library;
import java.util.List;
/**
* Mapper 接口
*
@@ -11,4 +13,11 @@ import com.ai.da.mapper.primary.entity.Library;
*/
public interface LibraryMapper extends CommonMapper<Library> {
List<Library> selectCommonLib(Long organizationId, String sort, long limit, long offset);
Long selectCommonLibCount(Long organizationId);
List<Library> selectAllSubAccLib(Long organizationId, String sort, long limit, long offset);
Long selectAllSubAccLibCount(Long organizationId);
}

View File

@@ -0,0 +1,7 @@
package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Organization;
public interface OrganizationMapper extends CommonMapper<Organization> {
}

View File

@@ -117,6 +117,8 @@ public class Account implements Serializable {
private String organizationName;
private Long organizationId;
private Long parentId;
private Integer isAdmin;

View File

@@ -0,0 +1,18 @@
package com.ai.da.mapper.primary.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("t_education_library")
public class EducationLibrary extends BaseEntity{
private Long educationId;
private Long classId;
// 元素开放的范围 部门 | 公司
private String scope;
private Long libraryId;
}

View File

@@ -0,0 +1,18 @@
package com.ai.da.mapper.primary.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("t_enterprise_library")
public class EnterpriseLibrary extends BaseEntity{
private Long enterpriseId;
private Long departmentId;
// 元素开放的范围 部门 | 公司
private String scope;
private Long libraryId;
}

View File

@@ -0,0 +1,23 @@
package com.ai.da.mapper.primary.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("t_organization")
public class Organization extends BaseEntity{
// 企业、教育、部门、班级名
private String name;
// 企业 || 教育 Enterprise || Education
private String type;
// 分类类型root/department/grade等
private String categoryType;
// 分类层级
private String level;
// 父分类ID自引用
private Long parentId;
// 状态
private Integer status;
}

View File

@@ -60,6 +60,12 @@ public class Portfolio implements Serializable {
@ApiModelProperty(value = "作品集作者ID")
private Long accountId;
// 学校/企业id
private Long organizationId;
// 该条作品是否在该组织公开 默认不公开 01为公开
private Integer isPublic;
@ApiModelProperty(value = "创建时间")
private LocalDateTime createDate;

View File

@@ -15,4 +15,6 @@ public class QueryPortfolioPageDTO extends PageQueryBaseVo {
private Long accountId;
private Long tagId;
private Long organizationId;
}

View File

@@ -2,6 +2,7 @@ package com.ai.da.service;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.Organization;
import com.ai.da.mapper.primary.entity.Questionnaire;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.*;
@@ -58,4 +59,8 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO);
List<String> getAllGenerateFuncName();
void addOrganization(String name, String type);
List<Organization> queryOrganization(String type);
}

View File

@@ -90,4 +90,12 @@ public interface LibraryService extends IService<Library> {
void moveLibraryDate() throws ParseException;
Map<String, String> addSysModelToLib(long sysModelId);
boolean saveToOrganizationLibrary(Long libraryId);
void deleteFromPublicLib(Long libraryId);
PageBaseResponse<Library> getPublicLib(String order, long page, long size);
PageBaseResponse<Library> getAllSubAccLib(String order, long page, long size);
}

View File

@@ -62,4 +62,6 @@ public interface PortfolioService extends IService<Portfolio> {
List<Long> getFolloweeList(Long accountId);
// List<PortfolioVO> queryPortfolioByTag(String tagName, Long tagId);
void setPortfolioToPublic(Long portfolioId);
}

View File

@@ -10,6 +10,7 @@ import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.Organization;
import com.ai.da.mapper.primary.entity.Questionnaire;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.*;
@@ -160,11 +161,11 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
role = "prsn";
break;
default:
throw new BusinessException("Sorry, you don't have permission", ResultEnum.PROMPT.getCode());
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
}
return designMapper.getDesignStatistic(startTime, endTime, ids, email, role);
} else {
throw new BusinessException("Sorry, you don't have permission", ResultEnum.PROMPT.getCode());
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
}
}
@@ -876,7 +877,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
role = "prsn";
break;
default:
throw new BusinessException("Sorry, you don't have permission");
throw new BusinessException("have.no.permission");
}
Integer size = queryDTO.getSize();
int offset = (queryDTO.getPage() - 1) * size;
@@ -901,7 +902,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
return new PageBaseResponse<>();
}
}else {
throw new BusinessException("Sorry, you don't have permission");
throw new BusinessException("have.no.permission");
}
}
@@ -909,4 +910,26 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
return CreditsEventsEnum.generateFunctionNames();
}
@Resource
private OrganizationMapper organizationMapper;
public void addOrganization(String name, String type){
Organization organization = new Organization();
organization.setName(name);
organization.setType(type);
organization.setCategoryType("root");
organization.setCreateTime(LocalDateTime.now());
organizationMapper.insert(organization);
}
public List<Organization> queryOrganization(String type){
// 查询所有的组织名及id
switch (type){
case "Enterprise":
case "Education":
return organizationMapper.selectList(new QueryWrapper<Organization>().eq("type", type).eq("category_type", "root"));
default:
throw new BusinessException("Unknown type");
}
}
}

View File

@@ -48,6 +48,7 @@ import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -80,6 +81,12 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
private GenerateService generateService;
@Resource
private MinioUtil minioUtil;
@Resource
private AccountMapper accountMapper;
@Resource
private EductionLibraryMapper eductionLibraryMapper;
@Resource
private EnterpriseLibraryMapper enterpriseLibraryMapper;
@Value("${minio.bucketName.users}")
private String users;
@@ -879,4 +886,109 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
resp.put("url", minioUtil.getPreSignedUrl(library.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
return resp;
}
public boolean saveToOrganizationLibrary(Long libraryId){
// 1、判断该用户是否属于某个组织
Long accountId = UserContext.getUserHolder().getId();
Account account = accountMapper.selectById(accountId);
if (Objects.nonNull(account.getOrganizationId())){
// 2、添加元素信息到对应的住址表里
switch(account.getSystemUser()){
case 5:
case 6:
EnterpriseLibrary enterpriseLibrary = enterpriseLibraryMapper.selectOne(new QueryWrapper<EnterpriseLibrary>().eq("library_id", libraryId));
if (Objects.nonNull(enterpriseLibrary)){
throw new BusinessException("element.already.exists");
}
// 存储到企业表
enterpriseLibrary = new EnterpriseLibrary();
enterpriseLibrary.setEnterpriseId(account.getOrganizationId());
enterpriseLibrary.setLibraryId(libraryId);
enterpriseLibrary.setCreateTime(LocalDateTime.now());
enterpriseLibraryMapper.insert(enterpriseLibrary);
log.info("企业用户添加元素到公共库");
return true;
case 7:
case 8:
EducationLibrary educationLibrary = eductionLibraryMapper.selectOne(new QueryWrapper<EducationLibrary>().eq("library_id", libraryId));
if (Objects.nonNull(educationLibrary)){
throw new BusinessException("element.already.exists");
}
// 存储到教育表
educationLibrary = new EducationLibrary();
educationLibrary.setEducationId(account.getOrganizationId());
educationLibrary.setLibraryId(libraryId);
educationLibrary.setCreateTime(LocalDateTime.now());
eductionLibraryMapper.insert(educationLibrary);
log.info("教育版用户添加元素到公共库");
return true;
default:
return false;
}
}
return false;
}
// 删除公共库中的元素
public void deleteFromPublicLib(Long libraryId){
// 谁有权限删除公共库里的东西1、元素所有者 2、管理员
Long accountId = UserContext.getUserHolder().getId();
Account account = accountMapper.selectById(accountId);
Library library = libraryMapper.selectById(libraryId);
if (account.getSystemUser().equals(5)
|| account.getSystemUser().equals(7)
|| library.getAccountId().equals(accountId)){
switch (account.getSystemUser()){
case 5:
case 6:
enterpriseLibraryMapper.delete(new QueryWrapper<EnterpriseLibrary>().eq("library_id", libraryId));
break;
case 7:
case 8:
eductionLibraryMapper.delete(new QueryWrapper<EducationLibrary>().eq("library_id", libraryId));
break;
}
}else {
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
}
}
// 查询企业或教育的公共库
public PageBaseResponse<Library> getPublicLib(String order, long page, long size){
Long accountId = UserContext.getUserHolder().getId();
Account account = accountMapper.selectById(accountId);
if (Objects.isNull(account.getOrganizationId())){
throw new BusinessException("未查询到您的组织信息,无法获取公共库的元素", ResultEnum.PROMPT.getCode());
}
Long organizationId = account.getOrganizationId();
long offset = (page - 1) * size;
List<Library> libraries = libraryMapper.selectCommonLib(organizationId, order, size, offset);
Long count = libraryMapper.selectCommonLibCount(organizationId);
long pages = (long) Math.ceil(count / size);
return new PageBaseResponse<>(libraries, page, size, count, pages == 0 ? 1 : pages);
}
// 管理员查所有子账号的library
public PageBaseResponse<Library> getAllSubAccLib(String order, long page, long size){
// 1、判断当前账号是不是管理员
Long accountId = UserContext.getUserHolder().getId();
Account account = accountMapper.selectById(accountId);
long offset = (page - 1) * size;
switch(account.getSystemUser()){
case 5:
case 7:
if (Objects.isNull(account.getOrganizationId())){
throw new BusinessException("未查询到您的组织信息,无法获取元素", ResultEnum.PROMPT.getCode());
}
List<Library> libraries = libraryMapper.selectAllSubAccLib(account.getOrganizationId(), order, size, offset);
Long count = libraryMapper.selectAllSubAccLibCount(account.getOrganizationId());
long pages = (long) Math.ceil(count / size);
return new PageBaseResponse<>(libraries, page, size, count, pages == 0 ? 1 : pages);
default:
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
}
}
}

View File

@@ -184,6 +184,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
portfolio.setIsDeleted(0);
portfolio.setCanvasId(canvas.getId());
portfolio.setPortfolioDes(portfolioDTO.getPortfolioDes());
if (Objects.isNull(portfolioDTO.getIsPublic())){
portfolio.setIsPublic(0);
}else {
portfolio.setIsPublic(portfolioDTO.getIsPublic());
}
portfolio.setOrganizationId(accountMapper.selectById(authPrincipalVo.getId()).getOrganizationId());
if (portfolioDTO.getOpenSource() == 1) {
// 副本存储对象
@@ -430,6 +436,12 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
return queryPortfolioByTag(null, query.getTagId(), query.getPage(), query.getSize());
}
if (Objects.nonNull(query.getOrganizationId())){
qw.eq("organization_id", query.getOrganizationId());
}else {
qw.isNull("is_public").or().eq("is_public", 1);
}
/*List<Portfolio> topThree = new ArrayList<>();
List<Long> excludeIds = new ArrayList<>(); // 存放需要排除的 ID 列表
// 获取前三点赞和前三浏览的作品集,并将其排除在分页查询之外
@@ -1184,4 +1196,24 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
return userFollows.stream().map(UserFollow::getFolloweeId).collect(Collectors.toList());
}
public void setPortfolioToPublic(Long portfolioId){
// 判断当前用户与作品用户是不是一家公司的
Long accountId = UserContext.getUserHolder().getId();
Account currentAccount = accountMapper.selectById(accountId);
Portfolio portfolio = baseMapper.selectById(portfolioId);
if (Objects.isNull(portfolio)){
throw new BusinessException("unknown portfolio");
}
if (Objects.nonNull(portfolio.getOrganizationId())
&& Objects.nonNull(currentAccount.getOrganizationId())
&& portfolio.getOrganizationId().equals(currentAccount.getOrganizationId())){
portfolio.setIsPublic(1);
portfolio.setUpdateDate(LocalDateTime.now());
baseMapper.updateById(portfolio);
}else {
throw new BusinessException("have.no.permission", ResultEnum.PROMPT.getCode());
}
}
}