|
|
@@ -8,12 +8,14 @@ import com.gree.mall.manager.commonmapper.AdminMapper;
|
|
|
import com.gree.mall.manager.constant.Constant;
|
|
|
import com.gree.mall.manager.enums.RedisPrefixEnum;
|
|
|
import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
+import com.gree.mall.manager.logic.StorageLogic;
|
|
|
import com.gree.mall.manager.plus.entity.*;
|
|
|
import com.gree.mall.manager.plus.service.*;
|
|
|
import com.gree.mall.manager.utils.ApplicationContextUtils;
|
|
|
import com.gree.mall.manager.utils.CommonUtils;
|
|
|
import com.gree.mall.manager.utils.RedisUtil;
|
|
|
import com.gree.mall.manager.utils.oss.OSSUtil;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@@ -37,52 +39,32 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
public class CommonLogic {
|
|
|
|
|
|
@Value("${spring.profiles.active}")
|
|
|
private String active;
|
|
|
|
|
|
- @Autowired
|
|
|
- RedisUtil redisUtil;
|
|
|
- @Autowired
|
|
|
- AdminCompanyWechatService AdminCompanyWechatService;
|
|
|
- @Autowired
|
|
|
- CommonFileService commonFileService;
|
|
|
- @Autowired
|
|
|
- OrderInfoService orderInfoService;
|
|
|
- @Autowired
|
|
|
- RegionService regionService;
|
|
|
- @Autowired
|
|
|
- AdminUserService adminUserService;
|
|
|
- @Autowired
|
|
|
- AdminCompanyWechatService adminCompanyWechatService;
|
|
|
- @Autowired
|
|
|
- AdminUserWebsitRelaService adminUserWebsitRelaService;
|
|
|
- @Autowired
|
|
|
- AdminMapper adminMapper;
|
|
|
- @Autowired
|
|
|
- AdminWebsitService adminWebsitService;
|
|
|
- @Autowired
|
|
|
- UserService userService;
|
|
|
- @Autowired
|
|
|
- OSSUtil ossUtil;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- AdminDeptService adminDeptService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- AdminUserDeptRelaService adminUserDeptRelaService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- AdminDeptWebsitService adminDeptWebsitService;
|
|
|
- @Autowired
|
|
|
- IncrKeyValueService incrKeyValueService;
|
|
|
+ private final RedisUtil redisUtil;
|
|
|
+ private final CommonFileService commonFileService;
|
|
|
+ private final RegionService regionService;
|
|
|
+ private final AdminUserService adminUserService;
|
|
|
+ private final AdminCompanyWechatService adminCompanyWechatService;
|
|
|
+ private final AdminUserWebsitRelaService adminUserWebsitRelaService;
|
|
|
+ private final AdminWebsitService adminWebsitService;
|
|
|
+ private final OSSUtil ossUtil;
|
|
|
+ private final AdminDeptService adminDeptService;
|
|
|
+ private final AdminUserDeptRelaService adminUserDeptRelaService;
|
|
|
+ private final AdminDeptWebsitService adminDeptWebsitService;
|
|
|
+ private final IncrKeyValueService incrKeyValueService;
|
|
|
+ private final AdminUserStorageRelaService adminUserStorageRelaService;
|
|
|
+
|
|
|
|
|
|
public Map<String, String> getOSSConfig() throws UnsupportedEncodingException {
|
|
|
return ossUtil.getConfig();
|
|
|
}
|
|
|
|
|
|
- public AdminUserCom getAdminUser(){
|
|
|
+ public AdminUserCom getAdminUser() {
|
|
|
HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
|
|
|
return this.getAdminUser(request);
|
|
|
}
|
|
|
@@ -90,20 +72,20 @@ public class CommonLogic {
|
|
|
/**
|
|
|
* 获取帐号以及部门id集合
|
|
|
*/
|
|
|
- public AdminUserCom getAdminUser(HttpServletRequest request){
|
|
|
+ public AdminUserCom getAdminUser(HttpServletRequest request) {
|
|
|
String userId = CommonUtils.getUserId(request);
|
|
|
String token = CommonUtils.getToken(request);
|
|
|
- return this.getAdminUser(userId,token);
|
|
|
+ return this.getAdminUser(userId, token);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public AdminUserCom getAdminUser(String userId, String token){
|
|
|
+ public AdminUserCom getAdminUser(String userId, String token) {
|
|
|
|
|
|
//方便测试用
|
|
|
- if(userId == null && !active.equals("prd")){
|
|
|
+ if (userId == null && !active.equals("prd")) {
|
|
|
AdminUser admin = adminUserService.lambdaQuery().eq(AdminUser::getUserName, "admin").one();
|
|
|
AdminUserCom adminUserCom = new AdminUserCom();
|
|
|
- BeanUtils.copyProperties(admin,adminUserCom);
|
|
|
+ BeanUtils.copyProperties(admin, adminUserCom);
|
|
|
AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getById("1831608878894858241");
|
|
|
adminUserCom.setAdminCompanyWechat(adminCompanyWechat);
|
|
|
adminUserCom.setJoinCode(adminCompanyWechat.getJoinCode());
|
|
|
@@ -111,49 +93,43 @@ public class CommonLogic {
|
|
|
List<AdminUserDeptRela> adminUserDeptRelas = adminUserDeptRelaService.lambdaQuery().in(AdminUserDeptRela::getAdminUserId, admin.getAdminUserId()).list();
|
|
|
if (!CollectionUtils.isEmpty(adminUserDeptRelas)) {
|
|
|
List<String> deptIds = adminUserDeptRelas.stream().map(AdminUserDeptRela::getAdminDeptId).collect(Collectors.toList());
|
|
|
- adminUserCom.setAdminDept(adminDeptService.lambdaQuery().in(AdminDept::getAdminDeptId,deptIds).list());
|
|
|
+ adminUserCom.setAdminDept(adminDeptService.lambdaQuery().in(AdminDept::getAdminDeptId, deptIds).list());
|
|
|
}
|
|
|
|
|
|
return adminUserCom;
|
|
|
}
|
|
|
String redisKey = RedisPrefixEnum.TOKEN_MGR.toString() + token;
|
|
|
- AdminUserCom adminUserCom = (AdminUserCom)redisUtil.get(redisKey);
|
|
|
- if(adminUserCom != null) {
|
|
|
+ AdminUserCom adminUserCom = (AdminUserCom) redisUtil.get(redisKey);
|
|
|
+ if (adminUserCom != null) {
|
|
|
return adminUserCom;
|
|
|
}
|
|
|
|
|
|
AdminUser adminUser = adminUserService.getById(userId);
|
|
|
- if(adminUser == null){
|
|
|
+ if (adminUser == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- if(!adminUser.getStatus()){
|
|
|
+ if (!adminUser.getStatus()) {
|
|
|
throw new RemoteServiceException("帐号已被禁用");
|
|
|
}
|
|
|
adminUserCom = new AdminUserCom();
|
|
|
- BeanUtils.copyProperties(adminUser,adminUserCom);
|
|
|
-
|
|
|
-
|
|
|
+ BeanUtils.copyProperties(adminUser, adminUserCom);
|
|
|
|
|
|
//商品出入库是否关联条码\
|
|
|
AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getById(adminUser.getCompanyWechatId());
|
|
|
- if(adminCompanyWechat != null){
|
|
|
+ if (adminCompanyWechat != null) {
|
|
|
adminUserCom.setJoinCode(adminCompanyWechat.getJoinCode());
|
|
|
}
|
|
|
|
|
|
List<AdminUserDeptRela> adminUserDeptRelaList = adminUserDeptRelaService.lambdaQuery()
|
|
|
.eq(AdminUserDeptRela::getAdminUserId, adminUser.getAdminUserId()).list();
|
|
|
|
|
|
-
|
|
|
- //所有帐号
|
|
|
- // adminUserCom = this.websitAccount(adminUserCom);
|
|
|
-
|
|
|
List<AdminUserWebsitRela> websitList = adminUserWebsitRelaService.lambdaQuery().eq(AdminUserWebsitRela::getAdminUserId, userId).list();
|
|
|
- if(!CollectionUtils.isEmpty(websitList)){
|
|
|
+ if (CollectionUtil.isNotEmpty(websitList)) {
|
|
|
List<String> adminWebsitIds = websitList.stream().map(AdminUserWebsitRela::getAdminWebsitId).distinct().collect(Collectors.toList());
|
|
|
List<String> companyWechatIds = websitList.stream().map(AdminUserWebsitRela::getCompanyWechatId).distinct().collect(Collectors.toList());
|
|
|
|
|
|
List<AdminWebsit> list = new ArrayList<>();
|
|
|
- for(String websitId : adminWebsitIds) {
|
|
|
+ for (String websitId : adminWebsitIds) {
|
|
|
list.addAll(this.queryAllChild(list, websitId));
|
|
|
}
|
|
|
List<String> websitIds = list.stream().map(AdminWebsit::getWebsitId).distinct().collect(Collectors.toList());
|
|
|
@@ -174,7 +150,7 @@ public class CommonLogic {
|
|
|
}
|
|
|
|
|
|
|
|
|
- if (!CollectionUtils.isEmpty(adminUserDeptRelaList)){
|
|
|
+ if (!CollectionUtils.isEmpty(adminUserDeptRelaList)) {
|
|
|
|
|
|
List<String> deptids = adminUserDeptRelaList.stream().map(AdminUserDeptRela::getAdminDeptId).collect(Collectors.toList());
|
|
|
List<AdminDept> adminDepts = adminDeptService.lambdaQuery().in(AdminDept::getAdminDeptId, deptids).list();
|
|
|
@@ -185,7 +161,7 @@ public class CommonLogic {
|
|
|
if (!CollectionUtils.isEmpty(adminUserCom.getAdminWebsitIds())) {
|
|
|
adminUserCom.getAdminWebsitIds().addAll(collect);
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
adminUserCom.setAdminWebsitIds(collect);
|
|
|
}
|
|
|
|
|
|
@@ -197,7 +173,12 @@ public class CommonLogic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ final List<AdminUserStorageRela> storageRelaList = adminUserStorageRelaService.lambdaQuery()
|
|
|
+ .eq(AdminUserStorageRela::getAdminUserId, adminUser.getAdminUserId())
|
|
|
+ .list();
|
|
|
+ if (CollectionUtil.isNotEmpty(storageRelaList)) {
|
|
|
+ adminUserCom.setStorageIds(storageRelaList.stream().map(AdminUserStorageRela::getStorageId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
|
|
|
return adminUserCom;
|
|
|
}
|
|
|
@@ -205,12 +186,12 @@ public class CommonLogic {
|
|
|
/**
|
|
|
* 部门帐号
|
|
|
*/
|
|
|
- public AdminUserCom websitAccount(AdminUserCom adminUserCom){
|
|
|
+ public AdminUserCom websitAccount(AdminUserCom adminUserCom) {
|
|
|
String userId = adminUserCom.getAdminUserId();
|
|
|
//非平台账号
|
|
|
- if(adminUserCom.getType() != 2){
|
|
|
+ if (adminUserCom.getType() != 2) {
|
|
|
List<AdminUserWebsitRela> websitList = adminUserWebsitRelaService.lambdaQuery().eq(AdminUserWebsitRela::getAdminUserId, userId).list();
|
|
|
- if(CollectionUtils.isEmpty(websitList)){
|
|
|
+ if (CollectionUtils.isEmpty(websitList)) {
|
|
|
return adminUserCom;
|
|
|
}
|
|
|
|
|
|
@@ -219,7 +200,7 @@ public class CommonLogic {
|
|
|
|
|
|
|
|
|
List<AdminWebsit> list = new ArrayList<>();
|
|
|
- for(String websitId : adminWebsitIds) {
|
|
|
+ for (String websitId : adminWebsitIds) {
|
|
|
list.addAll(this.queryAllChild(list, websitId));
|
|
|
}
|
|
|
List<String> websitIds = list.stream().map(AdminWebsit::getWebsitId).distinct().collect(Collectors.toList());
|
|
|
@@ -230,7 +211,7 @@ public class CommonLogic {
|
|
|
adminUserCom.setCompanyWechatIds(companyWechatIds);
|
|
|
adminUserCom.setAdminWebsitIds(websitIds.stream().distinct().collect(Collectors.toList()));
|
|
|
adminUserCom.setOnlyRead(companyWechatIds.size() > 1);
|
|
|
- // adminUserCom.setAdminWebsit(adminWebsit);
|
|
|
+ // adminUserCom.setAdminWebsit(adminWebsit);
|
|
|
//获取当前登录人的企业微信配置
|
|
|
AdminCompanyWechat adminCompanyWechat = this.getAdminCompanyWechat(companyWechatIds.get(0));
|
|
|
adminUserCom.setAdminCompanyWechat(adminCompanyWechat);
|
|
|
@@ -241,26 +222,25 @@ public class CommonLogic {
|
|
|
/**
|
|
|
* 获取企业微信配置
|
|
|
*/
|
|
|
- public AdminCompanyWechat getAdminCompanyWechat(String companyWechatId){
|
|
|
+ public AdminCompanyWechat getAdminCompanyWechat(String companyWechatId) {
|
|
|
AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getById(companyWechatId);
|
|
|
return adminCompanyWechat;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 递归查询所有数据
|
|
|
*/
|
|
|
- public List<AdminWebsit> queryAllChild(List<AdminWebsit> list,String id){
|
|
|
- if(id == null || id.equals("0")){
|
|
|
+ public List<AdminWebsit> queryAllChild(List<AdminWebsit> list, String id) {
|
|
|
+ if (id == null || id.equals("0")) {
|
|
|
return list;
|
|
|
}
|
|
|
List<AdminWebsit> adminWebsits = adminWebsitService.lambdaQuery().eq(AdminWebsit::getParentId, id).list();
|
|
|
- if(adminWebsits.size() == 0){
|
|
|
+ if (adminWebsits.size() == 0) {
|
|
|
return list;
|
|
|
}
|
|
|
- for(AdminWebsit adminWebsit:adminWebsits){
|
|
|
- this.queryAllChild(list,adminWebsit.getWebsitId());
|
|
|
+ for (AdminWebsit adminWebsit : adminWebsits) {
|
|
|
+ this.queryAllChild(list, adminWebsit.getWebsitId());
|
|
|
}
|
|
|
list.addAll(adminWebsits);
|
|
|
return list;
|
|
|
@@ -269,36 +249,37 @@ public class CommonLogic {
|
|
|
/**
|
|
|
* 附件归属绑定
|
|
|
*/
|
|
|
- public void bindFile(String objId,String objType,List<String> fileIds){
|
|
|
+ public void bindFile(String objId, String objType, List<String> fileIds) {
|
|
|
//先删除后绑定
|
|
|
commonFileService.lambdaUpdate()
|
|
|
- .eq(CommonFile::getObjId,objId)
|
|
|
- .eq(CommonFile::getObjType,objType)
|
|
|
- .notIn(CommonFile::getId,fileIds).remove();
|
|
|
+ .eq(CommonFile::getObjId, objId)
|
|
|
+ .eq(CommonFile::getObjType, objType)
|
|
|
+ .notIn(CommonFile::getId, fileIds).remove();
|
|
|
|
|
|
- for(int i =0;i< fileIds.size();i++) {
|
|
|
+ for (int i = 0; i < fileIds.size(); i++) {
|
|
|
//这里分开每次存储的时候,每个图片创建时间加1秒,方便图片排序用
|
|
|
commonFileService.lambdaUpdate()
|
|
|
.set(CommonFile::getObjId, objId)
|
|
|
.set(CommonFile::getObjType, objType)
|
|
|
- .set(CommonFile::getCreateTime, DateUtils.addSeconds(new Date(),i))
|
|
|
+ .set(CommonFile::getCreateTime, DateUtils.addSeconds(new Date(), i))
|
|
|
.eq(CommonFile::getId, fileIds.get(i))
|
|
|
.update();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 附件归属绑定
|
|
|
*/
|
|
|
- public void bindFileFile(String objId,String objType,List<CommonFile> fileIds){
|
|
|
- if(org.apache.commons.collections4.CollectionUtils.isEmpty(fileIds)){
|
|
|
+ public void bindFileFile(String objId, String objType, List<CommonFile> fileIds) {
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(fileIds)) {
|
|
|
return;
|
|
|
}
|
|
|
//先删除后绑定
|
|
|
commonFileService.lambdaUpdate()
|
|
|
- .eq(CommonFile::getObjId,objId)
|
|
|
- .eq(CommonFile::getObjType,objType).remove();
|
|
|
+ .eq(CommonFile::getObjId, objId)
|
|
|
+ .eq(CommonFile::getObjType, objType).remove();
|
|
|
|
|
|
- for(CommonFile file : fileIds) {
|
|
|
+ for (CommonFile file : fileIds) {
|
|
|
file.setId(null);
|
|
|
file.setObjId(objId);
|
|
|
file.setObjType(objType);
|
|
|
@@ -309,10 +290,10 @@ public class CommonLogic {
|
|
|
/**
|
|
|
* 查询附件列表
|
|
|
*/
|
|
|
- public List<CommonFile> queryFileByObjId(String objId,String objType){
|
|
|
+ public List<CommonFile> queryFileByObjId(String objId, String objType) {
|
|
|
return commonFileService.lambdaQuery()
|
|
|
- .eq(CommonFile::getObjId,objId)
|
|
|
- .eq(CommonFile::getObjType,objType)
|
|
|
+ .eq(CommonFile::getObjId, objId)
|
|
|
+ .eq(CommonFile::getObjType, objType)
|
|
|
.orderByAsc(CommonFile::getCreateTime)
|
|
|
.list();
|
|
|
}
|
|
|
@@ -320,9 +301,9 @@ public class CommonLogic {
|
|
|
/**
|
|
|
* 查询附件列表
|
|
|
*/
|
|
|
- public List<String> queryFileUrlsByObjId(String objId,String objType){
|
|
|
+ public List<String> queryFileUrlsByObjId(String objId, String objType) {
|
|
|
List<CommonFile> commonFiles = this.queryFileByObjId(objId, objType);
|
|
|
- if(commonFiles.size() == 0){
|
|
|
+ if (commonFiles.size() == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
return commonFiles.stream().map(CommonFile::getUrl).collect(Collectors.toList());
|
|
|
@@ -331,11 +312,12 @@ public class CommonLogic {
|
|
|
|
|
|
/**
|
|
|
* 上传附件
|
|
|
+ *
|
|
|
* @param file
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public CommonFile uploadFile( MultipartFile file) throws IOException, RemoteServiceException {
|
|
|
+ public CommonFile uploadFile(MultipartFile file) throws IOException, RemoteServiceException {
|
|
|
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
return null;
|
|
|
@@ -375,8 +357,8 @@ public class CommonLogic {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public List<Region> queryRegionList(String pid){
|
|
|
- return regionService.lambdaQuery().eq(Region::getPid,pid).list();
|
|
|
+ public List<Region> queryRegionList(String pid) {
|
|
|
+ return regionService.lambdaQuery().eq(Region::getPid, pid).list();
|
|
|
}
|
|
|
|
|
|
public String getFile(String key) throws IOException {
|
|
|
@@ -385,12 +367,12 @@ public class CommonLogic {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 生成订单号
|
|
|
- * @param start 前缀
|
|
|
+ *
|
|
|
+ * @param start 前缀
|
|
|
* @param orderType 订单类型
|
|
|
- * @param length 一般13 位
|
|
|
+ * @param length 一般13 位
|
|
|
* @return
|
|
|
*/
|
|
|
public String generateNo(String start, String orderType, int length) {
|
|
|
@@ -423,7 +405,7 @@ public class CommonLogic {
|
|
|
|
|
|
public InputStream getFileInputStreamByUrl(String strUrl) {
|
|
|
try {
|
|
|
- log.info("【附件路径】:{}",strUrl);
|
|
|
+ log.info("【附件路径】:{}", strUrl);
|
|
|
URL url = new URL(strUrl);
|
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
conn.setRequestMethod("GET");
|
|
|
@@ -431,13 +413,14 @@ public class CommonLogic {
|
|
|
InputStream inStream = conn.getInputStream();// 通过输入流获取图片数据
|
|
|
return inStream;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("生成附件失败"+e.getMessage());
|
|
|
+ log.error("生成附件失败" + e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后台计算值
|
|
|
+ *
|
|
|
* @param frontVal
|
|
|
* @param afterVal
|
|
|
* @param operator
|