Commit 87362ee5 by liudonglong

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

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