|
@@ -1,6 +1,7 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementDistributionDao;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxPmqManagementDistributionDetailService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxPmqManagementDistributionService;
|
|
@@ -11,14 +12,22 @@ import com.rongwei.bsentity.domain.ZhcxPmqManagementRecoredDo;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxPmqManagementRecoredDao;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxPmqManagementRecoredService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.rongwei.bsentity.dto.sqlServer.JuFileInfoDto;
|
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.sql.*;
|
|
|
import java.util.*;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -28,9 +37,23 @@ import java.util.*;
|
|
|
* @author wm
|
|
|
* @since 2024-10-30
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqManagementRecoredDao, ZhcxPmqManagementRecoredDo> implements ZhcxPmqManagementRecoredService {
|
|
|
|
|
|
+ @Value("${nxsystem.url:#{null}}")
|
|
|
+ private String nxurl;
|
|
|
+ @Value("${nxsystem.dbname:#{null}}")
|
|
|
+ private String nxdbname;
|
|
|
+ @Value("${nxsystem.dbuser:#{null}}")
|
|
|
+ private String nxdbuser;
|
|
|
+ @Value("${nxsystem.dbpw:#{null}}")
|
|
|
+ private String nxdbpw;
|
|
|
+ @Value("${nxsystem.dburlfix:#{null}}")
|
|
|
+ private String nxurlfix;
|
|
|
+ @Value("${nxsystem.filepath:#{null}}")
|
|
|
+ private String nxfilepath;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ZhcxPmqManagementDistributionService zhcxPmqManagementDistributionService;
|
|
|
|
|
@@ -40,6 +63,9 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
@Autowired
|
|
|
private ZhcxPmqManagementDistributionDao zhcxPmqManagementDistributionDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysFileItemService sysFileItemService;
|
|
|
+
|
|
|
@Override
|
|
|
public R generateDistributionDetail(Map<String, Object> map) {
|
|
|
// 第二层主表id
|
|
@@ -85,4 +111,86 @@ public class ZhcxPmqManagementRecoredServiceImpl extends ServiceImpl<ZhcxPmqMana
|
|
|
zhcxPmqManagementDistributionDetailService.updateClosedStateInSecondFloor(id);
|
|
|
return R.ok("派单成功");
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R filePreview(String id) {
|
|
|
+ ZhcxPmqManagementRecoredDo recoredDo = this.getById(id);
|
|
|
+ if(Objects.isNull(recoredDo)){
|
|
|
+ return R.error("数据异常,请联系管理员");
|
|
|
+ }
|
|
|
+ // 创建结果返回集
|
|
|
+ HashMap<String, String> resultMap = new HashMap<>();
|
|
|
+ // 判断是否已经生成了文件数据
|
|
|
+ String files = recoredDo.getFiles();
|
|
|
+ if(StringUtils.isNotBlank(files)){
|
|
|
+ SysFileItemDo sysFileItemDo = sysFileItemService.getById(files);
|
|
|
+ resultMap.put("fileId",sysFileItemDo.getId());
|
|
|
+ resultMap.put("fileType",sysFileItemDo.getFiletype());
|
|
|
+ return R.ok(resultMap);
|
|
|
+ }
|
|
|
+ String rid = recoredDo.getRid();
|
|
|
+ String fileid = recoredDo.getFileid();
|
|
|
+ if(StringUtils.isEmpty(rid) || StringUtils.isEmpty(fileid)){
|
|
|
+ return R.error("暂无文件可预览");
|
|
|
+ }
|
|
|
+ // 根据rid和fileid 去sqlserver拿数据
|
|
|
+ List<JuFileInfoDto> fileList = getFileInfoInSqlServer(rid,fileid);
|
|
|
+ if(fileList.isEmpty()){
|
|
|
+ return R.error("获取文件失败");
|
|
|
+ }
|
|
|
+ // 去构建sys_file_item
|
|
|
+ String uuid = SecurityUtil.getUUID();
|
|
|
+ JuFileInfoDto fileInfoDto = fileList.get(0);
|
|
|
+ // 获取文件类型
|
|
|
+ String filetype = FileUtil.getSuffix(fileInfoDto.getFileName());
|
|
|
+ // 获取文件名 => fileid+后缀
|
|
|
+ String filename = fileInfoDto.getFileId()+"."+filetype;
|
|
|
+ // 文件全路径
|
|
|
+ String fullPath = nxfilepath + FileUtil.FILE_SEPARATOR + fileInfoDto.getDir() + FileUtil.FILE_SEPARATOR + filename;
|
|
|
+ // 判断文件是否存在
|
|
|
+ if(FileUtil.isEmpty(new File(fullPath))){
|
|
|
+ return R.error("暂无法获取文件");
|
|
|
+ }
|
|
|
+ SysFileItemDo fileItemDo = new SysFileItemDo();
|
|
|
+ fileItemDo.setId(uuid);
|
|
|
+ fileItemDo.setFilename(filename);
|
|
|
+ fileItemDo.setFilesize(FileUtil.size(FileUtil.file(fullPath)));
|
|
|
+ fileItemDo.setFiletype(filetype);
|
|
|
+ fileItemDo.setStoragetype("1");
|
|
|
+ fileItemDo.setFullpath(fullPath);
|
|
|
+ fileItemDo.setRemark("三单文件");
|
|
|
+ sysFileItemService.save(fileItemDo);
|
|
|
+ // 更新记录表
|
|
|
+ baseMapper.updateFilesById(uuid,recoredDo.getId());
|
|
|
+ resultMap.put("fileId",uuid);
|
|
|
+ resultMap.put("fileType",filetype);
|
|
|
+ return R.ok(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JuFileInfoDto> getFileInfoInSqlServer(String rid,String fileid){
|
|
|
+ // 结果集
|
|
|
+ List<JuFileInfoDto> resultList = new ArrayList<>();
|
|
|
+ String url ="jdbc:sqlserver://"+nxurl+":1433;databaseName="+nxdbname+";"+nxurlfix+"";
|
|
|
+ log.info("SQLSERVER文件读取连接字符串" + url);
|
|
|
+ try(Connection connection = DriverManager.getConnection(url,nxdbuser,nxdbpw);
|
|
|
+ Statement statement = connection.createStatement()) {
|
|
|
+ String sqlStr = "SELECT * FROM [JU_fileinfo] WHERE FileID = '"+fileid+"' AND RecordID = '"+rid+"'";
|
|
|
+ log.info("SQLSERVER文件读取SQL:" + sqlStr);
|
|
|
+ ResultSet resultSet = statement.executeQuery(sqlStr);
|
|
|
+ while (resultSet.next()) {
|
|
|
+ JuFileInfoDto fileInfoDto = new JuFileInfoDto();
|
|
|
+ fileInfoDto.setFileId(resultSet.getString(1));
|
|
|
+ fileInfoDto.setRecordId(resultSet.getString(2));
|
|
|
+ fileInfoDto.setFileName(resultSet.getString(3));
|
|
|
+ fileInfoDto.setFileBinary(resultSet.getString(4));
|
|
|
+ fileInfoDto.setDir(resultSet.getString(5));
|
|
|
+ fileInfoDto.setNxfsId(resultSet.getString(6));
|
|
|
+ resultList.add(fileInfoDto);
|
|
|
+ }
|
|
|
+ }catch(Exception e2){
|
|
|
+ log.error("SQLSERVER文件读取异常");
|
|
|
+ e2.printStackTrace();
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
}
|