集成大华
parent
9dd1fb1e4c
commit
0e63a0092e
|
|
@ -55,4 +55,11 @@ smb:
|
|||
user: root
|
||||
password: '@EwLEkf56oTYP-gU'
|
||||
basePath: /mnt/gbsfile/gwj/file/
|
||||
|
||||
dahua:
|
||||
config:
|
||||
dockFlag: 1
|
||||
prefix: https://skqhdg.porthebei.com:9008/yjkmRy/
|
||||
username: shuangkong
|
||||
password: qinan@202604
|
||||
clientId: mkmj_management
|
||||
clientSecret: 5ef82f7c-9926-46a3-8d07-136fd054849c
|
||||
|
|
|
|||
|
|
@ -56,3 +56,11 @@ smb:
|
|||
password: 'SJSKaqhb@20240131'
|
||||
basePath: /mnt/vdc2/qask/file/uploadFiles2/
|
||||
|
||||
dahua:
|
||||
config:
|
||||
dockFlag: 1
|
||||
prefix: https://skqhdg.porthebei.com:9008/yjkmRy/
|
||||
username: shuangkong
|
||||
password: qinan@202604
|
||||
clientId: mkmj_management
|
||||
clientSecret: 5ef82f7c-9926-46a3-8d07-136fd054849c
|
||||
|
|
|
|||
|
|
@ -49,3 +49,11 @@ openapi:
|
|||
apiCode: test:01
|
||||
#多个可以逗号隔开,可以为空
|
||||
tenantIds: 1838408702262321152
|
||||
dahua:
|
||||
config:
|
||||
dockFlag: 1
|
||||
prefix: https://skqhdg.porthebei.com:9008/yjkmRy/
|
||||
username: shuangkong
|
||||
password: qinan@202604
|
||||
clientId: mkmj_management
|
||||
clientSecret: 5ef82f7c-9926-46a3-8d07-136fd054849c
|
||||
|
|
|
|||
|
|
@ -1,27 +1,31 @@
|
|||
package com.zcloud.basic.info.command;
|
||||
|
||||
import com.alibaba.cola.dto.MultiResponse;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
import com.jjb.saas.framework.auth.model.SSOUser;
|
||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.zcloud.basic.info.command.convertor.ImgFilesCoConvertor;
|
||||
import com.zcloud.basic.info.domain.config.DaHuaConfig;
|
||||
import com.zcloud.basic.info.domain.gateway.ImgFilesGateway;
|
||||
import com.zcloud.basic.info.domain.model.ImgFilesE;
|
||||
import com.zcloud.basic.info.dto.ImgFilesAddCmd;
|
||||
import com.jjb.saas.framework.auth.model.SSOUser;
|
||||
import com.zcloud.basic.info.dto.clientobject.ImgFilesCO;
|
||||
import com.zcloud.basic.info.dto.clientobject.ImgFilesInfoCO;
|
||||
import com.zcloud.basic.info.persistence.dataobject.ImgFilesDO;
|
||||
import com.zcloud.basic.info.persistence.repository.ImgFilesRepository;
|
||||
import com.zcloud.gbscommon.utils.FileUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.math3.analysis.function.Sin;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -37,8 +41,25 @@ public class ImgFilesAddExe {
|
|||
private final ImgFilesGateway imgFilesGateway;
|
||||
private final ImgFilesCoConvertor imgFilesCoConvertor;
|
||||
private final ImgFilesRepository imgFilesRepository;
|
||||
private final DaHuaConfig daHuaConfig;
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SingleResponse<ImgFilesCO> execute(ImgFilesAddCmd cmd) {
|
||||
if (daHuaConfig.getDockFlag() == 1 && (cmd.getType() == 608 || cmd.getType() == 13)){
|
||||
try {
|
||||
for (MultipartFile multipartFile : cmd.getFiles()){
|
||||
String base64ImgStr = FileUtil.multipartFileToBase64(multipartFile);
|
||||
JSONObject resultJsonObject = daHuaConfig.uploadPersonAvatar(base64ImgStr);
|
||||
// 如果不合格,直接返回不合格
|
||||
if (resultJsonObject.getBool("success")){
|
||||
cmd.setDaHuaFilePath(resultJsonObject.getJSONObject("data").getStr("fileUrl"));
|
||||
} else {
|
||||
return SingleResponse.buildFailure(resultJsonObject.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
SSOUser ssoUser = AuthContext.getCurrentUser();
|
||||
Long tenantId = 1L;
|
||||
if (ssoUser != null && ssoUser.getTenantId() != null){
|
||||
|
|
@ -49,7 +70,7 @@ public class ImgFilesAddExe {
|
|||
boolean res = false;
|
||||
ImgFilesCO imgFilesCO = new ImgFilesCO();
|
||||
try {
|
||||
String filePath = imgFilesE.initAdd(tenantId, imgFilesE);
|
||||
String filePath = imgFilesE.initAdd(daHuaConfig.getDockFlag(), tenantId, imgFilesE);
|
||||
imgFilesCO.setFilePath(filePath);
|
||||
res = true;
|
||||
} catch (Exception e) {
|
||||
|
|
@ -62,8 +83,29 @@ public class ImgFilesAddExe {
|
|||
return SingleResponse.of(imgFilesCO);
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SingleResponse<ImgFilesInfoCO> batchExecute(ImgFilesAddCmd cmd) {
|
||||
|
||||
if (daHuaConfig.getDockFlag() == 1 && (cmd.getType() == 608 || cmd.getType() == 13)){
|
||||
Map<String, MultipartFile> filesMap = new HashMap<>();
|
||||
try {
|
||||
for (MultipartFile multipartFile : cmd.getFiles()){
|
||||
String base64ImgStr = FileUtil.multipartFileToBase64(multipartFile);
|
||||
JSONObject resultJsonObject = daHuaConfig.uploadPersonAvatar(base64ImgStr);
|
||||
// 如果不合格,直接返回不合格
|
||||
if (resultJsonObject.getBool("success")){
|
||||
filesMap.put(resultJsonObject.getJSONObject("data").getStr("fileUrl"), multipartFile);
|
||||
} else {
|
||||
return SingleResponse.buildFailure(resultJsonObject.toString());
|
||||
}
|
||||
}
|
||||
cmd.setFilesMap(filesMap);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
SSOUser ssoUser = AuthContext.getCurrentUser();
|
||||
Long tenantId = 1L;
|
||||
if (ssoUser != null && ssoUser.getTenantId() != null){
|
||||
|
|
@ -74,7 +116,12 @@ public class ImgFilesAddExe {
|
|||
boolean res = false;
|
||||
ImgFilesInfoCO imgFilesCO = new ImgFilesInfoCO();
|
||||
try {
|
||||
List<ImgFilesE> imgFilesEList = imgFilesE.initBatchAdd(tenantId, imgFilesE);
|
||||
List<ImgFilesE> imgFilesEList = new ArrayList<>();
|
||||
if (daHuaConfig.getDockFlag() == 1 && (cmd.getType() == 608 || cmd.getType() == 13)){
|
||||
imgFilesEList = imgFilesE.initDaHuaBatchAdd(tenantId, imgFilesE);
|
||||
} else {
|
||||
imgFilesEList = imgFilesE.initBatchAdd(tenantId, imgFilesE);
|
||||
}
|
||||
List<ImgFilesDO> imgFilesDOList = imgFilesCoConvertor.converEsToDOs(imgFilesEList);
|
||||
imgFilesRepository.saveBatch(imgFilesDOList);
|
||||
List<ImgFilesCO> imgFilesCOList = imgFilesCoConvertor.converDOsToCOs(imgFilesDOList);
|
||||
|
|
@ -90,5 +137,6 @@ public class ImgFilesAddExe {
|
|||
}
|
||||
return SingleResponse.of(imgFilesCO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* web-client
|
||||
|
|
@ -47,5 +48,11 @@ public class ImgFilesAddCmd extends Command {
|
|||
|
||||
@ApiModelProperty(value = "路径", name = "filePath")
|
||||
private String filePath;
|
||||
|
||||
@ApiModelProperty
|
||||
private String daHuaFilePath;
|
||||
|
||||
@ApiModelProperty
|
||||
private Map<String, MultipartFile> filesMap;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.zcloud.basic.info.domain.config;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.zcloud.gbscommon.dahuaDevice.DaHuaDeviceCommon;
|
||||
import com.zcloud.gbscommon.dahuaDevice.DhuaConfig;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author zhangyue
|
||||
* 大华对接
|
||||
* @date 2026/4/20 13:46
|
||||
*/
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "dahua.config")
|
||||
@Data
|
||||
public class DaHuaConfig {
|
||||
private Integer dockFlag;
|
||||
private String prefix;
|
||||
private String username;
|
||||
private String password;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
|
||||
protected DaHuaDeviceCommon getDaHuaDeviceCommon() {
|
||||
return new DaHuaDeviceCommon(new DhuaConfig(dockFlag, prefix, username, password, clientId, clientSecret));
|
||||
}
|
||||
|
||||
public JSONObject imageQualityDetection(String base64ImgStr) throws Exception {
|
||||
return getDaHuaDeviceCommon().imageQualityDetection(base64ImgStr);
|
||||
}
|
||||
public JSONObject uploadPersonAvatar(String base64ImgStr) throws Exception {
|
||||
return getDaHuaDeviceCommon().uploadPersonAvatar(base64ImgStr);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,17 @@ package com.zcloud.basic.info.domain.model;
|
|||
|
||||
import com.jjb.saas.framework.domain.model.BaseE;
|
||||
import com.zcloud.basic.info.domain.utils.Smb;
|
||||
import com.zcloud.gbscommon.utils.*;
|
||||
import com.zcloud.gbscommon.utils.DateUtil;
|
||||
import com.zcloud.gbscommon.utils.Tools;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* web-domain
|
||||
|
|
@ -66,16 +67,42 @@ public class ImgFilesE extends BaseE {
|
|||
//环境
|
||||
private String env;
|
||||
|
||||
private String daHuaFilePath;
|
||||
|
||||
private Map<String, MultipartFile> filesMap;
|
||||
|
||||
|
||||
public String initAdd(Long tenantId, ImgFilesE baseImgFilesE) throws Exception {
|
||||
|
||||
MultipartFile[] files = baseImgFilesE.getFiles();
|
||||
Long corpinfoId = ObjectUtils.isEmpty(baseImgFilesE.getCorpinfoId()) ? tenantId : baseImgFilesE.getCorpinfoId();
|
||||
if (baseImgFilesE.getType() == 608 || baseImgFilesE.getType() == 13){
|
||||
String resultFilePath = Smb.saveDaHuaFile(files[0], baseImgFilesE.getDaHuaFilePath());
|
||||
return resultFilePath;
|
||||
} else {
|
||||
String filePath = corpinfoId.toString() + "/" + DateUtil.getMonth() + "/" + baseImgFilesE.getPath();
|
||||
// 文件上传并获取上传路径
|
||||
String resultFilePath = Smb.saveFile(files[0], filePath);
|
||||
return resultFilePath;
|
||||
}
|
||||
|
||||
}
|
||||
public String initAdd(Integer dockFlag, Long tenantId, ImgFilesE baseImgFilesE) throws Exception {
|
||||
|
||||
MultipartFile[] files = baseImgFilesE.getFiles();
|
||||
Long corpinfoId = ObjectUtils.isEmpty(baseImgFilesE.getCorpinfoId()) ? tenantId : baseImgFilesE.getCorpinfoId();
|
||||
if (dockFlag == 1 && (baseImgFilesE.getType() == 608 || baseImgFilesE.getType() == 13)){
|
||||
String resultFilePath = Smb.saveDaHuaFile(files[0], baseImgFilesE.getDaHuaFilePath());
|
||||
return resultFilePath;
|
||||
} else {
|
||||
String filePath = corpinfoId.toString() + "/" + DateUtil.getMonth() + "/" + baseImgFilesE.getPath();
|
||||
// 文件上传并获取上传路径
|
||||
String resultFilePath = Smb.saveFile(files[0], filePath);
|
||||
return resultFilePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<ImgFilesE> initBatchAdd(Long tenantId, ImgFilesE baseImgFilesE) throws Exception {
|
||||
MultipartFile[] files = baseImgFilesE.getFiles();
|
||||
List<ImgFilesE> imgFilesList = new ArrayList<ImgFilesE>();
|
||||
|
|
@ -101,6 +128,36 @@ public class ImgFilesE extends BaseE {
|
|||
return imgFilesList;
|
||||
}
|
||||
|
||||
public List<ImgFilesE> initDaHuaBatchAdd( Long tenantId, ImgFilesE baseImgFilesE) throws Exception {
|
||||
MultipartFile[] files = baseImgFilesE.getFiles();
|
||||
List<ImgFilesE> imgFilesList = new ArrayList<ImgFilesE>();
|
||||
String foreignKey = ObjectUtils.isEmpty(baseImgFilesE.getForeignKey()) ? Tools.get32UUID() : baseImgFilesE.getForeignKey();
|
||||
|
||||
Long corpinfoId = ObjectUtils.isEmpty(baseImgFilesE.getCorpinfoId()) ? tenantId : baseImgFilesE.getCorpinfoId();
|
||||
Map<String, MultipartFile> filesMap = baseImgFilesE.getFilesMap();
|
||||
for (Map.Entry<String, MultipartFile> entry : filesMap.entrySet()) {
|
||||
ImgFilesE imgFile = new ImgFilesE();
|
||||
BeanUtils.copyProperties(imgFile, baseImgFilesE);
|
||||
// 生成文件名
|
||||
int lastSlash = entry.getKey().lastIndexOf("/");
|
||||
// String dirPath = entry.getKey().substring(0, lastSlash + 1);
|
||||
String fileName = entry.getKey().substring(lastSlash + 1);
|
||||
// 文件上传并获取上传路径
|
||||
String resultFilePath = Smb.saveDaHuaFile(entry.getValue(), entry.getKey());
|
||||
imgFile.setImgFilesId(Tools.get32UUID());
|
||||
imgFile.setFilePath(resultFilePath);
|
||||
imgFile.setType(baseImgFilesE.getType());
|
||||
imgFile.setForeignKey(foreignKey);
|
||||
imgFile.setFileName(fileName);
|
||||
imgFile.setCorpinfoId(corpinfoId);
|
||||
// imgFile.setMd5(FileUtil.getMD5(file));
|
||||
imgFilesList.add(imgFile);
|
||||
|
||||
}
|
||||
baseImgFilesE.setForeignKey(foreignKey);
|
||||
return imgFilesList;
|
||||
}
|
||||
|
||||
|
||||
public void deleteFile(String filePath) throws Exception {
|
||||
Smb.deleteFile(filePath);
|
||||
|
|
|
|||
|
|
@ -286,5 +286,14 @@ public class Smb {
|
|||
// 返回文件保存目录
|
||||
return filePath + "/" + fileName;
|
||||
}
|
||||
|
||||
public static String saveDaHuaFile(MultipartFile file, String filePath) throws Exception{
|
||||
// 生成文件名
|
||||
int lastSlash = filePath.lastIndexOf("/");
|
||||
String dirPath = filePath.substring(0, lastSlash + 1);
|
||||
String fileName = filePath.substring(lastSlash + 1);
|
||||
// 根据项目类型生成项目文件
|
||||
sshSftp(file, fileName, dirPath);
|
||||
// 返回文件保存目录
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,11 +175,11 @@ public class UserGatewayImpl implements UserGateway {
|
|||
log.info("GBS修改用户开始,用户信息:{}", JSONUtil.toJsonStr(updateCmd));
|
||||
Response response = userFacade.update(updateCmd);
|
||||
log.info("GBS修改用户结束,用户id:{},结果:{}", JSONUtil.toJsonStr(response));
|
||||
UserUpdatePasswordCmd updatePasswordCmd = new UserUpdatePasswordCmd();
|
||||
updatePasswordCmd.setId(userE.getId());
|
||||
updatePasswordCmd.setPassword(userE.getPassword());
|
||||
updatePasswordCmd.setVersion(1);
|
||||
userFacade.updatePassword(updatePasswordCmd);
|
||||
// UserUpdatePasswordCmd updatePasswordCmd = new UserUpdatePasswordCmd();
|
||||
// updatePasswordCmd.setId(userE.getId());
|
||||
// updatePasswordCmd.setPassword(userE.getPassword());
|
||||
// updatePasswordCmd.setVersion(1);
|
||||
// userFacade.updatePassword(updatePasswordCmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue