Commit 87362ee5 by liudonglong

海外固资同步补充 Model 字段,并在变更日志记录成本中心编码与创建人部门变动后的值。

1 parent 76c5c8b0
......@@ -23,6 +23,12 @@ sql/alter_add_changelog_cost_center.sql
sql/create_overseas_tables.sql
```
若库中已有海外固资表,不要重复执行建表(会 DROP),改为执行增量脚本:
```bash
sql/alter_overseas_add_model_and_changelog_dept.sql
```
## 2. 修改配置
编辑 **`WEB-INF/config.txt`**(项目模板见根目录 `config.txt`):
......
-- ============================================================
-- 已有库增量:海外固资
-- 1. EAM_海外固资同步数据表 增加接口新字段 Model
-- 2. EAM_海外固资同步变更日志表 增加 创建人部门(costCenterCode/createddeptid 变动时落库)
-- ============================================================
ALTER TABLE `EAM_海外固资同步数据表`
ADD COLUMN `Model` VARCHAR(255) DEFAULT NULL COMMENT 'Model 型号' AFTER `localOffice`;
ALTER TABLE `EAM_海外固资同步变更日志表`
ADD COLUMN `创建人部门` VARCHAR(128) DEFAULT NULL COMMENT '创建人部门变动后的值(未变则为空)' AFTER `成本中心描述`,
ADD KEY `idx_created_dept` (`创建人部门`);
......@@ -42,6 +42,7 @@ CREATE TABLE `EAM_海外固资同步数据表` (
`lineManagerDept` VARCHAR(255) DEFAULT NULL COMMENT 'Line Manager Dept.',
`lineManagerEmployId` VARCHAR(64) DEFAULT NULL COMMENT 'Line Manager Employee ID',
`localOffice` VARCHAR(255) DEFAULT NULL COMMENT 'Local Office',
`Model` VARCHAR(255) DEFAULT NULL COMMENT 'Model 型号',
`modifiedtime` VARCHAR(64) DEFAULT NULL COMMENT '修改时间',
`modifier` VARCHAR(64) DEFAULT NULL COMMENT '修改人',
`name` VARCHAR(255) DEFAULT NULL COMMENT '数据标题',
......@@ -78,10 +79,12 @@ CREATE TABLE `EAM_海外固资同步变更日志表` (
`变动说明` TEXT NOT NULL COMMENT '字段变更明细',
`成本中心编码` VARCHAR(64) DEFAULT NULL COMMENT '成本中心编码变动后的值(未变则为空)',
`成本中心描述` VARCHAR(255) DEFAULT NULL COMMENT '成本中心描述变动后的值(未变则为空)',
`创建人部门` VARCHAR(128) DEFAULT NULL COMMENT '创建人部门变动后的值(未变则为空)',
`日期` DATE NOT NULL COMMENT '变更记录日期',
`备注` VARCHAR(500) DEFAULT NULL COMMENT '备注(如同步批次号、traceId)',
PRIMARY KEY (`ID`),
KEY `idx_assetNo` (`固资编码`),
KEY `idx_date` (`日期`),
KEY `idx_cost_center_code` (`成本中心编码`)
KEY `idx_cost_center_code` (`成本中心编码`),
KEY `idx_created_dept` (`创建人部门`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='海外固资同步变更日志表';
......@@ -26,10 +26,10 @@ public final class OverseasFixedAssetFields {
"createdtime", "creater", "currency", "deviceBrand", "deviceCountry", "deviceType", "deviceUser",
"deviceUserName", "devicesStatus", "excludingTaxAmount", "hasBeenRequisition", "isDomesticFa",
"isThereAnInventory", "lineManager", "lineManagerDept", "lineManagerEmployId", "localOffice",
"modifiedtime", "modifier", "name", "owner", "ownerdeptid", "ownerdeptquerycode", "purchaseDate",
"purchasePrice", "sequenceno", "sequencestatus", "serialNo", "taxAmount", "totalPaymentAmount",
"userCountry", "userEmployeeNo", "userMailingAddress", "userPhoneNo", "version", "warehousingDate",
"whetherTriggerRequisition", "workflowinstanceid"
"Model", "modifiedtime", "modifier", "name", "owner", "ownerdeptid", "ownerdeptquerycode",
"purchaseDate", "purchasePrice", "sequenceno", "sequencestatus", "serialNo", "taxAmount",
"totalPaymentAmount", "userCountry", "userEmployeeNo", "userMailingAddress", "userPhoneNo",
"version", "warehousingDate", "whetherTriggerRequisition", "workflowinstanceid"
));
public static final Set<String> DATETIME_FIELDS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
......@@ -79,6 +79,7 @@ public final class OverseasFixedAssetFields {
mapping.put("lineManagerDept", "lineManagerDept");
mapping.put("lineManagerEmployId", "lineManagerEmployId");
mapping.put("localOffice", "localOffice");
mapping.put("Model", "Model");
mapping.put("modifiedtime", "modifiedtime");
mapping.put("modifier", "modifier");
mapping.put("name", "name");
......@@ -132,6 +133,7 @@ public final class OverseasFixedAssetFields {
labels.put("lineManagerDept", "直属经理部门");
labels.put("lineManagerEmployId", "直属经理工号");
labels.put("localOffice", "本地办公室");
labels.put("Model", "型号");
labels.put("modifiedtime", "修改时间");
labels.put("modifier", "修改人");
labels.put("name", "数据标题");
......
......@@ -179,26 +179,34 @@ public class OverseasFixedAssetDao {
public void insertChangeLog(Connection conn, String assetNo, String changeDesc, String remark)
throws SQLException {
insertChangeLog(conn, assetNo, changeDesc, remark, null, null);
insertChangeLog(conn, assetNo, changeDesc, remark, null, null, null);
}
public void insertChangeLog(Connection conn, String assetNo, String changeDesc, String remark,
String costCenterCode, String costCenterDesc) throws SQLException {
insertChangeLog(conn, assetNo, changeDesc, remark, costCenterCode, costCenterDesc, null);
}
public void insertChangeLog(Connection conn, String assetNo, String changeDesc, String remark,
String costCenterCode, String costCenterDesc, String createdDeptId) throws SQLException {
String renderedSql = "INSERT INTO `" + LOG_TABLE
+ "` (`固资编码`, `变动说明`, `成本中心编码`, `成本中心描述`, `日期`, `备注`) VALUES ("
+ "` (`固资编码`, `变动说明`, `成本中心编码`, `成本中心描述`, `创建人部门`, `日期`, `备注`) VALUES ("
+ quote(assetNo) + ", " + quote(changeDesc) + ", " + quote(costCenterCode) + ", "
+ quote(costCenterDesc) + ", CURDATE(), " + quote(remark) + ")";
+ quote(costCenterDesc) + ", " + quote(createdDeptId) + ", CURDATE(), "
+ quote(remark) + ")";
SyncFileLogger.info("海外固资新增变更日志表 SQL [assetNo=" + assetNo + "]:\n" + renderedSql);
String sql = "INSERT INTO `" + LOG_TABLE
+ "` (`固资编码`, `变动说明`, `成本中心编码`, `成本中心描述`, `日期`, `备注`) VALUES (?, ?, ?, ?, CURDATE(), ?)";
+ "` (`固资编码`, `变动说明`, `成本中心编码`, `成本中心描述`, `创建人部门`, `日期`, `备注`)"
+ " VALUES (?, ?, ?, ?, ?, CURDATE(), ?)";
PreparedStatement ps = conn.prepareStatement(sql);
try {
ps.setString(1, assetNo);
ps.setString(2, changeDesc);
setNullableString(ps, 3, costCenterCode);
setNullableString(ps, 4, costCenterDesc);
ps.setString(5, remark);
setNullableString(ps, 5, createdDeptId);
ps.setString(6, remark);
int rows = ps.executeUpdate();
if (rows <= 0) {
throw new SQLException("海外固资新增变更日志表失败,影响行数为 0, assetNo=" + assetNo);
......
......@@ -8,7 +8,6 @@ import com.solax.sync.client.OverseasFixedAssetApiClient;
import com.solax.sync.constant.OverseasFixedAssetFields;
import com.solax.sync.dao.OverseasFixedAssetDao;
import com.solax.sync.model.SyncResult;
import com.solax.sync.util.ChangeComparator;
import com.solax.sync.util.DbUtil;
import com.solax.sync.util.JsonRecordUtil;
import com.solax.sync.util.OverseasChangeComparator;
......@@ -151,8 +150,8 @@ public class OverseasFixedAssetSyncService {
}
String changeDesc = OverseasChangeComparator.buildChangeDescription(oldRow, newRow);
ChangeComparator.CostCenterSnapshot costCenter =
OverseasChangeComparator.extractChangedCostCenter(oldRow, newRow);
OverseasChangeComparator.FieldChangeSnapshot fieldChanges =
OverseasChangeComparator.extractChangedFields(oldRow, newRow);
if (wasDeleted) {
changeDesc = "【恢复】接口重新返回,取消删除标记\n" + changeDesc;
result.incrementRestored();
......@@ -162,7 +161,8 @@ public class OverseasFixedAssetSyncService {
}
dao.insertChangeLog(conn, assetNo, changeDesc, remark,
costCenter.getCostCenterCode(), costCenter.getCostCenterDesc());
fieldChanges.getCostCenterCode(), fieldChanges.getCostCenterDesc(),
fieldChanges.getCreatedDeptId());
dao.update(conn, result.getBatchNo(), newRow);
result.incrementUpdated();
}
......
......@@ -10,6 +10,7 @@ public final class OverseasChangeComparator {
public static final String COL_COST_CENTER_CODE = "costCenterCode";
public static final String COL_COST_CENTER_DESC = "costCenter";
public static final String COL_CREATED_DEPT_ID = "createddeptid";
private OverseasChangeComparator() {
}
......@@ -46,17 +47,25 @@ public final class OverseasChangeComparator {
return !buildChangeDescription(oldRow, newRow).isEmpty();
}
public static ChangeComparator.CostCenterSnapshot extractChangedCostCenter(
Map<String, String> oldRow, Map<String, String> newRow) {
/**
* 提取变更日志表需单独落库的字段:成本中心编码/描述、创建人部门。
* 未变动则对应字段为 null。
*/
public static FieldChangeSnapshot extractChangedFields(Map<String, String> oldRow,
Map<String, String> newRow) {
String code = null;
String desc = null;
String createdDeptId = null;
if (fieldChanged(oldRow, newRow, COL_COST_CENTER_CODE)) {
code = JsonRecordUtil.normalize(newRow.get(COL_COST_CENTER_CODE));
}
if (fieldChanged(oldRow, newRow, COL_COST_CENTER_DESC)) {
desc = JsonRecordUtil.normalize(newRow.get(COL_COST_CENTER_DESC));
}
return new ChangeComparator.CostCenterSnapshot(code, desc);
if (fieldChanged(oldRow, newRow, COL_CREATED_DEPT_ID)) {
createdDeptId = JsonRecordUtil.normalize(newRow.get(COL_CREATED_DEPT_ID));
}
return new FieldChangeSnapshot(code, desc, createdDeptId);
}
private static boolean fieldChanged(Map<String, String> oldRow, Map<String, String> newRow,
......@@ -70,4 +79,28 @@ public final class OverseasChangeComparator {
private static String display(String value) {
return value.isEmpty() ? "(空)" : value;
}
public static final class FieldChangeSnapshot {
private final String costCenterCode;
private final String costCenterDesc;
private final String createdDeptId;
public FieldChangeSnapshot(String costCenterCode, String costCenterDesc, String createdDeptId) {
this.costCenterCode = costCenterCode;
this.costCenterDesc = costCenterDesc;
this.createdDeptId = createdDeptId;
}
public String getCostCenterCode() {
return costCenterCode;
}
public String getCostCenterDesc() {
return costCenterDesc;
}
public String getCreatedDeptId() {
return createdDeptId;
}
}
}
## 查询海外固资所有
## 查询海外固资所有
......@@ -78,6 +78,7 @@
| &emsp;&emsp;lineManagerDept | Line Manager Dept. | string | |
| &emsp;&emsp;lineManagerEmployId | Line Manager Employee ID | string | |
| &emsp;&emsp;localOffice | Local Office | string | |
| &emsp;&emsp;Model | Model 型号 | string | |
| &emsp;&emsp;modifiedtime | 修改时间 | string(date-time) | |
| &emsp;&emsp;modifier | 修改人 | string | |
| &emsp;&emsp;name | 数据标题 | string | |
......@@ -138,6 +139,7 @@
"lineManagerDept": "",
"lineManagerEmployId": "",
"localOffice": "",
"Model": "",
"modifiedtime": "",
"modifier": "",
"name": "",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!