人员回溯功能开发
parent
ec7ff05616
commit
0d9e03507b
@ -0,0 +1,12 @@
|
||||
package com.api.organization.web;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/28
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Path("/bs/hrmorganization/danikorresource")
|
||||
public class DanikorResourceBackController extends com.engine.organization.web.DanikorResourceBackController {
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.engine.organization.entity.column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/16
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class TableColumnPO {
|
||||
private String tableName;
|
||||
private String columnName;
|
||||
private String columnType;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TableColumnPO that = (TableColumnPO) o;
|
||||
return Objects.equals(columnName, that.columnName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(columnName);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.engine.organization.entity.danikor.vo;
|
||||
|
||||
import com.engine.organization.annotation.OrganizationTable;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/17
|
||||
* @version: 1.0
|
||||
*/
|
||||
@OrganizationTable(pageId = "e1b72792-9f71-11ed-aa42-00e04c680716",
|
||||
orderby = " t.dsporder ",
|
||||
sortway = " asc",
|
||||
primarykey = "id"
|
||||
)
|
||||
public class ResourceBackVO {
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.engine.organization.job;
|
||||
|
||||
import com.engine.organization.entity.column.TableColumnPO;
|
||||
import com.engine.organization.mapper.danikor.DanikorResourceMapper;
|
||||
import com.engine.organization.mapper.extend.ExtendInfoMapper;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.interfaces.schedule.BaseCronJob;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 同步用户数据定时服务
|
||||
*
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/16
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class DanikorSyncUserJob extends BaseCronJob {
|
||||
|
||||
// select * into hrmresource_back FROM hrmresource where 1=2;
|
||||
// alter table hrmresource_back add sync_date date null;
|
||||
// alter table hrmresource_back add default getdate() for sync_date;
|
||||
// alter table hrmresource_back add sync_id int identity(1,1);
|
||||
private static final String RESOURCE_MAIN = "hrmresource";
|
||||
private static final String RESOURCE_BACK = "hrmresource_back";
|
||||
|
||||
// CREATE TABLE cus_fielddata_back (
|
||||
// seqorder int NOT NULL,
|
||||
// [scope] varchar(1000) NULL,
|
||||
// scopeid int NOT NULL,
|
||||
// id int NOT NULL,
|
||||
// sync_date date null,
|
||||
// sync_id int identity(1,1)
|
||||
// );
|
||||
// alter table cus_fielddata_back add default getdate() for sync_date;
|
||||
private static final String CUS_MAIN = "cus_fielddata";
|
||||
private static final String CUS_BACK = "cus_fielddata_back";
|
||||
|
||||
// select * into hrmsubcompany_back FROM hrmsubcompany where 1=2;
|
||||
// alter table hrmsubcompany_back add sync_date date null;
|
||||
// alter table hrmsubcompany_back add default getdate() for sync_date;
|
||||
// alter table hrmsubcompany_back add sync_id int identity(1,1);
|
||||
private static final String COMPANY_MAIN = "hrmsubcompany";
|
||||
private static final String COMPANY_BACK = "hrmsubcompany_back";
|
||||
|
||||
private static final String COMPANY_DEFINED_MAIN = "hrmsubcompanydefined";
|
||||
private static final String COMPANY_DEFINED_BACK = "hrmsubcompanydefined_back";
|
||||
|
||||
private static final String DEPARTMENT_MAIN = "hrmdepartment";
|
||||
private static final String DEPARTMENT_BACK = "hrmdepartment_back";
|
||||
|
||||
private static final String DEPARTMENT_DEFINED_MAIN = "hrmdepartmentdefined";
|
||||
private static final String DEPARTMENT_DEFINED_BACK = "hrmdepartmentdefined_back";
|
||||
|
||||
private DanikorResourceMapper getDanikorResourceMapper() {
|
||||
return MapperProxyFactory.getProxy(DanikorResourceMapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
// 比较两张表的表结构
|
||||
List<TableColumnPO> cusFieldDataList = getDanikorResourceMapper().getColumnInfoByTableName(CUS_MAIN);
|
||||
List<TableColumnPO> cusFieldDataBackList = getDanikorResourceMapper().getColumnInfoByTableName(CUS_BACK);
|
||||
List<TableColumnPO> resourceDataList = getDanikorResourceMapper().getColumnInfoByTableName(RESOURCE_MAIN);
|
||||
for (TableColumnPO tableColumnPO : cusFieldDataList) {
|
||||
if (!cusFieldDataBackList.contains(tableColumnPO)) {
|
||||
// 为回溯表创建字段
|
||||
MapperProxyFactory.getProxy(ExtendInfoMapper.class).addTableColumn(CUS_BACK, tableColumnPO.getColumnName(), tableColumnPO.getColumnType());
|
||||
}
|
||||
}
|
||||
// 同步表数据
|
||||
RecordSet rs = new RecordSet();
|
||||
String resourceColumns = resourceDataList.stream().map(TableColumnPO::getColumnName).collect(Collectors.joining(","));
|
||||
String customColumns = cusFieldDataList.stream().map(TableColumnPO::getColumnName).collect(Collectors.joining(","));
|
||||
// 同步主表数据
|
||||
String sql = "insert into " + RESOURCE_BACK + "(" + resourceColumns + ") select " + resourceColumns + " from " + RESOURCE_MAIN;
|
||||
rs.execute(sql);
|
||||
// 同步明细表数据
|
||||
sql = "insert into " + CUS_BACK + "(" + customColumns + ") select " + customColumns + " from " + CUS_MAIN;
|
||||
rs.execute(sql);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.engine.organization.mapper.danikor;
|
||||
|
||||
import com.engine.organization.entity.column.TableColumnPO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/16
|
||||
* @version: 1.0
|
||||
*/
|
||||
public interface DanikorResourceMapper {
|
||||
/**
|
||||
* 查询表结构信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<TableColumnPO> getColumnInfoByTableName(@Param("tableName") String tableName);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.engine.organization.mapper.danikor.DanikorResourceMapper">
|
||||
|
||||
|
||||
<select id="getColumnInfoByTableName" resultType="com.engine.organization.entity.column.TableColumnPO">
|
||||
select a.name as tableName, b.name as columnName, c.fielddbtype as columnType
|
||||
from sysobjects a
|
||||
inner join syscolumns b on a.id = b.id and a.xtype = 'U'
|
||||
left join cus_formdict c on b.name = c.fieldname
|
||||
where a.name = #{tableName}
|
||||
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,26 @@
|
||||
package com.engine.organization.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/17
|
||||
* @version: 1.0
|
||||
*/
|
||||
public interface DanikorResourceBackService {
|
||||
|
||||
/**
|
||||
* 人员回溯列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> listPage(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 获取搜索条件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getSearchCondition();
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.engine.organization.service.impl;
|
||||
|
||||
import com.api.browser.bean.SearchConditionGroup;
|
||||
import com.api.browser.bean.SearchConditionItem;
|
||||
import com.cloudstore.eccom.constant.WeaBoolAttr;
|
||||
import com.cloudstore.eccom.pc.table.WeaTableColumn;
|
||||
import com.cloudstore.eccom.pc.table.WeaTableOperates;
|
||||
import com.cloudstore.eccom.result.WeaResultMsg;
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.component.OrganizationWeaTable;
|
||||
import com.engine.organization.entity.column.TableColumnPO;
|
||||
import com.engine.organization.entity.danikor.vo.ResourceBackVO;
|
||||
import com.engine.organization.mapper.danikor.DanikorResourceMapper;
|
||||
import com.engine.organization.mapper.resource.HrmResourceMapper;
|
||||
import com.engine.organization.service.DanikorResourceBackService;
|
||||
import com.engine.organization.util.OrganizationFormItemUtil;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.general.Util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/17
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class DanikorResourceBackServiceImpl extends Service implements DanikorResourceBackService {
|
||||
private HrmResourceMapper getHrmResourceMapper() {
|
||||
return MapperProxyFactory.getProxy(HrmResourceMapper.class);
|
||||
}
|
||||
|
||||
private DanikorResourceMapper getDanikorResourceMapper() {
|
||||
return MapperProxyFactory.getProxy(DanikorResourceMapper.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> listPage(Map<String, Object> params) {
|
||||
HrmResourceServiceImpl resourceService = ServiceUtil.getService(HrmResourceServiceImpl.class, user);
|
||||
OrganizationWeaTable<ResourceBackVO> table = new OrganizationWeaTable<>(user, ResourceBackVO.class);
|
||||
String syncDate = Util.null2String(params.get("syncDate"));
|
||||
String sqlForm = "from hrmresource t left join cus_fielddata t0 on t.id = t0.id and t0.scopeid ='-1' left join cus_fielddata t1 on t.id = t1.id and t1.scopeid ='1' left join cus_fielddata t2 on t.id = t2.id and t2.scopeid ='3' left join hrmjobtitles t3 on t.jobtitle=t3.id left join hrmjobactivities t4 on t3.jobactivityid=t4.id left join hrmjobgroups t5 on t4.jobgroupid=t5.id ";
|
||||
String sqlWhere = "where 1 = 1 ";
|
||||
String cusTableName = "cus_fielddata";
|
||||
if (StringUtils.isNotBlank(syncDate)) {
|
||||
sqlWhere += " and t.sync_date = '" + syncDate + "'";
|
||||
sqlForm = "from hrmresource_back t left join cus_fielddata_back t0 on t.id = t0.id and t0.scopeid = '-1' and t.sync_date = t0.sync_date left join cus_fielddata_back t1 on t.id = t1.id and t1.scopeid = '1' and t.sync_date = t1.sync_date left join cus_fielddata_back t2 on t.id = t2.id and t2.scopeid = '3' and t.sync_date = t2.sync_date left join hrmjobtitles t3 on t.jobtitle = t3.id left join hrmjobactivities t4 on t3.jobactivityid = t4.id left join hrmjobgroups t5 on t4.jobgroupid = t5.id ";
|
||||
cusTableName = "cus_fielddata_back";
|
||||
}
|
||||
table.setSqlform(sqlForm);
|
||||
table.setSqlwhere(sqlWhere);
|
||||
table.setOperates(new WeaTableOperates());
|
||||
List<WeaTableColumn> weaTableColumnList = new ArrayList<>();
|
||||
List<String> fields = new ArrayList<>();
|
||||
List<SearchConditionGroup> allConditions = resourceService.getAllConditions();
|
||||
|
||||
//初次使用,无模板初始值
|
||||
String columns = "-1_hrm_lastname,-1_hrm_departmentid,-1_hrm_subcompanyid1,-1_hrm_jobtitle,-1_hrm_mobile,-1_hrm_telephone,-1_hrm_managerid,-1_hrm_dsporder";
|
||||
|
||||
List<String> cusFieldNames = getDanikorResourceMapper().getColumnInfoByTableName(cusTableName).stream().map(TableColumnPO::getColumnName).collect(Collectors.toList());
|
||||
List<String> columnList = Arrays.asList(columns.split(","));
|
||||
BigDecimal decimal = new BigDecimal(100 / columnList.size());
|
||||
for (SearchConditionGroup allCondition : allConditions) {
|
||||
List<SearchConditionItem> items = allCondition.getItems();
|
||||
for (SearchConditionItem item : items) {
|
||||
String columnName = item.getDomkey()[0];
|
||||
String scopeId = columnName.split("_")[0];
|
||||
String fieldName = columnName.substring(columnName.lastIndexOf("_") + 1);
|
||||
if (columnName.contains("_cus_") && !cusFieldNames.contains(fieldName)) {
|
||||
continue;
|
||||
}
|
||||
fields.add(resourceService.buildTableSql(columnName) + " as " + resourceService.buildTableSql(columnName).replace(".", "_"));
|
||||
|
||||
WeaTableColumn weaTableColumn = new WeaTableColumn();
|
||||
weaTableColumn.setText(getHrmResourceMapper().queryLabelName(fieldName, scopeId));
|
||||
weaTableColumn.setColumn(resourceService.buildTableSql(columnName).replace(".", "_"));
|
||||
|
||||
weaTableColumn.setDisplay(columnList.contains(columnName) ? WeaBoolAttr.TRUE : WeaBoolAttr.FALSE);
|
||||
if ("-1_hrm_subcompanyid1".equals(columnName)) {
|
||||
weaTableColumn.setTransmethod("com.engine.organization.transmethod.HrmResourceTransMethod.getCompanyName");
|
||||
} else {
|
||||
weaTableColumn.setTransmethod("com.engine.organization.transmethod.HrmResourceTransMethod.getFieldTrueValue");
|
||||
}
|
||||
weaTableColumn.setOtherpara(columnName);
|
||||
weaTableColumn.setWidth(decimal.setScale(2, RoundingMode.HALF_UP).doubleValue() + "%");
|
||||
weaTableColumnList.add(weaTableColumn);
|
||||
}
|
||||
}
|
||||
|
||||
// 增加id字段,跳转人员卡片
|
||||
WeaTableColumn weaTableColumn = new WeaTableColumn();
|
||||
weaTableColumn.setColumn("id");
|
||||
weaTableColumn.setDisplay(WeaBoolAttr.FALSE);
|
||||
|
||||
weaTableColumnList.add(weaTableColumn);
|
||||
fields.add("t.id");
|
||||
table.setBackfields(StringUtils.join(fields, ","));
|
||||
table.setColumns(weaTableColumnList);
|
||||
WeaResultMsg result = new WeaResultMsg(false);
|
||||
result.putAll(table.makeDataResult());
|
||||
result.success();
|
||||
return new HashMap<>(result.getResultMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getSearchCondition() {
|
||||
Map<String, Object> apiDatas = new HashMap<>();
|
||||
List<SearchConditionGroup> addGroups = new ArrayList<>();
|
||||
List<SearchConditionItem> conditionItems = new ArrayList<>();
|
||||
SearchConditionItem syncDate = OrganizationFormItemUtil.datePickerItem(user, 2, 16, false, 2, "查询时间", "syncDate");
|
||||
conditionItems.add(syncDate);
|
||||
addGroups.add(new SearchConditionGroup("高级搜索条件", true, conditionItems));
|
||||
apiDatas.put("conditions", addGroups);
|
||||
return apiDatas;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.engine.organization.web;
|
||||
|
||||
import com.engine.common.util.ParamUtil;
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.organization.util.response.ReturnResult;
|
||||
import com.engine.organization.wrapper.DanikorResourceBackWrapper;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/28
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class DanikorResourceBackController {
|
||||
|
||||
public DanikorResourceBackWrapper getDanikorResourceBackWrapper(User user) {
|
||||
return ServiceUtil.getService(DanikorResourceBackWrapper.class, user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取list列表
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Path("/listPage")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult listPage(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
Map<String, Object> map = ParamUtil.request2Map(request);
|
||||
return ReturnResult.successed(getDanikorResourceBackWrapper(user).listPage(map));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getSearchCondition")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult getSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
return ReturnResult.successed(getDanikorResourceBackWrapper(user).getSearchCondition());
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.engine.organization.wrapper;
|
||||
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.organization.service.DanikorResourceBackService;
|
||||
import com.engine.organization.service.impl.DanikorResourceBackServiceImpl;
|
||||
import com.engine.organization.util.OrganizationWrapper;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2023/01/28
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class DanikorResourceBackWrapper extends OrganizationWrapper {
|
||||
|
||||
private DanikorResourceBackService getDanikorResourceBackService(User user) {
|
||||
return ServiceUtil.getService(DanikorResourceBackServiceImpl.class, user);
|
||||
}
|
||||
|
||||
public Map<String, Object> listPage(Map<String, Object> params) {
|
||||
return getDanikorResourceBackService(user).listPage(params);
|
||||
}
|
||||
|
||||
public Map<String, Object> getSearchCondition(){
|
||||
return getDanikorResourceBackService(user).getSearchCondition();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue