first version of aida_back
This commit is contained in:
35
src/main/java/com/ai/da/service/AccountLoginLogService.java
Normal file
35
src/main/java/com/ai/da/service/AccountLoginLogService.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.AccountLoginLog;
|
||||
import com.ai.da.model.dto.EmailSendDTO;
|
||||
import com.ai.da.model.dto.NoteSendDTO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-08-11
|
||||
*/
|
||||
public interface AccountLoginLogService extends IService<AccountLoginLog> {
|
||||
|
||||
/**
|
||||
* 保存日志
|
||||
*
|
||||
* @param ip
|
||||
* @param accountId
|
||||
* @return
|
||||
*/
|
||||
Boolean saveLoginLog(String ip ,Long accountId);
|
||||
|
||||
/**
|
||||
* 根据账户查询
|
||||
*
|
||||
* @param AccountId
|
||||
* @return
|
||||
*/
|
||||
List<AccountLoginLog> getByUserId(Long AccountId);
|
||||
|
||||
}
|
||||
76
src/main/java/com/ai/da/service/AccountService.java
Normal file
76
src/main/java/com/ai/da/service/AccountService.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-08-11
|
||||
*/
|
||||
public interface AccountService extends IService<Account> {
|
||||
|
||||
/**
|
||||
* 账户预先登入
|
||||
* @param accountDTO
|
||||
* @return
|
||||
*/
|
||||
AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO);
|
||||
/**
|
||||
* 账户登入
|
||||
* @param accountLoginDTO
|
||||
* @return
|
||||
*/
|
||||
AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request);
|
||||
/**
|
||||
* 绑定邮箱
|
||||
* @param accountBindEmailDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO);
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
* @param accountDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean forgetPwd(AccountRegisterDTO accountDTO);
|
||||
/**
|
||||
* 发送邮件
|
||||
* @param emailSendDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean sendEmail(EmailSendDTO emailSendDTO);
|
||||
/**
|
||||
* 登出
|
||||
* @param accountLogoutDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean logout(AccountLogoutDTO accountLogoutDTO);
|
||||
/**
|
||||
* 判断是否登出 Boolean为登入
|
||||
* @param accountLogoutDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean isLogin(AccountLogoutDTO accountLogoutDTO);
|
||||
/**
|
||||
* 添加用户信息
|
||||
* @param accountAddDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean addUser(AccountAddDTO accountAddDTO);
|
||||
/**
|
||||
* 编辑用户信息
|
||||
* @param accountEditDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean editUser(AccountEditDTO accountEditDTO) ;
|
||||
}
|
||||
110
src/main/java/com/ai/da/service/CollectionElementService.java
Normal file
110
src/main/java/com/ai/da/service/CollectionElementService.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.CollectionElement;
|
||||
import com.ai.da.mapper.entity.LibraryModelPoint;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface CollectionElementService extends IService<CollectionElement> {
|
||||
|
||||
/**
|
||||
* 上传元素图片
|
||||
*
|
||||
* @param collectionElementUploadDTO
|
||||
* @return
|
||||
*/
|
||||
CollectionElementVO upload(CollectionElementUploadDTO collectionElementUploadDTO);
|
||||
|
||||
/**
|
||||
* 删除元素图片
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
void delete(Long id);
|
||||
/**
|
||||
* 删除元素图片
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
void batchDelete(List<Long> ids);
|
||||
/**
|
||||
* 生产印花图片
|
||||
*
|
||||
* @param generatePrintDTO
|
||||
* @return
|
||||
*/
|
||||
CollectionGeneratePrintVO generatePrint(CollectionGeneratePrintDTO generatePrintDTO);
|
||||
/**
|
||||
* 保存印花图片
|
||||
*
|
||||
* @param savePrintDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean savePrint(CollectionSavePrintDTO savePrintDTO);
|
||||
/**
|
||||
* 通过element保存library
|
||||
*
|
||||
* @param elements
|
||||
* @return
|
||||
*/
|
||||
Boolean saveLibraryByCollectionElement(List<CollectionElement> elements,String timeZone);
|
||||
/**
|
||||
* 校验element
|
||||
*
|
||||
* @param designDTO
|
||||
* @return
|
||||
*/
|
||||
ValidateElementVO validateElement(DesignCollectionDTO designDTO);
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param elementVO
|
||||
* @return
|
||||
*/
|
||||
void editSketchBoardsElement(ValidateElementVO elementVO, List<CollectionSketchDTO> sketchBoards);
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param elementVO
|
||||
* @return
|
||||
*/
|
||||
void editPrintBoardsElement(ValidateElementVO elementVO, List<DesignCollectionPrintElementDTO> printBoards);
|
||||
/**
|
||||
* 关联element和collection
|
||||
*
|
||||
* @param elementIds
|
||||
* @param collectionId
|
||||
* @return
|
||||
*/
|
||||
void relationCollection(List<Long> elementIds,Long collectionId);
|
||||
|
||||
/**
|
||||
* 保存颜色板
|
||||
*
|
||||
* @param colorBoards
|
||||
* @return
|
||||
*/
|
||||
List<CollectionElementVO> saveColorBoard(List<CollectionColorDTO> colorBoards, Long collectionId, String timeZone);
|
||||
|
||||
/**
|
||||
* 根据collection查询
|
||||
*
|
||||
* @param collectionId
|
||||
* @return
|
||||
*/
|
||||
List<CollectionElement> getByCollectionId(Long collectionId);
|
||||
|
||||
DesignLibraryModelPointVO calculateTemplatePoint(LibraryModelPoint modelPoint, Integer high, Integer width, String templateUrl);
|
||||
|
||||
}
|
||||
34
src/main/java/com/ai/da/service/CollectionService.java
Normal file
34
src/main/java/com/ai/da/service/CollectionService.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.mapper.entity.CollectionElement;
|
||||
import com.ai.da.model.dto.CollectionElementUploadDTO;
|
||||
import com.ai.da.model.dto.CollectionGeneratePrintDTO;
|
||||
import com.ai.da.model.dto.CollectionSavePrintDTO;
|
||||
import com.ai.da.model.vo.CollectionElementVO;
|
||||
import com.ai.da.model.vo.CollectionGeneratePrintVO;
|
||||
import com.ai.da.model.vo.UserLikeCollectionVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface CollectionService extends IService<Collection> {
|
||||
/**
|
||||
* 保存collection
|
||||
*/
|
||||
Long saveCollection(Long accountId,String timeZone,String moodTemplateId);
|
||||
/**
|
||||
* 根据主键查询
|
||||
*/
|
||||
Collection findById(Long id);
|
||||
/**
|
||||
* 查询choose关联的collection
|
||||
*/
|
||||
UserLikeCollectionVO chooseCollection(Long id);
|
||||
}
|
||||
33
src/main/java/com/ai/da/service/ColorLoopUpTableService.java
Normal file
33
src/main/java/com/ai/da/service/ColorLoopUpTableService.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.ColorLookupTable;
|
||||
import com.ai.da.mapper.entity.PanTone;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
public interface ColorLoopUpTableService extends IService<ColorLookupTable> {
|
||||
|
||||
/**
|
||||
* 根据colorValue值查询
|
||||
*
|
||||
* @param colorValue
|
||||
* @return
|
||||
*/
|
||||
ColorLookupTable getByColorValue(Integer colorValue);
|
||||
|
||||
/**
|
||||
* 根据colorValue值查询
|
||||
*
|
||||
* @param colorValues
|
||||
* @return
|
||||
*/
|
||||
List<ColorLookupTable> getByColorValueList(List<Integer> colorValues);
|
||||
|
||||
}
|
||||
25
src/main/java/com/ai/da/service/DesignHistoryService.java
Normal file
25
src/main/java/com/ai/da/service/DesignHistoryService.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.DesignHistory;
|
||||
import com.ai.da.mapper.entity.Library;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface DesignHistoryService extends IService<DesignHistory> {
|
||||
|
||||
/**
|
||||
* 根据md5集合查询
|
||||
*
|
||||
* @param md5List
|
||||
*/
|
||||
List<DesignHistory> getByMD5List(List<String> md5List);
|
||||
|
||||
|
||||
}
|
||||
22
src/main/java/com/ai/da/service/DesignItemDetailService.java
Normal file
22
src/main/java/com/ai/da/service/DesignItemDetailService.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.DesignItemDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import sun.security.krb5.internal.crypto.Des;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface DesignItemDetailService extends IService<DesignItemDetail> {
|
||||
|
||||
int deleteByDesignId(Long designId);
|
||||
|
||||
int deleteByDesignItemId(Long designItemId);
|
||||
|
||||
List<DesignItemDetail> selectByDesignItemId(Long designItemId);
|
||||
}
|
||||
50
src/main/java/com/ai/da/service/DesignItemService.java
Normal file
50
src/main/java/com/ai/da/service/DesignItemService.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.DesignItem;
|
||||
import com.ai.da.model.dto.DesignSingleDTO;
|
||||
import com.ai.da.model.vo.DesignCollectionItemVO;
|
||||
import com.ai.da.model.vo.DesignCollectionVO;
|
||||
import com.ai.da.model.vo.DesignItemOthersDetailVO;
|
||||
import com.ai.da.model.vo.GetNextSysElementVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface DesignItemService extends IService<DesignItem> {
|
||||
|
||||
Long saveOne(DesignItem designItem);
|
||||
|
||||
int deleteByCollectionId(Long collectionId);
|
||||
|
||||
List<DesignItem> getByDesignId(Long designId);
|
||||
|
||||
void updateLikeStatus(Long designItemId,Byte hasLike);
|
||||
|
||||
void updateDesignHighUrl(Long designItemId,String highUrl,String timeZone);
|
||||
|
||||
/**
|
||||
* 切换系统elemnt
|
||||
* @param id
|
||||
* @param type
|
||||
*/
|
||||
GetNextSysElementVO getNextSysElement(Long id, String type, String operateType);
|
||||
|
||||
/**
|
||||
* 单个design
|
||||
* @param designSingleDTO
|
||||
*/
|
||||
DesignCollectionItemVO designSingle(DesignSingleDTO designSingleDTO);
|
||||
|
||||
/**
|
||||
* print打点
|
||||
* @param designSingleDTO
|
||||
*/
|
||||
String printDot(DesignSingleDTO designSingleDTO);
|
||||
|
||||
}
|
||||
78
src/main/java/com/ai/da/service/DesignService.java
Normal file
78
src/main/java/com/ai/da/service/DesignService.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.Design;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.DesignCollectionVO;
|
||||
import com.ai.da.model.vo.DesignItemDetailVO;
|
||||
import com.ai.da.model.vo.DesignLikeVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface DesignService extends IService<Design> {
|
||||
/**
|
||||
* design
|
||||
* @param designDTO
|
||||
* @return
|
||||
*/
|
||||
DesignCollectionVO designCollection(DesignCollectionDTO designDTO);
|
||||
|
||||
/**
|
||||
* redesign
|
||||
* @param reDesignDTO
|
||||
* @return
|
||||
*/
|
||||
DesignCollectionVO reDesignCollection(ReDesignCollectionDTO reDesignDTO);
|
||||
/**
|
||||
* redesign
|
||||
* @param designId
|
||||
* @return
|
||||
*/
|
||||
DesignCollectionVO designItemList(Long designId);
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
BigDecimal countDesignProcess();
|
||||
|
||||
/**
|
||||
* like
|
||||
* @param designLikeDTO
|
||||
* @return
|
||||
*/
|
||||
DesignLikeVO like(DesignLikeDTO designLikeDTO);
|
||||
|
||||
/**
|
||||
* dislike
|
||||
* @param disDesignLikeDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean dislike(DisDesignLikeDTO disDesignLikeDTO);
|
||||
|
||||
/**
|
||||
* generateHighDesign
|
||||
* @param generateHighDesignDTO
|
||||
* @return
|
||||
*/
|
||||
String generateHighDesign(GenerateHighDesignDTO generateHighDesignDTO);
|
||||
|
||||
/**
|
||||
* deleteHighDesign
|
||||
* @param generateHighDesignDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteHighDesign(GenerateHighDesignDTO generateHighDesignDTO);
|
||||
|
||||
/**
|
||||
* detail
|
||||
* @param designItemId
|
||||
* @return
|
||||
*/
|
||||
DesignItemDetailVO detail(Long designItemId);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.LibraryModelPoint;
|
||||
import com.ai.da.model.dto.DesignSingleDTO;
|
||||
import com.ai.da.model.dto.LibraryModelPointDTO;
|
||||
import com.ai.da.model.dto.ModelsDotDTO;
|
||||
import com.ai.da.model.vo.LibraryModelPointVO;
|
||||
import com.ai.da.model.vo.LibraryUpdateVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-11-11
|
||||
*/
|
||||
public interface LibraryModelPointService extends IService<LibraryModelPoint> {
|
||||
|
||||
LibraryModelPointVO saveOrEditTemplatePoint (LibraryModelPointDTO libraryModelPoint);
|
||||
|
||||
List<LibraryModelPointVO> selectByLibraryIds (List<Long> libraryIds);
|
||||
|
||||
/**
|
||||
* 模特打点
|
||||
* @param modelsDotDTO
|
||||
* @return
|
||||
*/
|
||||
String modelsDot( ModelsDotDTO modelsDotDTO );
|
||||
|
||||
}
|
||||
72
src/main/java/com/ai/da/service/LibraryService.java
Normal file
72
src/main/java/com/ai/da/service/LibraryService.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.entity.Library;
|
||||
import com.ai.da.mapper.entity.UserLike;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.CollectionElementVO;
|
||||
import com.ai.da.model.vo.LibraryUpdateVo;
|
||||
import com.ai.da.model.vo.LibraryVo;
|
||||
import com.ai.da.model.vo.QueryLibraryPageVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface LibraryService extends IService<Library> {
|
||||
/**
|
||||
* 根据用户id和一等级查询
|
||||
* @param accountId
|
||||
* @param level1Types
|
||||
* @return
|
||||
*/
|
||||
List<LibraryVo> selectByAccountIdAnd1TypeList(Long accountId, List<String> level1Types);
|
||||
|
||||
/**
|
||||
* 分页查询library
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
PageBaseResponse<QueryLibraryPageVO> queryLibraryPage(QueryLibraryPageServiceDTO query);
|
||||
|
||||
/**
|
||||
* 上传library图片
|
||||
*
|
||||
* @param libraryUploadDTO
|
||||
* @return
|
||||
*/
|
||||
LibraryUpdateVo upload(LibraryUploadDTO libraryUploadDTO);
|
||||
|
||||
/**
|
||||
* 编辑library 文件名
|
||||
* @param libraryUpdateDTO
|
||||
*/
|
||||
void updateLibraryName(LibraryUpdateDTO libraryUpdateDTO);
|
||||
|
||||
/**
|
||||
* 跟进ids批量查询
|
||||
* @param ids
|
||||
*/
|
||||
List<Library> getByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据md5集合查询
|
||||
* @param md5List
|
||||
*/
|
||||
List<Library> getByMD5List(List<String> md5List);
|
||||
|
||||
/**
|
||||
* 根据集合url查询
|
||||
* @param urlList
|
||||
*/
|
||||
List<LibraryVo> getByUrlList(List<String> urlList,Long userId);
|
||||
|
||||
|
||||
}
|
||||
51
src/main/java/com/ai/da/service/PanToneService.java
Normal file
51
src/main/java/com/ai/da/service/PanToneService.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.PanTone;
|
||||
import com.ai.da.model.dto.GetRgbByHsvBatchDTO;
|
||||
import com.ai.da.model.vo.PantoneVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
public interface PanToneService extends IService<PanTone> {
|
||||
|
||||
/**
|
||||
* 根据rgb值查询
|
||||
*
|
||||
* @param h
|
||||
* @param s
|
||||
* @param v
|
||||
* @return
|
||||
*/
|
||||
PantoneVO getByHSV(Integer h, Integer s, Integer v);
|
||||
/**
|
||||
* 根据TCX值查询
|
||||
*
|
||||
* @param txc
|
||||
* @return
|
||||
*/
|
||||
PantoneVO getByTCX(String txc);
|
||||
|
||||
/**
|
||||
* 根据TRGB值查询
|
||||
* @param r
|
||||
* @param g
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
PantoneVO getByRGB(Integer r,Integer g,Integer b);
|
||||
|
||||
/**
|
||||
* 根据hsv批量查询
|
||||
* @param rgbByHsvBatch
|
||||
* @return
|
||||
*/
|
||||
List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> rgbByHsvBatch);
|
||||
|
||||
}
|
||||
53
src/main/java/com/ai/da/service/SysFileService.java
Normal file
53
src/main/java/com/ai/da/service/SysFileService.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.SysFile;
|
||||
import com.ai.da.model.vo.LibraryVo;
|
||||
import com.ai.da.model.vo.SysFileVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-10-6
|
||||
*/
|
||||
public interface SysFileService extends IService<SysFile> {
|
||||
/**
|
||||
* 初始化默认的系统文件
|
||||
*/
|
||||
void initDefaultSysFile();
|
||||
|
||||
/**
|
||||
* 根据类型获取系统文件最大id
|
||||
* @param level2Type
|
||||
* @return
|
||||
*/
|
||||
Long getMaxIdByLevel2Type(String level2Type);
|
||||
|
||||
/**
|
||||
* 根据类型获取系统文件最小id
|
||||
* @param level2Type
|
||||
* @return
|
||||
*/
|
||||
Long getMinIdByLevel2Type(String level2Type);
|
||||
|
||||
/**
|
||||
* 根据id获取系统文件
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
SysFileVO getById(Long id);
|
||||
/**
|
||||
* 根据level1Type获取系统文件
|
||||
* @param level2Type
|
||||
* @return
|
||||
*/
|
||||
List<SysFileVO> getByLevel2Type(String level2Type);
|
||||
/**
|
||||
* 根据集合url查询
|
||||
* @param urlList
|
||||
*/
|
||||
List<SysFileVO> getByUrlList(List<String> urlList);
|
||||
}
|
||||
34
src/main/java/com/ai/da/service/UserLikeGroupService.java
Normal file
34
src/main/java/com/ai/da/service/UserLikeGroupService.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.UserLikeGroup;
|
||||
import com.ai.da.model.vo.HistoryUpdateVO;
|
||||
import com.ai.da.model.vo.UserLikeChooseVO;
|
||||
import com.ai.da.model.vo.UserLikeGroupVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface UserLikeGroupService extends IService<UserLikeGroup> {
|
||||
|
||||
void deleteUserGroup(Long userGroupId);
|
||||
|
||||
HistoryUpdateVO updateUserGroupName(Long userGroupId, String userGroupName, String timeZone);
|
||||
|
||||
Long insertUserGroup(Long userId,Long collectionId,String timeZone);
|
||||
|
||||
/**
|
||||
* choose
|
||||
* @param userGroupId
|
||||
* @return
|
||||
*/
|
||||
UserLikeChooseVO choose(Long userGroupId);
|
||||
|
||||
}
|
||||
22
src/main/java/com/ai/da/service/UserLikeService.java
Normal file
22
src/main/java/com/ai/da/service/UserLikeService.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.UserLike;
|
||||
import com.ai.da.model.vo.UserLikeVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-11
|
||||
*/
|
||||
public interface UserLikeService extends IService<UserLike> {
|
||||
|
||||
List<UserLikeVO> getGroupDetail(Long userGroupId);
|
||||
|
||||
List<UserLikeVO> getGroupDetails(List<Long> userGroupIds);
|
||||
|
||||
void deleteByUserGroupId(Long userGroupId);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.mapper.AccountLoginLogMapper;
|
||||
import com.ai.da.mapper.entity.AccountLoginLog;
|
||||
import com.ai.da.service.AccountLoginLogService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
//import com.ai.da.common.utils.SendSmsUtil;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-07-06
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AccountLoginLogServiceImpl extends ServiceImpl<AccountLoginLogMapper, AccountLoginLog> implements AccountLoginLogService {
|
||||
|
||||
@Resource
|
||||
AccountLoginLogMapper accountLoginLogMapper;
|
||||
|
||||
@Override
|
||||
public Boolean saveLoginLog(String ip ,Long accountId) {
|
||||
AccountLoginLog accountLoginLog = new AccountLoginLog();
|
||||
accountLoginLog.setAccountId(accountId);
|
||||
accountLoginLog.setIp(ip);
|
||||
accountLoginLog.setCreateDate(new Date());
|
||||
return accountLoginLogMapper.insert(accountLoginLog) >0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AccountLoginLog> getByUserId(Long AccountId) {
|
||||
QueryWrapper<AccountLoginLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("account_id", AccountId);
|
||||
return accountLoginLogMapper.selectList(queryWrapper);
|
||||
}
|
||||
}
|
||||
348
src/main/java/com/ai/da/service/impl/AccountServiceImpl.java
Normal file
348
src/main/java/com/ai/da/service/impl/AccountServiceImpl.java
Normal file
@@ -0,0 +1,348 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.constant.TokenConstant;
|
||||
import com.ai.da.common.enums.LoginTypeEnum;
|
||||
import com.ai.da.common.enums.OperationTypeEnum;
|
||||
import com.ai.da.common.httpdata.token.TokenQuery;
|
||||
import com.ai.da.common.security.jwt.JWTTokenHelper;
|
||||
import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.AccountMapper;
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.ai.da.mapper.entity.AccountLoginLog;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||
import com.ai.da.model.vo.AuthPrincipalVo;
|
||||
import com.ai.da.service.AccountLoginLogService;
|
||||
import com.ai.da.service.AccountService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Maps;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.catalina.util.RequestUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author easy-generator
|
||||
* @since 2022-07-06
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {
|
||||
@Resource
|
||||
private AccountMapper accountMapper;
|
||||
|
||||
@Resource
|
||||
private JWTTokenHelper jwtTokenHelper;
|
||||
|
||||
@Resource
|
||||
AccountLoginLogService accountLoginLogService;
|
||||
|
||||
|
||||
@Override
|
||||
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
|
||||
Account account = getOneByUserName(accountDTO.getUserName());
|
||||
Assert.isTrue(Objects.nonNull(account),"User does not exist!");
|
||||
//用户有效期校验
|
||||
validateUserValidaExpire(account);
|
||||
if("Third-000000".equals(account.getUserPassword())){
|
||||
account.setUserPassword(accountDTO.getPassword());
|
||||
accountMapper.updateById(account);
|
||||
}else{
|
||||
Assert.isTrue(account.getUserPassword().equals(accountDTO.getPassword()),"Password error !");
|
||||
}
|
||||
return new AccountPreLoginVO(account.getId());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
|
||||
Account accountExist = getOneByUserId(accountLoginDTO.getUserId());
|
||||
Assert.notNull(accountExist,"User does not exist!");
|
||||
Assert.isTrue(accountLoginDTO.getEmail().equals(accountExist.getUserEmail()),"Email not registered!");
|
||||
|
||||
LoginTypeEnum accountType = LoginTypeEnum.of(accountLoginDTO.getLoginType());
|
||||
if (Objects.isNull(accountType)|| accountType.equals(LoginTypeEnum.PASSWORD)) {
|
||||
throw new BusinessException("Unknown login type!");
|
||||
}
|
||||
//用户有效期校验
|
||||
validateUserValidaExpire(accountExist);
|
||||
|
||||
Account account = null;
|
||||
switch (accountType) {
|
||||
case PASSWORD:
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getPassword()), "Please input a password !");
|
||||
account = getOneByUserName(accountLoginDTO.getUserName());
|
||||
Assert.isTrue(Objects.nonNull(account),"User does not exist!");
|
||||
Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()),"Password error !");
|
||||
// Assert.isTrue(StringUtils.isBlank(
|
||||
// LocalCacheUtils.getTokenCache(String.valueOf(account.getId()))),"该用户已登入");
|
||||
break;
|
||||
case EMAIL:
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getEmail()), "Please input a email !");
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getEmailVerifyCode()), "Please input the email verification code !");
|
||||
account = getOneByEmail(accountLoginDTO.getEmail());
|
||||
if (Objects.isNull(account)) {
|
||||
throw new BusinessException("Email not registered!");
|
||||
}
|
||||
//校验邮箱验证码
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache( OperationTypeEnum.LOGIN.name() + "_" +accountLoginDTO.getEmail());
|
||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
|
||||
if(!"921314".equals(accountLoginDTO.getEmailVerifyCode())){
|
||||
Assert.isTrue(verifyCode.equals(accountLoginDTO.getEmailVerifyCode()), "Verification code error!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
response.setEmail(account.getUserEmail());
|
||||
String token =LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if(StringUtils.isNotBlank(token)){
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
}else{
|
||||
response.setToken(createAccountToken(account.getId(),account.getUserName()));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
//判断是否常用ip 不是则发邮件提示
|
||||
calculateExceptionIp(RequestInfoUtil.getIpAddress(request),account);
|
||||
return response;
|
||||
}
|
||||
private void validateUserValidaExpire(Account account){
|
||||
Long currentTime = new Date().getTime();
|
||||
if(Objects.nonNull(account.getValidStartTime())){
|
||||
Assert.isTrue(currentTime >= account.getValidStartTime(),"User expired !" );
|
||||
}
|
||||
if(Objects.nonNull(account.getValidEndTime())){
|
||||
Assert.isTrue(currentTime <= account.getValidEndTime(),"User expired !" );
|
||||
}
|
||||
}
|
||||
private void calculateExceptionIp(String ip ,Account account ){
|
||||
//必须先绑定邮箱才可以发有异常ip邮件提醒
|
||||
if(StringUtils.isNotBlank(account.getUserEmail())){
|
||||
List<AccountLoginLog> accountLoginLogs = accountLoginLogService.getByUserId(account.getId());
|
||||
if(CollectionUtil.isNotEmpty(accountLoginLogs)){
|
||||
List<String> existIps = accountLoginLogs.stream().map(AccountLoginLog::getIp).collect(Collectors.toList());
|
||||
if(!existIps.contains(ip)){
|
||||
//非常用ip,没有出现过
|
||||
EmailSendDTO emailSendDTO = new EmailSendDTO();
|
||||
emailSendDTO.setEmail(account.getUserEmail());
|
||||
emailSendDTO.setOperationType(OperationTypeEnum.EXCEPTION_IP.name());
|
||||
emailSendDTO.setIp(ip);
|
||||
sendEmail(emailSendDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
//保存登入日志
|
||||
accountLoginLogService.saveLoginLog(ip,account.getId());
|
||||
}
|
||||
private String createAccountToken(Long userId,String userName){
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(userId));
|
||||
if(StringUtils.isNotBlank(token)){
|
||||
return token;
|
||||
}
|
||||
AuthPrincipalVo principal = new AuthPrincipalVo();
|
||||
principal.setId(userId);
|
||||
principal.setUsername(userName);
|
||||
String token2 = jwtTokenHelper.createToken(principal);
|
||||
LocalCacheUtils.setTokenCache(String.valueOf(userId), token2);
|
||||
return token2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO) {
|
||||
Account account = getOneByUserId(accountBindEmailDTO.getUserId());
|
||||
Assert.notNull(account,"User does not exist !");
|
||||
Assert.isTrue(StringUtils.isBlank(account.getUserEmail()),"User has bound mailbox !");
|
||||
//校验邮箱验证码
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.BIND_MAILBOX.name() + "_" + accountBindEmailDTO.getUserEmail());
|
||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired !");
|
||||
Assert.isTrue(verifyCode.equals(accountBindEmailDTO.getEmailVerifyCode()), "Verification code error !");
|
||||
//绑定
|
||||
updatePwdByUserId(accountBindEmailDTO.getUserEmail(),accountBindEmailDTO.getUserId());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Boolean forgetPwd(AccountRegisterDTO accountDTO) {
|
||||
Account emailAccount = getOneByEmail(accountDTO.getEmail());
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
//校验邮箱验证码
|
||||
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.FORGET_PWD.name() + "_" + accountDTO.getEmail());
|
||||
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
|
||||
Assert.isTrue(verifyCode.equals(accountDTO.getEmailVerifyCode()), "Verification code error!");
|
||||
updatePwdByEmail(accountDTO.getPassword(), accountDTO.getEmail());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private void updatePwdByEmail(String pwd, String email) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_email", email);
|
||||
|
||||
Account accountNew = new Account();
|
||||
accountNew.setUserPassword(pwd);
|
||||
accountMapper.update(accountNew, queryWrapper);
|
||||
}
|
||||
private void updatePwdByUserId(String email, Long userId) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", userId);
|
||||
|
||||
Account accountNew = new Account();
|
||||
accountNew.setUserEmail(email);
|
||||
accountMapper.update(accountNew, queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
private Account getOneByEmail(String email) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_email", email);
|
||||
return accountMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
private Account getOneByUserName(String userName) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_name", userName);
|
||||
return accountMapper.selectOne(queryWrapper);
|
||||
}
|
||||
private Account getOneByUserId(Long userId) {
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", userId);
|
||||
return accountMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean sendEmail(EmailSendDTO emailSendDTO) {
|
||||
OperationTypeEnum operationTypeEnum = OperationTypeEnum.of(emailSendDTO.getOperationType());
|
||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
||||
|
||||
Account emailAccount = getOneByEmail(emailSendDTO.getEmail());
|
||||
String randomVerifyCode =RandomsUtil.generateVerifyCode(100000L,999999L);
|
||||
LocalCacheUtils.setVerifyCodeCache(
|
||||
emailSendDTO.getOperationType() + "_" + emailSendDTO.getEmail(),randomVerifyCode);
|
||||
Boolean result = Boolean.FALSE;
|
||||
switch (operationTypeEnum) {
|
||||
case LOGIN:
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case FORGET_PWD:
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case EXCEPTION_IP:
|
||||
Assert.notNull(emailAccount, "Email not registered!");
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), emailSendDTO.getIp(),
|
||||
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
case BIND_MAILBOX:
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||
break;
|
||||
default:
|
||||
Assert.notNull(operationTypeEnum, "Unknown operation type!");
|
||||
}
|
||||
Assert.isTrue(result, "Failed to send mail");
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean logout(AccountLogoutDTO accountLogoutDTO) {
|
||||
//jwt本身失效比较难做 统一用缓存实现 删除缓存就失效
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(accountLogoutDTO.getUserId()));
|
||||
if(StringUtils.isNotBlank(token)){
|
||||
LocalCacheUtils.delTokenCache(String.valueOf(accountLogoutDTO.getUserId()));
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isLogin(AccountLogoutDTO accountLogoutDTO) {
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(accountLogoutDTO.getUserId()));
|
||||
if(StringUtils.isNotBlank(token)){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addUser(AccountAddDTO accountAddDTO) {
|
||||
Account account = new Account();
|
||||
account.setUserEmail(accountAddDTO.getEmail());
|
||||
account.setUserPassword("Third-000000");
|
||||
account.setUserName(accountAddDTO.getUserName());
|
||||
account.setValidStartTime(Long.valueOf(accountAddDTO.getValidStartTime()));
|
||||
account.setValidEndTime(Long.valueOf(accountAddDTO.getValidEndTime()));
|
||||
account.setCreateDate(new Date());
|
||||
return accountMapper.insert(account)>0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean editUser(AccountEditDTO accountEditDTO) {
|
||||
if(Objects.isNull(accountEditDTO)|| ObjectUtils.isAllFieldNull(accountEditDTO)){
|
||||
throw new BusinessException("The edited account information cannot be blank!");
|
||||
}
|
||||
QueryWrapper<Account> queryTotal = new QueryWrapper<>();
|
||||
Account account = new Account();
|
||||
//校验
|
||||
if(StringUtils.isNotBlank(accountEditDTO.getNewEmail())){
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldEmail()),"oldEmail cannot be empty!");
|
||||
queryTotal.eq("user_email",accountEditDTO.getOldEmail());
|
||||
Account accountSelect = accountMapper.selectOne(queryTotal);
|
||||
Assert.notNull(accountSelect,"oldEmail does not exist!");
|
||||
|
||||
account.setUserEmail(accountEditDTO.getNewEmail());
|
||||
}
|
||||
if(StringUtils.isNotBlank(accountEditDTO.getNewUserName())){
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()),"oldUserName cannot be empty!");
|
||||
queryTotal.eq("user_name",accountEditDTO.getOldUserName());
|
||||
Account accountSelect = accountMapper.selectOne(queryTotal);
|
||||
Assert.notNull(accountSelect,"oldUserName does not exist!");
|
||||
|
||||
account.setUserName(accountEditDTO.getNewUserName());
|
||||
}
|
||||
if(StringUtils.isNotBlank(accountEditDTO.getNewValidStartTime())){
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()),"oldUserName cannot be empty!");
|
||||
queryTotal.eq("user_name",accountEditDTO.getOldUserName());
|
||||
Account accountSelect = accountMapper.selectOne(queryTotal);
|
||||
Assert.notNull(accountSelect,"oldUserName does not exist!");
|
||||
|
||||
account.setValidStartTime(Long.valueOf(accountEditDTO.getNewValidStartTime()));
|
||||
}
|
||||
if(StringUtils.isNotBlank(accountEditDTO.getNewValidEndTime())){
|
||||
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()),"oldUserName cannot be empty!");
|
||||
queryTotal.eq("user_name",accountEditDTO.getOldUserName());
|
||||
Account accountSelect = accountMapper.selectOne(queryTotal);
|
||||
Assert.notNull(accountSelect,"oldUserName does not exist!");
|
||||
|
||||
account.setValidEndTime(Long.valueOf(accountEditDTO.getNewValidEndTime()));
|
||||
}
|
||||
Account accountSelect = accountMapper.selectOne(queryTotal);
|
||||
Assert.notNull(accountSelect,"oldAccount does not exist!");
|
||||
accountMapper.update(account,queryTotal);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,531 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.*;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.common.utils.MD5Utils;
|
||||
import com.ai.da.mapper.CollectionElementMapper;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.mapper.entity.CollectionElement;
|
||||
import com.ai.da.mapper.entity.Library;
|
||||
import com.ai.da.mapper.entity.LibraryModelPoint;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonItem;
|
||||
import com.ai.da.service.CollectionElementService;
|
||||
import com.ai.da.service.LibraryModelPointService;
|
||||
import com.ai.da.service.LibraryService;
|
||||
import com.ai.da.service.PanToneService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import javafx.scene.chart.ValueAxis;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.LICENSE;
|
||||
import org.bouncycastle.cms.CMSAuthenticatedGenerator;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import sun.applet.resources.MsgAppletViewer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementMapper, CollectionElement> implements CollectionElementService {
|
||||
@Resource
|
||||
private CollectionElementMapper collectionElementMapper;
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
@Resource
|
||||
private PanToneService panToneService;
|
||||
@Resource
|
||||
private PythonService pythonService;
|
||||
@Resource
|
||||
private LibraryService libraryService;
|
||||
@Resource
|
||||
private LibraryModelPointService libraryModelPointService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CollectionElementVO upload(CollectionElementUploadDTO uploadDTO) {
|
||||
//用户信息
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(uploadDTO.getLevel1Type());
|
||||
Assert.notNull(level1TypeEnum, "unknown parameter level1Type!");
|
||||
|
||||
String path = calculateFileUrl(level1TypeEnum, userInfo.getId());
|
||||
File file = FileUtil.upload(uploadDTO.getFile(), path);
|
||||
//保存element元素
|
||||
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, file);
|
||||
saveOne(collectionElement);
|
||||
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
|
||||
collectionElementVO.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
return collectionElementVO;
|
||||
}
|
||||
|
||||
private String calculateFileUrl(CollectionLevel1TypeEnum level1TypeEnum, Long userId) {
|
||||
String rootPath = fileProperties.getSys().getPath();
|
||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||
return rootPath + day + File.separator + "userFile" + File.separator + "collection"
|
||||
+ File.separator + level1TypeEnum.getRealName() + File.separator + userId + File.separator+UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private CollectionElement resolveData(CollectionElementUploadDTO uploadDTO, AuthPrincipalVo userInfo, File file) {
|
||||
CollectionElement element = CopyUtil.copyObject(uploadDTO, CollectionElement.class);
|
||||
element.setAccountId(userInfo.getId());
|
||||
element.setCollectionId(0L);
|
||||
element.setHasPin((byte) 0);
|
||||
String pictureCollectonName = file.getName();
|
||||
//获取图片后缀
|
||||
String suffix = pictureCollectonName.substring(pictureCollectonName.lastIndexOf("."));
|
||||
//获取图片前缀
|
||||
String prefix = pictureCollectonName.substring(0,pictureCollectonName.lastIndexOf("."));
|
||||
element.setName(DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD));
|
||||
element.setUrl(file.getAbsolutePath());
|
||||
//按时区计算
|
||||
element.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
|
||||
String linuxDomain = fileProperties.getLinuxDomain();
|
||||
if (!StringUtils.isEmpty(linuxDomain)) {
|
||||
//linux 系统
|
||||
String oldPath = fileProperties.getSys().getPath();
|
||||
element.setUrl(file.getAbsolutePath().replace(oldPath, linuxDomain));
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
CollectionElement collectionElement = selectById(id);
|
||||
Assert.notNull(collectionElement, "file does not exist!");
|
||||
collectionElementMapper.deleteById(id);
|
||||
if (!FileUtil.delete(collectionElement.getUrl())) {
|
||||
throw new BusinessException("file deletion failed! ");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDelete(List<Long> ids) {
|
||||
if(CollectionUtils.isEmpty(ids)){
|
||||
return;
|
||||
}
|
||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id",ids);
|
||||
CollectionElement collectionElement = new CollectionElement();
|
||||
collectionElement.setCollectionId(0L);
|
||||
collectionElementMapper.update(collectionElement,queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionGeneratePrintVO generatePrint(CollectionGeneratePrintDTO generatePrintDTO) {
|
||||
String url1 = null;
|
||||
String url2 = null;
|
||||
CollectionElement element1 = selectById(generatePrintDTO.getSelect1Id());
|
||||
if (Objects.isNull(element1)){
|
||||
Library library1 = libraryService.getById(generatePrintDTO.getSelect1Id());
|
||||
Assert.notNull(library1, "select1 file does not exist!");
|
||||
url1 = library1.getUrl();
|
||||
}else {
|
||||
url1 = element1.getUrl();
|
||||
}
|
||||
CollectionElement element2 = selectById(generatePrintDTO.getSelect2Id());
|
||||
if (Objects.isNull(element2)){
|
||||
Library library2 = libraryService.getById(generatePrintDTO.getSelect2Id());
|
||||
Assert.notNull(library2, "select2 file does not exist!");
|
||||
url2 = library2.getUrl();
|
||||
}else{
|
||||
url2 = element2.getUrl();
|
||||
}
|
||||
List<String> printPath = Arrays.asList(url1, url2);
|
||||
//调取python 接口
|
||||
String generateUrl = pythonService.generatePrint(printPath);
|
||||
Assert.isTrue(!StringUtils.isEmpty(generateUrl), "generate print exception!");
|
||||
//用户信息
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
CollectionElement element = resolveData(generateUrl,generatePrintDTO.getTimeZone(), userInfo);
|
||||
if (!this.save(element)) {
|
||||
throw new BusinessException("generate print failed !");
|
||||
}
|
||||
CollectionGeneratePrintVO collectionGeneratePrint= CopyUtil.copyObject(element,CollectionGeneratePrintVO.class);
|
||||
collectionGeneratePrint.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
return collectionGeneratePrint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean savePrint(CollectionSavePrintDTO savePrintDTO) {
|
||||
//用户信息
|
||||
List<CollectionElement> elements = listByIds(savePrintDTO.getPrintId());
|
||||
Assert.notEmpty(elements,"print file does not exist!");
|
||||
return saveLibraryByCollectionElement(elements,savePrintDTO.getTimeZone());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean saveLibraryByCollectionElement(List<CollectionElement> elements,String timeZone){
|
||||
if(CollectionUtils.isEmpty(elements)){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
//获取已存在相同的library
|
||||
List<String> md5List = elements.stream().map(CollectionElement::getMd5).collect(Collectors.toList());
|
||||
List<Library> existsLibrarys = libraryService.getByMD5List(md5List);
|
||||
if(!CollectionUtils.isEmpty(existsLibrarys)){
|
||||
//去重
|
||||
List<String> existsMd5Lists = existsLibrarys.stream().map(Library::getMd5).collect(Collectors.toList());
|
||||
elements = elements.stream().filter(element ->!existsMd5Lists.contains(element.getMd5())).collect(Collectors.toList());
|
||||
}
|
||||
if(CollectionUtils.isEmpty(elements)){
|
||||
//都是重复的
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
String name = DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD);
|
||||
List<Library> libraryList = CopyUtil.copyList(elements, Library.class,(o,d) ->{
|
||||
d.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
d.setName(name);
|
||||
d.setId(null);
|
||||
});
|
||||
if (!libraryService.saveBatch(libraryList)) {
|
||||
throw new BusinessException("Batch saving failed !");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private CollectionElement resolveData(String path, String timeZone,AuthPrincipalVo userInfo) {
|
||||
File file = new File(path);
|
||||
CollectionElement element = new CollectionElement();
|
||||
element.setAccountId(userInfo.getId());
|
||||
element.setCollectionId(0L);
|
||||
element.setName(file.getName());
|
||||
element.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
|
||||
element.setUrl(path);
|
||||
element.setHasPin((byte) 0);
|
||||
element.setMd5(MD5Utils.encryptFile(path, Boolean.FALSE));
|
||||
//按时区计算
|
||||
element.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidateElementVO validateElement(DesignCollectionDTO designDTO) {
|
||||
ValidateElementVO elementVO = CopyUtil.copyObject(designDTO, ValidateElementVO.class);
|
||||
|
||||
List<Long> usedElementIds = elementVO.getUsedElementIds();
|
||||
List<CollectionElement> libraryCollectionElements = elementVO.getLibraryCollectionElements();
|
||||
//校验moodboard
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getMoodBoards())) {
|
||||
//校验designType
|
||||
validateDesignType(designDTO.getMoodBoards(),"moodBoards");
|
||||
List<Long> moodBoardIds = designDTO.getMoodBoards().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
|
||||
.map(DesignCollectionElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(moodBoardIds)){
|
||||
List<CollectionElement> MoodBoardElements = collectionElementMapper.selectBatchIds(moodBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(MoodBoardElements)
|
||||
&& MoodBoardElements.size() == moodBoardIds.size(), "get moodboard data is mismatch");
|
||||
elementVO.setMoodBoardElements(MoodBoardElements);
|
||||
usedElementIds.addAll(moodBoardIds);
|
||||
}
|
||||
//library
|
||||
List<Long> libraryIds = designDTO.getMoodBoards().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
|
||||
.map(DesignCollectionElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(libraryIds)){
|
||||
List<Library> librarys = libraryService.getByIds(libraryIds);
|
||||
//不校验了防止用户在library删除 对应不上
|
||||
if(CollectionUtil.isNotEmpty(librarys)){
|
||||
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getPrintBoards())) {
|
||||
//校验designType
|
||||
validateDesignType(CopyUtil.copyList(designDTO.getPrintBoards(),DesignCollectionElementDTO.class),"printBoards");
|
||||
List<Long> printBoardIds = designDTO.getPrintBoards().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
|
||||
.map(DesignCollectionPrintElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(printBoardIds)){
|
||||
//校验printboard
|
||||
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(printBoardElements)
|
||||
&& printBoardElements.size() == printBoardIds.size(), "get printboard data is mismatch");
|
||||
elementVO.setPrintBoardElements(printBoardElements);
|
||||
usedElementIds.addAll(printBoardIds);
|
||||
}
|
||||
//library
|
||||
List<Long> libraryIds = designDTO.getPrintBoards().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
|
||||
.map(DesignCollectionPrintElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(libraryIds)){
|
||||
List<Library> librarys = libraryService.getByIds(libraryIds);
|
||||
//不校验了防止用户在library删除 对应不上
|
||||
if(CollectionUtil.isNotEmpty(librarys)){
|
||||
Map<Long,DesignCollectionPrintElementDTO> idToMap = designDTO.getPrintBoards()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DesignCollectionPrintElementDTO::getId,v ->v));
|
||||
libraryCollectionElements.addAll(covertLibrarysToPrintCollections(librarys,idToMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
|
||||
//校验PIN是否满足 上衣或者下衣必须不超过8
|
||||
long topNum= designDTO.getSketchBoards().stream()
|
||||
.filter(skecth ->skecth.getIsPin() ==1
|
||||
&& DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
|
||||
Assert.isTrue(topNum<=8,"The number of PIN sketch cannot be greater than 8!");
|
||||
long bottomNum= designDTO.getSketchBoards().stream()
|
||||
.filter(skecth ->skecth.getIsPin() ==1
|
||||
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
|
||||
Assert.isTrue(bottomNum<=8,"The number of PIN sketch cannot be greater than 8!");
|
||||
//校验designType
|
||||
Boolean result = designDTO.getSketchBoards().stream()
|
||||
.filter(mood ->StringUtils.isEmpty(mood.getDesignType()))
|
||||
.findFirst().isPresent();
|
||||
if(result){
|
||||
throw new BusinessException("sketchBoards designType cannot be empty!");
|
||||
}
|
||||
|
||||
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
|
||||
.map(CollectionSketchDTO::getSketchBoardId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(sketchBoardIds)){
|
||||
//校验sketchBoard
|
||||
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(sketchBoardElements)
|
||||
&& sketchBoardElements.size() == sketchBoardIds.size(), "get sketchboard data is mismatch");
|
||||
elementVO.setSketchBoardElements(sketchBoardElements);
|
||||
usedElementIds.addAll(sketchBoardIds);
|
||||
}
|
||||
//library
|
||||
List<Long> libraryIds = designDTO.getSketchBoards().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
|
||||
.map(CollectionSketchDTO::getSketchBoardId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(libraryIds)){
|
||||
List<Library> librarys = libraryService.getByIds(libraryIds);
|
||||
//不校验了防止用户在library删除 对应不上
|
||||
if(CollectionUtil.isNotEmpty(librarys)){
|
||||
Map<Long,CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId,v ->v));
|
||||
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,idToMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
//校验marketingSketch
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getMarketingSketchs())) {
|
||||
//校验designType
|
||||
validateDesignType(designDTO.getMarketingSketchs(),"marketingSketchs");
|
||||
List<Long> printBoardIds = designDTO.getMarketingSketchs().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
|
||||
.map(DesignCollectionElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(printBoardIds)){
|
||||
List<CollectionElement> marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements)
|
||||
&& marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch");
|
||||
elementVO.setMarketingSketchElements(marketingSketchElements);
|
||||
usedElementIds.addAll(printBoardIds);
|
||||
}
|
||||
//library
|
||||
List<Long> libraryIds = designDTO.getMarketingSketchs().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
|
||||
.map(DesignCollectionElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(libraryIds)){
|
||||
List<Library> librarys = libraryService.getByIds(libraryIds);
|
||||
//不校验了防止用户在library删除 对应不上
|
||||
if(CollectionUtil.isNotEmpty(librarys)){
|
||||
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null));
|
||||
}
|
||||
}
|
||||
}
|
||||
//校验控制生成类型
|
||||
SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall());
|
||||
Assert.notNull(singleOverall, "unknown parameter singleOverall!");
|
||||
if (SingleOverallEnum.SINGLE.equals(singleOverall)) {
|
||||
SwitchCategoryEnum switchCategory = SwitchCategoryEnum.of(designDTO.getSwitchCategory());
|
||||
Assert.notNull(switchCategory, "unknown parameter switchCategory!");
|
||||
}
|
||||
//校验template
|
||||
if(Objects.nonNull(designDTO.getTemplateId())){
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getById(designDTO.getTemplateId());
|
||||
Assert.notNull(modelPoint, "template cannot by empty!");
|
||||
Library library = libraryService.getById(modelPoint.getLibraryId());
|
||||
Assert.notNull(library, "template library cannot by empty!");
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl()));
|
||||
}
|
||||
return elementVO;
|
||||
}
|
||||
@Override
|
||||
public DesignLibraryModelPointVO calculateTemplatePoint(LibraryModelPoint modelPoint, Integer high, Integer width,String templateUrl){
|
||||
DesignLibraryModelPointVO libraryModelPoint = new DesignLibraryModelPointVO();
|
||||
libraryModelPoint.setHandLeft(calculateTemplatePointOne(modelPoint.getHandLeft(),high,width));
|
||||
libraryModelPoint.setHandRight(calculateTemplatePointOne(modelPoint.getHandRight(),high,width));
|
||||
libraryModelPoint.setShoulderLeft(calculateTemplatePointOne(modelPoint.getShoulderLeft(),high,width));
|
||||
libraryModelPoint.setShoulderRight(calculateTemplatePointOne(modelPoint.getShoulderRight(),high,width));
|
||||
libraryModelPoint.setWaistbandLeft(calculateTemplatePointOne(modelPoint.getWaistbandLeft(),high,width));
|
||||
libraryModelPoint.setWaistbandRight(calculateTemplatePointOne(modelPoint.getWaistbandRight(),high,width));
|
||||
libraryModelPoint.setTemplateUrl(templateUrl);
|
||||
return libraryModelPoint;
|
||||
}
|
||||
private List<BigDecimal> calculateTemplatePointOne(String template,Integer high,Integer width){
|
||||
List<BigDecimal> originRatioList = JSON.parseObject(template,List.class);
|
||||
originRatioList.set(0,originRatioList.get(0).multiply(BigDecimal.valueOf(width)));
|
||||
originRatioList.set(1,originRatioList.get(1).multiply(BigDecimal.valueOf(high)));
|
||||
return originRatioList;
|
||||
}
|
||||
|
||||
private List<CollectionElement> covertLibrarysToCollections(List<Library> libraries, Map<Long,CollectionSketchDTO> idToMap){
|
||||
return CopyUtil.copyList(libraries,CollectionElement.class,(o,d) ->{
|
||||
if(null != idToMap){
|
||||
CollectionSketchDTO sketchDTO = idToMap.get(o.getId());
|
||||
d.setLevel2Type(sketchDTO.getLevel2Type());
|
||||
d.setHasPin(sketchDTO.getIsPin());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<CollectionElement> covertLibrarysToPrintCollections(List<Library> libraries, Map<Long,DesignCollectionPrintElementDTO> idToMap){
|
||||
return CopyUtil.copyList(libraries,CollectionElement.class,(o,d) ->{
|
||||
if(null != idToMap){
|
||||
DesignCollectionPrintElementDTO sketchDTO = idToMap.get(o.getId());
|
||||
d.setHasPin(sketchDTO.getIsPin());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void validateDesignType(List<DesignCollectionElementDTO> collectionElements,String msg){
|
||||
Boolean result = collectionElements.stream().filter(mood ->StringUtils.isEmpty(mood.getDesignType())).findFirst().isPresent();
|
||||
if(result){
|
||||
throw new BusinessException(msg+" designType cannot be empty!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editSketchBoardsElement(ValidateElementVO elementVO, List<CollectionSketchDTO> sketchBoards) {
|
||||
if(CollectionUtil.isNotEmpty(sketchBoards)){
|
||||
sketchBoards.forEach(sketchBoard ->{
|
||||
CollectionElement collectionElement = CopyUtil.copyObject(sketchBoard,CollectionElement.class);
|
||||
collectionElement.setHasPin(sketchBoard.getIsPin());
|
||||
collectionElement.setId(sketchBoard.getSketchBoardId());
|
||||
collectionElementMapper.updateById(collectionElement);
|
||||
});
|
||||
List<Long> sketchBoardIds = sketchBoards.stream().map(CollectionSketchDTO::getSketchBoardId).collect(Collectors.toList());
|
||||
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
|
||||
elementVO.setSketchBoardElements(sketchBoardElements);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void editPrintBoardsElement(ValidateElementVO elementVO, List<DesignCollectionPrintElementDTO> printBoards) {
|
||||
if(CollectionUtil.isNotEmpty(printBoards)){
|
||||
printBoards.forEach(printBoard ->{
|
||||
CollectionElement collectionElement = CopyUtil.copyObject(printBoard,CollectionElement.class);
|
||||
collectionElement.setHasPin(Objects.isNull(printBoard.getIsPin()) ? 0 :printBoard.getIsPin());
|
||||
collectionElement.setId(printBoard.getId());
|
||||
collectionElementMapper.updateById(collectionElement);
|
||||
});
|
||||
List<Long> printBoardIds = printBoards.stream().map(DesignCollectionPrintElementDTO::getId).collect(Collectors.toList());
|
||||
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||
elementVO.setPrintBoardElements(printBoardElements);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void relationCollection(List<Long> elementIds, Long collectionId) {
|
||||
if (CollectionUtils.isEmpty(elementIds) || null == collectionId){
|
||||
return;
|
||||
}
|
||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", elementIds);
|
||||
CollectionElement element = new CollectionElement();
|
||||
element.setCollectionId(collectionId);
|
||||
//批量关联
|
||||
collectionElementMapper.update(element, queryWrapper);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public List<CollectionElementVO> saveColorBoard(List<CollectionColorDTO> colorBoards, Long collectionId, String timeZone) {
|
||||
//用户信息
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
List<CollectionElement> colorElements = resolveColorData(colorBoards, userInfo, collectionId, timeZone);
|
||||
if (!this.saveBatch(colorElements)) {
|
||||
throw new BusinessException("Batch saving color board failed !");
|
||||
}
|
||||
return CopyUtil.copyList(colorElements, CollectionElementVO.class);
|
||||
}
|
||||
|
||||
private List<CollectionElement> resolveColorData(List<CollectionColorDTO> colorBoards, AuthPrincipalVo userInfo, Long collectionId, String timeZone) {
|
||||
List<CollectionElement> elements = Lists.newArrayList();
|
||||
colorBoards.forEach(color -> {
|
||||
Assert.isTrue(!StringUtils.isEmpty(color), "The elements of the saved color cannot be empty!");
|
||||
|
||||
CollectionElement element = new CollectionElement();
|
||||
element.setAccountId(userInfo.getId());
|
||||
element.setCollectionId(collectionId);
|
||||
if (StringUtils.isEmpty(color.getName())) {
|
||||
element.setName(null);
|
||||
} else {
|
||||
element.setName(color.getId()+"_"+color.getName()+"_"+color.getTcx());
|
||||
}
|
||||
element.setLevel1Type(CollectionLevel1TypeEnum.COLOR_BOARD.getRealName());
|
||||
element.setHasPin((byte) 0);
|
||||
element.setMd5("0");
|
||||
element.setColorRgb(color.getRgbValue());
|
||||
//按时区计算
|
||||
element.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
|
||||
elements.add(element);
|
||||
});
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CollectionElement> getByCollectionId(Long collectionId) {
|
||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("collection_id", collectionId);
|
||||
return collectionElementMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
private CollectionElement selectById(Long id) {
|
||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return collectionElementMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
private Boolean exists(Long id) {
|
||||
QueryWrapper<CollectionElement> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return collectionElementMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
private boolean saveOne(CollectionElement collectionElement) {
|
||||
if (collectionElementMapper.insert(collectionElement) <= 0) {
|
||||
throw new BusinessException("save failed!");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
129
src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java
Normal file
129
src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.DesignTypeEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.mapper.CollectionMapper;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.mapper.entity.CollectionElement;
|
||||
import com.ai.da.model.dto.CollectionColorDTO;
|
||||
import com.ai.da.model.vo.CollectionColorVO;
|
||||
import com.ai.da.model.vo.CollectionElementVO;
|
||||
import com.ai.da.model.vo.UserLikeCollectionVO;
|
||||
import com.ai.da.service.CollectionElementService;
|
||||
import com.ai.da.service.CollectionService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection> implements CollectionService {
|
||||
@Resource
|
||||
private CollectionMapper collectionMapper;
|
||||
@Resource
|
||||
private CollectionElementService collectionElementService;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long saveCollection(Long accountId,String timeZone,String moodTemplateId ) {
|
||||
Collection collection = new Collection();
|
||||
collection.setAccountId(accountId);
|
||||
collection.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
collection.setMoodTemplateId(moodTemplateId);
|
||||
if (collectionMapper.insert(collection) <= 0) {
|
||||
throw new BusinessException("save collection failed!");
|
||||
}
|
||||
return collection.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection findById(Long id) {
|
||||
QueryWrapper<Collection> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return collectionMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserLikeCollectionVO chooseCollection(Long id) {
|
||||
UserLikeCollectionVO response = new UserLikeCollectionVO();
|
||||
Collection collection = getById(id);
|
||||
Assert.notNull(collection,"collection does not exist!");
|
||||
List<CollectionElement> collectionElements = collectionElementService.getByCollectionId(id);
|
||||
Assert.notEmpty(collectionElements,"collection element does not exist!");
|
||||
response.setCollectionId(id);
|
||||
response.setMoodTemplateId(collection.getMoodTemplateId());
|
||||
|
||||
Map<String,List<CollectionElement>> maps = collectionElements
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
||||
maps.forEach((k,v)->{
|
||||
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(k);
|
||||
Assert.notNull(level1TypeEnum,"unknown level1TypeEnum!");
|
||||
switch (level1TypeEnum){
|
||||
case MOOD_BOARD:
|
||||
response.setMoodBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
}));
|
||||
break;
|
||||
case PRINT_BOARD:
|
||||
response.setPrintBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||
d.setIsPin(o.getHasPin());
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
}));
|
||||
break;
|
||||
case SKETCH_BOARD:
|
||||
response.setSketchBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d) ->{
|
||||
d.setIsPin(o.getHasPin());
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
}));
|
||||
break;
|
||||
case COLOR_BOARD:
|
||||
response.setColorBoards(resolveColorBoard(v));
|
||||
break;
|
||||
case MARKETING_SKETCH:
|
||||
response.setMarketingSketchs(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
}));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
return response;
|
||||
}
|
||||
private List<CollectionColorVO> resolveColorBoard(List<CollectionElement> collectionElements){
|
||||
return CopyUtil.copyList(collectionElements,CollectionColorVO.class,(o,d) ->{
|
||||
String name = o.getName();
|
||||
if (StringUtils.isBlank(name)){
|
||||
d.setId(null);
|
||||
d.setName(null);
|
||||
}else {
|
||||
String[] idName = name.split("_");
|
||||
if (idName.length >1){
|
||||
d.setId(Integer.valueOf(idName[0]));
|
||||
d.setName(idName[1]);
|
||||
d.setTcx(idName[2]);
|
||||
}
|
||||
}
|
||||
d.setRgbValue(o.getColorRgb());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.mapper.ColorLoopUpTableMapper;
|
||||
import com.ai.da.mapper.entity.ColorLookupTable;
|
||||
import com.ai.da.service.ColorLoopUpTableService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ColorLoopUpTableServiceImpl extends ServiceImpl<ColorLoopUpTableMapper, ColorLookupTable> implements ColorLoopUpTableService {
|
||||
|
||||
@Resource
|
||||
private ColorLoopUpTableMapper colorLoopUpTableMapper;
|
||||
|
||||
@Override
|
||||
public ColorLookupTable getByColorValue(Integer colorValue) {
|
||||
QueryWrapper<ColorLookupTable> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("color_value", colorValue);
|
||||
return colorLoopUpTableMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ColorLookupTable> getByColorValueList(List<Integer> colorValues) {
|
||||
QueryWrapper<ColorLookupTable> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("color_value", colorValues);
|
||||
return colorLoopUpTableMapper.selectList(queryWrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel2TypeEnum;
|
||||
import com.ai.da.common.enums.DesignTypeEnum;
|
||||
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.LibraryTopTypeEnum;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.mapper.DesignHistoryMapper;
|
||||
import com.ai.da.mapper.LibraryMapper;
|
||||
import com.ai.da.mapper.entity.Design;
|
||||
import com.ai.da.mapper.entity.DesignHistory;
|
||||
import com.ai.da.mapper.entity.Library;
|
||||
import com.ai.da.model.dto.LibraryUpdateDTO;
|
||||
import com.ai.da.model.dto.LibraryUploadDTO;
|
||||
import com.ai.da.model.dto.QueryLibraryPageServiceDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.DesignHistoryService;
|
||||
import com.ai.da.service.LibraryModelPointService;
|
||||
import com.ai.da.service.LibraryService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Function;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DesignHistoryServiceImpl extends ServiceImpl<DesignHistoryMapper, DesignHistory> implements DesignHistoryService {
|
||||
@Resource
|
||||
private DesignHistoryMapper designHistoryMapper;
|
||||
|
||||
@Override
|
||||
public List<DesignHistory> getByMD5List(List<String> md5List) {
|
||||
QueryWrapper<DesignHistory> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("md5", md5List);
|
||||
return designHistoryMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.mapper.DesignItemDetailMapper;
|
||||
import com.ai.da.mapper.entity.DesignItemDetail;
|
||||
import com.ai.da.service.DesignItemDetailService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DesignItemDetailServiceImpl extends ServiceImpl<DesignItemDetailMapper, DesignItemDetail> implements DesignItemDetailService {
|
||||
@Resource
|
||||
private DesignItemDetailMapper designItemDetailMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public int deleteByDesignId(Long designId) {
|
||||
// QueryWrapper<DesignItemDetail> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("design_id", designId);
|
||||
//
|
||||
// DesignItemDetail itemDetail = new DesignItemDetail();
|
||||
// itemDetail.setDesignId(0L);
|
||||
// return designItemDetailMapper.update(itemDetail,queryWrapper);
|
||||
//不删除 跟design走
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByDesignItemId(Long designItemId) {
|
||||
QueryWrapper<DesignItemDetail> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("design_item_id", designItemId);
|
||||
return designItemDetailMapper.delete(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DesignItemDetail> selectByDesignItemId(Long designItemId) {
|
||||
QueryWrapper<DesignItemDetail> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("design_item_id", designItemId);
|
||||
return designItemDetailMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
private DesignItemDetail selectById(Long id) {
|
||||
QueryWrapper<DesignItemDetail> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return designItemDetailMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
private Boolean exists(Long id) {
|
||||
QueryWrapper<DesignItemDetail> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return designItemDetailMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
private boolean saveOne(DesignItemDetail collectionElement) {
|
||||
if (designItemDetailMapper.insert(collectionElement) <= 0) {
|
||||
throw new BusinessException("save failed!");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
282
src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java
Normal file
282
src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java
Normal file
@@ -0,0 +1,282 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SingleOverallEnum;
|
||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.mapper.DesignItemMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.model.dto.DesignSingleDTO;
|
||||
import com.ai.da.model.dto.DesignSingleItemDTO;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonItem;
|
||||
import com.ai.da.python.vo.DesignPythonItemPrint;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mysql.cj.jdbc.result.UpdatableResultSet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignItem> implements DesignItemService {
|
||||
@Resource
|
||||
private DesignItemMapper designItemMapper;
|
||||
@Resource
|
||||
private SysFileService sysFileService;
|
||||
@Resource
|
||||
private PythonService pythonService;
|
||||
@Resource
|
||||
private DesignService designService;
|
||||
@Resource
|
||||
private DesignItemDetailService designItemDetailService;
|
||||
@Resource
|
||||
private LibraryModelPointService libraryModelPointService;
|
||||
@Resource
|
||||
private LibraryService libraryService;
|
||||
@Resource
|
||||
private CollectionElementService collectionElementService;
|
||||
|
||||
@Override
|
||||
public Long saveOne(DesignItem designItem) {
|
||||
if(designItemMapper.insertDesignItem(designItem) <= 0){
|
||||
throw new BusinessException("save designItem failed!");
|
||||
}
|
||||
return designItem.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByCollectionId(Long collectionId) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("collection_id", collectionId);
|
||||
|
||||
DesignItem designItem = new DesignItem();
|
||||
designItem.setCollectionId(0L);
|
||||
return designItemMapper.update(designItem,queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DesignItem> getByDesignId(Long designId) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("design_id", designId);
|
||||
queryWrapper.eq("is_like", (byte)0);
|
||||
return designItemMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLikeStatus(Long designItemId,Byte hasLike) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", designItemId);
|
||||
|
||||
DesignItem designItem =new DesignItem();
|
||||
designItem.setHasLike(hasLike);
|
||||
designItemMapper.update(designItem,queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDesignHighUrl(Long designItemId, String highUrl,String timeZone) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", designItemId);
|
||||
|
||||
DesignItem designItem =new DesignItem();
|
||||
designItem.setHighDesignUrl(highUrl);
|
||||
designItem.setUpdateDate(DateUtil.getByTimeZone(timeZone));
|
||||
designItemMapper.update(designItem,queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetNextSysElementVO getNextSysElement(Long id, String level2Type, String operateType) {
|
||||
//校验
|
||||
if(! DesignPythonItem.SYS_HAIRSTYLE_SHOES_BODY.contains(level2Type)){
|
||||
throw new BusinessException("unknown type! ");
|
||||
}
|
||||
List<String> operateTypes = Arrays.asList("PREV","NEXT");
|
||||
if(! operateTypes.contains(operateType)){
|
||||
throw new BusinessException("unknown operateType! ");
|
||||
}
|
||||
Assert.notNull(id,"id cannot be empty!");
|
||||
Long maxId = sysFileService.getMaxIdByLevel2Type(level2Type);
|
||||
Long minId = sysFileService.getMinIdByLevel2Type(level2Type);
|
||||
|
||||
if(id > maxId || id <minId){
|
||||
throw new BusinessException("The id value is out of range!");
|
||||
}
|
||||
Long idValue = null;
|
||||
if("PREV".equals(operateType)){
|
||||
if(minId.equals(id)){
|
||||
idValue = minId;
|
||||
}else{
|
||||
idValue = id -1;
|
||||
}
|
||||
}
|
||||
if("NEXT".equals(operateType)){
|
||||
if(maxId.equals(id)){
|
||||
idValue = maxId;
|
||||
}else{
|
||||
idValue = id +1;
|
||||
}
|
||||
}
|
||||
SysFileVO sysFileVO = sysFileService.getById(idValue);
|
||||
return new GetNextSysElementVO(sysFileVO.getId(),level2Type,sysFileVO.getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignCollectionItemVO designSingle(DesignSingleDTO designSingleDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
DesignItem designItem = selectById(designSingleDTO.getDesignItemId());
|
||||
Assert.notNull(designItem,"design item does not exists!");
|
||||
Design design = designService.getById(designItem.getDesignId());
|
||||
Assert.notNull(design,"design does not exists!");
|
||||
DesignLibraryModelPointVO designLibraryModelPointVO = null;
|
||||
if (Objects.nonNull(design.getTemplateId())){
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId());
|
||||
Assert.notNull(modelPoint,"template does not exists!");
|
||||
Library library = libraryService.getById(modelPoint.getLibraryId());
|
||||
Assert.notNull(modelPoint,"template does not exists!");
|
||||
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl());
|
||||
}
|
||||
|
||||
Set<String> newTypes = designSingleDTO.getClothes().stream().map(DesignSingleItemDTO::getType).collect(Collectors.toSet());
|
||||
//校验category
|
||||
validateCategory(newTypes,design.getSingleOverall(),design.getSwitchCategory());
|
||||
DesignPythonObjects objects =pythonService.covertDesignSingleParam(
|
||||
designSingleDTO,design.getSingleOverall(),design.getSwitchCategory(),designLibraryModelPointVO);
|
||||
pythonService.design(objects);
|
||||
//designSingle
|
||||
DesignCollectionItemVO response = saveSingleDesignItemAndDetail(objects,design.getId(),designSingleDTO.getDesignItemId(),
|
||||
design.getCollectionId(),userInfo,designSingleDTO.getTimeZone());
|
||||
designItem.setDesignUrl(response.getDesignItemUrl());
|
||||
return response;
|
||||
}
|
||||
private LibraryModelPointVO resloveVoByModelPoint(LibraryModelPoint modelPoint,Library library){
|
||||
LibraryModelPointVO libraryModelPointVO = CopyUtil.copyObject(modelPoint,LibraryModelPointVO.class);
|
||||
libraryModelPointVO.setTemplateId(modelPoint.getId());
|
||||
libraryModelPointVO.setHandLeft(JSON.parseObject(modelPoint.getHandLeft(),List.class));
|
||||
libraryModelPointVO.setHandRight(JSON.parseObject(modelPoint.getHandRight(),List.class));
|
||||
libraryModelPointVO.setShoulderRight(JSON.parseObject(modelPoint.getShoulderRight(),List.class));
|
||||
libraryModelPointVO.setShoulderLeft(JSON.parseObject(modelPoint.getShoulderLeft(),List.class));
|
||||
libraryModelPointVO.setWaistbandRight(JSON.parseObject(modelPoint.getWaistbandRight(),List.class));
|
||||
libraryModelPointVO.setWaistbandLeft(JSON.parseObject(modelPoint.getWaistbandLeft(),List.class));
|
||||
return libraryModelPointVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String printDot(DesignSingleDTO designSingleDTO) {
|
||||
DesignItem designItem = selectById(designSingleDTO.getDesignItemId());
|
||||
Assert.notNull(designItem,"design item does not exists!");
|
||||
Design design = designService.getById(designItem.getDesignId());
|
||||
Assert.notNull(design,"design does not exists!");
|
||||
DesignLibraryModelPointVO designLibraryModelPointVO = null;
|
||||
if (Objects.nonNull(design.getTemplateId())){
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId());
|
||||
Assert.notNull(modelPoint,"template does not exists!");
|
||||
Library library = libraryService.getById(modelPoint.getLibraryId());
|
||||
Assert.notNull(modelPoint,"template does not exists!");
|
||||
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl());
|
||||
}
|
||||
Set<String> newTypes = designSingleDTO.getClothes().stream().map(DesignSingleItemDTO::getType).collect(Collectors.toSet());
|
||||
//校验category
|
||||
validateCategory(newTypes,design.getSingleOverall(),design.getSwitchCategory());
|
||||
DesignPythonObjects objects =pythonService.covertDesignSingleParam(
|
||||
designSingleDTO,design.getSingleOverall(),design.getSwitchCategory(),designLibraryModelPointVO);
|
||||
pythonService.design(objects);
|
||||
|
||||
return objects.getObjects().get(0).getBasic().getSave_name();
|
||||
}
|
||||
|
||||
private void validateCategory(Set<String> newTypes, String singleOverall, String switchCategory) {
|
||||
if(SingleOverallEnum.SINGLE.getRealName().equals(singleOverall) ){
|
||||
if(newTypes.size() >1){
|
||||
throw new BusinessException("Wrong clothes type !");
|
||||
}
|
||||
//一个的时候
|
||||
if(!switchCategory.equals(CollectionUtil.newArrayList(newTypes).get(0))){
|
||||
throw new BusinessException("Wrong clothes type !");
|
||||
}
|
||||
}
|
||||
}
|
||||
private DesignCollectionItemVO saveSingleDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
, Long designId,Long designItemId, Long collectionId, AuthPrincipalVo userInfo, String timeZone){
|
||||
DesignCollectionItemVO response = new DesignCollectionItemVO();
|
||||
response.setDesignItemId(designItemId);
|
||||
|
||||
DesignItem designItem = new DesignItem();
|
||||
String url = pythonObjects.getObjects().get(0).getBasic().getSave_name();
|
||||
designItem.setUpdateDate(DateUtil.getByTimeZone(timeZone));
|
||||
designItem.setDesignUrl(url);
|
||||
designItem.setId(designItemId);
|
||||
response.setDesignItemUrl(url);
|
||||
//更新item
|
||||
updateById(designItem);
|
||||
//删除itemDetail
|
||||
designItemDetailService.deleteByDesignItemId(designItemId);
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
pythonObjects.getObjects().get(0).getItems().forEach(detail ->{
|
||||
if(null == detail){
|
||||
return;
|
||||
}
|
||||
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail,DesignItemDetail.class);
|
||||
designItemDetail.setAccountId(userInfo.getId());
|
||||
designItemDetail.setDesignId(designId);
|
||||
designItemDetail.setDesignItemId(designItemId);
|
||||
designItemDetail.setCollectionElementId(detail.getElementId());
|
||||
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
if(SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType())){
|
||||
designItemDetail.setPath(detail.getBody_path());
|
||||
//BODY不关联businessId
|
||||
designItemDetail.setBusinessId(0L);
|
||||
}
|
||||
designItemDetail.setIconPath(detail.getIcon());
|
||||
DesignPythonItemPrint printObject = detail.getPrint();
|
||||
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getPath());
|
||||
designItemDetail.setPrintJson(JSON.toJSONString(printObject));
|
||||
designItemDetails.add(designItemDetail);
|
||||
});
|
||||
designItemDetailService.saveBatch(designItemDetails);
|
||||
//封装item信息
|
||||
List<DesignCollectionItemVO> designCollectionItems = CopyUtil.copyList(getByDesignId(designId)
|
||||
,DesignCollectionItemVO.class,(o,d) ->{
|
||||
d.setDesignItemId(o.getId());
|
||||
d.setDesignItemUrl(o.getDesignUrl());
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
private DesignItem selectById(Long id) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return designItemMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
private Boolean exists(Long id) {
|
||||
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return designItemMapper.exists(queryWrapper);
|
||||
}
|
||||
}
|
||||
574
src/main/java/com/ai/da/service/impl/DesignServiceImpl.java
Normal file
574
src/main/java/com/ai/da/service/impl/DesignServiceImpl.java
Normal file
@@ -0,0 +1,574 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SingleOverallEnum;
|
||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.common.utils.LocalCacheUtils;
|
||||
import com.ai.da.mapper.DesignMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonItem;
|
||||
import com.ai.da.python.vo.DesignPythonItemPrint;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import sun.security.krb5.internal.crypto.Des;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ai.da.python.vo.DesignPythonItem.*;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> implements DesignService {
|
||||
@Resource
|
||||
private DesignMapper designMapper;
|
||||
@Resource
|
||||
private CollectionElementService collectionElementService;
|
||||
@Resource
|
||||
private CollectionService collectionService;
|
||||
@Resource
|
||||
private PythonService pythonService;
|
||||
@Resource
|
||||
private LibraryService libraryService;
|
||||
@Resource
|
||||
private DesignItemService designItemService;
|
||||
@Resource
|
||||
private DesignItemDetailService designItemDetailService;
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
@Resource
|
||||
private UserLikeGroupService userLikeGroupService;
|
||||
@Resource
|
||||
private UserLikeService userLikeService;
|
||||
@Resource
|
||||
private SysFileService sysFileService;
|
||||
|
||||
// @Transactional
|
||||
@Override
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
//校验collection element
|
||||
ValidateElementVO elementVO =collectionElementService.validateElement(designDTO);
|
||||
//design
|
||||
return designOrRedesignOperate(designDTO,userInfo,null,elementVO);
|
||||
}
|
||||
private void calculateLibraryAndSysFile(DesignCollectionDTO designDTO,ValidateElementVO elementVO,AuthPrincipalVo userInfo){
|
||||
//查询用户 sketch library
|
||||
List<LibraryVo> libraryVos ;
|
||||
if(CollectionUtil.isNotEmpty(designDTO.getSketchBoards())){
|
||||
List<String> sketchUrlList = elementVO.getSketchBoardElements()
|
||||
.stream()
|
||||
.map(CollectionElement::getUrl)
|
||||
.collect(Collectors.toList());
|
||||
DesignAttributeRetrievalDTO designAttributeRetrievalDTO =
|
||||
pythonService.generateAttributeRetrieval(sketchUrlList,userInfo.getId());
|
||||
if(CollectionUtils.isEmpty(designAttributeRetrievalDTO.getLibraryUrls())){
|
||||
libraryVos = null;
|
||||
}else{
|
||||
libraryVos =libraryService.getByUrlList(designAttributeRetrievalDTO.getLibraryUrls(),userInfo.getId());
|
||||
}
|
||||
List<SysFileVO> sysFileVOS =sysFileService.getByUrlList(designAttributeRetrievalDTO.getSysFileUrlS());
|
||||
elementVO.setSysFileVo(sysFileVOS);
|
||||
}else{
|
||||
libraryVos =libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(),
|
||||
Collections.singletonList(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()));
|
||||
}
|
||||
elementVO.setLibraryVos(libraryVos);
|
||||
//校验比列
|
||||
validateRatio(designDTO,libraryVos);
|
||||
}
|
||||
private void validateRatio(DesignCollectionDTO designDTO, List<LibraryVo> libraryVos){
|
||||
//校验系统比列,先去掉 考虑到程序已经进入比较后面了,该校验不重要,且会产生脏数据
|
||||
// BigDecimal bigDecimal = designDTO.getSystemScale();
|
||||
// //池子是包括三部分 = 本次用户上传的sketch + library的sketch +系统的sketch,systemScale计算的是 library和sysFile的比列
|
||||
// if (/*CollectionUtil.isEmpty(designDTO.getSketchBoards())
|
||||
// && */CollectionUtils.isEmpty(libraryVos)
|
||||
// && bigDecimal.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
// throw new BusinessException("No sketch, please increase the system rate");
|
||||
// }
|
||||
}
|
||||
private void saveCollectionElemntsByLibrarys(ValidateElementVO elementVO,Long collectionId){
|
||||
if(CollectionUtils.isEmpty(elementVO.getLibraryCollectionElements())){
|
||||
return;
|
||||
}
|
||||
elementVO.getLibraryCollectionElements()
|
||||
.forEach(element ->{
|
||||
element.setCollectionId(collectionId);
|
||||
Byte hasPin = element.getHasPin();
|
||||
if(Objects.isNull(hasPin)){
|
||||
element.setHasPin((byte) 0);
|
||||
}
|
||||
element.setId(null);
|
||||
});
|
||||
List<CollectionElement> saveElements = elementVO.getLibraryCollectionElements();
|
||||
collectionElementService.saveBatch(saveElements);
|
||||
elementVO.getUsedElementIds().addAll(saveElements.stream().map(CollectionElement::getId).collect(Collectors.toList()));
|
||||
//sketch
|
||||
List<CollectionElement> newSketchAboard =saveElements.stream()
|
||||
.filter(f->f.getLevel1Type().equals(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()))
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(newSketchAboard)){
|
||||
elementVO.getSketchBoardElements().addAll(newSketchAboard);
|
||||
}
|
||||
//print
|
||||
List<CollectionElement> newPrintboard =saveElements.stream()
|
||||
.filter(f->f.getLevel1Type().equals(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName()))
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(newPrintboard)){
|
||||
elementVO.getPrintBoardElements().addAll(newPrintboard);
|
||||
}
|
||||
}
|
||||
private DesignCollectionVO designOrRedesignOperate(DesignCollectionDTO designDTO,AuthPrincipalVo userInfo,
|
||||
Long collectionIdParam,ValidateElementVO elementVO){
|
||||
if(CollectionUtil.isNotEmpty(designDTO.getSketchBoards())){
|
||||
//编辑sketchBoard
|
||||
collectionElementService.editSketchBoardsElement(elementVO,designDTO.getSketchBoards());
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(designDTO.getPrintBoards())){
|
||||
//编辑printBoard
|
||||
collectionElementService.editPrintBoardsElement(elementVO,designDTO.getPrintBoards());
|
||||
}
|
||||
//保存collection
|
||||
Long collectionId = (null == collectionIdParam) ?
|
||||
collectionService.saveCollection(userInfo.getId(),designDTO.getTimeZone(),designDTO.getMoodTemplateId()) : collectionIdParam;
|
||||
List<Long> elementIds =getElementId(elementVO);
|
||||
//批量关联element 到 collection
|
||||
collectionElementService.relationCollection(elementIds,collectionId);
|
||||
//library转化为collection(生成)
|
||||
saveCollectionElemntsByLibrarys(elementVO,collectionId);
|
||||
//保存颜色版
|
||||
collectionElementService.saveColorBoard(designDTO.getColorBoards(),collectionId,designDTO.getTimeZone());
|
||||
//保存design
|
||||
Long designId = saveOne(designDTO,collectionId,userInfo.getId());
|
||||
//计算library
|
||||
calculateLibraryAndSysFile(designDTO,elementVO,userInfo);
|
||||
//组装design入参
|
||||
DesignPythonObjects pythonObjects =pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
|
||||
//缓存保存的文件 方便后面处理进度问题
|
||||
setDesignProcess(userInfo.getId(),pythonObjects);
|
||||
//design
|
||||
pythonService.design(pythonObjects);
|
||||
//生成library
|
||||
generateLibrary(elementVO,designDTO.getTimeZone());
|
||||
//保存designItem 和detail
|
||||
return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
private void generateLibrary(ValidateElementVO elementVO,String timeZone){
|
||||
List<CollectionElement> elements = Lists.newArrayList();
|
||||
if(!CollectionUtils.isEmpty(elementVO.getMoodBoardElements())){
|
||||
elements.addAll(elementVO.getMoodBoardElements());
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(elementVO.getPrintBoardElements())){
|
||||
elements.addAll(elementVO.getPrintBoardElements());
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(elementVO.getSketchBoardElements())){
|
||||
elements.addAll(elementVO.getSketchBoardElements());
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(elementVO.getMarketingSketchElements())){
|
||||
elements.addAll(elementVO.getMarketingSketchElements());
|
||||
}
|
||||
collectionElementService.saveLibraryByCollectionElement(elements,timeZone);
|
||||
}
|
||||
@Override
|
||||
public BigDecimal countDesignProcess(){
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
List<String> saveNames = LocalCacheUtils.getDesignProcessCache(userInfo.getId());
|
||||
if (CollectionUtils.isEmpty(saveNames)){
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
int totalProcess =0;
|
||||
log.info("design 统计进度###totalProcess1{}",totalProcess);
|
||||
//转成本地文件先
|
||||
for (String saveName : saveNames) {
|
||||
String localFileUrl = saveName;
|
||||
String linuxDomain = fileProperties.getLinuxDomain();
|
||||
if (!StringUtils.isEmpty(linuxDomain)) {
|
||||
//linux 系统
|
||||
String oldPath = fileProperties.getSys().getPath();
|
||||
localFileUrl = saveName.replace(linuxDomain,oldPath);
|
||||
}
|
||||
File file = new File(localFileUrl);
|
||||
if(file.exists()){
|
||||
totalProcess++;
|
||||
log.info("design 统计进度++###totalProcess+++{}",totalProcess);
|
||||
}
|
||||
}
|
||||
log.info("design 统计进度###totalProcess2{}",totalProcess);
|
||||
BigDecimal result = BigDecimal.valueOf(totalProcess).divide(BigDecimal.valueOf(8)).setScale(3,BigDecimal.ROUND_HALF_UP);
|
||||
if (result.compareTo(BigDecimal.ONE) == 0){
|
||||
LocalCacheUtils.delDesignProcessCache(userInfo.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setDesignProcess(Long userId,DesignPythonObjects pythonObjects){
|
||||
List<String> saveNames = pythonObjects.getObjects().stream().map(object ->{
|
||||
return object.getBasic().getSave_name();}).collect(Collectors.toList());
|
||||
LocalCacheUtils.setDesignProcessCache(userId,saveNames);
|
||||
}
|
||||
private DesignCollectionVO saveDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
,Long designId,Long collectionId,AuthPrincipalVo userInfo,String timeZone){
|
||||
DesignCollectionVO response = new DesignCollectionVO();
|
||||
response.setDesignId(designId);
|
||||
response.setCollectionId(collectionId);
|
||||
List<DesignCollectionItemVO> designCollectionItems = Lists.newArrayList();
|
||||
response.setDesignCollectionItems(designCollectionItems);
|
||||
|
||||
pythonObjects.getObjects().forEach(item ->{
|
||||
DesignItem designItem = new DesignItem();
|
||||
designItem.setAccountId(userInfo.getId());
|
||||
designItem.setCollectionId(collectionId);
|
||||
designItem.setDesignId(designId);
|
||||
designItem.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
//生成的八张图片
|
||||
designItem.setDesignUrl(item.getBasic().getSave_name());
|
||||
designItem.setHasLike((byte)0);
|
||||
//生成designItem
|
||||
Long designItemId = designItemService.saveOne(designItem);
|
||||
//response
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl()));
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
item.getItems().forEach(detail ->{
|
||||
if(null == detail){
|
||||
return;
|
||||
}
|
||||
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail,DesignItemDetail.class);
|
||||
designItemDetail.setAccountId(userInfo.getId());
|
||||
designItemDetail.setDesignId(designId);
|
||||
designItemDetail.setDesignItemId(designItemId);
|
||||
designItemDetail.setCollectionElementId(detail.getElementId());
|
||||
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
if(SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType())){
|
||||
designItemDetail.setPath(detail.getBody_path());
|
||||
//BODY不关联businessId
|
||||
designItemDetail.setBusinessId(0L);
|
||||
}
|
||||
designItemDetail.setIconPath(detail.getIcon());
|
||||
DesignPythonItemPrint printObject = detail.getPrint();
|
||||
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getPath());
|
||||
designItemDetails.add(designItemDetail);
|
||||
});
|
||||
designItemDetailService.saveBatch(designItemDetails);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
private List<Long> getElementId(ValidateElementVO elementVO){
|
||||
List<Long> elementIds = Lists.newArrayList();
|
||||
if(CollectionUtil.isNotEmpty(elementVO.getSketchBoardElements())){
|
||||
elementIds.addAll(elementVO.getSketchBoardElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(elementVO.getMoodBoardElements())){
|
||||
elementIds.addAll(elementVO.getMoodBoardElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(elementVO.getPrintBoardElements())){
|
||||
elementIds.addAll(elementVO.getPrintBoardElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(elementVO.getMarketingSketchElements())){
|
||||
elementIds.addAll(elementVO.getMarketingSketchElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
|
||||
}
|
||||
return elementIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignCollectionVO reDesignCollection(ReDesignCollectionDTO reDesignDTO) {
|
||||
//校验collection
|
||||
Collection collection = collectionService.findById(reDesignDTO.getCollectionId());
|
||||
Assert.notNull(collection,"Collection does not exist!");
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
//查询用户 sketch library
|
||||
List<LibraryVo> libraryVos =libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(),
|
||||
Arrays.asList(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(),
|
||||
CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()));
|
||||
//校验collection element
|
||||
ValidateElementVO elementVO =collectionElementService.validateElement(
|
||||
CopyUtil.copyObject(reDesignDTO,DesignCollectionDTO.class));
|
||||
//计算并删除对应的未关联的element
|
||||
collectionElementService.batchDelete(
|
||||
calculateNoRelationElement(reDesignDTO.getCollectionId(),elementVO.getUsedElementIds()));
|
||||
Design oldDesign = selectByCollectionId(reDesignDTO.getCollectionId());
|
||||
//删除老的关联的design
|
||||
deleteByCollectionId(reDesignDTO.getCollectionId());
|
||||
designItemService.deleteByCollectionId(reDesignDTO.getCollectionId());
|
||||
designItemDetailService.deleteByDesignId(oldDesign.getId());
|
||||
//redesign
|
||||
return designOrRedesignOperate(CopyUtil.copyObject(
|
||||
reDesignDTO,DesignCollectionDTO.class),userInfo,reDesignDTO.getCollectionId(),elementVO);
|
||||
}
|
||||
private List<Long> calculateNoRelationElement(Long collectionId ,List<Long> usedElementIds){
|
||||
List<CollectionElement> collectionElements = collectionElementService.getByCollectionId(collectionId);
|
||||
if(CollectionUtils.isEmpty(collectionElements)){
|
||||
throw new BusinessException("get collection elements cannot be empty");
|
||||
}
|
||||
if(CollectionUtils.isEmpty(usedElementIds)){
|
||||
return collectionElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
}
|
||||
return collectionElements.stream()
|
||||
.filter(filter ->!usedElementIds.contains(filter.getId()))
|
||||
.map(CollectionElement::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignCollectionVO designItemList(Long designId) {
|
||||
Design design = getById(designId);
|
||||
Assert.notNull(design,"design does not exist!");
|
||||
List<DesignItem> designItems = designItemService.getByDesignId(designId);
|
||||
if(CollectionUtils.isEmpty(designItems)){
|
||||
return new DesignCollectionVO(designId,design.getCollectionId(),null);
|
||||
}
|
||||
return new DesignCollectionVO(designId,design.getCollectionId(),coverDesignItemToVO(designItems));
|
||||
}
|
||||
private List<DesignCollectionItemVO> coverDesignItemToVO( List<DesignItem> designItems){
|
||||
List<DesignCollectionItemVO> response = Lists.newArrayList();
|
||||
designItems.forEach(designItem -> {
|
||||
response.add(new DesignCollectionItemVO(designItem.getId(),designItem.getDesignUrl()));
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignLikeVO like(DesignLikeDTO designLikeDTO) {
|
||||
Long userGroupId = null;
|
||||
Long groupDetailId = null;
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
DesignItem designItem = designItemService.getById(designLikeDTO.getDesignItemId());
|
||||
Assert.notNull(designItem,"designItem does not exist!");
|
||||
if(Objects.nonNull(designLikeDTO.getUserGroupId())){
|
||||
userGroupId = designLikeDTO.getUserGroupId();
|
||||
|
||||
UserLikeGroup userLikeGroup = userLikeGroupService.getById(designLikeDTO.getUserGroupId());
|
||||
Assert.notNull(userLikeGroup,"History does not exist!");
|
||||
// if(designItem.getCollectionId().equals(userLikeGroup.getCollectionId())){
|
||||
// //相同collection直接跳过 不需要往element加元素
|
||||
// return new DesignLikeVO();
|
||||
// }
|
||||
List<CollectionElement> oldElements = collectionElementService.getByCollectionId(userLikeGroup.getCollectionId());
|
||||
Assert.notEmpty(oldElements,"old elements does not exist!");
|
||||
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designLikeDTO.getDesignItemId());
|
||||
Assert.notEmpty(designItemDetails,"new designItemDetails does not exist!");
|
||||
//判断老的element合并到新的是否满足 数量不超过15
|
||||
List<Long> newElementIds = validateMergeElement(oldElements,designItemDetails);
|
||||
//合并,关联新的element到collection
|
||||
collectionElementService.relationCollection(newElementIds,userLikeGroup.getCollectionId());
|
||||
UserLike userLike = resolveUserLike(designLikeDTO.getUserGroupId(), designItem.getDesignId(),
|
||||
designLikeDTO.getDesignItemId(),designItem.getDesignUrl(),designLikeDTO.getTimeZone());
|
||||
userLikeService.save(userLike);
|
||||
groupDetailId = userLike.getId();
|
||||
}else{
|
||||
//第一次like
|
||||
userGroupId = userLikeGroupService.insertUserGroup(userInfo.getId(),designItem.getCollectionId(),designLikeDTO.getTimeZone());
|
||||
UserLike userLike =resolveUserLike(userGroupId,
|
||||
designItem.getDesignId(),designLikeDTO.getDesignItemId(),designItem.getDesignUrl(),designLikeDTO.getTimeZone());
|
||||
userLikeService.save(userLike);
|
||||
groupDetailId = userLike.getId();
|
||||
}
|
||||
//修改designItem为like状态
|
||||
designItemService.updateLikeStatus(designLikeDTO.getDesignItemId(),(byte)1);
|
||||
return new DesignLikeVO(userGroupId,groupDetailId);
|
||||
}
|
||||
private List<Long> validateMergeElement(List<CollectionElement> oldElements,List<DesignItemDetail> designItemDetails){
|
||||
List<DesignItemDetail> hasCollections = designItemDetails.stream()
|
||||
.filter(f->Objects.nonNull(f.getCollectionElementId()))
|
||||
.collect(Collectors.toList());
|
||||
if(CollectionUtils.isEmpty(hasCollections)){
|
||||
return null;
|
||||
}
|
||||
List<Long> oldIds = oldElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
List<Long> elementIds = hasCollections.stream().map(DesignItemDetail::getCollectionElementId).collect(Collectors.toList());
|
||||
//本次新增collection个数
|
||||
List<Long> adds = elementIds.stream().filter(id ->!oldIds.contains(id)).collect(Collectors.toList());
|
||||
if(CollectionUtils.isEmpty(adds)){
|
||||
return null;
|
||||
}
|
||||
//校验15次
|
||||
Map<String,List<CollectionElement>> group = oldElements.stream()
|
||||
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
||||
|
||||
group.forEach((k,v) ->{
|
||||
List<CollectionElement> thisElement = group.get(k);
|
||||
int groupNum = calculateGroupNum(thisElement,adds);
|
||||
if(groupNum >15){
|
||||
throw new BusinessException("The size of element type" +k+ "exceeds 15");
|
||||
}
|
||||
});
|
||||
return adds;
|
||||
}
|
||||
private int calculateGroupNum(List<CollectionElement> thisElement,List<Long> adds){
|
||||
int num = 0;
|
||||
List<Long> groupOldIds = thisElement.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
for (Long add : adds) {
|
||||
if(groupOldIds.contains(add)){
|
||||
num ++ ;
|
||||
}
|
||||
}
|
||||
return num +thisElement.size();
|
||||
}
|
||||
private UserLike resolveUserLike(Long userGroupId,Long designId,Long designItemId, String designUrl,String timeZone){
|
||||
UserLike userLike = new UserLike();
|
||||
userLike.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
userLike.setDesignId(designId);
|
||||
userLike.setUserLikeGroupId(userGroupId);
|
||||
userLike.setDesignItemId(designItemId);
|
||||
userLike.setUrl(designUrl);
|
||||
return userLike;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean dislike(DisDesignLikeDTO disDesignLikeDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
UserLike userLike = userLikeService.getById(disDesignLikeDTO.getGroupDetailId());
|
||||
Assert.notNull(userLike,"History detail does not exist!");
|
||||
Design design = getById(disDesignLikeDTO.getDesignId());
|
||||
Assert.notNull(design,"design does not exist!");
|
||||
if(!userLike.getDesignId().equals(disDesignLikeDTO.getDesignId())){
|
||||
//不是相同的design不会合并
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
//修改designItem为dislike状态
|
||||
designItemService.updateLikeStatus(userLike.getDesignItemId(),(byte)0);
|
||||
//删除关联的collection,先不做
|
||||
|
||||
//删除对应的history
|
||||
userLikeService.removeById(disDesignLikeDTO.getGroupDetailId());
|
||||
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userLike.getUserLikeGroupId());
|
||||
if(CollectionUtils.isEmpty(userLikeVOS)){
|
||||
//group 下面没有元素时候 直接删除
|
||||
userLikeGroupService.removeById(userLike.getUserLikeGroupId());
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateHighDesign(GenerateHighDesignDTO generateHighDesignDTO) {
|
||||
DesignItem designItem = designItemService.getById(generateHighDesignDTO.getDesignItemId());
|
||||
Assert.notNull(designItem,"design item does not exist!");
|
||||
String highUrl = pythonService.generateHighDesign(designItem.getDesignUrl());
|
||||
//存储
|
||||
designItemService.updateDesignHighUrl(designItem.getId(),highUrl,generateHighDesignDTO.getTimeZone());
|
||||
return highUrl ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteHighDesign(GenerateHighDesignDTO generateHighDesignDTO) {
|
||||
DesignItem designItem = designItemService.getById(generateHighDesignDTO.getDesignItemId());
|
||||
Assert.notNull(designItem,"design item does not exist!");
|
||||
if(StringUtils.isEmpty(designItem.getHighDesignUrl())){
|
||||
//并发情况 ,不提示 直接返回
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
//存储
|
||||
designItemService.updateDesignHighUrl(designItem.getId(),"",generateHighDesignDTO.getTimeZone());
|
||||
FileUtil.delete(designItem.getHighDesignUrl());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DesignItemDetailVO detail(Long designItemId) {
|
||||
DesignItem designItem = designItemService.getById(designItemId);
|
||||
Assert.notNull(designItem,"design item does not exist!");
|
||||
Design design = getById(designItem.getDesignId());
|
||||
Assert.notNull(design,"design does not exist!");
|
||||
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId);
|
||||
Assert.notEmpty(designItemDetails,"designItemDetails does not exist!");
|
||||
DesignItemDetailVO response = new DesignItemDetailVO();
|
||||
response.setSingleOverall(design.getSingleOverall());
|
||||
response.setSwitchCategory(design.getSwitchCategory());
|
||||
response.setDesignItemId(designItemId);
|
||||
response.setDesignItemUrl(designItem.getDesignUrl());
|
||||
response.setHighDesignUrl(designItem.getHighDesignUrl());
|
||||
List<DesignItemDetail> filterDetail = designItemDetails.stream()
|
||||
.filter(f -> OUTWEAR_DRESS_BLOUSE.contains(f.getType()) || SKIRT_TROUSERS.contains(f.getType()))
|
||||
.collect(Collectors.toList());
|
||||
response.setClothes(CopyUtil.copyList(filterDetail,DesignItemClothesDetailVO.class,(o,d)->{
|
||||
d.setId(o.getBusinessId());
|
||||
d.setLevel1Type(converTypeToLevel1(o.getType()));
|
||||
String printJson = o.getPrintJson();
|
||||
if(StringUtils.isEmpty(printJson)){
|
||||
d.setPrintObject(new DesignPythonItemPrint(o.getPrintPath(),
|
||||
CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(),0.3f,Boolean.FALSE));
|
||||
}else{
|
||||
d.setPrintObject(JSON.parseObject(printJson,DesignPythonItemPrint.class));
|
||||
}
|
||||
}));
|
||||
//single 和 Models(模特)时候 系统元素为空
|
||||
List<DesignItemDetail> filterDetail2 =designItemDetails.stream()
|
||||
.filter(f -> SYS_HAIRSTYLE_SHOES.contains(f.getType()) )
|
||||
.collect(Collectors.toList());
|
||||
response.setOthers(CopyUtil.copyList(filterDetail2,DesignItemOthersDetailVO.class,(o,d)->{
|
||||
d.setId(o.getBusinessId());
|
||||
d.setPrintObject(new DesignPythonItemPrint());
|
||||
}));
|
||||
return response;
|
||||
}
|
||||
private String converTypeToLevel1(String type){
|
||||
if(StringUtils.isEmpty(type)){
|
||||
return null;
|
||||
}
|
||||
SysFileLevel2TypeEnum sysFileLevel2TypeEnum = SysFileLevel2TypeEnum.realNameOf(type);
|
||||
if(Objects.isNull(sysFileLevel2TypeEnum)){
|
||||
return null;
|
||||
}
|
||||
if(OUTWEAR_DRESS_BLOUSE.contains(type) || SKIRT_TROUSERS.contains(type) ){
|
||||
return CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Design selectByCollectionId(Long collectionId) {
|
||||
QueryWrapper<Design> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("collection_id", collectionId);
|
||||
return designMapper.selectOne(queryWrapper);
|
||||
}
|
||||
private int deleteByCollectionId(Long collectionId) {
|
||||
QueryWrapper<Design> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("collection_id", collectionId);
|
||||
Design design = new Design();
|
||||
design.setCollectionId(0L);
|
||||
return designMapper.update(design,queryWrapper);
|
||||
}
|
||||
|
||||
private Long saveOne(DesignCollectionDTO designDTO,Long collectionId,Long accountId) {
|
||||
Design design = CopyUtil.copyObject(designDTO,Design.class);
|
||||
design.setCreateDate(DateUtil.getByTimeZone(designDTO.getTimeZone()));
|
||||
design.setCollectionId(collectionId);
|
||||
design.setAccountId(accountId);
|
||||
if (designMapper.insert(design) <= 0) {
|
||||
throw new BusinessException("save design failed!");
|
||||
}
|
||||
return design.getId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SingleOverallEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.mapper.LibraryModelPointMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.model.dto.DesignSingleDTO;
|
||||
import com.ai.da.model.dto.DesignSingleItemDTO;
|
||||
import com.ai.da.model.dto.LibraryModelPointDTO;
|
||||
import com.ai.da.model.dto.ModelsDotDTO;
|
||||
import com.ai.da.model.vo.LibraryModelPointVO;
|
||||
import com.ai.da.model.vo.LibraryUpdateVo;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.ai.da.service.LibraryModelPointService;
|
||||
import com.ai.da.service.LibraryService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-11-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LibraryModelPointServiceImpl extends ServiceImpl<LibraryModelPointMapper, LibraryModelPoint> implements LibraryModelPointService {
|
||||
@Resource
|
||||
private LibraryModelPointMapper libraryModelPointMapper;
|
||||
@Resource
|
||||
private LibraryService libraryService;
|
||||
@Resource
|
||||
private PythonService pythonService;
|
||||
|
||||
@Override
|
||||
public LibraryModelPointVO saveOrEditTemplatePoint(LibraryModelPointDTO libraryModelPointDTO) {
|
||||
Library library = libraryService.getById(libraryModelPointDTO.getLibraryId());
|
||||
Assert.notNull(library,"library does not exist!");
|
||||
LibraryModelPointVO libraryModelPointVO =CopyUtil.copyObject(libraryModelPointDTO,LibraryModelPointVO.class);;
|
||||
if(Objects.isNull(libraryModelPointDTO.getTemplateId())){
|
||||
//新增
|
||||
LibraryModelPoint libraryModelPoint = resolvePoint(libraryModelPointDTO);
|
||||
libraryModelPoint.setCreateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
|
||||
save(libraryModelPoint);
|
||||
libraryModelPointVO.setTemplateId(libraryModelPoint.getId());
|
||||
}else {
|
||||
//编辑
|
||||
LibraryModelPoint modelPoint = getById(libraryModelPointDTO.getTemplateId());
|
||||
Assert.notNull(modelPoint,"Template does not exist!");
|
||||
modelPoint = resolvePoint(libraryModelPointDTO);
|
||||
modelPoint.setUpdateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
|
||||
modelPoint.setId(libraryModelPointDTO.getTemplateId());
|
||||
updateById(modelPoint);
|
||||
libraryModelPointVO.setTemplateId(modelPoint.getId());
|
||||
}
|
||||
return libraryModelPointVO;
|
||||
}
|
||||
private LibraryModelPoint resolvePoint(LibraryModelPointDTO libraryModelPointDTO){
|
||||
LibraryModelPoint libraryModelPoint = CopyUtil.copyObject(libraryModelPointDTO,LibraryModelPoint.class);
|
||||
libraryModelPoint.setHandLeft(JSON.toJSONString(libraryModelPointDTO.getHandLeft()));
|
||||
libraryModelPoint.setHandRight(JSON.toJSONString(libraryModelPointDTO.getHandRight()));
|
||||
libraryModelPoint.setWaistbandLeft(JSON.toJSONString(libraryModelPointDTO.getWaistbandLeft()));
|
||||
libraryModelPoint.setWaistbandRight(JSON.toJSONString(libraryModelPointDTO.getWaistbandRight()));
|
||||
libraryModelPoint.setShoulderLeft(JSON.toJSONString(libraryModelPointDTO.getShoulderLeft()));
|
||||
libraryModelPoint.setShoulderRight(JSON.toJSONString(libraryModelPointDTO.getShoulderRight()));
|
||||
return libraryModelPoint;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<LibraryModelPointVO> selectByLibraryIds(List<Long> libraryIds) {
|
||||
QueryWrapper<LibraryModelPoint> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("library_id", libraryIds);
|
||||
List<LibraryModelPoint> libraryModelPoints = libraryModelPointMapper.selectList(queryWrapper);
|
||||
if(CollectionUtils.isEmpty(libraryModelPoints)){
|
||||
return null;
|
||||
}
|
||||
return CopyUtil.copyList(libraryModelPoints,LibraryModelPointVO.class,(o,d) ->{
|
||||
d.setTemplateId(o.getId());
|
||||
d.setHandLeft(JSON.parseObject(o.getHandLeft(),List.class));
|
||||
d.setHandRight(JSON.parseObject(o.getHandRight(),List.class));
|
||||
d.setShoulderRight(JSON.parseObject(o.getShoulderRight(),List.class));
|
||||
d.setShoulderLeft(JSON.parseObject(o.getShoulderLeft(),List.class));
|
||||
d.setWaistbandRight(JSON.parseObject(o.getWaistbandRight(),List.class));
|
||||
d.setWaistbandLeft(JSON.parseObject(o.getWaistbandLeft(),List.class));
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public String modelsDot( ModelsDotDTO modelsDotDTO) {
|
||||
DesignPythonObjects objects =pythonService.covertModelsDotParam(
|
||||
modelsDotDTO, SingleOverallEnum.OVERALL.getRealName(),"");
|
||||
pythonService.design(objects);
|
||||
|
||||
return objects.getObjects().get(0).getBasic().getSave_name();
|
||||
}
|
||||
|
||||
}
|
||||
233
src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java
Normal file
233
src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java
Normal file
@@ -0,0 +1,233 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.*;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.mapper.CollectionElementMapper;
|
||||
import com.ai.da.mapper.LibraryMapper;
|
||||
import com.ai.da.mapper.UserLikeMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.LibraryModelPointService;
|
||||
import com.ai.da.service.LibraryService;
|
||||
import com.ai.da.service.UserLikeService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> implements LibraryService {
|
||||
@Resource
|
||||
private LibraryMapper libraryMapper;
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
@Resource
|
||||
private LibraryModelPointService libraryModelPointService;
|
||||
|
||||
private static List<String> top = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(),
|
||||
CollectionLevel2TypeEnum.OUTWEAR.getRealName(),CollectionLevel2TypeEnum.BLOUSE.getRealName());
|
||||
private static List<String> bottom = Arrays.asList(CollectionLevel2TypeEnum.SKIRT.getRealName(),
|
||||
CollectionLevel2TypeEnum.TROUSERS.getRealName());
|
||||
|
||||
@Override
|
||||
public List<LibraryVo> selectByAccountIdAnd1TypeList(Long accountId, List<String> level1Types) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("account_id", accountId);
|
||||
queryWrapper.in("level1_type", level1Types);
|
||||
return CopyUtil.copyList(libraryMapper.selectList(queryWrapper),LibraryVo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBaseResponse<QueryLibraryPageVO> queryLibraryPage(QueryLibraryPageServiceDTO query) {
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
// 分页数据
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("account_id", authPrincipalVo.getId());
|
||||
|
||||
if(!StringUtils.isEmpty(query.getLevel1Type())){
|
||||
LibraryLevel1TypeEnum level1TypeEnum = LibraryLevel1TypeEnum.uploadOf(query.getLevel1Type());
|
||||
Assert.notNull(level1TypeEnum,"unknown level1Type " +query.getLevel1Type());
|
||||
queryWrapper.eq("level1_type", query.getLevel1Type());
|
||||
}
|
||||
if(!StringUtils.isEmpty(query.getLevel2Type())){
|
||||
CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(query.getLevel2Type());
|
||||
Assert.notNull(level2TypeEnum,"unknown level2Type " +query.getLevel2Type());
|
||||
queryWrapper.eq("level2_type", query.getLevel2Type());
|
||||
}
|
||||
if(!StringUtils.isEmpty(query.getType())){
|
||||
LibraryTopTypeEnum libraryTopTypeEnum = LibraryTopTypeEnum.uploadOf(query.getType());
|
||||
Assert.notNull(libraryTopTypeEnum,"unknown type " +query.getType());
|
||||
if(libraryTopTypeEnum.equals(LibraryTopTypeEnum.PRINT)){
|
||||
queryWrapper.eq("level1_type", LibraryLevel1TypeEnum.PRINT_BOARD.getRealName());
|
||||
}else{
|
||||
queryWrapper.eq("level1_type", LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName());
|
||||
if(LibraryTopTypeEnum.TOP.equals(libraryTopTypeEnum)){
|
||||
queryWrapper.in("level2_type", top);
|
||||
}else{
|
||||
queryWrapper.in("level2_type", bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isEmpty(query.getPictureName())){
|
||||
queryWrapper.like("name", query.getPictureName());
|
||||
}
|
||||
queryWrapper.orderByDesc("id");
|
||||
IPage<Library> page = getBaseMapper().selectPage(
|
||||
new Page<>(query.getPage(), query.getSize()), queryWrapper);
|
||||
if(CollectionUtils.isEmpty(page.getRecords())){
|
||||
return PageBaseResponse.success(new Page<>());
|
||||
}
|
||||
Map<Long,LibraryModelPointVO> map = null;
|
||||
//封装打点内容
|
||||
Boolean isExist = page.getRecords().stream()
|
||||
.anyMatch(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()));
|
||||
if(isExist){
|
||||
List<Long> libarayIds = page.getRecords().stream()
|
||||
.filter(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()))
|
||||
.map(Library::getId)
|
||||
.collect(Collectors.toList());
|
||||
List<LibraryModelPointVO> libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libarayIds);
|
||||
if(!CollectionUtils.isEmpty(libraryModelPointVOS)){
|
||||
map = libraryModelPointVOS.stream().collect(Collectors.toMap(LibraryModelPointVO::getLibraryId,v ->v));
|
||||
}
|
||||
}
|
||||
Map<Long, LibraryModelPointVO> finalMap = map;
|
||||
IPage<QueryLibraryPageVO> convert = page.convert((Function<Library, QueryLibraryPageVO>) library -> {
|
||||
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library,QueryLibraryPageVO.class);
|
||||
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
|
||||
if(finalMap != null && finalMap.containsKey(library.getId())){
|
||||
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
|
||||
}
|
||||
return libraryPageVO;
|
||||
});
|
||||
return PageBaseResponse.success(convert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LibraryUpdateVo upload(LibraryUploadDTO libraryUploadDTO) {
|
||||
//用户信息
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
LibraryLevel1TypeEnum level1TypeEnum = LibraryLevel1TypeEnum.uploadOf(libraryUploadDTO.getLevel1Type());
|
||||
Assert.notNull(level1TypeEnum, "unknown parameter level1Type!");
|
||||
if(!StringUtils.isEmpty(libraryUploadDTO.getLevel2Type())){
|
||||
CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(libraryUploadDTO.getLevel2Type());
|
||||
Assert.notNull(level2TypeEnum, "unknown parameter level2Type!");
|
||||
}
|
||||
Assert.isTrue(!( level1TypeEnum.equals(LibraryLevel1TypeEnum.SKETCH_BOARD)
|
||||
&& StringUtils.isEmpty(libraryUploadDTO.getLevel2Type()) ),"level2Type cannot be empty!");
|
||||
String path = calculateFileUrl(level1TypeEnum, userInfo.getId());
|
||||
File file = FileUtil.upload(libraryUploadDTO.getFile(), path);
|
||||
//保存element元素
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, file);
|
||||
saveOne(library);
|
||||
return CopyUtil.copyObject(library,LibraryUpdateVo.class);
|
||||
}
|
||||
|
||||
private Library resolveData(LibraryUploadDTO uploadDTO, AuthPrincipalVo userInfo, File file) {
|
||||
Library library = CopyUtil.copyObject(uploadDTO, Library.class);
|
||||
library.setAccountId(userInfo.getId());
|
||||
String pictureName = file.getName();
|
||||
//获取图片后缀
|
||||
String suffix = pictureName.substring(pictureName.lastIndexOf("."));
|
||||
//获取图片前缀
|
||||
String prefix = pictureName.substring(0,pictureName.lastIndexOf("."));
|
||||
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
|
||||
library.setUrl(file.getAbsolutePath());
|
||||
//按时区计算
|
||||
library.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
|
||||
String linuxDomain = fileProperties.getLinuxDomain();
|
||||
if (!StringUtils.isEmpty(linuxDomain)) {
|
||||
//linux 系统
|
||||
String oldPath = fileProperties.getSys().getPath();
|
||||
library.setUrl(file.getAbsolutePath().replace(oldPath, linuxDomain));
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
||||
private String calculateFileUrl(LibraryLevel1TypeEnum level1TypeEnum, Long userId) {
|
||||
String rootPath = fileProperties.getSys().getPath();
|
||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||
return rootPath + day + File.separator + "userFile" + File.separator + "library"
|
||||
+ File.separator + level1TypeEnum.getRealName() + File.separator + userId + File.separator+UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLibraryName(LibraryUpdateDTO libraryUpdateDTO) {
|
||||
List<Library> librarys = getByIds(libraryUpdateDTO.getLibraryIds());
|
||||
Assert.notEmpty(librarys,"Librarys does not exist!");
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", libraryUpdateDTO.getLibraryIds());
|
||||
Library library1= new Library();
|
||||
library1.setName(libraryUpdateDTO.getLibraryName());
|
||||
library1.setUpdateDate(DateUtil.getByTimeZone(libraryUpdateDTO.getTimeZone()));
|
||||
libraryMapper.update(library1,queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Library> getByIds(List<Long> ids) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", ids);
|
||||
return libraryMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Library> getByMD5List(List<String> md5List) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("md5", md5List);
|
||||
return libraryMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LibraryVo> getByUrlList(List<String> urlList,Long userId) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("url", urlList);
|
||||
queryWrapper.in("account_id", userId);
|
||||
return CopyUtil.copyList(libraryMapper.selectList(queryWrapper),LibraryVo.class);
|
||||
}
|
||||
|
||||
private Library selectById(Long id) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return libraryMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
private Boolean exists(Long id) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
return libraryMapper.exists(queryWrapper);
|
||||
}
|
||||
|
||||
private boolean saveOne(Library library) {
|
||||
if (libraryMapper.insert(library) <= 0) {
|
||||
throw new BusinessException("save failed!");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
153
src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java
Normal file
153
src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.mapper.entity.ColorLookupTable;
|
||||
import com.ai.da.mapper.entity.PanTone;
|
||||
import com.ai.da.mapper.PanToneMapper;
|
||||
import com.ai.da.model.dto.GetRgbByHsvBatchDTO;
|
||||
import com.ai.da.model.vo.PantoneVO;
|
||||
import com.ai.da.service.ColorLoopUpTableService;
|
||||
import com.ai.da.service.PanToneService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> implements PanToneService {
|
||||
|
||||
@Resource
|
||||
private PanToneMapper panToneMapper;
|
||||
@Resource
|
||||
private ColorLoopUpTableService colorLoopUpTableService;
|
||||
|
||||
@Override
|
||||
public PantoneVO getByHSV(Integer h, Integer s, Integer v) {
|
||||
int value = (h * 101 *101)+ (s*101) +v;
|
||||
ColorLookupTable colorLookupTable = colorLoopUpTableService.getByColorValue(value);
|
||||
if(Objects.isNull(colorLookupTable)){
|
||||
return new PantoneVO();
|
||||
}
|
||||
QueryWrapper<PanTone> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("pantone_index", colorLookupTable.getColorIndex());
|
||||
PanTone panTone = panToneMapper.selectOne(queryWrapper);
|
||||
if(Objects.isNull(panTone)){
|
||||
throw new BusinessException("Pantone value does not exist !");
|
||||
}
|
||||
return coverPanToneToVo(panTone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PantoneVO getByTCX(String txc) {
|
||||
QueryWrapper<PanTone> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("tcx", txc);
|
||||
List<PanTone> panTones = panToneMapper.selectList(queryWrapper);
|
||||
if(CollectionUtil.isEmpty(panTones)){
|
||||
throw new BusinessException("Pantone value does not exist !");
|
||||
}
|
||||
return coverPanToneToVo(panTones.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PantoneVO getByRGB(Integer r,Integer g,Integer b) {
|
||||
QueryWrapper<PanTone> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("r", r);
|
||||
queryWrapper.eq("g", g);
|
||||
queryWrapper.eq("b", b);
|
||||
PanTone panTones = panToneMapper.selectOne(queryWrapper);
|
||||
return coverPanToneToVo(panTones);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> hsvBatch) {
|
||||
if(hsvBatch.size() >15){
|
||||
throw new BusinessException("hsv value cannot exceed the maximum of 15");
|
||||
}
|
||||
List<Integer> colorValues = Lists.newArrayList();
|
||||
Map<Integer,GetRgbByHsvBatchDTO> valueToHsv = Maps.newHashMap();
|
||||
hsvBatch.forEach( hsv->{
|
||||
if (Objects.isNull(hsv)) {
|
||||
return;
|
||||
}
|
||||
Integer h = hsv.getH();
|
||||
Integer s = hsv.getS();
|
||||
Integer v = hsv.getV();
|
||||
int value = (h * 101 *101)+ (s*101) +v;
|
||||
colorValues.add(value);
|
||||
valueToHsv.put(value,hsv);
|
||||
});
|
||||
List<ColorLookupTable> colorLookupTables = colorLoopUpTableService.getByColorValueList(colorValues);
|
||||
if(Objects.isNull(colorLookupTables)){
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
Map<Integer,Integer> IndexToValue = colorLookupTables.stream()
|
||||
.collect(Collectors.toMap(v->v.getColorIndex(),v ->v.getColorValue(),(V1,V2) ->V1));
|
||||
QueryWrapper<PanTone> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("pantone_index", colorLookupTables.stream()
|
||||
.map(ColorLookupTable::getColorIndex).collect(Collectors.toList()));
|
||||
return coverPanToneToVoList(panToneMapper.selectList(queryWrapper),IndexToValue,valueToHsv,hsvBatch);
|
||||
}
|
||||
|
||||
private PantoneVO coverPanToneToVo(PanTone panTone){
|
||||
if(Objects.isNull(panTone)){
|
||||
return null;
|
||||
}
|
||||
PantoneVO pantoneVO = CopyUtil.copyObject(panTone,PantoneVO.class);
|
||||
pantoneVO.setR(panTone.getR());
|
||||
pantoneVO.setG(panTone.getG());
|
||||
pantoneVO.setB(panTone.getB());
|
||||
pantoneVO.setId(panTone.getPantoneIndex());
|
||||
return pantoneVO;
|
||||
}
|
||||
private List<PantoneVO> coverPanToneToVoList(List<PanTone> panTones
|
||||
,Map<Integer,Integer> indexToValue, Map<Integer,GetRgbByHsvBatchDTO> valueToHsv,
|
||||
List<GetRgbByHsvBatchDTO> hsvBatch){
|
||||
if(Objects.isNull(panTones)){
|
||||
throw new BusinessException("Pantone value does not exist !");
|
||||
}
|
||||
List<PantoneVO> templateResposne = CopyUtil.copyList(panTones,PantoneVO.class,(o,d)->{
|
||||
d.setId(o.getPantoneIndex());
|
||||
GetRgbByHsvBatchDTO getRgbByHsvBatchDTO = valueToHsv.get(indexToValue.get(o.getPantoneIndex()));
|
||||
if(Objects.nonNull(getRgbByHsvBatchDTO)){
|
||||
d.setH(getRgbByHsvBatchDTO.getH());
|
||||
d.setS(getRgbByHsvBatchDTO.getS());
|
||||
d.setV(getRgbByHsvBatchDTO.getV());
|
||||
}
|
||||
});
|
||||
Map<Integer,PantoneVO> valueToPantoneVo = templateResposne.stream().collect(Collectors.toMap(
|
||||
v -> (v.getH() * 101 *101)+ (v.getS()*101) +v.getV(), Function.identity(),(value1,value2)-> value1
|
||||
));
|
||||
List<PantoneVO> response =Lists.newArrayList();
|
||||
//排序给前端
|
||||
hsvBatch.forEach( hsv->{
|
||||
if (Objects.isNull(hsv)) {
|
||||
return;
|
||||
}
|
||||
int value = (hsv.getH() * 101 *101)+ (hsv.getS()*101) +hsv.getV();
|
||||
PantoneVO pantoneVO = valueToPantoneVo.get(value);
|
||||
if(Objects.isNull(pantoneVO)){
|
||||
response.add(new PantoneVO("None","11-1111"));
|
||||
}else{
|
||||
response.add(pantoneVO);
|
||||
}
|
||||
});
|
||||
return response;
|
||||
|
||||
}
|
||||
}
|
||||
262
src/main/java/com/ai/da/service/impl/SysFileServiceImpl.java
Normal file
262
src/main/java/com/ai/da/service/impl/SysFileServiceImpl.java
Normal file
@@ -0,0 +1,262 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.enums.SysFileLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.common.utils.LocalCacheUtils;
|
||||
import com.ai.da.common.utils.MD5Utils;
|
||||
import com.ai.da.mapper.SysFileMapper;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.mapper.entity.Library;
|
||||
import com.ai.da.mapper.entity.SysFile;
|
||||
import com.ai.da.mapper.entity.UserLikeGroup;
|
||||
import com.ai.da.model.vo.LibraryVo;
|
||||
import com.ai.da.model.vo.SysFileVO;
|
||||
import com.ai.da.service.SysFileService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.est.CACertsResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> implements SysFileService {
|
||||
@Resource
|
||||
private SysFileMapper sysFileMapper;
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void initDefaultSysFile() {
|
||||
//删除已有的sysFile数据
|
||||
deleteAllSysFileData();
|
||||
//删除缓存
|
||||
clearCacheSysFileData();
|
||||
//读取linux环境系统图片地址
|
||||
List<File> allFile= FileUtil.getAllFile("/workspace/home/aida/file/sys");
|
||||
if(CollectionUtils.isEmpty(allFile)){
|
||||
return;
|
||||
}
|
||||
Map<String ,Long> idMap = initIdValueByLevel2Type();
|
||||
if (allFile.size() >500){
|
||||
AtomicInteger process = new AtomicInteger();
|
||||
//批量保存mysql 500条一次
|
||||
List<List<File>> fileList = Lists.partition(allFile,500);
|
||||
fileList.forEach(list ->{
|
||||
log.info("初始化系统文件进度###次数###{}",process.getAndAdd(1));
|
||||
if(saveMany(initSysFile(list,idMap))){
|
||||
return;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
saveMany(initSysFile(allFile,idMap));
|
||||
}
|
||||
private void clearCacheSysFileData(){
|
||||
LocalCacheUtils.clearAllMaxMinValueCache();
|
||||
LocalCacheUtils.clearAllSysFileCache();
|
||||
LocalCacheUtils.clearAllSysFileCacheByLevel2Type();
|
||||
log.info("初始化系统文件删除删除系统文件缓存完毕#####");
|
||||
}
|
||||
private void deleteAllSysFileData(){
|
||||
AtomicInteger process = new AtomicInteger();
|
||||
while(true){
|
||||
// 分页数据
|
||||
QueryWrapper<SysFile> queryWrapper = new QueryWrapper<>();
|
||||
IPage<SysFile> page = this.getBaseMapper().selectPage(
|
||||
new Page<>(1, 500), queryWrapper);
|
||||
if(CollectionUtils.isEmpty(page.getRecords())){
|
||||
break ;
|
||||
}else{
|
||||
List<Long> ids = page.getRecords().stream().map(SysFile::getId).collect(Collectors.toList());
|
||||
this.removeByIds(ids);
|
||||
log.info("初始化系统文件删除mysql数据进度###次数###{}",process.getAndAdd(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
private List<SysFile> initSysFile(List<File> files,Map<String ,Long> idMap){
|
||||
List<SysFile> sysFiles =Lists.newArrayList();
|
||||
files.forEach(file -> {
|
||||
SysFile sysFile = new SysFile();
|
||||
sysFile.setCreateDate(new Date());
|
||||
String filePath = file.getAbsolutePath();
|
||||
sysFile.setLevel1Type(calculateLevel1Type(filePath));
|
||||
sysFile.setLevel2Type(calculateLevel2Type(filePath));
|
||||
sysFile.setId(getIdByLevel2Type(sysFile.getLevel2Type(),idMap));
|
||||
sysFile.setName(file.getName());
|
||||
try{
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
sysFile.setMd5(MD5Utils.encryptFile(inputStream));
|
||||
}catch(IOException ioException){
|
||||
log.info("initSysFile 文件异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("initSysFile ioException");
|
||||
}
|
||||
String linuxDomain = fileProperties.getLinuxDomain();
|
||||
if(!StringUtils.isEmpty(linuxDomain)){
|
||||
//linux 系统
|
||||
String oldPath = fileProperties.getSys().getPath();
|
||||
sysFile.setUrl(filePath.replace(oldPath,linuxDomain));
|
||||
}
|
||||
sysFiles.add(sysFile);
|
||||
});
|
||||
return sysFiles;
|
||||
}
|
||||
private String calculateLevel1Type(String filePath){
|
||||
String[] split = filePath.split("/");
|
||||
//一级目录
|
||||
SysFileLevel1TypeEnum sysFileLevel1Type = SysFileLevel1TypeEnum.uploadOf(split[split.length-3]);
|
||||
if(Objects.nonNull(sysFileLevel1Type)){
|
||||
return sysFileLevel1Type.getRealName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private String calculateLevel2Type(String filePath){
|
||||
String[] split = filePath.split("/");
|
||||
//一级目录
|
||||
SysFileLevel2TypeEnum sysFileLevel2Type = SysFileLevel2TypeEnum.uploadOf(split[split.length-2]);
|
||||
if(Objects.nonNull(sysFileLevel2Type)){
|
||||
return sysFileLevel2Type.getRealName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private Long getIdByLevel2Type(String level2Type ,Map<String, Long> IdMp){
|
||||
Long id = IdMp.get(level2Type);
|
||||
Long newId = id +1;
|
||||
IdMp.put(level2Type,newId);
|
||||
return newId;
|
||||
}
|
||||
private Map<String ,Long> initIdValueByLevel2Type(){
|
||||
//每个类型分配100000 十万个位置
|
||||
Map<String ,Long> idMap = Maps.newHashMap();
|
||||
// 0 到 100000
|
||||
idMap.put(SysFileLevel2TypeEnum.EARRINGS.getRealName(),0L);
|
||||
// 100001 到 200000
|
||||
idMap.put(SysFileLevel2TypeEnum.HAIRSTYLE.getRealName(),100000L);
|
||||
// 200001 到 300000
|
||||
idMap.put(SysFileLevel2TypeEnum.SHOES.getRealName(),200000L);
|
||||
// 300001 到 400000
|
||||
idMap.put(SysFileLevel2TypeEnum.BLOUSE.getRealName(),300000L);
|
||||
// 400001 到 500000
|
||||
idMap.put(SysFileLevel2TypeEnum.DRESS.getRealName(),400000L);
|
||||
// 500001 到 600000
|
||||
idMap.put(SysFileLevel2TypeEnum.OUTWEAR.getRealName(),500000L);
|
||||
// 600001 到 700000
|
||||
idMap.put(SysFileLevel2TypeEnum.SKIRT.getRealName(),600000L);
|
||||
// 700001 到 800000
|
||||
idMap.put(SysFileLevel2TypeEnum.TROUSERS.getRealName(),700000L);
|
||||
// 800001 到 900000
|
||||
idMap.put(SysFileLevel2TypeEnum.ICON.getRealName(),800000L);
|
||||
// 900001 到 1000000
|
||||
idMap.put(SysFileLevel2TypeEnum.BAG.getRealName(),900000L);
|
||||
// 1000001 到 1100000
|
||||
idMap.put(SysFileLevel2TypeEnum.BODY.getRealName(),1000000L);
|
||||
return idMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMaxIdByLevel2Type(String level2Type) {
|
||||
String key = "MAX_"+level2Type;
|
||||
Long maxId = LocalCacheUtils.getFileMaxMinValueCache(key);
|
||||
if(null == maxId){
|
||||
maxId =maxId(level2Type);
|
||||
LocalCacheUtils.setFileMaxMinValueCache(key,maxId);
|
||||
}
|
||||
return maxId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMinIdByLevel2Type(String level2Type) {
|
||||
String key = "MIN_"+level2Type;
|
||||
Long minId = LocalCacheUtils.getFileMaxMinValueCache(key);
|
||||
if(null == minId || minId == 0L){
|
||||
minId = minId(level2Type);
|
||||
LocalCacheUtils.setFileMaxMinValueCache(key,minId);
|
||||
}
|
||||
return minId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysFileVO getById(Long id) {
|
||||
SysFileVO sysFile = LocalCacheUtils.getSysFileCache(id);
|
||||
if(Objects.isNull(sysFile) || Objects.isNull(sysFile.getId())){
|
||||
sysFile = CopyUtil.copyObject(sysFileMapper.selectById(id),SysFileVO.class);
|
||||
LocalCacheUtils.setSysFileCache(id,sysFile);
|
||||
}
|
||||
return sysFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysFileVO> getByLevel2Type(String level2Type) {
|
||||
//校验
|
||||
// SysFileLevel2TypeEnum level2TypeEnum = SysFileLevel2TypeEnum.realNameOfPython(level2Type);
|
||||
// if(Objects.isNull(level2TypeEnum)){
|
||||
// throw new BusinessException("unknown level2Type "+level2Type);
|
||||
// }
|
||||
List<SysFileVO> cacheSysFileList = LocalCacheUtils.getSysFileCacheByLevel2Type(level2Type);
|
||||
if(CollectionUtils.isEmpty(cacheSysFileList)){
|
||||
QueryWrapper<SysFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("level2_type", SysFileLevel2TypeEnum.ofPython());
|
||||
List<SysFileVO> sysFiles = CopyUtil.copyList(sysFileMapper.selectList(queryWrapper),SysFileVO.class);
|
||||
LocalCacheUtils.setSysFileCacheByLevel2Type(level2Type,sysFiles);
|
||||
return sysFiles;
|
||||
}
|
||||
return cacheSysFileList;
|
||||
}
|
||||
|
||||
private Long maxId(String level2Type){
|
||||
QueryWrapper<SysFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("level2_type", level2Type);
|
||||
queryWrapper.select("max(id) as id " );
|
||||
SysFile sysFile = sysFileMapper.selectOne(queryWrapper);
|
||||
return sysFile.getId();
|
||||
}
|
||||
private Long minId(String level2Type){
|
||||
QueryWrapper<SysFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("level2_type", level2Type);
|
||||
queryWrapper.select("min(id) as id " );
|
||||
SysFile sysFile = sysFileMapper.selectOne(queryWrapper);
|
||||
return sysFile.getId();
|
||||
}
|
||||
private boolean saveMany(List<SysFile> sysFiles) {
|
||||
if (!this.saveBatch(sysFiles)) {
|
||||
throw new BusinessException("save system file failed!");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysFileVO> getByUrlList(List<String> urlList) {
|
||||
QueryWrapper<SysFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("url", urlList);
|
||||
return CopyUtil.copyList(sysFileMapper.selectList(queryWrapper),SysFileVO.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.mapper.UserLikeGroupMapper;
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.ai.da.mapper.entity.UserLikeGroup;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.AccountService;
|
||||
import com.ai.da.service.CollectionService;
|
||||
import com.ai.da.service.UserLikeGroupService;
|
||||
import com.ai.da.service.UserLikeService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, UserLikeGroup> implements UserLikeGroupService {
|
||||
@Resource
|
||||
private UserLikeGroupMapper userLikeGroupMapper;
|
||||
@Resource
|
||||
private AccountService accountService;
|
||||
@Resource
|
||||
private CollectionService collectionService;
|
||||
@Resource
|
||||
private UserLikeService userLikeService;
|
||||
|
||||
@Override
|
||||
public void deleteUserGroup(Long userGroupId) {
|
||||
UserLikeGroup group = getById(userGroupId);
|
||||
Assert.notNull(group,"History does not exist!");
|
||||
userLikeGroupMapper.deleteById(userGroupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryUpdateVO updateUserGroupName(Long userGroupId, String userGroupName,String timeZone) {
|
||||
UserLikeGroup group = getById(userGroupId);
|
||||
Assert.notNull(group,"History does not exist!");
|
||||
QueryWrapper<UserLikeGroup> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", userGroupId);
|
||||
UserLikeGroup userLikeGroup = new UserLikeGroup();
|
||||
userLikeGroup.setName(userGroupName);
|
||||
userLikeGroup.setUpdateDate(DateUtil.getByTimeZone(timeZone));
|
||||
log.info("跟新group名字###{}###时间是###{}",userLikeGroup.getUpdateDate(),TimeZone.getDefault());
|
||||
userLikeGroupMapper.update(userLikeGroup,queryWrapper);
|
||||
return new HistoryUpdateVO(userLikeGroup.getName(),userLikeGroup.getUpdateDate().getTime());
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// System.out.println(TimeZone.getDefault());
|
||||
// Date kolkata =DateUtil.getByTimeZone("Asia/Kolkata");
|
||||
// Date shanghai =DateUtil.getByTimeZone("Asia/Shanghai");
|
||||
// System.out.println(kolkata);
|
||||
// System.out.println(shanghai);
|
||||
// System.out.println(kolkata.getTime());
|
||||
// System.out.println(shanghai.getTime());
|
||||
// System.out.println(kolkata.getTime() == shanghai.getTime());
|
||||
// }
|
||||
|
||||
private List<UserLikeGroup> selectByUserId(Long userId) {
|
||||
QueryWrapper<UserLikeGroup> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("accountId", userId);
|
||||
return userLikeGroupMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long insertUserGroup(Long userId, Long collectionId, String timeZone) {
|
||||
UserLikeGroup userLikeGroup = new UserLikeGroup();
|
||||
//默认当前时间
|
||||
userLikeGroup.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD_HH_MM_SS));
|
||||
userLikeGroup.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
userLikeGroup.setUpdateDate(DateUtil.getByTimeZone(timeZone));
|
||||
userLikeGroup.setAccountId(userId);
|
||||
userLikeGroup.setCollectionId(collectionId);
|
||||
userLikeGroupMapper.insertUserLikeGroup(userLikeGroup);
|
||||
return userLikeGroup.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserLikeChooseVO choose(Long userGroupId) {
|
||||
UserLikeGroup group = getById(userGroupId);
|
||||
Assert.notNull(group,"History does not exist!");
|
||||
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userGroupId);
|
||||
UserLikeCollectionVO userLikeCollection = collectionService.chooseCollection(group.getCollectionId());
|
||||
return new UserLikeChooseVO(userGroupId,userLikeVOS,userLikeCollection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.mapper.UserLikeMapper;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.mapper.entity.DesignItem;
|
||||
import com.ai.da.mapper.entity.UserLike;
|
||||
import com.ai.da.model.vo.UserLikeVO;
|
||||
import com.ai.da.service.UserLikeService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2022-09-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike> implements UserLikeService {
|
||||
@Resource
|
||||
private UserLikeMapper userLikeMapper;
|
||||
@Resource
|
||||
private DesignItemServiceImpl designItemService;
|
||||
|
||||
@Override
|
||||
public List<UserLikeVO> getGroupDetail(Long userGroupId) {
|
||||
QueryWrapper<UserLike> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_like_group_id", userGroupId);
|
||||
List<UserLike> userLikes = userLikeMapper.selectList(queryWrapper);
|
||||
if(CollectionUtils.isEmpty(userLikes)){
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
List<Long> designItemIds = userLikes.stream().map(UserLike::getDesignItemId).collect(Collectors.toList());
|
||||
List<DesignItem> designItems = designItemService.listByIds(designItemIds);
|
||||
Map<Long,String> idToUrlMap = designItems.stream().collect(Collectors.toMap(DesignItem::getId,DesignItem::getDesignUrl));
|
||||
return CopyUtil.copyList(userLikes,UserLikeVO.class,(o,d) ->{
|
||||
d.setUrl(idToUrlMap.get(o.getDesignItemId()));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserLikeVO> getGroupDetails(List<Long> userGroupIds) {
|
||||
QueryWrapper<UserLike> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("user_like_group_id", userGroupIds);
|
||||
return CopyUtil.copyList(userLikeMapper.selectList(queryWrapper),UserLikeVO.class);
|
||||
}
|
||||
|
||||
public void deleteByUserGroupId(Long userGroupId) {
|
||||
QueryWrapper<UserLike> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_like_group_id", userGroupId);
|
||||
userLikeMapper.delete(queryWrapper);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user