|
@@ -0,0 +1,210 @@
|
|
|
+package sys.sc.formplugin;
|
|
|
+
|
|
|
+import com.alibaba.druid.support.logging.Log;
|
|
|
+import com.alibaba.druid.support.logging.LogFactory;
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
|
+import kd.bos.entity.EntityMetadataCache;
|
|
|
+import kd.bos.exception.KDException;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.schedule.api.MessageHandler;
|
|
|
+import kd.bos.schedule.executor.AbstractTask;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
+import sys.sc.opplugin.utils.SftpClient;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+ * @author cjz
|
|
|
+ * @date 2024/9/10 9:00
|
|
|
+ * @description:日常更新行名行号调度计划
|
|
|
+ */
|
|
|
+public class UpdateBankDailyTask extends AbstractTask {
|
|
|
+ private static final Log log = LogFactory.getLog(UpdateBankDailyTask.class);
|
|
|
+ public static String host="192.168.10.69";
|
|
|
+ public static String username="root";
|
|
|
+ public static int port = 22;
|
|
|
+ public static String password="Kd@86262007";
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MessageHandler getMessageHandle() {
|
|
|
+ return super.getMessageHandle();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
|
|
|
+ log.info("----------------------获取服务器连接------------------------");
|
|
|
+
|
|
|
+ SftpClient sftpClient=new SftpClient(host,username,password,port);
|
|
|
+ try {
|
|
|
+ sftpClient.connect();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ String mes="-----------------正在执行任务,读取行名行号---------------------";
|
|
|
+ log.info(mes+requestContext);
|
|
|
+
|
|
|
+ List<String> selector = Arrays.asList(
|
|
|
+ "number", "name"
|
|
|
+ );
|
|
|
+
|
|
|
+ String bd_bebank="bd_bebank";
|
|
|
+ try {
|
|
|
+ List<DynamicObject> createdataList = new ArrayList<>();
|
|
|
+ List<DynamicObject> updatedataList = new ArrayList<>();
|
|
|
+
|
|
|
+ String fileurl = getFileUrl("hmhhurl");
|
|
|
+
|
|
|
+ DynamicObjectType dynamicObjectType = EntityMetadataCache.getDataEntityType(bd_bebank);
|
|
|
+
|
|
|
+ DynamicObject country= BusinessDataServiceHelper
|
|
|
+ .loadSingle("bd_country","number", new QFilter[]{new QFilter("number", QCP.equals, "001")});
|
|
|
+
|
|
|
+ DynamicObject[] existingData = BusinessDataServiceHelper
|
|
|
+ .load(dynamicObjectType.getName(), String.join(",", selector)+",enable,nckd_datasource", null);
|
|
|
+
|
|
|
+ Map<String, DynamicObject> existingDataMap = new HashMap<>();
|
|
|
+ for (DynamicObject obj : existingData) {
|
|
|
+
|
|
|
+ existingDataMap.put(obj.getString(selector.get(0)), obj);
|
|
|
+ }
|
|
|
+ Set<String> processeddubilidSet = new HashSet<>();
|
|
|
+
|
|
|
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(sftpClient.fileInputStream(fileurl)))) {
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+
|
|
|
+ line = line.replace("|$|", "");
|
|
|
+
|
|
|
+ String[] fields = line.split("\u0001");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String dubil_id = fields[0];
|
|
|
+ boolean isUpdated = false;
|
|
|
+ DynamicObject data;
|
|
|
+ processeddubilidSet.add(dubil_id);
|
|
|
+ if (existingDataMap.containsKey(dubil_id)) {
|
|
|
+
|
|
|
+ data = existingDataMap.get(dubil_id);
|
|
|
+ for (int i = 0; i < selector.size(); i++) {
|
|
|
+ String fieldName = selector.get(i);
|
|
|
+ String newValue = fields[i];
|
|
|
+ String existingValue = data.getString(fieldName);
|
|
|
+
|
|
|
+ if (!Objects.equals(existingValue, newValue)) {
|
|
|
+ data.set(fieldName, newValue);
|
|
|
+ isUpdated = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isUpdated) {
|
|
|
+ updatedataList.add(data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ data = new DynamicObject(dynamicObjectType);
|
|
|
+ for (int i = 0; i < selector.size(); i++) {
|
|
|
+ data.set(selector.get(i), fields[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ data.set("country",country);
|
|
|
+
|
|
|
+ data.set("provincetxt","江西");
|
|
|
+
|
|
|
+ data.set("citytxt","南昌");
|
|
|
+
|
|
|
+ data.set("union_number",fields[0]);
|
|
|
+
|
|
|
+ data.set("enable","1");
|
|
|
+
|
|
|
+ data.set("nckd_datasource","1");
|
|
|
+ createdataList.add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sftpClient.disconnect();
|
|
|
+
|
|
|
+ DynamicObject[] autoData = BusinessDataServiceHelper
|
|
|
+ .load(dynamicObjectType.getName()
|
|
|
+ , String.join(",", selector)+",enable,nckd_datasource",
|
|
|
+ new QFilter[]{new QFilter("nckd_datasource", QCP.equals, "1")});
|
|
|
+ for (DynamicObject autoDatum : autoData) {
|
|
|
+
|
|
|
+ if (!processeddubilidSet.contains(autoDatum.getString("number"))) {
|
|
|
+
|
|
|
+ autoDatum.set("enable", "0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SaveServiceHelper.save(autoData);
|
|
|
+
|
|
|
+ for (Map.Entry<String, DynamicObject> entry : existingDataMap.entrySet()) {
|
|
|
+ String dubil_id = entry.getKey();
|
|
|
+ DynamicObject data = entry.getValue();
|
|
|
+ if (!processeddubilidSet.contains(dubil_id)) {
|
|
|
+
|
|
|
+ updatedataList.add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!createdataList.isEmpty()) {
|
|
|
+ SaveServiceHelper.save(dynamicObjectType, createdataList.toArray(new DynamicObject[0]));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!updatedataList.isEmpty()) {
|
|
|
+ SaveServiceHelper.save(updatedataList.get(0).getDynamicObjectType(), updatedataList.toArray(new DynamicObject[0]));
|
|
|
+ }
|
|
|
+ log.info("------------------数据已成功保存------------------");
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ log.info("----------------------读取文件时发生错误-----------------");
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new RuntimeException(ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isSupportReSchedule() {
|
|
|
+ return super.isSupportReSchedule();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String getFileUrl(String urlcode)
|
|
|
+ {
|
|
|
+
|
|
|
+ DynamicObject nckd_jkpzxx= BusinessDataServiceHelper
|
|
|
+ .loadSingle("nckd_jkpzxx", new QFilter[]{new QFilter("number", "=", urlcode)});
|
|
|
+
|
|
|
+ String nckd_filename=nckd_jkpzxx.getString("nckd_filename");
|
|
|
+
|
|
|
+ String nckd_url=nckd_jkpzxx.getString("nckd_url");
|
|
|
+
|
|
|
+ Date currentDate=new Date();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(currentDate);
|
|
|
+ calendar.add(Calendar.DATE, -1);
|
|
|
+
|
|
|
+ Date newDate = calendar.getTime();
|
|
|
+
|
|
|
+ SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
|
|
|
+ String datestr=sf.format(newDate);
|
|
|
+
|
|
|
+
|
|
|
+ if (nckd_url.equals("/var/appstatic/")) {
|
|
|
+ nckd_url="/home/kingdee/cosmic/nginx-appstatic/store/appstatic/";
|
|
|
+ }
|
|
|
+ String realPath = nckd_url+datestr+"/"+nckd_filename;
|
|
|
+ return realPath;
|
|
|
+ }
|
|
|
+}
|