Ver Fonte

三单附件

wangxuan há 8 meses atrás
pai
commit
53aebc4b86

+ 2 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxPmqManagementRecoredDao.java

@@ -31,4 +31,6 @@ public interface ZhcxPmqManagementRecoredDao extends BaseMapper<ZhcxPmqManagemen
      * @return
      */
     List<ZhcxPmqManagementDistributionDo> getDistributionsByPid(@Param("id") String id);
+
+    void updateFilesById(@Param("files") String files,@Param("id") String id);
 }

+ 7 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxPmqManagementRecoredService.java

@@ -22,4 +22,11 @@ public interface ZhcxPmqManagementRecoredService extends IService<ZhcxPmqManagem
      * @return
      */
     R generateDistributionDetail(Map<String, Object> map);
+
+    /**
+     * 文件预览接口
+     * @param id recored表id
+     * @return map集合:sys_file表id,文件类型
+     */
+    R filePreview(String id);
 }

+ 108 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPmqManagementRecoredServiceImpl.java

@@ -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;
+    }
 }

+ 31 - 5
business-common/src/main/java/com/rongwei/bscommon/sys/utils/SqlServerJdbcUtils.java

@@ -2,6 +2,7 @@ package com.rongwei.bscommon.sys.utils;
 
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.unit.DataUnit;
+import com.rongwei.bsentity.dto.sqlServer.JuFileInfoDto;
 import com.rongwei.bsentity.dto.sqlServer.ZhcxPmqManagementSource;
 import lombok.extern.slf4j.Slf4j;
 
@@ -17,11 +18,11 @@ import java.util.List;
 public class SqlServerJdbcUtils {
 
     // SQL Server连接URL
-    private static final String URL = "jdbc:sqlserver://192.168.0.204:1433;;databaseName=cctest";
+    private static final String URL = "jdbc:sqlserver://192.168.0.142:1433;;databaseName=cwbt6";
     // 用户名
     private static final String USERNAME = "sa";
     // 密码
-    private static final String PASSWORD = "Irongwei@1";
+    private static final String PASSWORD = "Sasa2014";
 
     public static List<ZhcxPmqManagementSource> queryZHCXPMQMANAGEMENTSOURCEData() {
         Security.setProperty("jdk.tls.client.protocols", "TLSv1.2,TLSv1.1,TLSv1");
@@ -92,10 +93,35 @@ public class SqlServerJdbcUtils {
         return data;
     }
 
+    private static List<JuFileInfoDto> getFileInfoInSqlServer(String rid, String fileid){
+        // 结果集
+        List<JuFileInfoDto> resultList = new ArrayList<>();
+        try(Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
+            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;
+    }
+
     public static void main(String[] args) {
-        List<ZhcxPmqManagementSource> zhcxPmqManagementSources = queryZHCXPMQMANAGEMENTSOURCEDataPRO();
-        for (ZhcxPmqManagementSource zhcxPmqManagementSource : zhcxPmqManagementSources) {
-            System.out.println(zhcxPmqManagementSource);
+        List<JuFileInfoDto> fileInfoInSqlServer = getFileInfoInSqlServer("9249143","882772");
+        for (JuFileInfoDto fileInfoDto : fileInfoInSqlServer) {
+            System.out.println(fileInfoDto);
         }
     }
 }

+ 9 - 0
business-common/src/main/resources/mybatis/business/ZhcxPmqManagementRecoredDao.xml

@@ -41,4 +41,13 @@
         ORDER BY
             TO_NUMBER(REPLACE(p.MACHINENO, '#', ''))
     </select>
+
+    <update id="updateFilesById">
+        UPDATE
+            INCONTROL.ZHCX_PMQ_MANAGEMENT_RECORED
+        SET
+            FILES = #{files}
+        WHERE
+            ID = #{id}
+    </update>
 </mapper>

+ 38 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/sqlServer/JuFileInfoDto.java

@@ -0,0 +1,38 @@
+package com.rongwei.bsentity.dto.sqlServer;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * sqlserver 映射表:JU_file_info
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class JuFileInfoDto {
+    /**
+     * 文件id
+     */
+    private String fileId;
+    /**
+     * 记录表id
+     */
+    private String recordId;
+    /**
+     * 文件名
+     */
+    private String fileName;
+    /**
+     * 文件二进制
+     */
+    private String fileBinary;
+    /**
+     * 文件路径
+     */
+    private String dir;
+    /**
+     * 这个不知道
+     */
+    private String nxfsId;
+}

+ 28 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxPmqManagementRecoredController.java

@@ -1,9 +1,19 @@
 package com.rongwei.bsserver.controller;
 
 
+import com.rongwei.bscommon.sys.service.ZhcxPmqManagementRecoredService;
+import com.rongwei.rwcommon.base.R;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Map;
+import java.util.Objects;
+
 /**
  * <p>
  * 三单管理_单据记录 前端控制器
@@ -12,9 +22,27 @@ import org.springframework.web.bind.annotation.RestController;
  * @author wm
  * @since 2024-10-30
  */
+@Slf4j
 @RestController
 @RequestMapping("/zhcxPmqManagementRecored")
 public class ZhcxPmqManagementRecoredController {
+    @Autowired
+    private ZhcxPmqManagementRecoredService managementRecoredService;
 
+    @PostMapping("/filePreview")
+    @ApiOperation("三单文件预览")
+    public R filePreview(@RequestBody Map<String,Object> map){
+        try {
+            if(Objects.isNull(map.get("id"))){
+                return R.error("id不能为空");
+            }
+            String id = (String) map.get("id");
+            log.info("三单文件预览->id:{}",id);
+            return managementRecoredService.filePreview(id);
+        } catch (Exception e) {
+            log.info(String.valueOf(e));
+            return R.error("文件预览异常");
+        }
+    }
 }