|
@@ -42,85 +42,87 @@ public class CreatDatDailyTask extends AbstractTask {
|
|
|
|
|
|
@Override
|
|
|
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
|
+ //获取调度参数
|
|
|
+ String frequency= (String) map.get("frequency");
|
|
|
//取已审核的数据
|
|
|
QFilter filter=new QFilter("status", QCP.equals,"C");
|
|
|
//数据表基础资料
|
|
|
DynamicObject[] tableDy=BusinessDataServiceHelper
|
|
|
.load(nckd_tablebasic,"id,nckd_tableentry,nckd_isable,nckd_entrycode,nckd_dooperation,number,nckd_biazppnum,creatdat",new QFilter[]{filter});
|
|
|
log.info("----------------------读取数据表基础资料-------------------");
|
|
|
- for (DynamicObject item:tableDy)
|
|
|
- {
|
|
|
- log.info("-------------------------获取服务器连接-----------------");
|
|
|
- List<String> fileList=new ArrayList<>();
|
|
|
- //获取表字段当前分录
|
|
|
- DynamicObjectCollection dynamicObjectCollection=item.getDynamicObjectCollection("nckd_tableentry");
|
|
|
- for (DynamicObject itemmen:dynamicObjectCollection) {
|
|
|
- //将打勾的字段导出
|
|
|
- if (itemmen.getBoolean("nckd_isable")) {
|
|
|
- //需要导入的标识写入list中
|
|
|
- fileList.add(itemmen.getString("nckd_entrycode"));
|
|
|
+ for (DynamicObject item:tableDy) {
|
|
|
+ //参数执行频率等于表的执行频率则生成文件
|
|
|
+ if (frequency.equals(item.getString("nckd_dooperation"))) {
|
|
|
+ log.info("-------------------------获取服务器连接-----------------");
|
|
|
+ List<String> fileList=new ArrayList<>();
|
|
|
+ //获取表字段当前分录
|
|
|
+ DynamicObjectCollection dynamicObjectCollection=item.getDynamicObjectCollection("nckd_tableentry");
|
|
|
+ for (DynamicObject itemmen:dynamicObjectCollection) {
|
|
|
+ //将打勾的字段导出
|
|
|
+ if (itemmen.getBoolean("nckd_isable")) {
|
|
|
+ //需要导入的标识写入list中
|
|
|
+ fileList.add(itemmen.getString("nckd_entrycode"));
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //任务执行频率
|
|
|
- String nckd_dooperation=item.getString("nckd_dooperation");
|
|
|
- //获取当前选择的表名
|
|
|
- String tablenumber=item.getString("number");
|
|
|
- //业务编码
|
|
|
- String bizappnum=item.getString("nckd_biazppnum");
|
|
|
- //接口配置信息获取
|
|
|
- //读取接口配置信息获取
|
|
|
- InterFaceImgUtils interFaceImgUtils=new InterFaceImgUtils("creatdat");
|
|
|
- //服务器路径
|
|
|
- String nckd_url=interFaceImgUtils.getServerUrl();
|
|
|
- //分割符号
|
|
|
- String spiltsign=interFaceImgUtils.getServerSplit();
|
|
|
- //结束符号
|
|
|
- String endsign=interFaceImgUtils.getServerEndsign();
|
|
|
- //上传文件到服务器中
|
|
|
- //服务器端口
|
|
|
- String host=interFaceImgUtils.getServerName();
|
|
|
- //服务器用户名
|
|
|
- String username=interFaceImgUtils.getServerUser();
|
|
|
- //服务器密码
|
|
|
- String password=interFaceImgUtils.getServerPassword();
|
|
|
- //服务器路径
|
|
|
- //服务器端口号
|
|
|
- int port= interFaceImgUtils.getProt();
|
|
|
- try {
|
|
|
+ //获取当前选择的表名
|
|
|
+ String tablenumber=item.getString("number");
|
|
|
+ //业务编码
|
|
|
+ String bizappnum=item.getString("nckd_biazppnum");
|
|
|
+ //接口配置信息获取
|
|
|
+ //读取接口配置信息获取
|
|
|
+ InterFaceImgUtils interFaceImgUtils=new InterFaceImgUtils("creatdat");
|
|
|
+ //服务器路径
|
|
|
+ String nckd_url=interFaceImgUtils.getServerUrl();
|
|
|
+ //分割符号
|
|
|
+ String spiltsign=interFaceImgUtils.getServerSplit();
|
|
|
+ //结束符号
|
|
|
+ String endsign=interFaceImgUtils.getServerEndsign();
|
|
|
//上传文件到服务器中
|
|
|
- SftpClient sftpClient=new SftpClient(host,username,password,port);
|
|
|
- //获取服务器连接
|
|
|
- sftpClient.connect();
|
|
|
- //创建文件夹,为当天日期
|
|
|
- Date currentDate=new Date();
|
|
|
- //设置日期格式
|
|
|
- SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
|
|
|
- String dateStr=sf.format(currentDate);
|
|
|
- String filePathWithDate=nckd_url+dateStr;
|
|
|
- //创建文件夹,名为当前日期
|
|
|
- sftpClient.creatDir(filePathWithDate);
|
|
|
- //临时文件
|
|
|
- File localFile = File.createTempFile(tablenumber, ".dat");
|
|
|
- File dest=new File(localFile.getParent()+File.separator+tablenumber.toUpperCase()+".dat");
|
|
|
- //重命名文件
|
|
|
- localFile.renameTo(dest);
|
|
|
- //文件写入
|
|
|
- DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,dest.getAbsolutePath(),spiltsign,endsign);
|
|
|
- //生成dat文件到本地
|
|
|
- datFileCreatUtils.creatDatFile();
|
|
|
- //从本地传文件到服务器
|
|
|
- sftpClient.fileCreat(dest.getAbsolutePath(),filePathWithDate);
|
|
|
- //上传后删除临时文件
|
|
|
- localFile.delete();
|
|
|
- dest.delete();
|
|
|
- //关闭连接
|
|
|
- sftpClient.disconnect();
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (SftpException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ //服务器端口
|
|
|
+ String host=interFaceImgUtils.getServerName();
|
|
|
+ //服务器用户名
|
|
|
+ String username=interFaceImgUtils.getServerUser();
|
|
|
+ //服务器密码
|
|
|
+ String password=interFaceImgUtils.getServerPassword();
|
|
|
+ //服务器路径
|
|
|
+ //服务器端口号
|
|
|
+ int port= interFaceImgUtils.getProt();
|
|
|
+ try {
|
|
|
+ //上传文件到服务器中
|
|
|
+ SftpClient sftpClient=new SftpClient(host,username,password,port);
|
|
|
+ //获取服务器连接
|
|
|
+ sftpClient.connect();
|
|
|
+ //创建文件夹,为当天日期
|
|
|
+ Date currentDate=new Date();
|
|
|
+ //设置日期格式
|
|
|
+ SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
|
|
|
+ String dateStr=sf.format(currentDate);
|
|
|
+ String filePathWithDate=nckd_url+dateStr;
|
|
|
+ //创建文件夹,名为当前日期
|
|
|
+ sftpClient.creatDir(filePathWithDate);
|
|
|
+ //临时文件
|
|
|
+ File localFile = File.createTempFile(tablenumber, ".dat");
|
|
|
+ File dest=new File(localFile.getParent()+File.separator+tablenumber.toUpperCase()+".dat");
|
|
|
+ //重命名文件
|
|
|
+ localFile.renameTo(dest);
|
|
|
+ //文件写入
|
|
|
+ DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,dest.getAbsolutePath(),spiltsign,endsign);
|
|
|
+ //生成dat文件到本地
|
|
|
+ datFileCreatUtils.creatDatFile();
|
|
|
+ //从本地传文件到服务器
|
|
|
+ sftpClient.fileCreat(dest.getAbsolutePath(),filePathWithDate);
|
|
|
+ //上传后删除临时文件
|
|
|
+ localFile.delete();
|
|
|
+ dest.delete();
|
|
|
+ //关闭连接
|
|
|
+ sftpClient.disconnect();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (SftpException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|