|
@@ -0,0 +1,774 @@
|
|
|
|
+package sys.sc.formplugin;
|
|
|
|
+
|
|
|
|
+import kd.bos.base.utils.msg.BaseMessage;
|
|
|
|
+import kd.bos.base.utils.msg.OrgMessage;
|
|
|
|
+import kd.bos.dataentity.entity.CloneUtils;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
|
|
+import kd.bos.entity.EntityMetadataCache;
|
|
|
|
+import kd.bos.entity.operate.result.OperationResult;
|
|
|
|
+import kd.bos.form.IFormView;
|
|
|
|
+import kd.bos.form.events.AfterDoOperationEventArgs;
|
|
|
|
+import kd.bos.form.events.BeforeDoOperationEventArgs;
|
|
|
|
+import kd.bos.list.plugin.AbstractListPlugin;
|
|
|
|
+import kd.bos.org.utils.OrgUtils;
|
|
|
|
+import kd.bos.orm.ORM;
|
|
|
|
+import kd.bos.orm.impl.ORMImpl;
|
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
+import kd.bos.sec.user.utils.UserOperationUtils;
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
|
+import kd.imc.bdm.common.constant.BotpCallBackLogConstant;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.EventObject;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+public class TestPlugin extends AbstractListPlugin {
|
|
|
|
+
|
|
|
|
+ //根据接口配置信息获取组织人员,拼接服务器文件路径url,参数为urlcode接口配置信息编码
|
|
|
|
+ public String getFileUrl(String urlcode) throws IOException {
|
|
|
|
+ //组织人员接口配置信息获取
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //从文件读取数据更新到基础资料中
|
|
|
|
+ public void generateDataFile(String filePath) {
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ DynamicObjectType dynamicObjectType = EntityMetadataCache.getDataEntityType("nckd_basicdata");
|
|
|
|
+ List<String> selector = Arrays.asList(
|
|
|
|
+ "nckd_employeeid", "nckd_name", "nckd_gender", "nckd_nl", "nckd_zzmm",
|
|
|
|
+ "nckd_zgxl", "nckd_szdwname", "nckd_szdwcode", "nckd_orgidname", "nckd_orgidcode",
|
|
|
|
+ "nckd_yjbmname", "nckd_yjbmcode", "nckd_posidname", "nckd_posidcode", "nckd_yggxlb",
|
|
|
|
+ "nckd_status", "nckd_sjh"
|
|
|
|
+ );
|
|
|
|
+ List<DynamicObject> createdataList = new ArrayList<>();
|
|
|
|
+ List<DynamicObject> updatedataList = new ArrayList<>();
|
|
|
|
+ //查出所有现有的数据
|
|
|
|
+ DynamicObject[] existingData = BusinessDataServiceHelper
|
|
|
|
+ .load(dynamicObjectType.getName(), String.join(",", selector) + ",nckd_updatedate,nckd_isdelete", null);
|
|
|
|
+ Map<String, DynamicObject> existingDataMap = new HashMap<>();
|
|
|
|
+ for (DynamicObject obj : existingData) {
|
|
|
|
+ existingDataMap.put(obj.getString("nckd_employeeid"), obj);
|
|
|
|
+ }
|
|
|
|
+ Set<String> processedGonghaoSet = new HashSet<>();
|
|
|
|
+ try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
|
|
|
+ String line;
|
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
|
+ //去掉换行符|$|
|
|
|
|
+ line = line.replace("|$|", "");
|
|
|
|
+ //空格符号,根据这个符号分割
|
|
|
|
+ String[] fields = line.split("\u0001");
|
|
|
|
+ //如果获取的数据行不等于预设字段的行,则跳过这行数据
|
|
|
|
+ if (fields.length != selector.size()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //获取工号
|
|
|
|
+ String gonghao = fields[0];
|
|
|
|
+ boolean isUpdated = false;
|
|
|
|
+ DynamicObject data;
|
|
|
|
+ processedGonghaoSet.add(gonghao);
|
|
|
|
+ if (existingDataMap.containsKey(gonghao)) {
|
|
|
|
+ //获取对应工号的数据
|
|
|
|
+ data = existingDataMap.get(gonghao);
|
|
|
|
+ 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) {
|
|
|
|
+ data.set("nckd_updatedate", new Date());
|
|
|
|
+ updatedataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //不存在这条数据则新增一条到data中
|
|
|
|
+ data = new DynamicObject(dynamicObjectType);
|
|
|
|
+ for (int i = 0; i < selector.size(); i++) {
|
|
|
|
+ data.set(selector.get(i), fields[i]);
|
|
|
|
+ }
|
|
|
|
+ Date now = new Date();
|
|
|
|
+ data.set("nckd_createdate", now);
|
|
|
|
+ data.set("nckd_updatedate", now);
|
|
|
|
+ createdataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (Map.Entry<String, DynamicObject> entry : existingDataMap.entrySet()) {
|
|
|
|
+ String gonghao = entry.getKey();
|
|
|
|
+ DynamicObject data = entry.getValue();
|
|
|
|
+
|
|
|
|
+ if (!processedGonghaoSet.contains(gonghao)) {
|
|
|
|
+ data.set("nckd_isdelete", true);
|
|
|
|
+ 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]));
|
|
|
|
+ }
|
|
|
|
+ this.getView().showMessage("数据已成功保存!");
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ this.getView().showMessage("读取文件时发生错误:" + ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void afterBindData(EventObject e) {
|
|
|
|
+ super.afterBindData(e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void afterDoOperation(AfterDoOperationEventArgs e) {
|
|
|
|
+ super.afterDoOperation(e);
|
|
|
|
+ String filePath = "D:/test.dat";
|
|
|
|
+ if ("scdatwj".equals(e.getOperateKey())) {//生成data文件
|
|
|
|
+ try {
|
|
|
|
+ DynamicObjectType dynamicObjectType = EntityMetadataCache.getDataEntityType("nckd_basicdata");
|
|
|
|
+ // 定义选择的字段
|
|
|
|
+ List<String> selector = new ArrayList<>();
|
|
|
|
+ selector.add("nckd_employeeid");
|
|
|
|
+ selector.add("nckd_name");
|
|
|
|
+ selector.add("nckd_gender");
|
|
|
|
+ selector.add("nckd_nl");
|
|
|
|
+ selector.add("nckd_zzmm");
|
|
|
|
+ selector.add("nckd_zgxl");
|
|
|
|
+ selector.add("nckd_szdwname");
|
|
|
|
+ selector.add("nckd_szdwcode");
|
|
|
|
+ selector.add("nckd_orgidname");
|
|
|
|
+ selector.add("nckd_orgidcode");
|
|
|
|
+ selector.add("nckd_yjbmname");
|
|
|
|
+ selector.add("nckd_yjbmcode");
|
|
|
|
+ selector.add("nckd_posidname");
|
|
|
|
+ selector.add("nckd_posidcode");
|
|
|
|
+ selector.add("nckd_yggxlb");
|
|
|
|
+ selector.add("nckd_status");
|
|
|
|
+ selector.add("nckd_sjh");
|
|
|
|
+ DynamicObject[] dataList = BusinessDataServiceHelper.load(dynamicObjectType.getName(), String.join(",", selector), null);
|
|
|
|
+ File file = new File(filePath);
|
|
|
|
+ //文件路径不存在则创建文件
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ File parentDir = file.getParentFile();
|
|
|
|
+ if (parentDir != null && !parentDir.exists()) {
|
|
|
|
+ parentDir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "GBK"))) {
|
|
|
|
+ for (DynamicObject data : dataList) {
|
|
|
|
+ StringBuilder line = new StringBuilder();
|
|
|
|
+ for (String field : selector) {
|
|
|
|
+ line.append(data.get(field) != null ? data.get(field).toString() : "").append("\u0001");
|
|
|
|
+ }
|
|
|
|
+ line.setLength(line.length() - 1);
|
|
|
|
+ line.append("|$|");
|
|
|
|
+ writer.write(line.toString());
|
|
|
|
+ writer.newLine();
|
|
|
|
+ }
|
|
|
|
+ this.getView().showMessage("数据文件已成功生成!");
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ this.getView().showMessage("生成数据文件时发生错误!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //更新人员
|
|
|
|
+ else if ("gxry".equals(e.getOperateKey())) {
|
|
|
|
+ //更新人员
|
|
|
|
+ // 从 nckd_basicdata 表中获取所有人员数据,假设通过某个条件查找
|
|
|
|
+ DynamicObject[] personDataArray = BusinessDataServiceHelper.load(
|
|
|
|
+ "nckd_basicdata",
|
|
|
|
+ "id,nckd_employeeid,nckd_name,nckd_gender,nckd_nl,nckd_zzmm,nckd_zgxl,nckd_orgidname,nckd_orgidcode,nckd_posidname,nckd_posidcode,nckd_yggxlb,nckd_status,nckd_sjh",
|
|
|
|
+ null
|
|
|
|
+ );
|
|
|
|
+ if (personDataArray == null || personDataArray.length == 0) {
|
|
|
|
+ this.getView().showMessage("未从 nckd_basicdata 表中获取到任何人员数据!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ String msg="";
|
|
|
|
+ // 人员类型写死的
|
|
|
|
+ for (DynamicObject personData : personDataArray) {
|
|
|
|
+ //获取id
|
|
|
|
+ String id=personData.getString("id");
|
|
|
|
+ // 获取工号
|
|
|
|
+ String gonghao = personData.getString("nckd_employeeid");
|
|
|
|
+ if (gonghao == null || gonghao.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 查询用户是否已存在
|
|
|
|
+ DynamicObject existingUser = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_user", new QFilter[]{new QFilter("number", "=", gonghao)}
|
|
|
|
+ );
|
|
|
|
+ // 用户已存在,进行数据更新
|
|
|
|
+ if (existingUser != null) {
|
|
|
|
+ //初始化
|
|
|
|
+ boolean isUpdated = false;
|
|
|
|
+ // 比较并更新性别
|
|
|
|
+ Object newGender = personData.get("nckd_gender");
|
|
|
|
+ if (!newGender.equals(existingUser.get("gender"))) {
|
|
|
|
+ existingUser.set("gender", newGender);
|
|
|
|
+ isUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ // 比较并更新手机号
|
|
|
|
+ Object newPhone = personData.get("nckd_sjh");
|
|
|
|
+ if (!newPhone.equals(existingUser.get("phone"))) {
|
|
|
|
+ existingUser.set("phone", newPhone);
|
|
|
|
+ isUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ //更新部门和岗位
|
|
|
|
+ DynamicObjectCollection existingDeptEntries = existingUser.getDynamicObjectCollection("entryentity");
|
|
|
|
+ //人员部门分录
|
|
|
|
+ DynamicObject existingDeptEntry = existingDeptEntries.isEmpty() ? null : existingDeptEntries.get(0);
|
|
|
|
+ // 获取新的部门信息
|
|
|
|
+ String deptCode = personData.getString("nckd_orgidcode");
|
|
|
|
+ DynamicObject newOrgInfo = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_adminorg", new QFilter[]{new QFilter("number", "=", deptCode)}
|
|
|
|
+ );
|
|
|
|
+ boolean deptUpdated = false;
|
|
|
|
+ if (newOrgInfo != null) {
|
|
|
|
+ if (existingDeptEntry == null) {
|
|
|
|
+ // 如果没有现有部门分录,则添加新的部门分录
|
|
|
|
+ existingDeptEntry = existingDeptEntries.addNew();
|
|
|
|
+ deptUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ // 比较并更新部门信息
|
|
|
|
+ if (!deptCode.equals(existingDeptEntry.get("dpt.number"))) {
|
|
|
|
+ existingDeptEntry.set("dpt", newOrgInfo);
|
|
|
|
+ deptUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ // 更新组织结构
|
|
|
|
+ DynamicObjectCollection structureInfoCollection = newOrgInfo.getDynamicObjectCollection("structure");
|
|
|
|
+ if (structureInfoCollection != null && !structureInfoCollection.isEmpty()) {
|
|
|
|
+ DynamicObject structureInfo = structureInfoCollection.get(0);
|
|
|
|
+ if(existingDeptEntry.getDynamicObject("orgstructure")!=null){
|
|
|
|
+ if (!structureInfo.getPkValue().equals(existingDeptEntry.getDynamicObject("orgstructure").getPkValue())) {
|
|
|
|
+ existingDeptEntry.set("orgstructure", structureInfo.getPkValue());
|
|
|
|
+ deptUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ existingDeptEntry.set("orgstructure", structureInfo.getPkValue());
|
|
|
|
+ deptUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 标记是否需要保存
|
|
|
|
+ if (deptUpdated) {
|
|
|
|
+ isUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ this.getView().showMessage("未找到部门编码为 " + deptCode + " 的部门信息!");
|
|
|
|
+ }
|
|
|
|
+ // 获取新的岗位信息
|
|
|
|
+ String postName = personData.getString("nckd_posidname");
|
|
|
|
+ if (!postName.equals(existingDeptEntry.getString("position"))) {
|
|
|
|
+ existingDeptEntry.set("position", postName);
|
|
|
|
+ isUpdated = true;
|
|
|
|
+ }
|
|
|
|
+ // 如果有更新则保存
|
|
|
|
+ if (isUpdated) {
|
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{existingUser});
|
|
|
|
+ msg+="工号为 " + gonghao + " 的用户信息已更新!";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ // 用户不存在,创建新用户
|
|
|
|
+ DynamicObjectType userType = EntityMetadataCache.getDataEntityType("bos_user");
|
|
|
|
+ DynamicObject userinfo = new DynamicObject(userType);
|
|
|
|
+ ORM impl = ORM.create();
|
|
|
|
+ userinfo.set("id", impl.genLongId("bos_user"));
|
|
|
|
+ userinfo.set("number", gonghao);
|
|
|
|
+ // 设置其他字段
|
|
|
|
+ userinfo.set("gender", personData.get("nckd_gender"));
|
|
|
|
+// userinfo.set("nckd_nl", personData.get("nckd_nl"));
|
|
|
|
+// userinfo.set("nckd_zzmm", personData.get("nckd_zzmm"));
|
|
|
|
+// userinfo.set("nckd_zgxl", personData.get("nckd_zgxl"));
|
|
|
|
+// userinfo.set("nckd_yggxlb", personData.get("nckd_yggxlb"));
|
|
|
|
+// userinfo.set("nckd_status", personData.get("nckd_status"));
|
|
|
|
+ //人员手机号
|
|
|
|
+ userinfo.set("phone", personData.get("nckd_sjh"));
|
|
|
|
+ // 设置其他固定字段
|
|
|
|
+ userinfo.set("startdate", new Date());
|
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
|
+ c.set(Calendar.YEAR, 2999);
|
|
|
|
+ userinfo.set("enddate", c.getTime());
|
|
|
|
+ userinfo.set("masterid", userinfo.get("id"));
|
|
|
|
+ userinfo.set("enable", 1);
|
|
|
|
+ userinfo.set("status", "C");
|
|
|
|
+ userinfo.set("password", "8HrquJnZfyOkmmHkpGLXfg==");
|
|
|
|
+ userinfo.set("isregisted", "1");
|
|
|
|
+ userinfo.set("isactived", "1");
|
|
|
|
+ userinfo.set("pswstrategy", "338333884850648064");
|
|
|
|
+ userinfo.set("psweffectivedate", new Date());
|
|
|
|
+ userinfo.set("useenddate", c.getTime());
|
|
|
|
+ // 设置姓名和拼音
|
|
|
|
+ String name = personData.getString("nckd_name");
|
|
|
|
+ userinfo.set("name", name);
|
|
|
|
+ String fullPinyin = UserOperationUtils.getFullSpellByName(name);
|
|
|
|
+ String simplePinyin = UserOperationUtils.getFirstSpellByName(name);
|
|
|
|
+ userinfo.set("fullpinyin", fullPinyin);
|
|
|
|
+ userinfo.set("simplepinyin", simplePinyin);
|
|
|
|
+ // 设置用户名
|
|
|
|
+ String username = UserOperationUtils.getUserNameByFormatedFullPinyin(
|
|
|
|
+ (long) userinfo.getPkValue(), fullPinyin, null
|
|
|
|
+ );
|
|
|
|
+ userinfo.set("username", username);
|
|
|
|
+ // 创建部门分录
|
|
|
|
+ DynamicObjectCollection bmflList = userinfo.getDynamicObjectCollection("entryentity");
|
|
|
|
+ DynamicObject bumeninfo = bmflList.addNew();
|
|
|
|
+ // 获取部门编码并在 bos_adminorg 表中查找部门信息
|
|
|
|
+ String deptCode = personData.getString("nckd_orgidcode");
|
|
|
|
+ DynamicObject orginfo = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_adminorg", new QFilter[]{new QFilter("number", "=", deptCode)}
|
|
|
|
+ );
|
|
|
|
+ if (orginfo != null) {
|
|
|
|
+ bumeninfo.set("dpt", orginfo);
|
|
|
|
+ // 获取组织的分录集合 structure 的第一条数据
|
|
|
|
+ DynamicObjectCollection structureInfoCollection = orginfo.getDynamicObjectCollection("structure");
|
|
|
|
+ if (structureInfoCollection != null && !structureInfoCollection.isEmpty()) {
|
|
|
|
+ DynamicObject structureInfo = structureInfoCollection.get(0); // 获取第一条结构信息
|
|
|
|
+ bumeninfo.set("orgstructure", structureInfo.getPkValue());
|
|
|
|
+ } else {
|
|
|
|
+ this.getView().showMessage("部门编码为 " + deptCode + " 的部门缺少组织结构信息,跳过该记录。");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String postName = personData.getString("nckd_posidname");;
|
|
|
|
+ bumeninfo.set("position", postName);
|
|
|
|
+ //所在岗位名称
|
|
|
|
+ String positionnumber = personData.getString("nckd_posidname");;
|
|
|
|
+ bumeninfo.set("post", positionnumber);
|
|
|
|
+ // 保存新用户信息
|
|
|
|
+ SaveServiceHelper.save(new DynamicObject[]{userinfo});
|
|
|
|
+ msg+="工号为 " + gonghao + " 的用户已创建!";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if("".equals(msg)){
|
|
|
|
+ this.getView().showMessage("没有需要更新或新增的人员");
|
|
|
|
+ }else{
|
|
|
|
+ this.getView().showMessage(msg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //更新组织
|
|
|
|
+ else if ("gxzz".equals(e.getOperateKey())){
|
|
|
|
+ // 获取形态信息 编码为 Orgform06 的 bos_org_pattern(部门组织)
|
|
|
|
+ DynamicObject xingtaiinfo = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_org_pattern", new QFilter[]{new QFilter("number", "=", "Orgform06")}
|
|
|
|
+ );
|
|
|
|
+ //获取形态信息,编码为 Orgform02 的bos_org_pattern(公司组织)
|
|
|
|
+ DynamicObject cpyinfo = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_org_pattern", new QFilter[]{new QFilter("number", "=", "Orgform02")}
|
|
|
|
+ );
|
|
|
|
+ // 查询 nckd_basicdata 表中需要更新的数据
|
|
|
|
+ DynamicObject[] nckdData = BusinessDataServiceHelper.load(
|
|
|
|
+ "nckd_basicdata",
|
|
|
|
+ "id,nckd_szdwcode,nckd_szdwname,nckd_yjbmcode,nckd_yjbmname,nckd_orgidcode,nckd_orgidname",
|
|
|
|
+ null
|
|
|
|
+ );
|
|
|
|
+ //行政组织
|
|
|
|
+ DynamicObject rootOrg = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_adminorg", new QFilter[]{new QFilter("number", "=", "jxyh")}
|
|
|
|
+ );
|
|
|
|
+ if (rootOrg == null) {
|
|
|
|
+ this.getView().showMessage("指定的上级组织 'jxyh' 未找到!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// DynamicObjectType adminOrgType = EntityMetadataCache.getDataEntityType("bos_adminorg");
|
|
|
|
+ IFormView orgview = ABillServiceHelper.createAddView("bos_adminorg");
|
|
|
|
+ for (DynamicObject record : nckdData) {
|
|
|
|
+ // 判断并创建或更新所在单位
|
|
|
|
+ //所在单位编码
|
|
|
|
+ String szdwbm = record.getString("nckd_szdwcode");
|
|
|
|
+ //所在单位名称
|
|
|
|
+ String szdwmc = record.getString("nckd_szdwname");
|
|
|
|
+ DynamicObject org = BusinessDataServiceHelper.loadSingle(
|
|
|
|
+ "bos_adminorg", new QFilter[]{new QFilter("number", "=", szdwbm)}
|
|
|
|
+ );
|
|
|
|
+ //没有单位则创建
|
|
|
|
+ if (org == null) {
|
|
|
|
+// org = new DynamicObject(adminOrgType);
|
|
|
|
+// IFormView orgview = ABillServiceHelper.createAddView("bos_adminorg");
|
|
|
|
+ //组织编码
|
|
|
|
+ orgview.getModel().setValue("number", szdwbm);
|
|
|
|
+ //组织名称
|
|
|
|
+ orgview.getModel().setValue("name", szdwmc);
|
|
|
|
+ //上级组织
|
|
|
|
+ orgview.getModel().setValue("parent", rootOrg);
|
|
|
|
+ //形态,设置形态为公司
|
|
|
|
+ orgview.getModel().setValue("orgpattern", cpyinfo);
|
|
|
|
+ //数据状态设置为已审核
|
|
|
|
+ orgview.getModel().setValue("status", "C");
|
|
|
|
+ //使用状态设置为可用
|
|
|
|
+ orgview.getModel().setValue("enable", "1");
|
|
|
|
+ OperationResult operationResult = ABillServiceHelper.saveOperate(orgview);
|
|
|
|
+ //保存不成功
|
|
|
|
+ if (!operationResult.isSuccess()) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ org = orgview.getModel().getDataEntity();
|
|
|
|
+ //如果存在单位则检查单位名是否一致,不一致则更新
|
|
|
|
+ }else if (!org.getString("name").equals(szdwmc))
|
|
|
|
+ {
|
|
|
|
+ //设置单位名称
|
|
|
|
+ org.set("name",szdwmc);
|
|
|
|
+ // 更新组织结构
|
|
|
|
+ DynamicObjectCollection structureInfoCollection = org.getDynamicObjectCollection("structure");
|
|
|
|
+ DynamicObject structureInfo = structureInfoCollection.get(0);
|
|
|
|
+ //设置长名称
|
|
|
|
+ structureInfo.set("fullname",rootOrg.getString("name")+"_"+szdwmc);
|
|
|
|
+ SaveServiceHelper.update(org);
|
|
|
|
+ }
|
|
|
|
+ // 判断一级机构编码 在行政组织中是否存在,不存在则新增
|
|
|
|
+ String yjjgbm = record.getString("nckd_yjbmcode");
|
|
|
|
+ String yjjgmc = record.getString("nckd_yjbmname");
|
|
|
|
+ //一级机构
|
|
|
|
+ DynamicObject yjjg = BusinessDataServiceHelper.loadSingle("bos_adminorg", new QFilter[]{new QFilter("number", "=", yjjgbm)});
|
|
|
|
+ if (yjjg == null) {
|
|
|
|
+// yjjg = new DynamicObject(adminOrgType);
|
|
|
|
+// IFormView yjjgView = ABillServiceHelper.createAddView("bos_adminorg");
|
|
|
|
+ IFormView yjjgView = orgview;
|
|
|
|
+ yjjgView.getModel().setValue("number", yjjgbm);
|
|
|
|
+ yjjgView.getModel().setValue("name", yjjgmc);
|
|
|
|
+ yjjgView.getModel().setValue("parent", org); // 父级组织为 org
|
|
|
|
+ yjjgView.getModel().setValue("orgpattern", xingtaiinfo);
|
|
|
|
+ yjjgView.getModel().setValue("status", "C");
|
|
|
|
+ yjjgView.getModel().setValue("enable", "1");
|
|
|
|
+ OperationResult yjjgOperationResult = ABillServiceHelper.saveOperate(yjjgView);
|
|
|
|
+ if (!yjjgOperationResult.isSuccess()) {
|
|
|
|
+ // Handle the failure case here
|
|
|
|
+ }
|
|
|
|
+ yjjg = yjjgView.getModel().getDataEntity();
|
|
|
|
+ } else if (!yjjg.getString("name").equals(yjjgmc)) {
|
|
|
|
+ yjjg.set("name",yjjgmc);
|
|
|
|
+ DynamicObjectCollection structureInfoCollection = yjjg.getDynamicObjectCollection("structure");
|
|
|
|
+ DynamicObject structureInfo = structureInfoCollection.get(0);
|
|
|
|
+ //设置长名称
|
|
|
|
+ structureInfo.set("fullname",rootOrg.getString("name")+"_"+szdwmc+"_"+yjjgmc);
|
|
|
|
+ SaveServiceHelper.update(yjjg);
|
|
|
|
+ }
|
|
|
|
+ // 判断所在部门编码 在行政组织中是否存在,不存在则新增
|
|
|
|
+ String szbmbm = record.getString("nckd_orgidcode");
|
|
|
|
+ String szbmmc = record.getString("nckd_orgidname");
|
|
|
|
+ //所在部门
|
|
|
|
+ DynamicObject szbm = BusinessDataServiceHelper.loadSingle("bos_adminorg", new QFilter[]{new QFilter("number", "=", szbmbm)});
|
|
|
|
+ if (szbm == null) {
|
|
|
|
+// szbm = new DynamicObject(adminOrgType);
|
|
|
|
+// IFormView szbmView = ABillServiceHelper.createAddView("bos_adminorg");
|
|
|
|
+ IFormView szbmView=orgview;
|
|
|
|
+ szbmView.getModel().setValue("number", szbmbm);
|
|
|
|
+ szbmView.getModel().setValue("name", szbmmc);
|
|
|
|
+ szbmView.getModel().setValue("parent", yjjg); // 设置父级为 yjjg
|
|
|
|
+ szbmView.getModel().setValue("orgpattern", xingtaiinfo);
|
|
|
|
+ szbmView.getModel().setValue("status", "C"); // 设置状态
|
|
|
|
+ szbmView.getModel().setValue("enable", "1"); // 设置为启用状态
|
|
|
|
+ // 保存操作
|
|
|
|
+ OperationResult szbmOperationResult = ABillServiceHelper.saveOperate(szbmView);
|
|
|
|
+ if (!szbmOperationResult.isSuccess()) {
|
|
|
|
+ // 如果保存失败,可以在这里处理错误
|
|
|
|
+ this.getView().showMessage("保存部门失败!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (szbmView.getModel() != null) {
|
|
|
|
+ szbm = szbmView.getModel().getDataEntity();
|
|
|
|
+ } else {
|
|
|
|
+ this.getView().showMessage("保存后未能获取到部门数据!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.getView().showMessage("行政组织数据已成功更新!");
|
|
|
|
+ } else if (!szbm.getString("name").equals(szbmmc)) {
|
|
|
|
+ szbm.set("name",szbmmc);
|
|
|
|
+ DynamicObjectCollection structureInfoCollection = szbm.getDynamicObjectCollection("structure");
|
|
|
|
+ DynamicObject structureInfo = structureInfoCollection.get(0);
|
|
|
|
+ //设置长名称
|
|
|
|
+ structureInfo.set("fullname",rootOrg.getString("name")+"_"+szdwmc+"_"+yjjgmc+"_"+szbmmc);
|
|
|
|
+ SaveServiceHelper.update(szbm);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //生成数据
|
|
|
|
+ else if ("scsj".equals(e.getOperateKey())) {//从文件读取数据插入基础资料
|
|
|
|
+ try {
|
|
|
|
+ generateDataFile(getFileUrl("organduserurl"));
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ throw new RuntimeException(ex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //减值数据
|
|
|
|
+ if ("jzsj".equals(e.getOperateKey()))
|
|
|
|
+ {
|
|
|
|
+ try {
|
|
|
|
+ //文件路径
|
|
|
|
+ String filelocation="D:/jzdata.dat";
|
|
|
|
+ //减值数据基础资料
|
|
|
|
+ DynamicObjectType dynamicObjectType = EntityMetadataCache.getDataEntityType("nckd_impairment");
|
|
|
|
+ //减值表字段
|
|
|
|
+ List<String> selector = Arrays.asList(
|
|
|
|
+ "nckd_dubil_id", "nckd_cust_id", "nckd_cur_cd", "nckd_dubil_amt", "nckd_asset_bal",
|
|
|
|
+ "nckd_stage_rslt", "nckd_ecl_ratio"
|
|
|
|
+ );
|
|
|
|
+ List<DynamicObject> createdataList = new ArrayList<>();
|
|
|
|
+ List<DynamicObject> updatedataList = new ArrayList<>();
|
|
|
|
+ //查出所有现有的数据
|
|
|
|
+ DynamicObject[] existingData = BusinessDataServiceHelper
|
|
|
|
+ .load(dynamicObjectType.getName(), String.join(",", selector) + ",nckd_isdelete", null);
|
|
|
|
+ Map<String, DynamicObject> existingDataMap = new HashMap<>();
|
|
|
|
+ for (DynamicObject obj : existingData) {
|
|
|
|
+ //单据号
|
|
|
|
+ existingDataMap.put(obj.getString("nckd_dubil_id"), obj);
|
|
|
|
+ }
|
|
|
|
+ Set<String> processeddubilidSet = new HashSet<>();
|
|
|
|
+ try (BufferedReader reader = new BufferedReader(new FileReader(filelocation))) {
|
|
|
|
+ String line;
|
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
|
+ //去掉换行符|$|
|
|
|
|
+ line = line.replace("|$|", "");
|
|
|
|
+ //空格符号,根据这个符号分割
|
|
|
|
+ String[] fields = line.split("\u0001");
|
|
|
|
+ //如果获取的数据行不等于预设字段的行,则跳过这行数据
|
|
|
|
+ if (fields.length != selector.size()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //获取单据号
|
|
|
|
+ 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) {
|
|
|
|
+// data.set("nckd_updatedate", new Date());
|
|
|
|
+ updatedataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //不存在这条数据则新增一条到data中
|
|
|
|
+ data = new DynamicObject(dynamicObjectType);
|
|
|
|
+ for (int i = 0; i < selector.size(); i++) {
|
|
|
|
+ data.set(selector.get(i), fields[i]);
|
|
|
|
+ }
|
|
|
|
+// Date now = new Date();
|
|
|
|
+// data.set("nckd_createdate", now);
|
|
|
|
+// data.set("nckd_updatedate", now);
|
|
|
|
+ createdataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //查找数据是否被删除
|
|
|
|
+ for (Map.Entry<String, DynamicObject> entry : existingDataMap.entrySet()) {
|
|
|
|
+ String dubil_id = entry.getKey();
|
|
|
|
+ DynamicObject data = entry.getValue();
|
|
|
|
+ if (!processeddubilidSet.contains(dubil_id)) {
|
|
|
|
+ data.set("nckd_isdelete", true);
|
|
|
|
+ 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]));
|
|
|
|
+ }
|
|
|
|
+ this.getView().showMessage("数据已成功保存!");
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ this.getView().showMessage("读取文件时发生错误:" + ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取接口配置表中组织人员的数据,返回服务器中文件路径
|
|
|
|
+ if ("jkpz".equals(e.getOperateKey())) {
|
|
|
|
+ try {
|
|
|
|
+ getFileUrl("organduserurl");
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ throw new RuntimeException(ex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //读取行名行号,存入对应基础资料中
|
|
|
|
+ if("hmhh".equals(e.getOperateKey())) {
|
|
|
|
+// String fileurl=getFileUrl("hmhhurl");
|
|
|
|
+ //行名行号表字段
|
|
|
|
+ List<String> selector = Arrays.asList(
|
|
|
|
+ "number", "name"
|
|
|
|
+ );
|
|
|
|
+ //文件路径
|
|
|
|
+ String fileurl="D:/hmhh.dat";
|
|
|
|
+ //行名行号表标识
|
|
|
|
+ String bd_bebank="bd_bebank";
|
|
|
|
+ try {
|
|
|
|
+ //基础资料
|
|
|
|
+ DynamicObjectType dynamicObjectType = EntityMetadataCache.getDataEntityType(bd_bebank);
|
|
|
|
+ //国家基础资料(中国)
|
|
|
|
+ DynamicObject country=BusinessDataServiceHelper
|
|
|
|
+ .loadSingle("bd_country","number", new QFilter[]{new QFilter("number", QCP.equals, "001")});
|
|
|
|
+ List<DynamicObject> createdataList = new ArrayList<>();
|
|
|
|
+ List<DynamicObject> updatedataList = new ArrayList<>();
|
|
|
|
+ //查出所有现有的数据
|
|
|
|
+ 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 FileReader(fileurl))) {
|
|
|
|
+ String line;
|
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
|
+ //去掉换行符|$|
|
|
|
|
+ line = line.replace("|$|", "");
|
|
|
|
+ //空格符号,根据这个符号分割
|
|
|
|
+ String[] fields = line.split("\u0001");
|
|
|
|
+ //如果获取的数据行不等于预设字段的行,则跳过这行数据
|
|
|
|
+// if (fields.length != selector.size()) {
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+ //获取单据号
|
|
|
|
+ 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中
|
|
|
|
+ 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");
|
|
|
|
+ //设置数据来源,0为手动更新,1为文件自动更新
|
|
|
|
+ data.set("nckd_datasource","1");
|
|
|
|
+ createdataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //获取自动添加的数据
|
|
|
|
+ DynamicObject[] autoData = BusinessDataServiceHelper
|
|
|
|
+ .load(dynamicObjectType.getName()
|
|
|
|
+ , String.join(",", selector)+",enable,nckd_datasource",
|
|
|
|
+ new QFilter[]{new QFilter("nckd_datasource", QCP.equals, "1")});
|
|
|
|
+ for (int i=0;i< autoData.length;i++)
|
|
|
|
+ {
|
|
|
|
+ //如果导入的数据在系统中没有则禁用
|
|
|
|
+ if (!processeddubilidSet.contains(autoData[i].getString("number"))) {
|
|
|
|
+ //设置禁用
|
|
|
|
+ autoData[i].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)) {
|
|
|
|
+// data.set("nckd_isdelete", true);
|
|
|
|
+ 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]));
|
|
|
|
+ }
|
|
|
|
+ this.getView().showMessage("数据已成功保存!");
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ this.getView().showMessage("读取文件时发生错误:" + ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|