代码提交、功能重写
This commit is contained in:
parent
0d9e03507b
commit
1cf8d42e75
|
|
@ -19,38 +19,60 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
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);
|
||||
//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;
|
||||
//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);
|
||||
//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 drop column id;
|
||||
//alter table hrmsubcompany_back add id int not null;
|
||||
//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";
|
||||
|
||||
//CREATE TABLE hrmsubcompanydefined_back (
|
||||
//id int NOT NULL,
|
||||
//subcomid int NOT NULL,
|
||||
//sync_date date null,
|
||||
//sync_id int identity(1,1)
|
||||
//);
|
||||
//alter table hrmsubcompanydefined_back add default getdate() for sync_date;
|
||||
private static final String COMPANY_DEFINED_MAIN = "hrmsubcompanydefined";
|
||||
private static final String COMPANY_DEFINED_BACK = "hrmsubcompanydefined_back";
|
||||
|
||||
//select * into hrmdepartment_back FROM hrmdepartment where 1=2;
|
||||
//alter table hrmdepartment_back add sync_date date null;
|
||||
//alter table hrmdepartment_back add default getdate() for sync_date;
|
||||
//alter table hrmdepartment_back drop column id;
|
||||
//alter table hrmdepartment_back add id int not null;
|
||||
//alter table hrmdepartment_back add sync_id int identity(1,1);
|
||||
private static final String DEPARTMENT_MAIN = "hrmdepartment";
|
||||
private static final String DEPARTMENT_BACK = "hrmdepartment_back";
|
||||
|
||||
//CREATE TABLE hrmdepartmentdefined_back (
|
||||
//id int NOT NULL,
|
||||
//deptid int NOT NULL,
|
||||
//sync_date date null,
|
||||
//sync_id int identity(1,1)
|
||||
//);
|
||||
//alter table hrmdepartmentdefined_back add default getdate() for sync_date;
|
||||
private static final String DEPARTMENT_DEFINED_MAIN = "hrmdepartmentdefined";
|
||||
private static final String DEPARTMENT_DEFINED_BACK = "hrmdepartmentdefined_back";
|
||||
|
||||
|
|
@ -60,26 +82,44 @@ public class DanikorSyncUserJob extends BaseCronJob {
|
|||
|
||||
@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)) {
|
||||
// 比较两张表的表结构,同步表结构、表数据
|
||||
syncTableFields(RESOURCE_MAIN, RESOURCE_BACK);
|
||||
syncTableFields(CUS_MAIN, CUS_BACK);
|
||||
|
||||
syncTableFields(COMPANY_MAIN, COMPANY_BACK);
|
||||
syncTableFields(COMPANY_DEFINED_MAIN, COMPANY_DEFINED_BACK);
|
||||
|
||||
syncTableFields(DEPARTMENT_MAIN, DEPARTMENT_BACK);
|
||||
syncTableFields(DEPARTMENT_DEFINED_MAIN, DEPARTMENT_DEFINED_BACK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步表字段
|
||||
*
|
||||
* @param mainTableName
|
||||
* @param backTableName
|
||||
*/
|
||||
private void syncTableFields(String mainTableName, String backTableName) {
|
||||
List<TableColumnPO> mainTableFields;
|
||||
List<TableColumnPO> backTableFields;
|
||||
if (CUS_MAIN.equals(mainTableName)) {
|
||||
mainTableFields = getDanikorResourceMapper().getCusColumnByTableName(mainTableName);
|
||||
backTableFields = getDanikorResourceMapper().getCusColumnByTableName(backTableName);
|
||||
} else {
|
||||
mainTableFields = getDanikorResourceMapper().getHrmColumnByTableName(mainTableName);
|
||||
backTableFields = getDanikorResourceMapper().getHrmColumnByTableName(backTableName);
|
||||
}
|
||||
for (TableColumnPO tableColumnPO : mainTableFields) {
|
||||
if (!backTableFields.contains(tableColumnPO)) {
|
||||
// 为回溯表创建字段
|
||||
MapperProxyFactory.getProxy(ExtendInfoMapper.class).addTableColumn(CUS_BACK, tableColumnPO.getColumnName(), tableColumnPO.getColumnType());
|
||||
MapperProxyFactory.getProxy(ExtendInfoMapper.class).addTableColumn(backTableName, 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 mainTableColumns = mainTableFields.stream().map(TableColumnPO::getColumnName).collect(Collectors.joining(","));
|
||||
// 同步主表数据
|
||||
String sql = "insert into " + RESOURCE_BACK + "(" + resourceColumns + ") select " + resourceColumns + " from " + RESOURCE_MAIN;
|
||||
String sql = "insert into " + backTableName + "(" + mainTableColumns + ") select " + mainTableColumns + " from " + mainTableName;
|
||||
rs.execute(sql);
|
||||
// 同步明细表数据
|
||||
sql = "insert into " + CUS_BACK + "(" + customColumns + ") select " + customColumns + " from " + CUS_MAIN;
|
||||
rs.execute(sql);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,20 @@ import java.util.List;
|
|||
*/
|
||||
public interface DanikorResourceMapper {
|
||||
/**
|
||||
* 查询表结构信息
|
||||
* 查询人员自定义表结构信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<TableColumnPO> getColumnInfoByTableName(@Param("tableName") String tableName);
|
||||
List<TableColumnPO> getCusColumnByTableName(@Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
* 查询组织架构表结构信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<TableColumnPO> getHrmColumnByTableName(@Param("tableName") String tableName);
|
||||
|
||||
Integer summaryData(@Param("tableName") String tableName, @Param("syncDate") String syncDate);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,48 @@
|
|||
<mapper namespace="com.engine.organization.mapper.danikor.DanikorResourceMapper">
|
||||
|
||||
|
||||
<select id="getColumnInfoByTableName" resultType="com.engine.organization.entity.column.TableColumnPO">
|
||||
<select id="getCusColumnByTableName" 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>
|
||||
|
||||
<select id="getHrmColumnByTableName" resultType="com.engine.organization.entity.column.TableColumnPO">
|
||||
select a.name as tableName, b.name as columnName, d.fielddbtype as columnType
|
||||
from sysobjects a
|
||||
inner join syscolumns b on a.id = b.id and a.xtype = 'U'
|
||||
left join hrm_formfield d on b.name = d.fieldname
|
||||
<if test="tableName=='hrmsubcompany' ">
|
||||
and d.groupid = 6
|
||||
</if>
|
||||
<if test="tableName=='hrmsubcompanydefined' ">
|
||||
and d.groupid = 6
|
||||
</if>
|
||||
<if test="tableName=='hrmdepartment'">
|
||||
and d.groupid = 7
|
||||
</if>
|
||||
<if test="tableName=='hrmdepartmentdefined'">
|
||||
and d.groupid = 7
|
||||
</if>
|
||||
<if test="tableName=='hrmresource'">
|
||||
and d.groupid < 6
|
||||
</if>
|
||||
where a.name = #{tableName}
|
||||
</select>
|
||||
<select id="summaryData" resultType="java.lang.Integer">
|
||||
select count(id)
|
||||
from ${tableName}
|
||||
where 1 = 1
|
||||
<if test="tableName == 'hrmresource'">
|
||||
and status < 4
|
||||
</if>
|
||||
<if test="tableName != 'hrmresource'">
|
||||
isnull(canceled, '0') = '0'
|
||||
</if>
|
||||
<if test="syncDate != null and syncDate !=''">
|
||||
and sync_date = #{syncDate}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.engine.organization.service;
|
||||
|
||||
import com.engine.organization.util.MenuBtn;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -23,4 +26,19 @@ public interface DanikorResourceBackService {
|
|||
* @return
|
||||
*/
|
||||
Map<String, Object> getSearchCondition();
|
||||
|
||||
/**
|
||||
* 获取列表页面按钮信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, List<MenuBtn>> getHasRight();
|
||||
|
||||
/**
|
||||
* 获取汇总数据
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getSummaryData(Map<String, Object> params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,11 @@ 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.MenuBtn;
|
||||
import com.engine.organization.util.OrganizationFormItemUtil;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.common.DateUtil;
|
||||
import weaver.general.Util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -45,9 +47,9 @@ public class DanikorResourceBackServiceImpl extends Service implements DanikorRe
|
|||
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 sqlWhere = "where t.status < 4 ";
|
||||
String cusTableName = "cus_fielddata";
|
||||
if (StringUtils.isNotBlank(syncDate)) {
|
||||
if (StringUtils.isNotBlank(syncDate) && !DateUtil.getDate(new Date()).equals(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";
|
||||
|
|
@ -62,7 +64,7 @@ public class DanikorResourceBackServiceImpl extends Service implements DanikorRe
|
|||
//初次使用,无模板初始值
|
||||
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> cusFieldNames = getDanikorResourceMapper().getCusColumnByTableName(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) {
|
||||
|
|
@ -118,4 +120,27 @@ public class DanikorResourceBackServiceImpl extends Service implements DanikorRe
|
|||
apiDatas.put("conditions", addGroups);
|
||||
return apiDatas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<MenuBtn>> getHasRight() {
|
||||
Map<String, List<MenuBtn>> btnDatas = new HashMap<>();
|
||||
ArrayList<MenuBtn> rightMenuList = new ArrayList<>();
|
||||
// 显示列定制
|
||||
rightMenuList.add(MenuBtn.rightMenu_btnColumn());
|
||||
btnDatas.put("rightMenu", rightMenuList);
|
||||
return btnDatas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getSummaryData(Map<String, Object> params) {
|
||||
HashMap<String, Object> returnMap = new HashMap<>();
|
||||
String syncDate = Util.null2String(params.get("syncDate"));
|
||||
if (DateUtil.getDate(new Date()).equals(syncDate)) {
|
||||
syncDate = null;
|
||||
}
|
||||
returnMap.put("subcompany", getDanikorResourceMapper().summaryData("hrmsubcompany", syncDate));
|
||||
returnMap.put("department", getDanikorResourceMapper().summaryData("hrmdepartment", syncDate));
|
||||
returnMap.put("person", getDanikorResourceMapper().summaryData("hrmresource", syncDate));
|
||||
return returnMap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,4 +58,29 @@ public class DanikorResourceBackController {
|
|||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getHasRight")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult getHasRight(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
return ReturnResult.successed(getDanikorResourceBackWrapper(user).getHasRight());
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getSummaryData")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult getSummaryData(@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).getSummaryData(map));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@ 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.MenuBtn;
|
||||
import com.engine.organization.util.OrganizationWrapper;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -23,7 +25,15 @@ public class DanikorResourceBackWrapper extends OrganizationWrapper {
|
|||
return getDanikorResourceBackService(user).listPage(params);
|
||||
}
|
||||
|
||||
public Map<String, Object> getSearchCondition(){
|
||||
public Map<String, Object> getSearchCondition() {
|
||||
return getDanikorResourceBackService(user).getSearchCondition();
|
||||
}
|
||||
|
||||
public Map<String, List<MenuBtn>> getHasRight() {
|
||||
return getDanikorResourceBackService(user).getHasRight();
|
||||
}
|
||||
|
||||
public Map<String, Object> getSummaryData(Map<String, Object> params) {
|
||||
return getDanikorResourceBackService(user).getSummaryData(params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue