diff --git a/src/com/engine/jclproduct/entity/bo/EmploymentRecordBo.java b/src/com/engine/jclproduct/entity/bo/EmploymentRecordBo.java index 69ccdd8..c2bf13c 100644 --- a/src/com/engine/jclproduct/entity/bo/EmploymentRecordBo.java +++ b/src/com/engine/jclproduct/entity/bo/EmploymentRecordBo.java @@ -85,7 +85,7 @@ public class EmploymentRecordBo { .orgStatus(dept.getCanceled() == 1 ? 1 : 0) .startDate(currentDate) .stopDate("9999-12-31") - .oId(dept.getSubcompanyId()) + .oId(dept.getDepartmentId()) .oType(1) .oName(dept.getDepartmentmark()) .oParentId(dept.getSupdepId()) @@ -93,6 +93,7 @@ public class EmploymentRecordBo { .changeType(dept.getCanceled() == 1 ? 2 : 0) .showorder(dept.getShoworder()) .organizationCode(dept.getDepartmentCode()) + .belongSub(dept.getSubcompanyId()) .build(); } diff --git a/src/com/engine/jclproduct/entity/po/OrganizationRecordPo.java b/src/com/engine/jclproduct/entity/po/OrganizationRecordPo.java index a01f1e0..b0f1323 100644 --- a/src/com/engine/jclproduct/entity/po/OrganizationRecordPo.java +++ b/src/com/engine/jclproduct/entity/po/OrganizationRecordPo.java @@ -17,6 +17,8 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class OrganizationRecordPo { + private Integer id; + private Integer orgStatus; private String startDate; @@ -41,7 +43,16 @@ public class OrganizationRecordPo { private String newOChargeId; + private String oldName; + + private Integer oldParentId; + + private String oldOChargeId; + private float showorder; private String organizationCode; + + //部门所属分部 + private Integer belongSub; } diff --git a/src/com/engine/jclproduct/entity/vo/TimeDepartmentVo.java b/src/com/engine/jclproduct/entity/vo/TimeDepartmentVo.java new file mode 100644 index 0000000..4c77120 --- /dev/null +++ b/src/com/engine/jclproduct/entity/vo/TimeDepartmentVo.java @@ -0,0 +1,91 @@ +package com.engine.jclproduct.entity.vo; + +import com.cloudstore.eccom.pc.table.WeaTableType; +import com.engine.jclproduct.annotation.WeaverTable; +import com.engine.jclproduct.annotation.WeaverTableColumn; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author liang.cheng + * @Date 2024/10/25 2:22 PM + * @Description: + * @Version 1.0 + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@WeaverTable(pageId = "195fd81d-95fb-4568-af05-1a564c863e21", + fields = "t.id," + + "t.orgStatus," + + "t.organizationCode," + + "t.oName," + + "t.oParentId," + + "t.oChargeId," + + "t.belongSub," + + "t.showorder", + fromSql = "FROM uf_orgChange t", + orderby = "showorder", + sortway = "asc", + primarykey = "id", + tableType = WeaTableType.NONE +) +public class TimeDepartmentVo { + + /** + * 主键 + */ + @WeaverTableColumn(column = "id",text = "序号", display = false) + private Integer id; + + /** + * 状态 + */ + @WeaverTableColumn( text = "状态", width = "10%", column = "orgStatus",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.sexOrgStatus") + private String orgStatus; + + /** + * 部门编码 + */ + @WeaverTableColumn( text = "部门编码", width = "10%", column = "organizationCode") + private String organizationCode; + + /** + * 部门名称 + */ + @WeaverTableColumn( text = "部门名称", width = "10%", column = "oName") + private String oName; + + /** + * 上级部门 + */ + @WeaverTableColumn( text = "上级部门", width = "10%", column = "oParentId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.departmentName") + private String oParentId; + + + /** + * 部门负责人 + */ + @WeaverTableColumn( text = "部门负责人", width = "10%", column = "oChargeId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.resourceName") + private String oChargeId; + + /** + * 所属分部 + */ + @WeaverTableColumn( text = "所属分部", width = "10%", column = "belongSub",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.subCompanyName") + private String belongSub; + + /** + * 显示顺序 + */ + @WeaverTableColumn( text = "显示顺序", width = "10%", column = "showorder") + private String showorder; + + + + +} diff --git a/src/com/engine/jclproduct/entity/vo/TimeSubCompanyVo.java b/src/com/engine/jclproduct/entity/vo/TimeSubCompanyVo.java index 85b6784..f91d696 100644 --- a/src/com/engine/jclproduct/entity/vo/TimeSubCompanyVo.java +++ b/src/com/engine/jclproduct/entity/vo/TimeSubCompanyVo.java @@ -26,7 +26,7 @@ import lombok.NoArgsConstructor; "t.oName," + "t.oParentId," + "t.showorder", - fromSql = "FROM uf_orgChange t where oType = 0", + fromSql = "FROM uf_orgChange t", orderby = "showorder", sortway = "asc", primarykey = "id", @@ -43,7 +43,7 @@ public class TimeSubCompanyVo { /** * 状态 */ - @WeaverTableColumn( text = "状态", width = "10%", column = "orgStatus",transmethod = "") + @WeaverTableColumn( text = "状态", width = "10%", column = "orgStatus",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.sexOrgStatus") private String orgStatus; /** diff --git a/src/com/engine/jclproduct/entity/vo/TransDepartmentVo.java b/src/com/engine/jclproduct/entity/vo/TransDepartmentVo.java new file mode 100644 index 0000000..c235c61 --- /dev/null +++ b/src/com/engine/jclproduct/entity/vo/TransDepartmentVo.java @@ -0,0 +1,104 @@ +package com.engine.jclproduct.entity.vo; + +import com.cloudstore.eccom.pc.table.WeaTableType; +import com.engine.jclproduct.annotation.WeaverTable; +import com.engine.jclproduct.annotation.WeaverTableColumn; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author liang.cheng + * @Date 2024/10/25 2:22 PM + * @Description: + * @Version 1.0 + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@WeaverTable(pageId = "4e0e4e0b-2440-4446-a9c6-e7fd44301bf7", + fields = "t.id," + + "t.orgStatus," + + "t.oName," + + "t.belongSub," + + "t.oldName," + + "t.oldOChargeId," + + "t.newName," + + "t.newParentId," + + "t.newOChargeId," + + "t.showorder", + fromSql = "FROM uf_orgChange t", + orderby = "showorder", + sortway = "asc", + primarykey = "id", + tableType = WeaTableType.NONE +) +public class TransDepartmentVo { + + /** + * 主键 + */ + @WeaverTableColumn(column = "id",text = "序号", display = false) + private Integer id; + + /** + * 状态 + */ + @WeaverTableColumn( text = "状态", width = "10%", column = "orgStatus",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.sexOrgStatus") + private String orgStatus; + + + /** + * 部门名称 + */ + @WeaverTableColumn( text = "部门名称", width = "10%", column = "oName") + private String oName; + + /** + * 所属分部 + */ + @WeaverTableColumn( text = "所属分部", width = "10%", column = "belongSub",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.subCompanyName") + private String belongSub; + + /** + * 变动前部门名称 + */ + @WeaverTableColumn( text = "变动前部门名称", width = "10%", column = "oldName") + private String oldName; + + /** + * 变动前上级部门 + */ + @WeaverTableColumn( text = "变动前上级部门", width = "10%", column = "oldParentId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.departmentName") + private String oldParentId; + + /** + * 变动前部门负责人 + */ + @WeaverTableColumn( text = "变动前部门负责人", width = "10%", column = "oldOChargeId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.resourceName") + private String oldOChargeId; + + /** + * 变动后部门名称 + */ + @WeaverTableColumn( text = "变动后部门名称", width = "10%", column = "newName") + private String newName; + + /** + * 变动后上级部门 + */ + @WeaverTableColumn( text = "变动后上级部门", width = "10%", column = "newParentId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.departmentName") + private String newParentId; + + /** + * 变动后部门负责人 + */ + @WeaverTableColumn( text = "变动后部门负责人", width = "10%", column = "newOChargeId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.resourceName") + private String newOChargeId; + + + +} diff --git a/src/com/engine/jclproduct/entity/vo/TransSubCompanyVo.java b/src/com/engine/jclproduct/entity/vo/TransSubCompanyVo.java new file mode 100644 index 0000000..448d6aa --- /dev/null +++ b/src/com/engine/jclproduct/entity/vo/TransSubCompanyVo.java @@ -0,0 +1,84 @@ +package com.engine.jclproduct.entity.vo; + +import com.cloudstore.eccom.pc.table.WeaTableType; +import com.engine.jclproduct.annotation.WeaverTable; +import com.engine.jclproduct.annotation.WeaverTableColumn; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author liang.cheng + * @Date 2024/10/25 2:22 PM + * @Description: + * @Version 1.0 + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@WeaverTable(pageId = "f3fbe166-778d-4ed7-b026-528c3262fa48", + fields = "t.id," + + "t.orgStatus," + + "t.oName," + + "t.oldName," + + "t.oldParentId," + + "t.newName," + + "t.newParentId", + fromSql = "FROM uf_orgChange t", + orderby = "showorder", + sortway = "asc", + primarykey = "id", + tableType = WeaTableType.NONE +) +public class TransSubCompanyVo { + + /** + * 主键 + */ + @WeaverTableColumn(column = "id",text = "序号", display = false) + private Integer id; + + /** + * 状态 + */ + @WeaverTableColumn( text = "状态", width = "5%", column = "orgStatus",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.sexOrgStatus") + private String orgStatus; + + + /** + * 分部名称 + */ + @WeaverTableColumn( text = "分部名称", width = "10%", column = "oName") + private String oName; + + /** + * 变动前分部名称 + */ + @WeaverTableColumn( text = "变动前分部名称", width = "10%", column = "oldName") + private String oldName; + + /** + * 变动前上级分部 + */ + @WeaverTableColumn( text = "变动前上级分部", width = "10%", column = "oldParentId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.subCompanyName") + private String oldParentId; + + + /** + * 变动后分部名称 + */ + @WeaverTableColumn( text = "变动后分部名称", width = "10%", column = "newName") + private String newName; + + /** + * 变动后上级分部 + */ + @WeaverTableColumn( text = "变动后上级分部", width = "10%", column = "newParentId",transmethod = "com.engine.jclproduct.transmethod.EmReportTransMethod.subCompanyName") + private String newParentId; + + + +} diff --git a/src/com/engine/jclproduct/service/impl/EmployeeRecordReportServiceImpl.java b/src/com/engine/jclproduct/service/impl/EmployeeRecordReportServiceImpl.java index 3764b94..3e1334d 100644 --- a/src/com/engine/jclproduct/service/impl/EmployeeRecordReportServiceImpl.java +++ b/src/com/engine/jclproduct/service/impl/EmployeeRecordReportServiceImpl.java @@ -223,27 +223,113 @@ public class EmployeeRecordReportServiceImpl extends Service implements Employee result = timeOrganization(params); break; case "1": - result = leaveResourece(params); + result = transOrganization(params); break; default: break; } - return result; } + private Map transOrganization(Map params) { + Map resultMap = new HashMap<>(8); + String type = Util.null2String(params.get("type")); + WeaResultMsg result = new WeaResultMsg(false); + if ("0".equals(type)) { + WeaverWeaTable table = new WeaverWeaTable<>(user, TransSubCompanyVo.class); + String sqlWhere = buildtransOrgSql(params); + table.setSqlwhere(sqlWhere); + result.putAll(table.makeDataResult()); + }else { + WeaverWeaTable table = new WeaverWeaTable<>(user, TransDepartmentVo.class); + String sqlWhere = buildtransOrgSql(params); + table.setSqlwhere(sqlWhere); + result.putAll(table.makeDataResult()); + } + result.success(); + resultMap.putAll(result.getResultMap()); + + return resultMap; + } + + private String buildtransOrgSql(Map params) { + String pointValue = Util.null2String(params.get("pointValue")); + String startDate = Util.null2String(params.get("startDate")); + String endDate = Util.null2String(params.get("endDate")); + String type = Util.null2String(params.get("type")); + + String sql = getLeaveSql(pointValue,startDate,endDate); + String sqlWhere = " where changeType = 1 and oType = "+type+sql; + String statusValue = Util.null2String(params.get("statusValue")); + if (StringUtils.isNotBlank(statusValue)) { + sqlWhere += " and orgStatus in ("+statusValue+")"; + } + String subCompanyId = Util.null2String(params.get("subCompanyId")); + if (StringUtils.isNotBlank(subCompanyId)) { + if("0".equals(type)) { + sqlWhere += " and oId ="+subCompanyId; + }else { + sqlWhere += " and belongSub ="+subCompanyId; + } + } + String departmentId = Util.null2String(params.get("departmentId")); + if (StringUtils.isNotBlank(departmentId) && "1".equals(type)) { + sqlWhere += " and oId ="+departmentId; + } + + return sqlWhere; + + } + private Map timeOrganization(Map params) { Map resultMap = new HashMap<>(8); - WeaverWeaTable table = new WeaverWeaTable<>(user, TimeSubCompanyVo.class); -// String sqlWhere = buildtimeResoureceSql(params); -// table.setSqlwhere(sqlWhere); + String type = Util.null2String(params.get("type")); WeaResultMsg result = new WeaResultMsg(false); - result.putAll(table.makeDataResult()); + if ("0".equals(type)) { + WeaverWeaTable table = new WeaverWeaTable<>(user, TimeSubCompanyVo.class); + String sqlWhere = buildtimeOrgSql(params); + table.setSqlwhere(sqlWhere); + result.putAll(table.makeDataResult()); + }else { + WeaverWeaTable table = new WeaverWeaTable<>(user, TimeDepartmentVo.class); + String sqlWhere = buildtimeOrgSql(params); + table.setSqlwhere(sqlWhere); + result.putAll(table.makeDataResult()); + } result.success(); resultMap.putAll(result.getResultMap()); + return resultMap; } + private String buildtimeOrgSql(Map params) { + String pointValue = Util.null2String(params.get("pointValue")); + String startDate = Util.null2String(params.get("startDate")); + String type = Util.null2String(params.get("type")); + + String sql = getPointSql(pointValue,startDate); + String sqlWhere = " where oType = "+type+" and "+sql; + + String statusValue = Util.null2String(params.get("statusValue")); + if (StringUtils.isNotBlank(statusValue)) { + sqlWhere += " and orgStatus in ("+statusValue+")"; + } + String subCompanyId = Util.null2String(params.get("subCompanyId")); + if (StringUtils.isNotBlank(subCompanyId)) { + if("0".equals(type)) { + sqlWhere += " and oId ="+subCompanyId; + }else { + sqlWhere += " and belongSub ="+subCompanyId; + } + } + String departmentId = Util.null2String(params.get("departmentId")); + if (StringUtils.isNotBlank(departmentId) && "1".equals(type)) { + sqlWhere += " and oId ="+departmentId; + } + + return sqlWhere; + } + private String buildtransferResoureceSql(Map params) { String pointValue = Util.null2String(params.get("pointValue")); String startDate = Util.null2String(params.get("startDate")); diff --git a/src/com/engine/jclproduct/service/impl/EmploymentRecordServiceImpl.java b/src/com/engine/jclproduct/service/impl/EmploymentRecordServiceImpl.java index 1459d2a..3810b7c 100644 --- a/src/com/engine/jclproduct/service/impl/EmploymentRecordServiceImpl.java +++ b/src/com/engine/jclproduct/service/impl/EmploymentRecordServiceImpl.java @@ -96,8 +96,9 @@ public class EmploymentRecordServiceImpl extends Service implements EmploymentRe //3.组织变更记录表 List organizationRecordPos = EmploymentRecordBo.buildOrganizationRecordPo(subCompany, department); - organizationRecordPos.forEach(e -> rs.executeUpdate("insert into uf_orgChange(orgStatus,startDate,stopDate,oId,oType,oName,oParentId,oChargeId,changeType,showorder,organizationCode) values(?,?,?,?,?,?,?,?,?,?,?)",e.getOrgStatus(), - e.getStartDate(),e.getStopDate(),e.getOId(),e.getOType(),e.getOName(),e.getOParentId(),e.getOChargeId(),e.getChangeType(),e.getShoworder(),e.getOrganizationCode())); + organizationRecordPos.forEach(e -> rs.executeUpdate("insert into uf_orgChange(orgStatus,startDate,stopDate,oId,oType,oName,oParentId,oChargeId,changeType,showorder,organizationCode,belongSub) values(?,?,?,?,?,?,?,?,?,?,?,?)",e.getOrgStatus(), + e.getStartDate(),e.getStopDate(),e.getOId(),e.getOType(),e.getOName(),e.getOParentId(),e.getOChargeId(),e.getChangeType(),e.getShoworder(),e.getOrganizationCode(),e.getBelongSub())); + map.put("msg3","组织变更记录表初始化完成,共"+organizationRecordPos.size()+"条数据"); diff --git a/src/com/engine/jclproduct/transmethod/EmReportTransMethod.java b/src/com/engine/jclproduct/transmethod/EmReportTransMethod.java index f9ce998..5e0d894 100644 --- a/src/com/engine/jclproduct/transmethod/EmReportTransMethod.java +++ b/src/com/engine/jclproduct/transmethod/EmReportTransMethod.java @@ -1,11 +1,16 @@ package com.engine.jclproduct.transmethod; +import cn.hutool.core.collection.CollectionUtil; import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.SubCompanyComInfo; import weaver.hrm.job.JobTitlesComInfo; import weaver.hrm.resource.ResourceComInfo; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + /** * @Author liang.cheng * @Date 2024/10/25 2:34 PM @@ -35,8 +40,14 @@ public class EmReportTransMethod { public static String resourceName(String id) { try { + List ids = Arrays.stream(id.split(",")) + .map(String::valueOf) + .collect(Collectors.toList()); ResourceComInfo resourceComInfo = new ResourceComInfo(); - return resourceComInfo.getLastname(id); + List names = ids.stream() + .map(resourceComInfo::getLastname) + .collect(Collectors.toList()); + return CollectionUtil.join(names,","); } catch (Exception e) { return ""; } @@ -80,5 +91,9 @@ public class EmReportTransMethod { } + public static String sexOrgStatus(String id) { + return "1".equals(id) ? "封存":"启用"; + } + } diff --git a/src/weaver/interfaces/jclproduct/OrganizationRecordCrob.java b/src/weaver/interfaces/jclproduct/OrganizationRecordCrob.java new file mode 100644 index 0000000..8977046 --- /dev/null +++ b/src/weaver/interfaces/jclproduct/OrganizationRecordCrob.java @@ -0,0 +1,202 @@ +package weaver.interfaces.jclproduct; + +import cn.hutool.core.collection.CollectionUtil; +import com.engine.jclproduct.entity.bo.EmploymentRecordBo; +import com.engine.jclproduct.entity.po.DepartmentPo; +import com.engine.jclproduct.entity.po.OrganizationRecordPo; +import com.engine.jclproduct.entity.po.SubCompanyPo; +import com.engine.jclproduct.utils.EmploymentUtil; +import com.weaver.general.Util; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.interfaces.schedule.BaseCronJob; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +/** + * @Author liang.cheng + * @Date 2024/11/11 10:25 AM + * @Description: 组织启用 封存 变动记录(上级变动 名称变动 负责人变动) + * @Version 1.0 + */ +public class OrganizationRecordCrob extends BaseCronJob { + + @Override + public void execute() { + + RecordSet rs = new RecordSet(); + //1.获取当前分部信息数据 + List subCompany = EmploymentUtil.getSubCompany(); + + //2.获取当前部门信息数据 + List department = EmploymentUtil.getDepartment(); + + //3.分部中间表更新集合 + List subCompanyUpdate = new ArrayList<>(); + + //4.分部中间表新增集合 + List subCompanyInsert = new ArrayList<>(); + + //5.部门中间表更新集合 + List departmentUpdate = new ArrayList<>(); + + //6.部门中间表新增集合 + List departmentInsert = new ArrayList<>(); + + //7.组织变动表新增集合 + List organizationRecordInsert = new ArrayList<>(); + + + //8.分部数据对比 + subCompany.forEach(e -> dutySubChange(e,subCompanyUpdate,subCompanyInsert,organizationRecordInsert)); + + //9.部门数据对比 + department.forEach(e-> dutyDeptChange(e,departmentUpdate,departmentInsert,organizationRecordInsert)); + + //10.数据更新(todo 是否考虑事务一致性) + subCompanyUpdate.forEach(e-> rs.executeUpdate("update uf_hrmsubcompany set subcompanyName=?,supsubcomId=?,showorder=?,canceled=?,subcompanyCode=? where subcompanyId = ?",e.getSubcompanyName(), + e.getSupsubcomId(),e.getShoworder(),e.getCanceled(),e.getSubcompanyCode(),e.getSubcompanyId())); + + subCompanyInsert.forEach(e-> rs.executeUpdate("insert into uf_hrmsubcompany(subcompanyId,subcompanyName,supsubcomId,showorder,canceled,subcompanyCode) values(?,?,?,?,?,?)",e.getSubcompanyId(),e.getSubcompanyName(), + e.getSupsubcomId(),e.getShoworder(),e.getCanceled(),e.getSubcompanyCode())); + + departmentUpdate.forEach(e-> rs.executeUpdate("update uf_hrmdepartment set departmentmark=?,subcompanyId=?,supdepId=?,showorder=?,canceled=?,departmentCode=?,bmfzr=? where departmentId = ?",e.getDepartmentmark(),e.getSubcompanyId(), + e.getSupdepId(),e.getShoworder(),e.getCanceled(),e.getDepartmentCode(),e.getBmfzr(),e.getDepartmentId())); + + departmentInsert.forEach(e -> rs.executeUpdate("insert into uf_hrmdepartment(departmentId,departmentmark,subcompanyId,supdepId,showorder,canceled,departmentCode,bmfzr) values(?,?,?,?,?,?,?,?)",e.getDepartmentId(),e.getDepartmentmark(),e.getSubcompanyId(), + e.getSupdepId(),e.getShoworder(),e.getCanceled(),e.getDepartmentCode(),e.getBmfzr())); + + organizationRecordInsert.forEach(e -> { + //1.更新上一条数据stopDate + List list = new ArrayList<>(); + rs.executeQuery("select id,startDate from uf_orgChange where OId = ? and oType = ?",e.getOId(),e.getOType()); + while (rs.next()) { + list.add(OrganizationRecordPo.builder().id(Util.getIntValue(rs.getString("id"))).startDate(Util.null2String(rs.getString("startDate"))).build()); + } + + if (CollectionUtil.isNotEmpty(list)) { + String date = DateUtil.getCurrentDate(); + OrganizationRecordPo latest = list.stream() + .max(Comparator.comparing(OrganizationRecordPo::getId)) + .orElse(null); + assert latest != null; + if (EmploymentUtil.compareDate(latest.getStartDate())) { + date = DateUtil.getYesterday(); + } + rs.executeUpdate("update uf_orgChange set stopDate = ? where id = ?",date,latest.getId()); + } + + rs.executeUpdate("insert into uf_orgChange(orgStatus,startDate,stopDate,oId,oType,oName,oParentId,oChargeId,changeType,showorder,organizationCode,newName,newParentId,newOChargeId,oldName,oldParentId,oldOChargeId,belongSub) " + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",e.getOrgStatus(), e.getStartDate(),e.getStopDate(),e.getOId(),e.getOType(),e.getOName(),e.getOParentId(),e.getOChargeId(),e.getChangeType(),e.getShoworder(),e.getOrganizationCode(),e.getNewName(), + e.getNewParentId(),e.getNewOChargeId(),e.getOldName(),e.getOldParentId(),e.getOldOChargeId(),e.getBelongSub()); + }); + + } + + /** + * 部门数据变化 + * @param departmentPo + * @param departmentUpdate + * @param departmentInsert + * @param organizationRecordInsert + */ + private void dutyDeptChange(DepartmentPo departmentPo, List departmentUpdate, List departmentInsert, List organizationRecordInsert) { + RecordSet rs = new RecordSet(); + //2.1 根据departmentId获取上一次部门中间表数据作对比 + rs.executeQuery("select departmentId,departmentmark,subcompanyId,supdepId,showorder,canceled,departmentCode,bmfzr from uf_hrmdepartment where departmentId = ?",departmentPo.getDepartmentId()); + if (rs.next()) { + DepartmentPo lastDepartmentPo = DepartmentPo.builder() + .departmentId(Util.getIntValue(rs.getString("departmentId"))) + .departmentmark(Util.null2String(rs.getString("departmentmark"))) + .subcompanyId(Util.getIntValue(rs.getString("subcompanyId"))) + .supdepId(Util.getIntValue(rs.getString("supdepId"))) + .showorder(Util.getFloatValue(rs.getString("showorder"))) + .canceled(Util.getIntValue(rs.getString("canceled"))) + .departmentCode(Util.null2String(rs.getString("departmentCode"))) + .bmfzr(Util.null2String(rs.getString("bmfzr"))) + .build(); + //1.状态比较 + if (!departmentPo.getCanceled().equals(lastDepartmentPo.getCanceled())) { + departmentUpdate.add(departmentPo); + OrganizationRecordPo organizationRecordPo = EmploymentRecordBo.setOrganizationRecordPo(null, departmentPo, 1); + organizationRecordInsert.add(organizationRecordPo); + } + //2.变动比较 + if (!departmentPo.getSupdepId().equals(lastDepartmentPo.getSupdepId()) + || !departmentPo.getDepartmentmark().equals(lastDepartmentPo.getDepartmentmark()) + || !departmentPo.getBmfzr().equals(lastDepartmentPo.getBmfzr())) { + departmentUpdate.add(departmentPo); + // 记录调动下新旧组织数据留痕 + OrganizationRecordPo organizationRecordPo = EmploymentRecordBo.setOrganizationRecordPo(null, departmentPo, 1); + organizationRecordPo.setChangeType(1); + organizationRecordPo.setOldParentId(lastDepartmentPo.getSupdepId()); + organizationRecordPo.setOldName(lastDepartmentPo.getDepartmentmark()); + organizationRecordPo.setOldOChargeId(lastDepartmentPo.getBmfzr()); + organizationRecordPo.setNewParentId(departmentPo.getSupdepId()); + organizationRecordPo.setNewName(departmentPo.getDepartmentmark()); + organizationRecordPo.setNewOChargeId(departmentPo.getBmfzr()); + organizationRecordInsert.add(organizationRecordPo); + } + }else { + departmentInsert.add(departmentPo); + OrganizationRecordPo organizationRecordPo = EmploymentRecordBo.setOrganizationRecordPo(null, departmentPo, 1); + organizationRecordInsert.add(organizationRecordPo); + } + + } + + /** + * 分部数据变化 + * @param subCompanyPo + * @param subCompanyUpdate + * @param subCompanyInsert + */ + private void dutySubChange(SubCompanyPo subCompanyPo, List subCompanyUpdate, List subCompanyInsert,List organizationRecordInsert) { + + RecordSet rs = new RecordSet(); + //2.1 根据subcompanyId获取上一次分部中间表数据作对比 + rs.executeQuery("select subcompanyId,subcompanyName,supsubcomId,showorder,canceled,subcompanyCode from uf_hrmsubcompany where subcompanyId = ?",subCompanyPo.getSubcompanyId()); + if (rs.next()) { + //数据存在作比较 + SubCompanyPo lastSubCompany = SubCompanyPo.builder() + .subcompanyId(Util.getIntValue(rs.getString("subcompanyId"))) + .subcompanyName(Util.null2String(rs.getString("subcompanyname"))) + .supsubcomId(Util.getIntValue(rs.getString("supsubcomId"))) + .showorder(Util.getFloatValue(rs.getString("showorder"))) + .canceled(Util.getIntValue(rs.getString("canceled"))) + .subcompanyCode(Util.null2String(rs.getString("subcompanycode"))) + .build(); + + // 状态比较 (启用 封存 E9物理删除无比较意义) + if (!subCompanyPo.getCanceled().equals(lastSubCompany.getCanceled())) { + subCompanyUpdate.add(subCompanyPo); + OrganizationRecordPo organizationRecordPo = EmploymentRecordBo.setOrganizationRecordPo(subCompanyPo, null, 0); + organizationRecordInsert.add(organizationRecordPo); + } + + //变动比较 + if (!subCompanyPo.getSupsubcomId().equals(lastSubCompany.getSupsubcomId()) + || !subCompanyPo.getSubcompanyName().equals(lastSubCompany.getSubcompanyName())) { + subCompanyUpdate.add(subCompanyPo); + // 记录调动下新旧组织数据留痕 + OrganizationRecordPo organizationRecordPo = EmploymentRecordBo.setOrganizationRecordPo(subCompanyPo, null, 0); + organizationRecordPo.setChangeType(1); + organizationRecordPo.setOldParentId(lastSubCompany.getSupsubcomId()); + organizationRecordPo.setOldName(lastSubCompany.getSubcompanyName()); + organizationRecordPo.setNewParentId(subCompanyPo.getSupsubcomId()); + organizationRecordPo.setNewName(subCompanyPo.getSubcompanyName()); + organizationRecordInsert.add(organizationRecordPo); + } + + }else { + //数据不存在新增 + subCompanyInsert.add(subCompanyPo); + OrganizationRecordPo organizationRecordPo = EmploymentRecordBo.setOrganizationRecordPo(subCompanyPo, null, 0); + organizationRecordInsert.add(organizationRecordPo); + } + + + } +}