花名册动态查询SQL

pull/127/head
dxfeng 2 years ago
parent 01c042ebbc
commit cfe08ddf4c

@ -26,8 +26,8 @@ import lombok.NoArgsConstructor;
"t.telephone," +
"t.managerid, " +
"t.dsporder ",
fromSql = "FROM hrmresource t ",
orderby = " dsporder ",
fromSql = "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' ",
orderby = " t.dsporder ",
sortway = " asc",
primarykey = "id",
operates = {

@ -6,7 +6,7 @@ package com.engine.organization.enums;
* @version: 1.0
*/
public enum HrmGroupEnum {
COMPANY(4), DEPARTMENT(5);
HRM_BASIC(-1), HRM_PERSONAL(1), HRM_WORK(3), COMPANY(4), DEPARTMENT(5);
HrmGroupEnum(Integer groupType) {
this.groupType = groupType;

@ -1,7 +1,6 @@
package com.engine.organization.service;
import com.engine.organization.entity.hrmresource.param.HrmRelationSaveParam;
import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam;
import com.engine.organization.entity.hrmresource.param.SearchTemplateParam;
import com.engine.organization.entity.searchtree.SearchTreeParams;
import org.apache.ibatis.annotations.Param;
@ -29,7 +28,7 @@ public interface HrmResourceService {
* @param params
* @return
*/
Map<String, Object> listPage(HrmResourceSearchParam params);
Map<String, Object> listPage(Map<String, Object> params);
/**
*

@ -2,6 +2,8 @@ package com.engine.organization.service.impl;
import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionType;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.cloudstore.eccom.result.WeaResultMsg;
@ -15,7 +17,6 @@ import com.engine.organization.entity.department.bo.DepartmentBO;
import com.engine.organization.entity.department.po.DepartmentPO;
import com.engine.organization.entity.hrmresource.bo.HrmRelationBO;
import com.engine.organization.entity.hrmresource.param.HrmRelationSaveParam;
import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam;
import com.engine.organization.entity.hrmresource.param.SearchTemplateParam;
import com.engine.organization.entity.hrmresource.po.HrmRelationPO;
import com.engine.organization.entity.hrmresource.po.SearchTemplatePO;
@ -25,6 +26,7 @@ import com.engine.organization.entity.job.bo.JobBO;
import com.engine.organization.entity.job.po.JobPO;
import com.engine.organization.entity.searchtree.SearchTree;
import com.engine.organization.entity.searchtree.SearchTreeParams;
import com.engine.organization.enums.HrmGroupEnum;
import com.engine.organization.mapper.comp.CompMapper;
import com.engine.organization.mapper.department.DepartmentMapper;
import com.engine.organization.mapper.hrmresource.HrmRelationMapper;
@ -107,10 +109,9 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
}
@Override
public Map<String, Object> listPage(HrmResourceSearchParam params) {
public Map<String, Object> listPage(Map<String, Object> params) {
OrganizationWeaTable<HrmResourceVO> table = new OrganizationWeaTable<>(user, HrmResourceVO.class);
Map<String, Object> searchParams = new HashMap<>();
String sqlWhere = buildSqlWhere(searchParams);
String sqlWhere = buildSqlWhere(params);
table.setSqlwhere(sqlWhere);
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
@ -149,11 +150,11 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
List<String> personalFieldsBuilder = new ArrayList<>();
List<String> workFieldsBuilder = new ArrayList<>();
for (String fieldName : split) {
if (fieldName.startsWith("-1")) {
if (fieldName.startsWith(HrmGroupEnum.HRM_BASIC.getGroupType().toString())) {
basicFieldsBuilder.add(fieldName.substring(fieldName.lastIndexOf("_") + 1));
} else if (fieldName.startsWith("1")) {
} else if (fieldName.startsWith(HrmGroupEnum.HRM_PERSONAL.getGroupType().toString())) {
personalFieldsBuilder.add(fieldName.substring(fieldName.lastIndexOf("_") + 1));
} else if (fieldName.startsWith("3")) {
} else if (fieldName.startsWith(HrmGroupEnum.HRM_WORK.getGroupType().toString())) {
workFieldsBuilder.add(fieldName.substring(fieldName.lastIndexOf("_") + 1));
}
}
@ -331,73 +332,37 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
private String buildSqlWhere(Map<String, Object> params) {
HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
List<SearchConditionItem> conditionItems = new ArrayList<>();
List<CusFormFieldPO> hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId("-1");
List<CusFormFieldPO> hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId(HrmGroupEnum.HRM_BASIC.getGroupType().toString());
createConditionItems(hrmFieldSearchConditionComInfo, hrmFieldsByScopeId, conditionItems);
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId("1");
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId(HrmGroupEnum.HRM_PERSONAL.getGroupType().toString());
createConditionItems(hrmFieldSearchConditionComInfo, hrmFieldsByScopeId, conditionItems);
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId("3");
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId(HrmGroupEnum.HRM_WORK.getGroupType().toString());
createConditionItems(hrmFieldSearchConditionComInfo, hrmFieldsByScopeId, conditionItems);
Map<String, SearchConditionItem> allFieldsMap = conditionItems.stream().collect(Collectors.toMap(item -> item.getDomkey()[0], item -> item, (k1, k2) -> k1));
DBType dbType = DBType.get(new RecordSet().getDBType());
String sqlWhere = " where 1=1 ";
//String sqlWhere = "";
StringBuilder sb = new StringBuilder(" where 1=1 ");
for (Map.Entry<String, Object> entry : params.entrySet()) {
String value = Util.null2String(entry.getValue());
if (StringUtils.isBlank(value)) {
continue;
}
String key = entry.getKey();
SearchConditionItem searchConditionItem = allFieldsMap.get(key);
buildDynamicSql(searchConditionItem, key, value, sb, dbType);
// 根据不同的类型,不同的查询方式
Object value = entry.getValue();
}
//String lastName = params.getLastName();
//if (StringUtils.isNotBlank(lastName)) {
// sqlWhere += " AND t.lastname " + dbType.like(lastName);
//}
//Long companyId = params.getCompanyId();
//if (null != companyId) {
// sqlWhere += " AND t.subcompanyid1 = '" + companyId + "'";
//}
//Long departmentId = params.getDepartmentId();
//if (null != departmentId) {
// sqlWhere += " AND t.departmentid = '" + departmentId + "'";
//}
//Long ecCompany = params.getEcCompany();
//if (null != ecCompany) {
// sqlWhere += " AND t.subcompanyid1 = '" + ecCompany + "'";
//}
//Long ecDepartment = params.getEcDepartment();
//if (null != ecDepartment) {
// sqlWhere += " AND t.departmentid = '" + ecDepartment + "'";
//}
//String telephone = params.getTelephone();
//if (StringUtils.isNotBlank(telephone)) {
// sqlWhere += " AND t.telephone " + dbType.like(telephone);
//}
//String mobile = params.getMobile();
//if (StringUtils.isNotBlank(mobile)) {
// sqlWhere += " AND t.mobile " + dbType.like(mobile);
//}
//Long jobTitle = params.getJobTitle();
//if (null != jobTitle) {
// JobPO ecJobTitleByJobId = JobBO.getEcJobTitleByJobId(jobTitle);
// if (null != ecJobTitleByJobId) {
// sqlWhere += " AND t.subcompanyid1 = '" + ecJobTitleByJobId.getEcCompany() + "'";
// sqlWhere += " AND t.departmentid = '" + ecJobTitleByJobId.getEcDepartment() + "'";
// sqlWhere += " AND t.jobtitle = '" + ecJobTitleByJobId.getEcJobTitle() + "'";
// } else {
// sqlWhere = " where 1 = 2 ";
// }
//}
// 分权查询
DetachUtil detachUtil = new DetachUtil(user);
String parentCompanyIds = detachUtil.getJclRoleLevels();
if (detachUtil.isDETACH()) {
sqlWhere += " And t.subcompanyid1 in(" + parentCompanyIds + ")";
sb.append(" And t.subcompanyid1 in(").append(parentCompanyIds).append(")");
}
return sqlWhere;
return sb.toString();
}
public List<SearchTree> getFilterCompany(String id, String type, String keyword) {
@ -602,21 +567,21 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
List<SearchConditionItem> workConditionItems = new ArrayList<>();
// 基本信息:-1
List<CusFormFieldPO> hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId("-1");
List<CusFormFieldPO> hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId(HrmGroupEnum.HRM_BASIC.getGroupType().toString());
createConditionItems(hrmFieldSearchConditionComInfo, hrmFieldsByScopeId, basicConditionItems);
if (CollectionUtils.isNotEmpty(basicConditionItems)) {
addGroups.add(new SearchConditionGroup("基本信息", true, basicConditionItems));
}
// 个人信息1
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId("1");
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId(HrmGroupEnum.HRM_PERSONAL.getGroupType().toString());
createConditionItems(hrmFieldSearchConditionComInfo, hrmFieldsByScopeId, personalConditionItems);
if (CollectionUtils.isNotEmpty(personalConditionItems)) {
addGroups.add(new SearchConditionGroup("个人信息", true, personalConditionItems));
}
// 工作信息3
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId("3");
hrmFieldsByScopeId = getSystemDataMapper().getHrmFieldsByScopeId(HrmGroupEnum.HRM_WORK.getGroupType().toString());
createConditionItems(hrmFieldSearchConditionComInfo, hrmFieldsByScopeId, workConditionItems);
if (CollectionUtils.isNotEmpty(workConditionItems)) {
addGroups.add(new SearchConditionGroup("工作信息", true, workConditionItems));
@ -646,6 +611,11 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
hrmFieldBean.setIsFormField(true);
SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
conditionItems.add(searchConditionItem);
// 如果为下拉框,添加一条空选项
if (searchConditionItem.getConditionType().equals(ConditionType.SELECT)) {
addEmptyForSelect(searchConditionItem);
}
}
}
@ -682,6 +652,10 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
hrmFieldBean.setIsScope(false);
SearchConditionItem searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
conditionItems.add(searchConditionItem);
// 如果为下拉框,添加一条空选项
if (searchConditionItem.getConditionType().equals(ConditionType.SELECT)) {
addEmptyForSelect(searchConditionItem);
}
}
if (CollectionUtils.isNotEmpty(conditionItems)) {
addGroups.add(new SearchConditionGroup(title, true, conditionItems));
@ -705,11 +679,11 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
List<String> personalFieldsBuilder = new ArrayList<>();
List<String> workFieldsBuilder = new ArrayList<>();
for (String fieldName : split) {
if (fieldName.startsWith("-1")) {
if (fieldName.startsWith(HrmGroupEnum.HRM_BASIC.getGroupType().toString())) {
basicFieldsBuilder.add(fieldName.substring(fieldName.lastIndexOf("_") + 1));
} else if (fieldName.startsWith("1")) {
} else if (fieldName.startsWith(HrmGroupEnum.HRM_PERSONAL.getGroupType().toString())) {
personalFieldsBuilder.add(fieldName.substring(fieldName.lastIndexOf("_") + 1));
} else if (fieldName.startsWith("3")) {
} else if (fieldName.startsWith(HrmGroupEnum.HRM_WORK.getGroupType().toString())) {
workFieldsBuilder.add(fieldName.substring(fieldName.lastIndexOf("_") + 1));
}
}
@ -730,16 +704,113 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
private void buildSearchConditionGroup(SearchTemplatePO templatePO, HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo, List<SearchConditionGroup> addGroups) {
String[] basicFields = Util.null2String(templatePO.getBasicFields()).split(",");
if (basicFields.length > 0) {
getTemplateItems(hrmFieldSearchConditionComInfo, addGroups, "基本信息", -1, basicFields);
getTemplateItems(hrmFieldSearchConditionComInfo, addGroups, "基本信息", HrmGroupEnum.HRM_BASIC.getGroupType(), basicFields);
}
String[] personalFields = Util.null2String(templatePO.getPersonalFields()).split(",");
if (personalFields.length > 0) {
getTemplateItems(hrmFieldSearchConditionComInfo, addGroups, "个人信息", 1, personalFields);
getTemplateItems(hrmFieldSearchConditionComInfo, addGroups, "个人信息", HrmGroupEnum.HRM_PERSONAL.getGroupType(), personalFields);
}
String[] workFields = Util.null2String(templatePO.getWorkFields()).split(",");
if (workFields.length > 0) {
getTemplateItems(hrmFieldSearchConditionComInfo, addGroups, "工作信息", 3, workFields);
getTemplateItems(hrmFieldSearchConditionComInfo, addGroups, "工作信息", HrmGroupEnum.HRM_WORK.getGroupType(), workFields);
}
}
/**
* whereSQL
*
* @param conditionItem
* @param key
* @param value
* @param sb
* @param dbType
*/
private void buildDynamicSql(SearchConditionItem conditionItem, String key, String value, StringBuilder sb, DBType dbType) {
if (null == conditionItem) {
return;
}
if (key.endsWith("workyear") || key.endsWith("companyworkyear")) {
conditionItem.setConditionType(ConditionType.INPUTNUMBER);
}
String tableSql = buildTableSql(key);
if (StringUtils.isBlank(tableSql)) {
return;
}
switch (conditionItem.getConditionType()) {
case INPUT:// 单行文本框
case TEXTAREA:// 多行文本框
sb.append(" and ").append(tableSql).append(dbType.like(value));
// 模糊搜索
break;
case INPUTNUMBER:// 数字
case SELECT://选择框
case BROWSER://浏览按钮
case CHECKBOX:
case SWITCH:
sb.append(" and ").append(dbType.ifNull(tableSql, "0")).append(" = '").append(value).append("' ");
break;
case DATE:
case DATEPICKER:
case TIMEPICKER:
case RANGEPICKER:
// 精准搜索
sb.append(" and ").append(tableSql).append(" = '").append(value).append("' ");
break;
default:
break;
}
}
/**
*
*
* @param key
* @return
*/
private String buildTableSql(String key) {
StringBuilder sb = new StringBuilder();
String[] s = key.split("_");
if (s.length < 3) {
return "";
}
String scopeId = s[0];
String tableName = s[1];
String fieldName = s[2];
if ("hrm".equals(tableName)) {
sb.append("t.").append(fieldName);
} else {
switch (scopeId) {
case "-1":
sb.append("t0.").append(fieldName);
break;
case "1":
sb.append("t1.").append(fieldName);
break;
case "3":
sb.append("t2.").append(fieldName);
break;
default:
return "";
}
}
return sb.toString();
}
private void addEmptyForSelect(SearchConditionItem searchConditionItem) {
searchConditionItem.setValue("");
List<SearchConditionOption> options = searchConditionItem.getOptions();
options.forEach(item -> {
item.setSelected(false);
});
SearchConditionOption searchConditionOption = new SearchConditionOption();
searchConditionOption.setSelected(true);
searchConditionOption.setKey("");
options.add(0, searchConditionOption);
}
}

@ -581,7 +581,7 @@ public class JobServiceImpl extends Service implements JobService {
//2.数据过滤
//3.数据插入
resourcePOS.forEach(resourcePO -> {
if (Objects.nonNull(resourcePO) && null != resourcePO.getJobtitle() && 0 != resourcePO.getJobtitle()) {
if (Objects.nonNull(resourcePO) && null != resourcePO.getJobtitle() && resourcePO.getJobtitle() > 0) {
int count = getJobMapper().selectByConditions(resourcePO);
if (count == 0) {
JobPO jobPO = JobPO.builder()

@ -6,4 +6,6 @@ public interface DBOperateAdapter {
String concat(String some);
String currentDate();
String ifNull(String some, String defaultValue);
}

@ -20,6 +20,11 @@ public enum DBType implements DBOperateAdapter {
public String currentDate() {
return "now()";
}
@Override
public String ifNull(String some, String defaultValue) {
return " ifnull(" + some + ",'" + defaultValue + "')";
}
},
SQLSERVER("sqlserver") {
@Override
@ -36,11 +41,16 @@ public enum DBType implements DBOperateAdapter {
public String currentDate() {
return "GETDATE()";
}
@Override
public String ifNull(String some, String defaultValue) {
return " isnull(" + some + ",'" + defaultValue + "')";
}
},
ORACLE("oracle") {
@Override
public String like(String some) {
return " like '%'||" + some + "||'%' ";
return " like '%" + some + "%' ";
}
@Override
@ -52,6 +62,11 @@ public enum DBType implements DBOperateAdapter {
public String currentDate() {
return "SYSDATE";
}
@Override
public String ifNull(String some, String defaultValue) {
return " NVL(" + some + ",'" + defaultValue + "')";
}
};
private String dbtype;

@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.organization.entity.hrmresource.param.HrmRelationSaveParam;
import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam;
import com.engine.organization.entity.hrmresource.param.SearchTemplateParam;
import com.engine.organization.entity.hrmresource.po.SearchTemplatePO;
import com.engine.organization.entity.searchtree.SearchTreeParams;
@ -67,8 +66,7 @@ public class HrmResourceController {
try {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> map = ParamUtil.request2Map(request);
HrmResourceSearchParam param = JSONObject.toJavaObject((JSON) JSONObject.toJSON(map), HrmResourceSearchParam.class);
return ReturnResult.successed(getHrmResourceWrapper(user).listPage(param));
return ReturnResult.successed(getHrmResourceWrapper(user).listPage(map));
} catch (Exception e) {
return ReturnResult.exceptionHandle(e);
}

@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.organization.annotation.Log;
import com.engine.organization.entity.hrmresource.param.HrmRelationSaveParam;
import com.engine.organization.entity.hrmresource.param.HrmResourceSearchParam;
import com.engine.organization.entity.hrmresource.param.SearchTemplateParam;
import com.engine.organization.entity.searchtree.SearchTreeParams;
import com.engine.organization.enums.LogModuleNameEnum;
@ -31,7 +30,7 @@ public class HrmResourceWrapper extends OrganizationWrapper {
return getHrmResourceService(user).getSearchTree(params);
}
public Map<String, Object> listPage(HrmResourceSearchParam params) {
public Map<String, Object> listPage(Map<String, Object> params) {
return getHrmResourceService(user).listPage(params);
}

Loading…
Cancel
Save