package com.product.org.admin.service; import com.product.admin.service.PublicService; import com.product.admin.service.SelectPersonnelService; import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import com.product.admin.service.UpdateLoginUserInfoService; import com.product.common.lang.StringUtils; import com.product.core.interceptor.support.DataValidateInterceptor; import com.product.core.spring.context.SpringBeanUtil; import com.product.email.service.SendEmailService; import com.product.core.cache.DataPoolCacheImpl; import com.product.core.config.CoreConst; import com.product.core.config.Global; import org.apache.commons.lang3.RandomStringUtils; import org.jsoup.helper.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.product.org.admin.config.SystemCode; import com.product.admin.service.CodeService; import com.product.core.dao.BaseDao; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldMetaEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.exception.BaseException; import com.product.core.permission.PermissionService; import com.product.core.service.support.AbstractBaseService; import com.product.core.service.support.QueryFilterService; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.core.transfer.Transactional; import com.product.core.util.JsonUtil; import com.product.module.sys.entity.SystemUser; import com.product.module.sys.service.UserService; import com.product.org.admin.config.CmnConst; import com.product.org.admin.service.idel.IStaffManagerService; import com.product.org.admin.util.SingletonUtil; import com.product.util.BaseUtil; /** * Copyright LX-BASE * * @Title: LX-BASE- * @Project: StaffManagerService * @Date: 2020-06-22 09:31 * @Author: 杜洪波 * @Description:员工管理 */ @Component public class StaffManagerService extends AbstractBaseService implements IStaffManagerService { @Autowired public BaseDao baseDao; @Autowired private UserService userService; @Autowired private CodeService codeService; @Autowired PermissionService permissionService; @Autowired private SendEmailService sendEmailService; @Autowired public CostCenterService costCenterService; @Autowired public QueryFilterService queryFilterService; @Autowired public TimeTaskChangeService timeTaskService; @Autowired private UpdateLoginUserInfoService updateLoginUserInfoService; @Autowired private SelectPersonnelService selectPersonnelService; /** * 获取当前用户上级领导userid * * @return * @throws BaseException */ public String getLeaderUserId() throws BaseException { return getLeaderUserId(SpringMVCContextHolder.getCurrentUser().getUser_id()); } /** * 获取上级领导user_id * * @param user_id user表id * @return * @throws BaseException */ public String getLeaderUserId(Object user_id) throws BaseException { FieldSetEntity fse = baseDao.getFieldSetEntityBySQL("SELECT user_id FROM product_sys_staffs WHERE tricode = (SELECT direct_leader_code FROM product_sys_staffs " + "WHERE USER_ID=?)", new Object[]{user_id}, false); if (fse != null) { return fse.getString(CmnConst.USER_ID); } return null; } public DataTableEntity listStaffInfoV2(FieldSetEntity fse) throws BaseException { PublicService publicService = SpringBeanUtil.getBean("publicService", PublicService.class); fse.setTableName("product_sys_staff_user_v"); return publicService.listTable(fse, true, 1, CmnConst.ORG_LEVEL_UUID, null); } /** * 员工信息列表 * * @param fse * @return * @throws BaseException */ public DataTableEntity listStaffInfo(FieldSetEntity fse) throws BaseException { fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid()); String dataFilter = permissionService.getDataFilter("a." + CmnConst.ORG_LEVEL_UUID); if (!StringUtils.isEmpty(dataFilter)) { dataFilter = " WHERE " + dataFilter; } else { dataFilter = ""; } // 高级搜索 String filter = queryFilterService.getQueryFilter(fse); if (!StringUtils.isEmpty(filter)) { if (dataFilter.length() > 0) { dataFilter += " and " + filter; } else { dataFilter = " where " + filter; } } StringBuilder sql = new StringBuilder(); /* sql.append("select * from ("); sql.append(" SELECT a.uuid uuid,b.uuid uuid1,c.uuid uuid2,d.uuid uuid3,e.uuid uuid4,f.uuid uuid5,a.staff_status,a.staff_avatar,b.user_id,b.user_account,b.STATUS,a.show_name,a.preferred_name,c.client_name,d.org_level_all,e.job_post_name,f.job_grade_name "); sql.append(" FROM product_sys_staffs a "); sql.append(" LEFT JOIN product_sys_users b ON b.user_id=a.user_id "); sql.append(" LEFT JOIN product_sys_clients c ON c.uuid=a.client_uuid "); sql.append(" LEFT JOIN product_sys_org_levels d ON d.uuid=a.dept_uuid "); sql.append(" LEFT JOIN product_sys_job_posts e ON e.uuid=a.job_post_uuid "); sql.append(" LEFT JOIN product_sys_job_post_grades f ON f.uuid=a.job_post_grade_uuid "); sql.append(dataFilter); sql.append(" ) b"); */ // sql.append("select * from ("); sql.append(" SELECT a.uuid uuid,b.uuid uuid1,c.uuid uuid2,d.uuid uuid3,a.staff_status,a.staff_avatar,a.show_name,a.preferred_name,b.user_id,b.user_account,b.status,c.org_level_all,d.job_post_name "); sql.append(" FROM product_sys_staffs a "); sql.append(" LEFT JOIN product_sys_users b ON b.user_id=a.user_id "); sql.append(" LEFT JOIN product_sys_org_levels c ON c.uuid=a.dept_uuid "); sql.append(" LEFT JOIN product_sys_job_posts d ON d.uuid=a.job_post_uuid "); sql.append(dataFilter); // sql.append(" ) b"); DataTableEntity dtStaffInfo = baseDao.listTable(sql.toString(), null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE)); dtStaffInfo.getMeta().addAliasTable(CmnConst.PRODUCT_SYS_STAFFS, "a"); dtStaffInfo.getMeta().addAliasTable("product_sys_users", "b"); dtStaffInfo.getMeta().addAliasTable("product_sys_org_levels", "c"); dtStaffInfo.getMeta().addAliasTable("product_sys_job_posts", "d"); /* if (dtStaffInfo.getRows() > 0) { String sostoken = Global.getSystemConfig("upload.key", ""); for (int i = 6; i < dtStaffInfo.getRows(); i++) { Map av = new HashMap(); FieldSetEntity staff = dtStaffInfo.getFieldSetEntity(i); if (!StringUtils.isEmpty(staff.getString(CmnConst.STAFF_AVATAR))) { FieldSetEntity atta = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, staff.getString(CmnConst.STAFF_AVATAR), false); if (atta != null) { av.put("path", atta.getString("attachment_domain") + "/" + atta.getString("attachment_container") + "/" + atta.getString("module_uuid") + "/" + atta.getString(CmnConst.ATTACHMENT_TITLE) + sostoken); av.put("name", atta.getString(CmnConst.ATTACHMENT_TITLE)); av.put("size", atta.getString("attachment_size")); av.put("uuid", atta.getString("uuid")); av.put(CmnConst.FIEL_NAME, atta.getString(CmnConst.FIEL_NAME)); } else { av.put("path", ""); av.put("name", ""); av.put("size", ""); av.put("uuid", ""); av.put(CmnConst.FIEL_NAME, ""); } } else { av.put("path", ""); av.put("name", ""); av.put("size", ""); av.put("uuid", ""); av.put(CmnConst.FIEL_NAME, ""); } staff.setValue(CmnConst.STAFF_AVATAR, av); } } */ // 查询为数据时,设置表名 if (dtStaffInfo != null && dtStaffInfo.getTableName() == null && dtStaffInfo.getMeta() != null) { dtStaffInfo.getMeta().setTableName(new String[]{"a", "b", "c", "d"}); } baseDao.loadPromptData(dtStaffInfo); return dtStaffInfo; } /** * 员工信息详情 v2 * * @param user_id * @return * @throws BaseException */ public FieldSetEntity findStaffInfoV2(String user_id) throws BaseException { return baseDao.getFieldSetEntityBySQL("select a.*,b.uuid user_uuid,b.user_name,b.user_account,'********' user_pwd,b.status FROM product_sys_users b join product_sys_staffs a on a.user_id=? and a.user_id=b.user_id", new Object[]{user_id}, false); } /** * 员工信息详情 * * @param uuid * @return * @throws BaseException */ public FieldSetEntity findStaffInfo(String uuid) throws BaseException { StringBuilder sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.child_name,a.christian_name,a.client_uuid,a.cost_center_uuid,a.created_by,a.created_utc_datetime,a.dept_uuid,a.direct_leader_code, "); sql.append(" a.entry_datetime,a.family_name,a.given_name,a.is_dept_manage,a.is_org_admin,a.is_org_manager,a.job_post_grade_uuid,a.job_post_uuid, "); sql.append(" a.org_level_uuid,a.preferred_name,a.probation_end,a.role_uuids,a.show_name,a.staff_code,a.staff_email,a.staff_id,a.staff_image, "); sql.append(" a.staff_status,a.tricode,a.updated_by,a.updated_utc_datetime,a.user_id,a.uuid, "); sql.append(" b.status,d.gender, "); sql.append(" c.attachment_url,concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) staff_avatar "); sql.append(" FROM product_sys_staffs a "); sql.append(" LEFT JOIN product_sys_users b ON a.user_id=b.user_id "); sql.append(" LEFT JOIN product_sys_attachments c ON a.staff_avatar=c.uuid "); sql.append(" LEFT JOIN product_sys_staff_personal_info d ON a.uuid=d.staff_uuid "); sql.append(" where a.uuid=? "); String sostoken = Global.getSystemConfig("upload.key", ""); FieldSetEntity fseStaff = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{sostoken, uuid}, false); baseDao.listInternationDataTable(fseStaff, null); return fseStaff; } /** * 员工新增 v2 * * @param fse * @return * @throws BaseException */ @Transactional @Override public String saveStaffInfo(FieldSetEntity fse) throws BaseException { FieldSetEntity fs; SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); // 用户账号 String user_account = fse.getString(CmnConst.USER_ACCOUNT); fse.setValue("show_name", fse.getString(CmnConst.USER_NAME)); fse.setValue(CmnConst.CLIENT_UUID, currentUser.getClient_uuid()); if (StringUtils.isEmpty(fse.getString(CmnConst.CLIENT_UUID))) { fse.setValue(CmnConst.CLIENT_UUID, currentUser.getClient_uuid()); } if (StringUtils.isEmpty(fse.getString(CmnConst.ORG_LEVEL_UUID))) { fse.setValue(CmnConst.ORG_LEVEL_UUID, currentUser.getOrg_level_uuid()); } // 判断是否为新增 if (StringUtils.isEmpty(fse.getString(CmnConst.USER_ID))) { if (StringUtils.isEmpty(user_account)) { // 账号为空 throw new BaseException(SystemCode.USER_ACCOUNT_IS_EMPTY.getValue(), SystemCode.USER_ACCOUNT_IS_EMPTY.getText()); } fs = baseDao.getFieldSetEntityBySQL("select user_account FROM product_sys_users where user_account=? limit 1", new Object[]{user_account}, false); if (fs != null && user_account.equals(fs.getString(user_account))) { // 账号已存在 throw new BaseException(SystemCode.USER_ACCOUNT_EXIST.getValue(), SystemCode.USER_ACCOUNT_EXIST.getText()); } } if (fse.getString(CmnConst.DIRECT_LEADER_CODE) == null) { fse.setValue(CmnConst.DIRECT_LEADER_CODE, ""); } String user_id = fse.getString(CmnConst.USER_ID); //生成员工上下级编码 String directLeaderTricode = fse.getString(CmnConst.DIRECT_LEADER_CODE); //获取领导编码 String leaderCode = null; if (StringUtils.isEmpty(directLeaderTricode)) { leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, ""); } else { FieldSetEntity fseLeader = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "tricode=?", new Object[]{directLeaderTricode}, false); leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, fseLeader.getString(CmnConst.LEADER_TRICODE)); } String preLeaderTricode = fse.getString(CmnConst.LEADER_TRICODE); fse.setValue(CmnConst.LEADER_TRICODE, leaderCode); // 更改下属的leader_tricode if (!StringUtils.isEmpty(preLeaderTricode) && !preLeaderTricode.equals(leaderCode)) { updateSubLeaderTricode(preLeaderTricode, leaderCode); } StringBuilder sql = new StringBuilder(); sql.append("select user_id,dept_uuid,ifnull(direct_leader_code,'') direct_leader_code,uuid FROM product_sys_staffs "); sql.append(" where user_id= ? and (direct_leader_code = ? "); sql.append(" or dept_uuid = ?"); sql.append(" )"); // 领导编码 String direct_leader_code = fse.getString(CmnConst.DIRECT_LEADER_CODE); FieldSetEntity tempFs = null; if (!StringUtils.isEmpty(user_id)) { // 修改员工查询上级领导或部门是否被改变 tempFs = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{user_id, direct_leader_code, fse.getString(CmnConst.DEPT_UUID)}, false); } if (tempFs == null || StringUtils.isEmpty(tempFs.getUUID())) { if (tempFs == null || !fse.getString(CmnConst.DEPT_UUID).equals(tempFs.getString(CmnConst.DEPT_UUID))) { FieldSetEntity deptFieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, fse.getString(CmnConst.DEPT_UUID), false); String org_level_code = deptFieldSet.getString(CmnConst.ORG_LEVEL_CODE); //目前不允许改变部门 String tricode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.TRICODE, org_level_code); fse.setValue(CmnConst.TRICODE, tricode); } } // 创建user表信息 fs = new FieldSetEntity(); fs.setTableName(CmnConst.PRODUCT_SYS_USERS); fs.setValue(CmnConst.USER_NAME, fse.getString(CmnConst.USER_NAME)); fs.setValue("gender", fse.getString("sex")); fs.setValue("user_mobile_number", fse.getString("mobile_phone")); fs.setValue("date_birth", fse.getString("birth_date")); if (StringUtils.isEmpty(user_id)) { // 新增时才做操作 fs.setValue(CmnConst.USER_ACCOUNT, user_account); fs.setValue(CmnConst.USER_PWD, userService.createPassWord(user_account, fse.getString(CmnConst.USER_PWD))); } else { String user_uuid = fse.getString("user_uuid"); if (!StringUtils.isEmpty(user_uuid)) { user_uuid = fse.getString("user_uuid"); } else { // 根据user_id 查询uuid FieldSetEntity temp = baseDao.getFieldSetEntityByFilter(fs.getTableName(), "user_id=?", new Object[]{user_id}, false); user_uuid = temp.getUUID(); // 防止user表uuid 查询不到 user_uuid.equals(user_uuid); } fs.setValue(CmnConst.UUID, user_uuid); } fs.setValue(CmnConst.STATUS, fse.getString(CmnConst.STATUS)); fs.setValue("contact_address", fse.getString("contact_address")); fs.setValue("inside_phone", fse.getString("office_telephone")); fs.setValue("user_primary_email", fse.getString(CmnConst.STAFF_EMAIL)); baseDao.saveFieldSetEntity(fs); if (StringUtils.isEmpty(user_id)) { fs = baseDao.getFieldSetEntity(fs.getTableName(), fs.getUUID(), false); user_id = fs.getString(CmnConst.USER_ID); fse.setValue(CmnConst.USER_ID, user_id); } // staff 表 员工状态 写死 为在职 fse.setValue("staff_status", 3); // 标记leader_tricode已经更新 fse.setCodeFieldUpdateFlat(CmnConst.LEADER_TRICODE, true); baseDao.saveFieldSetEntity(fse); fse.setValue("product_sys_users", fs); return user_id; } /** * 员工修改 v2 * * @param fse * @return * @throws BaseException */ @Override public boolean updateStaffInfoV2(FieldSetEntity fse) throws BaseException { return false; } /** * 员工删除 v2 * * @param uuid * @return * @throws BaseException */ @Override public boolean deleteStaffInfoV2(String uuid) throws BaseException { return false; } /** * 员工新增 * * @param fse * @return * @throws BaseException * @throws ParseException */ @Transactional public String addStaffInfo(FieldSetEntity fse) throws BaseException, Exception { //罗鑫2021年3月1日 开始时间不能大于结束时间 String entry_datetime = fse.getString("entry_datetime"); if (BaseUtil.strIsNull(entry_datetime)) { throw new BaseException(SystemCode.SYSTEM_ENTRY_DATE_IS_NOTNULL.getValue(), SystemCode.SYSTEM_ENTRY_DATE_IS_NOTNULL.getText(), this.getClass(), "public String addStaffInfo(FieldSetEntity fse) throws BaseException, Exception"); } String probation_end = fse.getString("probation_end"); if (!BaseUtil.strIsNull(probation_end)) { if (BaseUtil.temporalComparison(entry_datetime, probation_end)) { throw new BaseException(SystemCode.SYSTEM_ENTRY_DATE_FAIL.getValue(), SystemCode.SYSTEM_ENTRY_DATE_FAIL.getText(), this.getClass(), "public String addStaffInfo(FieldSetEntity fse) throws BaseException, Exception"); } } // 判断账号是否重复 String user_account = fse.getString(CmnConst.STAFF_EMAIL); DataTableEntity dtUser = baseDao.listTable(CmnConst.PRODUCT_SYS_USERS, "user_account=?", new Object[]{user_account}); if (!BaseUtil.dataTableIsEmpty(dtUser)) { throw new BaseException(SystemCode.SYSTEM_STAFF_ADD_FAIL_ACCOUNT_REPEAT.getValue(), SystemCode.SYSTEM_STAFF_ADD_FAIL_ACCOUNT_REPEAT.getText(), this.getClass(), "addStaff"); } // 随机生成8位密码 String passWord = RandomStringUtils.randomAlphanumeric(8); // 加密默认密码 String pwd = userService.createPassWord(fse.getString(CmnConst.STAFF_EMAIL), passWord); // 创建user表对象 FieldSetEntity fseUser = new FieldSetEntity(); FieldMetaEntity fmeMate = new FieldMetaEntity(); fseUser.setMeta(fmeMate); fmeMate.setTableName(new Object[]{CmnConst.PRODUCT_SYS_USERS}); // 填充user表必填数据 fseUser.setValue("user_name", fse.getString("show_name")); // 密码 fseUser.setValue(CmnConst.USER_ACCOUNT, fse.getString(CmnConst.STAFF_EMAIL)); // 登陆账号,邮箱 fseUser.setValue(CmnConst.USER_PWD, pwd); // 密码 fseUser.setValue(CmnConst.STATUS, 1); // 账号状态,启用 fseUser.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 创建人 fseUser.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); // 创建时间 fseUser.setValue(CmnConst.IS_MANAGER, 0); // 默认不是管理员 fseUser.setValue("user_primary_email", fse.getString(CmnConst.STAFF_EMAIL));// 邮箱 fseUser.setValue("default_language", fse.getString("default_language")); // 默认语言 // 创建user表信息 String userUUid = baseDao.add(fseUser, false); // 获取user_id String user_id = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_USERS, userUUid, false).getString(CmnConst.USER_ID); fse.setValue(CmnConst.USER_ID, user_id); // 关联user表uuid // 根据部门uuid生成员工编码,关联客户 String deptUUid = fse.getString(CmnConst.DEPT_UUID); FieldSetEntity fseOrgLevel = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, deptUUid, false); if (fseOrgLevel == null) { throw new BaseException(SystemCode.SYSTEM_STAFFS_ADD_FAIL.getValue(), SystemCode.SYSTEM_STAFFS_ADD_FAIL.getText(), this.getClass(), "addStaff"); } // 获取部门编码和客户uuid String clientUUid = fseOrgLevel.getString(CmnConst.CLIENT_UUID); // 生成员工编码 String staffCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.TRICODE, fseOrgLevel.getString(CmnConst.ORG_LEVEL_CODE)); //生成员工上下级编码 String directLeaderTricode = fse.getString(CmnConst.DIRECT_LEADER_CODE); //获取领导编码 String leaderCode = null; if (StringUtils.isEmpty(directLeaderTricode)) { leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, ""); } else { FieldSetEntity fseLeader = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "tricode=?", new Object[]{directLeaderTricode}, false); leaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, fseLeader.getString(CmnConst.LEADER_TRICODE)); } fse.setValue(CmnConst.LEADER_TRICODE, leaderCode); fse.setValue(CmnConst.TRICODE, staffCode); // 员工编码 fse.setValue(CmnConst.CLIENT_UUID, clientUUid);// 客户uuid fse.setValue(CmnConst.IS_ORG_ADMIN, 0); // 默认不为单位管理员 fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());// 创建人 fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); // 创建时间 //杜洪波 2020-01-25 14:59:00 将show_name同步到preferred_name DataTableEntity dtPerferredName = fse.getSubDataTable("show_name"); if (dtPerferredName != null) { DataTableEntity copyName = dtPerferredName.clones(); copyName.getMeta().setTableName(new String[]{"preferred_name"}); fse.addSubDataTable(copyName); } //员工状态判断 timeMatch(entry_datetime, probation_end, fse); fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid()); // 创建staff表信息 String staffUUid = baseDao.add(fse, true); //判断是否准备转正,添加转正单 if (fse.getInteger("staff_status") == 2) { timeTaskService.autoCreateApplicationForm(staffUUid, (new SimpleDateFormat("yyyy-MM-dd")).parse(entry_datetime), (new SimpleDateFormat("yyyy-MM-dd")).parse(probation_end)); } // 员工系统属性处理 String property_group_uuid = fse.getString(CmnConst.STAFF_PROPERTY_MASTER_UUID); if (!StringUtils.isEmpty(property_group_uuid)) { DataTableEntity dtSysPropertyDefalut = baseDao.listTable( CmnConst.PRODUCT_SYS_STAFF_PROPERTY_GROUP_DEFALUT_VALUE, "staff_property_group_uuid=?", new Object[]{property_group_uuid}, new String[]{CmnConst.STAFF_PROPERTY_MASTER_UUID, CmnConst.STAFF_PROPERTY_MASTER_CODE, CmnConst.VALUE, "effective_utc_datetime", "org_level_uuid"}); if (dtSysPropertyDefalut != null && dtSysPropertyDefalut.getRows() > 0) { FieldMetaEntity fseMate = dtSysPropertyDefalut.getMeta(); fseMate.setTableName(new String[]{CmnConst.PRODUCT_SYS_STAFF_PROPERTY}); dtSysPropertyDefalut.setMeta(fseMate); for (int i = 0; i < dtSysPropertyDefalut.getRows(); i++) { FieldSetEntity fseSysPropertyDefault = dtSysPropertyDefalut.getFieldSetEntity(i); fseSysPropertyDefault.getMeta().setTableName(new String[]{CmnConst.PRODUCT_SYS_STAFF_PROPERTY}); fseSysPropertyDefault.setValue(CmnConst.STAFF_UUID, user_id); } baseDao.add(dtSysPropertyDefalut); } } // 新增人员成本中心 if (!StringUtils.isEmpty(fse.getString(CmnConst.COST_CENTER_UUID))) { costCenterService.addStaffCostCenter(user_id, fse.getString(CmnConst.COST_CENTER_UUID), entry_datetime); } // 生成员工就业信息 FieldSetEntity fse_staff_employment_info = new FieldSetEntity(); FieldMetaEntity fseMate = new FieldMetaEntity(); fseMate.setTableName(new Object[]{CmnConst.PRODUCT_SYS_STAFF_EMPLOYMENT_INFO}); fse_staff_employment_info.setMeta(fseMate); fse_staff_employment_info.setValue("first_employment_date", entry_datetime); //第一次加入公司日期 fse_staff_employment_info.setValue("employment_date", entry_datetime); //加入公司日期 fse_staff_employment_info.setValue(CmnConst.PROBATION_END_DATE, probation_end); //试用结束日期 fse_staff_employment_info.setValue(CmnConst.STAFF_UUID, staffUUid); //员工表uuid baseDao.add(fse_staff_employment_info); //生成员工个人信息 FieldSetEntity fse_staff_personal_info = new FieldSetEntity(); fseMate.setTableName(new Object[]{CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO}); fse_staff_personal_info.setMeta(fseMate); fse_staff_personal_info.setValue(CmnConst.STAFF_UUID, staffUUid); fse_staff_personal_info.setValue("gender", fse.getString("gender")); baseDao.add(fse_staff_personal_info); //代码逻辑配置 timeTaskService.executeServiceChange(fse, CmnConst.PRODUCT_SYS_STAFFS); // 新增员工发送邮件 // 邮件内容 String login_url = URLEncoder.encode(Global.getSystemConfig("resetpwd.lxelogin_url", ""));//获取配置的员工登录页面 FieldSetEntity nfs = new FieldSetEntity(); nfs.setTableName("staffEmailContent"); nfs.setValue("login_url", login_url);// 登录页面 nfs.setValue("user_account", user_account);// 用户名 nfs.setValue("passWord", passWord);// 密码 String resultInfo = sendEmailService.parseMailTemplate(com.product.admin.config.CmnConst.NEW_EMPLOYEE_ACTIVATION, nfs); if (SystemCode.SYSTEM_OPERATION_SUCCESS.getText().equals(resultInfo)) { // luoxin 2020年12月25日 18:25:47 selectPersonnelService.updataGruopContent(fse.getString(CmnConst.DEPT_UUID), fse.getString("job_post_uuid"), staffUUid); return staffUUid; } else { throw new BaseException(SystemCode.SYSTEM_MAIL_SEND_FAIL.getValue(), SystemCode.SYSTEM_MAIL_SEND_FAIL.getText(), this.getClass(), "sendPasswordResetEmail"); } } /** * 新增员工,状态验证 * * @param entry_datetime 入职日期 * @param probation_end 试用结束日期 * @param fse * @return * @throws ParseException */ public void timeMatch(String entry_datetime, String probation_end, FieldSetEntity fse) throws Exception { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date entryTime = sd.parse(entry_datetime); Date probationTime = sd.parse(probation_end); Date currentTime = new Date(); if (entry_datetime.equals(probation_end)) { //判断入职日期与试用结束日期是否相等 if (entryTime.compareTo(currentTime) > 0) { fse.setValue("staff_status", 0); // 员工状态 0:准备入职 } else { fse.setValue("staff_status", 2); // 员工状态 2:准备转正 } } else { if (entryTime.compareTo(currentTime) > 0) { fse.setValue("staff_status", 0); // 员工状态 0:准备入职 } else if (entryTime.compareTo(currentTime) < 0 && probationTime.compareTo(currentTime) > 0) { fse.setValue("staff_status", 1); // 员工状态 1:试用 } else { fse.setValue("staff_status", 2); // 员工状态 2:准备转正 } } } /** * 员工编码重复验证 * * @param staff_code * @return * @throws BaseException */ public boolean staffCodeValitation(String staff_code) throws BaseException { SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); if (currentUser != null) { FieldSetEntity fse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "staff_code=? and org_level_uuid=?", new Object[]{staff_code, currentUser.getOrg_level_uuid()}, false); if (fse == null) { return true; } else { return false; } } else { return false; } } /** * 员工修改 1.不涉及部门修改,部门修改走员工变更 * * @param fse * @return * @throws BaseException */ @Transactional public boolean updateStaffInfo(FieldSetEntity fse) throws BaseException { boolean flag = true; // 修改保存不操作员工头像字段 2021年1月21日10:55:01 xupengcheng 避免查询详情时用同一字段返回url前端再提交回来保存 fse.remove(CmnConst.STAFF_AVATAR); // 修改user表信息 int user_id = fse.getInteger(CmnConst.USER_ID); FieldSetEntity fseUser = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?", new Object[]{user_id}, false); if (fseUser == null) { throw new BaseException(SystemCode.SYSTEM_STAFF_UPDATE_FAIL_USER_NO_EXIST.getValue(), SystemCode.SYSTEM_STAFF_UPDATE_FAIL_USER_NO_EXIST.getText(), this.getClass(), "updateStaffInfo"); } if ("1".equals(fse.getString(CmnConst.STATUS)) && "0".equals(fseUser.getString(CmnConst.STATUS))) { fseUser.setValue("login_fail_num", null); fseUser.setValue("locked_expire_time", null); } fseUser.setValue(CmnConst.STATUS, fse.getString(CmnConst.STATUS)); // 修改登录账户状态 baseDao.update(fseUser); // 获取员工原信息 FieldSetEntity originStaffInfo = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, fse.getUUID(), false); // 成本中心处理 // 1.原不存在,现不存在,不处理 // 2.原不存在,现存在,新增成本中心映射 // 3.原存在,现不存在,删除成本中心映射 // 4.原存在,现存在,修改成本中心映射 /* String origin_cost_center = originStaffInfo.getString(CmnConst.COST_CENTER_UUID); String new_cost_center = fse.getString(CmnConst.COST_CENTER_UUID); if (!new_cost_center.equals(origin_cost_center)) { if (!StringUtils.isEmpty(new_cost_center)) { // 杜洪波 updateTime 2020-12-17 09:48:00 if (!StringUtils.isEmpty(origin_cost_center)) { costCenterService.updateStaffCostCenter(user_id + "", new_cost_center, new Date()); } else { costCenterService.addStaffCostCenter(user_id + "", new_cost_center, new Date()); } } else { if (!StringUtils.isEmpty(origin_cost_center)) { costCenterService.deleteStaffCostCenter(user_id + ""); } } } */ // 处理文件删除 if (!StringUtils.isEmpty(fse.getString("del"))) { String[] dels = fse.getString("del").split(","); for (int i = 0; i < dels.length; i++) { baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, "uuid=?", new String[]{dels[i]}); } } /* DataTableEntity dtPerferredName = fse.getSubDataTable("show_name"); DataTableEntity copyName = dtPerferredName.clones(); for (int i = 0; i < copyName.getRows(); i++) { copyName.getFieldSetEntity(i).remove(CmnConst.UUID); } copyName.getMeta().setTableName(new String[]{"preferred_name"}); fse.addSubDataTable(copyName); baseDao.delete(CmnConst.PRODUCT_SYS_LANGUAGE_CONT_VALUES, "table_name=.PRODUCT_SYS_staffs' AND field_name='preferred_name' AND data_uuid=?", new Object[]{fse.getUUID()}); fse.remove("entry_datetime"); fse.remove("probation_end"); */ //上级领导变化 String originLeaderTricode = originStaffInfo.getString(CmnConst.DIRECT_LEADER_CODE); String newLeaderTricode = fse.getString(CmnConst.DIRECT_LEADER_CODE); if (!StringUtils.isEmpty(newLeaderTricode) && !originLeaderTricode.equals(newLeaderTricode)) { FieldSetEntity fseNewLeader = null; //新领导 String newLeaderCode = ""; String originLeaderCode = fse.getString(CmnConst.LEADER_TRICODE); if (!StringUtils.isEmpty(originLeaderTricode) && StringUtils.isEmpty(newLeaderTricode)) { //上级领导 有-->无 newLeaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, ""); } else { //上级领导 无-->有 或 旧-->新 fseNewLeader = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "tricode=?", new Object[]{newLeaderTricode}, false); newLeaderCode = codeService.createCode(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE, fseNewLeader.getString(CmnConst.LEADER_TRICODE)); } fse.setValue(CmnConst.LEADER_TRICODE, newLeaderCode); changeSubLeaderTricode(originLeaderCode, newLeaderCode); } // 修改staff表信息 flag = baseDao.update(fse); // luoxin 2020年12月25日 18:25:47 selectPersonnelService.updataGruopContent(fse.getString(CmnConst.DEPT_UUID), fse.getString("job_post_uuid"), fse.getString("uuid")); // xu pengcheng updateTime 2020年11月28日14:39:06 修改员工更新员工信息 updateLoginUserInfoService.updateUserInfoByUserId(user_id, 2, false); return flag; } /** * 变更后代leader_tricode编码 * * @param oldLeaderCode * @param newLeaderCode */ public void changeSubLeaderTricode(String oldLeaderCode, String newLeaderCode) { StringBuilder sql = new StringBuilder(); sql.append(" UPDATE product_sys_staffs "); sql.append(" SET leader_tricode=concat(replace(substring(leader_tricode,1,locate(?,leader_tricode)+length(?)),?,?),substring(leader_tricode,locate(?,leader_tricode)+length(?)+1)) "); sql.append(" WHERE leader_tricode LIKE ? "); baseDao.executeUpdate(sql.toString(), new Object[]{oldLeaderCode, oldLeaderCode, oldLeaderCode, newLeaderCode, oldLeaderCode, oldLeaderCode, oldLeaderCode + "%"}); DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, "tricode"); } /** * 变更后代leader_tricode编码 6c 2022年3月21日 16:42:31 * @param preLeaderTricode * @param newLeaderTricode */ private void updateSubLeaderTricode(String preLeaderTricode, String newLeaderTricode) { StringBuilder sql = new StringBuilder(128); sql.append("update product_sys_staffs set leader_tricode=concat(?,substring(leader_tricode,length(?)+1)) where leader_tricode like concat(?,'%') and leader_tricode<>?"); baseDao.executeUpdate(sql.toString(), new Object[]{newLeaderTricode, preLeaderTricode, preLeaderTricode, preLeaderTricode}); DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE); } /** * 员工账号冻结 * * @param user_id 登录用户user_id * @return * @throws BaseException */ public boolean staffFreezAccount(String user_id) throws BaseException { boolean flag = true; // 查找对应user表信息 FieldSetEntity fseUser = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?", new Object[]{user_id}, false); if (fseUser == null) { throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_USER_INFO_NO_EXIST.getText(), this.getClass(), "staffFreezAccount"); } fseUser.setValue(CmnConst.STATUS, 0); flag = baseDao.update(fseUser); return flag; } /** * 员工账号解冻 * * @param user_id 登录用户user_id * @return * @throws BaseException */ public boolean staffFreeAccount(String user_id) throws BaseException { boolean flag = true; // 查找对应user表信息 FieldSetEntity fseUser = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?", new Object[]{user_id}, false); if (fseUser == null) { throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_USER_INFO_NO_EXIST.getText(), this.getClass(), "staffFreezAccount"); } fseUser.setValue(CmnConst.STATUS, 1); flag = baseDao.update(fseUser); return flag; } /** * 员工删除 * * @param uuid 员工uuid * @return * @throws BaseException */ @Transactional public boolean deleteStaffInfo(String uuid) throws BaseException { // 处理地址 baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_ADDRESS, "staff_uuid=?", new String[]{uuid}); // 处理个人信息 baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO, "staff_uuid=?", new String[]{uuid}); // 处理银行信息 baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_BANK_ACCOUNT, "staff_uuid=?", new Object[]{uuid}); // 处理就业信息 baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_EMPLOYMENT_INFO, "staff_uuid=?", new Object[]{uuid}); // 处理联系人 baseDao.delete(CmnConst.PRODUCT_SYS_STAFF_EMERGENCY_CONTACT_INFO, "staff_uuid=?", new Object[]{uuid}); // 处理绑定成本中心 baseDao.delete("product_sys_staff_cost_center", "staff_uuid=?", new String[]{uuid}); // 处理员工文件信息 FieldSetEntity staff = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, uuid, false); if (staff != null && !StringUtils.isEmpty(staff.getString("staff_image"))) { String[] staff_images = staff.getString("staff_image").split(","); if (staff_images.length > 0) { for (int i = 0; i < staff_images.length; i++) { baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new Object[]{staff_images[i]}); } } } // 删除完成 return baseDao.delete(CmnConst.PRODUCT_SYS_STAFFS, "uuid=?", new String[]{uuid}); } /** * 员工重置密码 * * @param user_id 登录用户user_id * @return * @throws BaseException */ public boolean resetPassword(String user_id) throws BaseException { FieldSetEntity fse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_USERS, "user_id=?", new Object[]{user_id}, false); if (fse == null) { throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_USER_INFO_NO_EXIST.getText(), this.getClass(), "resetPassword"); } // 后端配置,重置密码模工=mail,则随机生成8位密码,发送到邮件,否则是默认初始密码 String passWord =com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL.equals(Global.getSystemConfig(com.product.admin.config.CmnConst.RESET_PWD_MODEL,com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL))? RandomStringUtils.randomAlphanumeric(8):Global.getSystemConfig(com.product.admin.config.CmnConst.INITIAL_PWD, null); // 加密默认密码 String pwd = userService.createPassWord(fse.getString(CmnConst.USER_ACCOUNT), passWord); fse.setValue(CmnConst.USER_PWD, pwd); if(com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL.equals(Global.getSystemConfig(com.product.admin.config.CmnConst.RESET_PWD_MODEL,com.product.admin.config.CmnConst.RESET_PWD_MODEL_MAIL))) { // 密码重置成功发送邮件(无模板,暂未调用) String login_url = URLEncoder.encode(Global.getSystemConfig("resetpwd.lxlogin_url", "")); FieldSetEntity nfs = new FieldSetEntity(); nfs.setTableName(com.product.admin.config.CmnConst.STAFF_EMAIL_CONTENT); nfs.setValue(com.product.admin.config.CmnConst.LOGIN_URL,login_url);// 登录页面 nfs.setValue(CmnConst.USER_ACCOUNT, fse.getString(CmnConst.USER_ACCOUNT));// 用户名 nfs.setValue(com.product.admin.config.CmnConst.PASS_WORD, passWord);// 随机新密码 nfs.setValue(com.product.admin.config.CmnConst.USER_PRIMARY_EMAIL, fse.getString(com.product.admin.config.CmnConst.USER_PRIMARY_EMAIL));// 接受邮件邮箱地址 sendEmailService.parseMailTemplate(com.product.admin.config.CmnConst.PLATFORM_ADMINISTRATOR_RESET_PASSWORD_EMAIL, nfs); } return baseDao.update(fse); } /** * 新增或修改员工个人信息,地址信息 * * @param fse * @return * @throws BaseException */ @Transactional public boolean staffPersonalAndAddress(FieldSetEntity fse) throws BaseException { DataTableEntity dtStaffPersonalInfo = fse.getSubDataTable(CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO); if (dtStaffPersonalInfo != null) { String brithTime = dtStaffPersonalInfo.getFieldSetEntity(0).getString("date_of_brith"); if (StringUtils.isEmpty(brithTime)) { // 杜洪波 updateTime 2020-12-17 09:48:00 dtStaffPersonalInfo.getFieldSetEntity(0).setValue("date_of_brith", null); } } return baseDao.update(fse, true); } /** * 新增或修改员工就业信息 * * @param fse * @return * @throws BaseException */ @Transactional public boolean staffEmploymentInfo(FieldSetEntity fse) throws BaseException { boolean flag = true; if (StringUtils.isEmpty(fse.getString(CmnConst.UUID))) { // 新增 fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); String uuid = baseDao.add(fse); if (StringUtils.isEmpty(uuid)) { return false; } } else { // 修改 fse.remove(CmnConst.CREATED_BY); fse.remove(CmnConst.CREATED_UTC_DATETIME); fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date()); flag = baseDao.update(fse); if (!flag) { throw new BaseException(SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getText(), this.getClass(), "staffEmploymentInfo"); } String employment_date = fse.getString("employment_date"); FieldSetEntity fseStaff = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, fse.getString(CmnConst.STAFF_UUID), false); if (fseStaff == null) { throw new BaseException(SystemCode.SYSTEM_STAFFS_FIND_FAIL.getValue(), SystemCode.SYSTEM_STAFFS_FIND_FAIL.getText(), this.getClass(), "staffEmploymentInfo"); } String user_id = fseStaff.getString(CmnConst.USER_ID); FieldSetEntity fs = baseDao.getFieldSetEntityByFilter("product_sys_staff_cost_center", "staff_uuid=?", new String[]{user_id}, false); if (fs != null) { fs.setValue("effective_start_date", employment_date); fs.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id()); fs.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date()); flag = baseDao.update(fs); if (!flag) { throw new BaseException(SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getValue(), SystemCode.SYSTEM_STAFF_EMPLOYMENT_UPDATE_FAIL.getText(), this.getClass(), "staffEmploymentInfo"); } } } return flag; } /** * 新增或修改人员银行信息 * * @param fse * @return * @throws BaseException */ @Transactional public boolean staffBankInfo(FieldSetEntity fse) throws BaseException { return baseDao.update(fse); } /** * 新增或修改紧急联系人信息 * * @param fse * @return * @throws BaseException */ @Transactional public boolean staffEmergencyContactInfo(FieldSetEntity fse) throws BaseException { return baseDao.update(fse); } /** * 员工属性列表 * * @param uuid 员工uuid * @return * @throws BaseException */ public JSONObject listStaffProperty(String staff_uuid, String user_id) throws BaseException { // 获取员工属性 DataTableEntity dtStaffProperty = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFF_PROPERTY, " staff_uuid=? ", new Object[]{user_id}); if (dtStaffProperty == null || dtStaffProperty.getRows() == 0) { // 生成员工属性 DataTableEntity dtStaffMaster = baseDao.listTable("product_sys_staff_property_master", null, new Object[]{}, new Object[]{"uuid", CmnConst.STAFF_PROPERTY_MASTER_CODE, CmnConst.PROMPT_NAME}); // 获取员工所属单位 FieldSetEntity fseStaffInfo = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, staff_uuid, false); String org_level_uuid = fseStaffInfo.getString(CmnConst.ORG_LEVEL_UUID); DataTableEntity dtNew = new DataTableEntity(); FieldMetaEntity fseMate = new FieldMetaEntity(); fseMate.setTableName(new Object[]{"product_sys_staff_property"}); for (int i = 0; i < dtStaffMaster.getRows(); i++) { FieldSetEntity fseMaster = dtStaffMaster.getFieldSetEntity(i); FieldSetEntity fseNew = new FieldSetEntity(); fseNew.setMeta(fseMate); fseNew.setValue(CmnConst.STAFF_UUID, user_id); fseNew.setValue(CmnConst.STAFF_PROPERTY_MASTER_UUID, fseMaster.getString("uuid")); fseNew.setValue(CmnConst.STAFF_PROPERTY_MASTER_CODE, fseMaster.getString(CmnConst.STAFF_PROPERTY_MASTER_CODE)); fseNew.setValue(CmnConst.ORG_LEVEL_UUID, org_level_uuid); dtNew.addFieldSetEntity(fseNew); } if (!BaseUtil.dataTableIsEmpty(dtNew)) { baseDao.add(dtNew); } } JSONObject jsonStaffProperty = new JSONObject(); StringBuilder sqlCommon = new StringBuilder(); sqlCommon.append(" SELECT "); sqlCommon.append( " d.staff_property_id,d.uuid,d.staff_uuid,e.uuid staff_property_master_uuid,e.staff_property_master_code,d.value,d.effective_utc_datetime,d.org_level_uuid,e.uuid, "); sqlCommon.append(" e.staff_property_master_name,e.prompt_name "); sqlCommon.append(" FROM ( "); sqlCommon.append(" SELECT "); sqlCommon.append( " a.staff_property_id,a.uuid,a.staff_uuid,a.staff_property_master_uuid,a.staff_property_master_code,a.value,a.effective_utc_datetime,a.org_level_uuid, "); sqlCommon.append( " CASE WHEN LOCATE( '|', a.staff_property_master_code) THEN REVERSE(SUBSTR(REVERSE(a.staff_property_master_code) FROM INSTR(REVERSE( a.staff_property_master_code ), '|' ) + 1 )) END AS parent_code "); sqlCommon.append(" FROM product_sys_staff_property AS a,( "); sqlCommon.append(" SELECT "); sqlCommon.append(" staff_property_master_uuid,MAX(effective_utc_datetime) AS effective_utc_datetime "); sqlCommon.append(" FROM product_sys_staff_property "); sqlCommon.append(" WHERE effective_utc_datetime <= NOW() AND staff_uuid = ? "); sqlCommon.append(" GROUP BY staff_property_master_uuid "); sqlCommon.append(" ) AS c "); sqlCommon.append( " WHERE a.staff_property_master_uuid = c.staff_property_master_uuid AND a.effective_utc_datetime = c.effective_utc_datetime AND a.staff_uuid = ? "); sqlCommon.append(" UNION ALL "); sqlCommon.append(" SELECT "); sqlCommon.append( " a.staff_property_id,a.uuid,a.staff_uuid,a.staff_property_master_uuid,a.staff_property_master_code,'',a.effective_utc_datetime,a.org_level_uuid, "); sqlCommon.append( " CASE WHEN LOCATE( '|', a.staff_property_master_code) THEN REVERSE(SUBSTR(REVERSE(a.staff_property_master_code) FROM INSTR(REVERSE( a.staff_property_master_code ), '|' ) + 1 )) END AS parent_code "); sqlCommon.append(" FROM product_sys_staff_property AS a,( "); sqlCommon.append(" SELECT "); sqlCommon.append(" staff_property_master_uuid,MIN(effective_utc_datetime) AS effective_utc_datetime "); sqlCommon.append(" FROM product_sys_staff_property "); sqlCommon.append(" WHERE staff_uuid= ? "); sqlCommon.append(" GROUP BY staff_property_master_uuid "); sqlCommon.append(" HAVING MIN(effective_utc_datetime) > NOW() "); sqlCommon.append(" ) AS c "); sqlCommon.append( " WHERE a.staff_property_master_uuid = c.staff_property_master_uuid AND a.effective_utc_datetime = c.effective_utc_datetime AND a.staff_uuid = ? "); sqlCommon.append(" UNION ALL "); sqlCommon.append(" SELECT "); sqlCommon.append( " a.staff_property_id,a.uuid,a.staff_uuid,a.staff_property_master_uuid,a.staff_property_master_code,'',a.effective_utc_datetime,a.org_level_uuid, "); sqlCommon.append( " CASE WHEN LOCATE( '|', a.staff_property_master_code) THEN REVERSE(SUBSTR(REVERSE(a.staff_property_master_code) FROM INSTR(REVERSE( a.staff_property_master_code ), '|' ) + 1 )) END AS parent_code "); sqlCommon.append(" FROM product_sys_staff_property AS a,( "); sqlCommon.append(" SELECT "); sqlCommon.append(" staff_property_master_uuid,staff_property_master_code "); sqlCommon.append(" FROM product_sys_staff_property "); sqlCommon.append(" WHERE staff_uuid= ? AND effective_utc_datetime IS NULL AND value IS NULL "); sqlCommon.append(" ) AS c "); sqlCommon.append(" WHERE a.staff_property_master_uuid = c.staff_property_master_uuid AND a.staff_uuid = ? "); sqlCommon.append(" ) AS d "); sqlCommon.append( " RIGHT JOIN product_sys_staff_property_master AS e ON d.staff_property_master_uuid = e.uuid AND d.staff_property_master_code=e.staff_property_master_code "); // 杜洪波 // updateTime // 2020-01-06 // 11:40:00 // 属性显示异常 String sqlParent = sqlCommon + " WHERE d.parent_code IS NULL ORDER BY e.sequence"; String sqlSub = sqlCommon + " WHERE d.parent_code IS NOT NULL ORDER BY e.sequence"; // 根属性 DataTableEntity dtParent = baseDao.listInternationDataTable(baseDao.listTable(sqlParent.toString(), new Object[]{user_id, user_id, user_id, user_id, user_id, user_id}), null); // 子属性 DataTableEntity dtSub = baseDao.listInternationDataTable(baseDao.listTable(sqlSub.toString(), new Object[]{user_id, user_id, user_id, user_id, user_id, user_id}), null); if (dtParent.getRows() > 0) { // 装载属性 JSONArray json = sysPropertyGroup(dtParent, dtSub); jsonStaffProperty.put(CmnConst.PRODUCT_SYS_STAFF_PROPERTY, json); } return jsonStaffProperty; } /** * 员工属性详情 * * @param staff_uuid 员工uuid * @param master_uuid 属性uuid * @return * @throws BaseException */ public DataTableEntity findStaffProperty(String staff_uuid, String master_uuid) throws BaseException { String sql = "select a.*,b.prompt_name FROM product_sys_staff_property a LEFT JOIN product_sys_staff_property_master b ON a.staff_property_master_code=b.staff_property_master_code where staff_uuid=? and staff_property_master_uuid=? "; return baseDao.listTable(sql, new Object[]{staff_uuid, master_uuid}); } /** * 员工属性组修改 * * @param fse * @return * @throws BaseException */ @Transactional public boolean updateStaffProperty(FieldSetEntity fse) throws BaseException { DataTableEntity dtStaffProperty = fse.getSubDataTable(CmnConst.PRODUCT_SYS_STAFF_PROPERTY); if (dtStaffProperty != null && dtStaffProperty.getRows() > 0) { int delCount = 0; int rowCount = dtStaffProperty.getRows(); for (int i = 0; i < rowCount; i++) { FieldSetEntity fseDefaultProperty = dtStaffProperty.getFieldSetEntity(i); String doMethod = fseDefaultProperty.getString("~type~"); if (doMethod != null && "del".equals(doMethod)) { delCount++; } } if (delCount == rowCount) { FieldSetEntity fseSaveDefaultProperty = dtStaffProperty.getFieldSetEntity(0); baseDao.executeUpdate( "update product_sys_staff_property set effective_utc_datetime = NULL,value=NULL where uuid=?", new Object[]{fseSaveDefaultProperty.getUUID()}); dtStaffProperty.removeFieldSetEntity(0); } if (dtStaffProperty.getRows() == 0) { return true; } else { return baseDao.update(dtStaffProperty); } } else { return true; } } /** * 员工个人信息详情 * * @param staff_uuid * @return * @throws BaseException */ public FieldSetEntity findStaffPersonalInfo(String staff_uuid) throws BaseException { FieldSetEntity fseStaffPersonal = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFF_PERSONAL_INFO, "staff_uuid=?", new Object[]{staff_uuid}, false); if (fseStaffPersonal == null) { return null; } String sql = "select *,case when effective_start_date mapStaffAddress = new HashMap(); mapStaffAddress.put(CmnConst.PRODUCT_SYS_STAFF_ADDRESS, dtStaffAddress); if (!mapStaffAddress.isEmpty()) { fseStaffPersonal.setSubData(mapStaffAddress); } return fseStaffPersonal; } /** * 员工地址详情 * * @param uuid * @return * @throws BaseException */ public FieldSetEntity findStaffAddressInfo(String uuid) throws BaseException { return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_ADDRESS, uuid, false); } /** * 员工就业信息详情 * * @param staff_uuid * @return * @throws BaseException */ public FieldSetEntity findStaffEmploymentInfo(String staff_uuid) throws BaseException { return baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFF_EMPLOYMENT_INFO, "staff_uuid=?", new Object[]{staff_uuid}, false); } /** * 员工银行信息列表 * * @param staff_uuid * @return * @throws BaseException */ public DataTableEntity listStaffBankInfo(String staff_uuid) throws BaseException { return baseDao.listTable(CmnConst.PRODUCT_SYS_STAFF_BANK_ACCOUNT, "staff_uuid=?", new Object[]{staff_uuid}); } /** * 员工银行详情 * * @param uuid * @return * @throws BaseException */ public FieldSetEntity findStaffBankInfo(String uuid) throws BaseException { return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_BANK_ACCOUNT, uuid, false); } /** * 员工紧急联系人列表 * * @param staff_uuid * @return * @throws BaseException */ public DataTableEntity listStaffEmergencyContactInfo(String staff_uuid) throws BaseException { return baseDao.listTable(CmnConst.PRODUCT_SYS_STAFF_EMERGENCY_CONTACT_INFO, "staff_uuid=?", new Object[]{staff_uuid}); } /** * 员工紧急联系人详情 * * @param uuid * @return * @throws BaseException */ public FieldSetEntity findStaffEmergencyContactInfo(String uuid) throws BaseException { return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_EMERGENCY_CONTACT_INFO, uuid, false); } /** * 员工属性封装 * * @param dataParent 根属性 * @param dataSub 子属性 * @return * @throws BaseException */ public JSONArray sysPropertyGroup(DataTableEntity dataParent, DataTableEntity dataSub) throws BaseException { JSONArray propertyArray = new JSONArray(); // 遍历根属性 for (int i = 0; i < dataParent.getRows(); i++) { JSONObject sysProperty = new JSONObject(); FieldSetEntity fs = dataParent.getFieldSetEntity(i); if (!StringUtils.isEmpty(fs.getString(CmnConst.STAFF_PROPERTY_MASTER_CODE))) { // 杜洪波 updateTime 2020-12-17 // 09:48:00 sysProperty.put(CmnConst.DATA_TYPE, dataParent.getString(i, CmnConst.DATA_TYPE)); // 数据类型 sysProperty.put(CmnConst.VALUE, dataParent.getString(i, CmnConst.VALUE)); // 默认值 sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_UUID, dataParent.getString(i, CmnConst.STAFF_PROPERTY_MASTER_UUID)); // uuid sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_CODE, dataParent.getString(i, CmnConst.STAFF_PROPERTY_MASTER_CODE)); // 编码code sysProperty.put(CmnConst.PARENT_CODE, dataParent.getString(i, CmnConst.PARENT_CODE)); // 父级编码code sysProperty.put(CmnConst.PROMPT_NAME, dataParent.getString(i, CmnConst.PROMPT_NAME)); // 参照名 sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_NAME, getPropertyNameLanguage(fs.getSubDataTable(CmnConst.STAFF_PROPERTY_MASTER_NAME))); // 属性名称 // 获取当前根属性的子属性 JSONArray moduleChild = sysPropertyGroupSub(dataSub, fs.getString(CmnConst.STAFF_PROPERTY_MASTER_CODE)); sysProperty.put("children", moduleChild); propertyArray.add(sysProperty); } } return propertyArray; } /** * 员工子属性封装 * * @param data * @param tricode_parent 父级属性节点编码 * @return * @throws BaseException */ public JSONArray sysPropertyGroupSub(DataTableEntity dataSub, String tricode_parent) throws BaseException { JSONArray propertyArray = new JSONArray(); // 遍历子属性 for (int i = 0; i < dataSub.getRows(); i++) { JSONObject sysProperty = new JSONObject(); FieldSetEntity fs = dataSub.getFieldSetEntity(i); // 匹配子属性 if (tricode_parent.equals(dataSub.getString(i, CmnConst.PARENT_CODE))) { // 装载属性 sysProperty.put(CmnConst.DATA_TYPE, dataSub.getString(i, CmnConst.DATA_TYPE)); // 数据类型 sysProperty.put(CmnConst.VALUE, dataSub.getString(i, CmnConst.VALUE)); sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_UUID, dataSub.getString(i, CmnConst.STAFF_PROPERTY_MASTER_UUID)); // uuid sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_CODE, dataSub.getString(i, CmnConst.STAFF_PROPERTY_MASTER_CODE)); // 属性编码 sysProperty.put(CmnConst.PARENT_CODE, dataSub.getString(i, CmnConst.PARENT_CODE)); // 父级属性编码 sysProperty.put(CmnConst.PROMPT_NAME, dataSub.getString(i, CmnConst.PROMPT_NAME)); // 参照名 sysProperty.put(CmnConst.STAFF_PROPERTY_MASTER_NAME, getPropertyNameLanguage(fs.getSubDataTable(CmnConst.STAFF_PROPERTY_MASTER_NAME))); // 属性名称 JSONArray jsonSub = sysPropertyGroupSub(dataSub, dataSub.getString(i, CmnConst.STAFF_PROPERTY_MASTER_CODE)); if (!jsonSub.isEmpty()) { sysProperty.put("children", jsonSub); } propertyArray.add(sysProperty); } } return propertyArray; } /** * 封装系统属性名称国际化 * * @return * @throws BaseException */ public List getPropertyNameLanguage(DataTableEntity dtPropertyLanguage) throws BaseException { List listPropertyName = new ArrayList(); if (dtPropertyLanguage != null && dtPropertyLanguage.getRows() > 0) { // 遍历获取语言代码和国际化值 FieldMetaEntity meta = dtPropertyLanguage.getMeta(); Object[] fields12 = meta.getFields(); List asList = new ArrayList<>(); asList.addAll(Arrays.asList(fields12)); Iterator iterator = asList.iterator(); for (int i = 0; i < dtPropertyLanguage.getRows(); i++) { while (iterator.hasNext()) { Object next = iterator.next(); if (!next.toString().equals("uuid") && !next.toString().equals("language_code")) { String string = dtPropertyLanguage.getString(i, next.toString()); if (!StringUtils.isEmpty(string)) { JSONObject propertyName = new JSONObject(); propertyName.put(next.toString(), string); listPropertyName.add(propertyName); iterator.remove(); break; } } else { iterator.remove(); } } } } return listPropertyName; } /** * 获取指定人员的所有直接下属 * * @param staffUuid */ public DataTableEntity loadDirectSubordinate(String staffUuid) throws BaseException { if (StringUtil.isBlank(staffUuid)) { return null; } return baseDao.listTable( "select * FROM product_sys_staffs where direct_leader_code=(select tricode FROM product_sys_staffs where uuid=? ) and direct_leader_code is not null", new String[]{staffUuid}); } /** * 获取指定人员的所有直接下属 * * @param user_id用户id */ public DataTableEntity loadDirectSubordinate(int user_id) throws BaseException { return baseDao.listTable( "select * FROM product_sys_staffs where direct_leader_code=(select tricode FROM product_sys_staffs where user_id=? ) and direct_leader_code is not null", new Object[]{user_id}); } /** * 获取指定人员的所有直接下属 * * @param staffUuid */ public DataTableEntity loadAllSubordinate(String staffUuid) throws BaseException { if (StringUtil.isBlank(staffUuid)) { return null; } FieldSetEntity fs = baseDao.getFieldSetEntity("product_sys_staffs", staffUuid, false); return loadAllSubordinate(fs); } /** * 获取指定人员的所有下属 * * @param user_id用户id */ public DataTableEntity loadAllSubordinate(int user_id) throws BaseException { FieldSetEntity fs = baseDao.getFieldSetEntityByFilter("product_sys_staffs", "user_id=?", new Object[]{user_id}, false); return loadAllSubordinate(fs); } /** * 获取指定人员的所有下属 * * @param fs staff */ public DataTableEntity loadAllSubordinate(FieldSetEntity fs) throws BaseException { if (fs == null || StringUtils.isEmpty(fs.getString(CmnConst.LEADER_TRICODE))) { return null; } // DataTableEntity c=baseDao.listTable("select getChildrenOrg('"+fs.getString(CmnConst.TRICODE)+"') a", new String[] {}); String sql = "select tricode uuid FROM product_sys_staffs where leader_tricode like ? AND leader_tricode !=?"; DataTableEntity c = baseDao.listTable(sql, new Object[]{fs.getString(CmnConst.LEADER_TRICODE) + "%", fs.getString(CmnConst.LEADER_TRICODE)}); Object[] uuid = c.getUuids(); if (c != null && c.getRows() > 0 && uuid != null) { // String b=c.getString(0,"a"); String b = org.apache.commons.lang3.StringUtils.join(uuid, ","); Object vs[] = BaseUtil.buildQuestionMarkFilter(" tricode ", " in ", b); if (vs != null && vs.length > 1 && vs[1] != null) { String filter = vs[0].toString(); List paras = (List) vs[1]; return baseDao.listTable("product_sys_staffs", filter, paras.toArray()); } } return null; } /** * 根据 staffUUID获取人员的直属领导 * * @param staffUuid 员工uuid * @throws BaseException 通用查询错误 * @return"product_sys_staffs的记录,没有查到则为null */ public FieldSetEntity loadStaffLeader(String staffUuid) throws BaseException { if (!StringUtil.isBlank(staffUuid)) { String sql = "select * FROM product_sys_staffs where tricode=(select DISTINCT direct_leader_code FROM product_sys_staffs where uuid=? and direct_leader_code is not null )"; DataTableEntity dt = baseDao.listTable(sql, new String[]{staffUuid}); if (dt.getRows() > 0) { return dt.getFieldSetEntity(0); } } return null; } /** * 获取人员的直属领导 * * @param userid"product_sys_user表id * @throws BaseException 通用查询错误 * @return"product_sys_staffs的记录,没有查到则为null */ public FieldSetEntity loadStaffLeader(Integer userid) throws BaseException { if (userid != null) { String sql = "select * FROM product_sys_staffs where tricode=(select DISTINCT direct_leader_code FROM product_sys_staffs where user_id=? and direct_leader_code is not null )"; DataTableEntity dt = baseDao.listTable(sql, new Integer[]{userid}); if (dt.getRows() > 0) { return dt.getFieldSetEntity(0); } } return null; } /** * 员工信息列表 * * @param fse * @return * @throws BaseException */ public DataTableEntity findStaffByCondition(FieldSetEntity fse) throws BaseException { StringBuilder sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.uuid, "); sql.append(" b.uuid, "); sql.append(" c.uuid, "); sql.append(" d.uuid, "); sql.append(" e.uuid, "); sql.append(" f.uuid, "); sql.append(" a.user_id, "); sql.append(" a.show_name, "); sql.append(" a.staff_code, "); sql.append(" a.staff_email, "); sql.append(" a.staff_status, "); sql.append(" "); sql.append(" a.christian_name, "); sql.append(" a.role_uuids, "); sql.append(" a.org_level_uuid, "); sql.append(" a.dept_uuid, "); sql.append(" a.staff_id, "); sql.append(" a.job_post_uuid, "); sql.append(" a.job_post_grade_uuid, "); sql.append( " (select uuid FROM product_sys_staffs where tricode=a.direct_leader_code AND tricode !=NULL) direct_leader_code, "); sql.append(" a.cost_center_uuid, "); sql.append(" a.entry_datetime, "); sql.append(" b.org_level_all org_level, "); sql.append(" h.org_level_all client_and_org, "); sql.append(" h.org_level_name dept_name, "); sql.append(" c.STATUS, "); sql.append(" d.job_post_name,e.job_grade_name, "); sql.append(" f.client_name,b.org_level_all"); sql.append( " ,concat(g.attachment_domain,'/',g.attachment_container,'/',g.module_uuid,'/',g.attachment_title,?) staff_avatar "); sql.append(" FROM "); sql.append(" product_sys_staffs AS a "); sql.append(" LEFT JOIN product_sys_org_levels b ON a.org_level_uuid = b.uuid "); sql.append(" LEFT JOIN product_sys_org_levels h ON a.dept_uuid = h.uuid "); sql.append(" LEFT JOIN product_sys_users c ON a.user_id = c.user_id "); sql.append(" LEFT JOIN product_sys_job_posts d ON a.job_post_uuid = d.uuid "); sql.append(" LEFT JOIN product_sys_job_post_grades e ON a.job_post_grade_uuid = e.uuid "); sql.append(" LEFT JOIN product_sys_clients f ON a.client_uuid = f.uuid "); sql.append(" LEFT JOIN product_sys_attachments g ON g.uuid = a.staff_avatar "); sql.append( " WHERE (a.org_level_uuid =? or ?=(SELECT uuid FROM product_sys_org_levels WHERE uuid='00000000-0000-0000-0000-000000000000'))"); String org_level_uuid = fse.getString(CmnConst.ORG_LEVEL_UUID); List params = new ArrayList<>(); params.add(Global.getSystemConfig("upload.key", "")); params.add(org_level_uuid); params.add(org_level_uuid); // luoxin 2020年12月14日 17:13:24 修改in 查询条件 if (!StringUtils.isEmpty(fse.getObject(CmnConst.FILTER))) { // 杜洪波 updateTime 2020-12-17 09:48:00 sql = sql.append("and staff_status in(?"); Object[] condition = fse.getString(CmnConst.FILTER).split(","); for (int i = 1; i < condition.length; i++) { sql.append(" ,?"); } sql.append(")"); params.addAll(Arrays.asList(condition)); } if (!StringUtils.isEmpty(fse.getString("notfilter"))) { // 杜洪波 updateTime 2020-12-17 09:48:00 String notfilter = fse.getString("notfilter"); String[] notfilterArr = notfilter.split(","); sql.append(" and a.uuid not in ("); List list = new ArrayList(); for (int i = 0; i < notfilterArr.length; i++) { list.add("?"); params.add(notfilterArr[i]); } String join = StringUtils.join(list.toArray(), ","); sql.append(join); sql.append(")"); } String key = fse.getString("key"); String value = fse.getString("value"); if (!(StringUtils.isEmpty(key) || StringUtils.isEmpty(value))) { String[] valueArray = value.split(","); if (!StringUtils.isArrayEmpty(valueArray)) { sql.append(" OR ").append(BaseUtil.buildQuestionMarkFilter("a." + key, valueArray.length, true)); params.addAll(Arrays.asList(valueArray)); } } DataTableEntity dt = baseDao.listTable(sql.toString(), params.toArray()); dt.getMeta().addAliasField("product_sys_staffs.show_name", "show_name"); dt.getMeta().addAliasField("product_sys_job_posts.job_post_name", "job_post_name"); dt.getMeta().addAliasField("product_sys_job_post_grades.job_grade_name", "job_grade_name"); dt.getMeta().addAliasField("product_sys_clients.client_name", "client_name"); dt.getMeta().addAliasField("product_sys_org_levels.org_level_all", CmnConst.ORG_LEVEL_ALL); return baseDao.listInternationDataTable(dt, null); // staff_avatar // String sostoken = Global.getSystemConfig("upload.key", ""); // if (listStaffInfo.getRows() > 0) { // for (int i = 0; i < listStaffInfo.getRows(); i++) { // FieldSetEntity staff = listStaffInfo.getFieldSetEntity(i); // if (!StringUtils.isEmpty(staff.getString(CmnConst.STAFF_AVATAR))) { // FieldSetEntity staff_avatar=baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ATTACHMENTS, "uuid=?", new String[]{staff.getString(CmnConst.STAFF_AVATAR)}, false); // Map avatar = new HashMap(); // avatar.put("path", staff_avatar.getString("attachment_domain") + "/" // + staff_avatar.getString("attachment_container") + "/" // + staff_avatar.getString("module_uuid") + "/" // + staff_avatar.getString(CmnConst.ATTACHMENT_TITLE) + sostoken); // avatar.put("name", staff_avatar.getString(CmnConst.ATTACHMENT_TITLE)); // avatar.put("size", staff_avatar.getString("attachment_size")); // avatar.put("uuid", staff_avatar.getString("uuid")); // avatar.put(CmnConst.FIEL_NAME, staff_avatar.getString(CmnConst.FIEL_NAME)); // staff.setValue(CmnConst.STAFF_AVATAR,avatar); // } else { // Map avatar = new HashMap(); // avatar.put("path", ""); // avatar.put("name", ""); // avatar.put("size", ""); // avatar.put("uuid", ""); // avatar.put(CmnConst.FIEL_NAME, ""); // staff.setValue(CmnConst.STAFF_AVATAR,avatar); // } // } // } // // return listStaffInfo; } /** * 根据staff_uuid获取员工上司和角色 * * @param fse * @return * @throws BaseException */ public DataTableEntity findStaffBossAndRole(FieldSetEntity fse) throws BaseException { String filter = fse.getString(CmnConst.FILTER); StringBuilder sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.uuid uuid, "); sql.append(" b.uuid uuid1, "); sql.append(" c.uuid uuid2, "); sql.append(" d.uuid uuid3, "); sql.append(" e.uuid uuid4, "); sql.append(" f.uuid uuid5, "); sql.append(" a.user_id, "); sql.append(" a.show_name, "); sql.append(" a.staff_code, "); sql.append(" a.client_uuid, "); sql.append(" a.org_level_uuid, "); sql.append(" a.dept_uuid, "); sql.append(" a.job_post_uuid, "); sql.append(" a.job_post_grade_uuid, "); if (!StringUtils.isEmpty(filter) && (filter.indexOf("-update") > -1 || filter.indexOf("add") > -1)) { // 杜洪波 // updateTime // 2020-12-17 // 09:48:00 sql.append(" a.role_uuids, "); sql.append(" a.direct_leader_code, "); sql.append(" a.cost_center_uuid, "); } sql.append(" c.STATUS "); sql.append(" FROM "); sql.append(" product_sys_staffs AS a "); sql.append(" LEFT JOIN product_sys_org_levels b ON a.org_level_uuid = b.uuid "); sql.append(" LEFT JOIN product_sys_users c ON a.user_id = c.user_id "); sql.append(" LEFT JOIN product_sys_job_posts d ON a.job_post_uuid = d.uuid "); sql.append(" LEFT JOIN product_sys_job_post_grades e ON a.job_post_grade_uuid = e.uuid "); sql.append(" LEFT JOIN product_sys_clients f ON a.client_uuid = f.uuid "); String org_level_uuid = fse.getString(CmnConst.ORG_LEVEL_UUID); sql.append(" WHERE (a.org_level_uuid ='" + org_level_uuid + "' or '" + org_level_uuid + "'=(SELECT uuid FROM product_sys_org_levels WHERE uuid='00000000-0000-0000-0000-000000000000'))"); if (!StringUtils.isEmpty(filter)) { // 杜洪波 updateTime 2020-12-17 09:48:00 sql.append(sqlFilter(filter)); } DataTableEntity listStaffInfo = baseDao.listTable(sql.toString(), new String[]{}); if (listStaffInfo != null && listStaffInfo.getRows() > 0) { baseDao.listInternationDataTable(listStaffInfo, null); baseDao.loadPromptData(listStaffInfo); } return listStaffInfo; } public FieldSetEntity findStaffDataByUUID(String staff_uuid) throws BaseException { return baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, staff_uuid, false); } /** * 通用查询过滤条件 * * @param filter * @return */ public String sqlFilter(String filter) { // 杜洪波 2020年12月15日 16:52:09 if ("StaffDimission-add".equals(filter)) { filter = " and a.staff_status in (0,1,2,3) and a.uuid not in (select apply_staff_uuid FROM product_sys_staff_termination where (result_status=1 or result_status=0))"; } else if ("StaffChange-add".equals(filter)) { filter = " and a.staff_status in (0,1,2,3) and a.uuid not in (select staff_uuid FROM product_sys_staff_movement where (result_status=0 or result_status=1))"; } else if (filter.contains("StaffDimission-update") || filter.contains("StaffChange-update")) { filter = " and a.uuid = '" + filter.substring(filter.lastIndexOf("&") + 1, filter.length()) + "'"; } else if ("SelectPersonnel-TheDeparture".equals(filter)) { filter = " and a.staff_status in (0,1,2,3,4,5)"; } else { filter = ""; } return filter; } /** * 员工头像修改 * * @param fse * @return * @throws BaseException */ @Transactional public boolean uploadStaffavatar(FieldSetEntity fse) throws BaseException { SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); if (currentUser != null) { int user_id = currentUser.getUser_id(); baseDao.executeUpdate("UPDATE product_sys_users SET thumbnail_img=? WHERE user_id=?", new Object[]{fse.getString(CmnConst.THUMBNSIL_IMG), user_id}); FieldSetEntity fseStaff = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFFS, "user_id=?", new Object[]{user_id}, false); if (fseStaff != null) { baseDao.executeUpdate("UPDATE product_sys_staffs SET staff_avatar=? WHERE user_id=?", new Object[]{fse.getString(CmnConst.THUMBNSIL_IMG), user_id}); } } else { throw new BaseException(SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_USER_INFO_NO_EXIST.getValue(), this.getClass(), "uploadStaffavatar"); } if (!StringUtils.isEmpty(fse.getString("del"))) { String[] dels = fse.getString("del").split(","); if (dels.length > 0) { for (int i = 0; i < dels.length; i++) { baseDao.delete(CmnConst.PRODUCT_SYS_ATTACHMENTS, new Object[]{dels[i]}); } } } return true; } /** * 获取公司所有部门+所有人员+搜索 * * @param fse * @return * @throws BaseException */ public List> listCompanyStaffs(FieldSetEntity fse, Object client_type, Object language_code) throws BaseException { // 查询所有指定组织机构下的组织机构 DataTableEntity coms = baseDao.listTable( "select * FROM product_sys_org_levels where org_level_code like CONCAT((select org_level_code FROM product_sys_org_levels where uuid=?),'%') order by org_level_code", new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)}); if (coms == null || coms.getRows() == 0) { return new ArrayList>(); } // 国际化 baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); // 查询所有指定组织机构下的所有人员 StringBuilder sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.uuid, "); sql.append(" user_id staff_id, "); sql.append(" tricode, "); sql.append(" preferred_name, "); sql.append( " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) "); sql.append(" staff_avatar, "); sql.append(" a.client_uuid, "); sql.append(" a.org_level_uuid, "); sql.append(" a.dept_uuid, "); sql.append(" a.staff_code, "); sql.append(" job_post_uuid, "); sql.append(" staff_status, "); sql.append(" job_post_name, "); sql.append(" b.uuid uuid1 "); sql.append(" FROM "); sql.append(" product_sys_staffs a "); sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid "); sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid "); sql.append(" WHERE "); sql.append(" staff_status <= 5 "); sql.append( " AND tricode LIKE CONCAT( ( SELECT org_level_code FROM product_sys_org_levels WHERE uuid = ? ), '%' ) "); DataTableEntity staffs = baseDao.listTable(sql.toString(), new Object[]{Global.getSystemConfig("upload.key", ""), fse.getString(CmnConst.ORG_LEVEL_UUID)}); if (staffs != null && staffs.getRows() > 0) { staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1"); // 国际化 baseDao.listInternationDataTable(staffs, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); } return convertOrgStaffInternation(coms, staffs); } /** * 获取当前人的可代理人 * * @param fse * @param userUuid 指定用户 * @param functionUuid 指定功能 * @param client_type 客户端类型 * @param language_code 语言编码 * @return * @throws BaseException */ public List> listAgentStaffs(FieldSetEntity fse, String staffUuid, String functionUuid, Object client_type, Object language_code) throws BaseException { // 查询所有指定组织机构下的所有人员 StringBuilder sql = new StringBuilder(); DataTableEntity staffs = new DataTableEntity(); if (!StringUtils.isEmpty(staffUuid)) { if (CmnConst.STAFF_TYPE_PRINCIPAL.equals(fse.getString(CmnConst.STAFF_TYPE))) //被代理人员 { sql.append(" SELECT distinct a.on_behalf_staff_uuid FROM product_sys_apply_on_behalf a left join product_sys_apply_on_behalf_details b on a.uuid=b.apply_on_behalf_uuid where concat(',',b.on_behalf_staff_uuid,',') like ? and now() BETWEEN a.effective_utc_start_date and a.effective_utc_end_date"); staffUuid = "%," + staffUuid + ",%"; } else { //代理人员 sql.append(" SELECT distinct b.on_behalf_staff_uuid FROM product_sys_apply_on_behalf a left join product_sys_apply_on_behalf_details b on a.uuid=b.apply_on_behalf_uuid where a.on_behalf_staff_uuid=? and now() BETWEEN a.effective_utc_start_date and a.effective_utc_end_date"); } Object ps[] = new Object[]{staffUuid}; if (!StringUtils.isEmpty(functionUuid)) { Object vs[] = BaseUtil.buildQuestionMarkFilter(" function_uuid ", " in ", functionUuid); if (vs != null && vs.length > 1 && vs[1] != null) { String filter = vs[0].toString(); List paras = (List) vs[1]; if (!StringUtils.isEmpty(filter) && paras.size() > 0) { sql.append(" and ").append(filter); paras.add(0, staffUuid); ps = paras.toArray(); } } } staffs = baseDao.listTable(sql.toString(), ps); StringBuilder v = new StringBuilder(); for (int i = 0; i < staffs.getRows(); i++) { if (v.length() > 0) { v.append(","); } v.append(staffs.getString(i, "on_behalf_staff_uuid")); } Object vs[] = BaseUtil.buildQuestionMarkFilter(" a.uuid ", " in ", v.toString()); if (vs != null && vs.length > 1 && vs[1] != null) { String filter = vs[0].toString(); List paras = (List) vs[1]; if (!StringUtils.isEmpty(filter) && paras.size() > 0) { // 查询所有指定组织机构下的所有人员 sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.uuid, "); sql.append(" user_id staff_id, "); sql.append(" tricode, "); sql.append(" preferred_name, "); sql.append( " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) "); sql.append(" staff_avatar, "); sql.append(" a.client_uuid, "); sql.append(" a.org_level_uuid, "); sql.append(" a.staff_code, "); sql.append(" a.dept_uuid, "); sql.append(" job_post_uuid, "); sql.append(" staff_status, "); sql.append(" job_post_name, "); sql.append(" b.uuid uuid1 "); sql.append(" FROM "); sql.append(" product_sys_staffs a "); sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid "); sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid "); sql.append(" WHERE "); sql.append(" staff_status <= 5 "); sql.append(" and ").append(filter); paras.add(0, Global.getSystemConfig("upload.key", "")); staffs = baseDao.listTable(sql.toString(), paras.toArray()); } } } Map org_level_uuids = new HashMap<>(); List uuids = new ArrayList<>(); StringBuilder b = new StringBuilder(); if (staffs != null && staffs.getRows() > 0) { staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1"); // 国际化 baseDao.listInternationDataTable(staffs, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); b.append(" uuid in ("); for (int i = 0; i < staffs.getRows(); i++) { if (org_level_uuids.get(staffs.getString(i, "dept_uuid")) == null) { org_level_uuids.put(staffs.getString(i, "dept_uuid"), staffs.getString(i, "dept_uuid")); if (uuids.size() > 0) { b.append(","); } b.append("?"); uuids.add(staffs.getString(i, "dept_uuid")); } } b.append(")"); } DataTableEntity coms = null; if (!uuids.isEmpty()) { // 查询所有指定组织机构下的组织机构 coms = baseDao.listTable("product_sys_org_levels", b.toString(), uuids.toArray()); // 国际化 baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); } if (coms == null || coms.getRows() == 0) { return new ArrayList<>(); } else { Map code = new HashMap<>(); for (int i = 0; i < coms.getRows(); i++) { getParentCode(coms.getString(i, "org_level_code"), code); } b.delete(0, b.length()); for (Object key : code.keySet()) { if (b.length() > 0) { b.append(","); } b.append("?"); } b.insert(0, " org_level_code in ("); b.append(")"); coms = baseDao.listTable("product_sys_org_levels", b.toString(), code.keySet().toArray()); } return convertOrgStaffInternation(coms, staffs); } /** * 获取当前人的直接下属 * * @param fse * @param userUuid 指定用户 * @param functionUuid 指定功能 * @param client_type 客户端类型 * @param language_code 语言编码 * @return * @throws BaseException */ public List> listDirectSubordinateStaffs(String staffUuid, Object client_type, Object language_code) throws BaseException { // 查询所有指定组织机构下的所有人员 StringBuilder sql = new StringBuilder(); DataTableEntity staffs = new DataTableEntity(); if (!StringUtils.isEmpty(staffUuid)) { // 查询所有指定组织机构下的所有人员 sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.uuid, "); sql.append(" user_id staff_id, "); sql.append(" tricode, "); sql.append(" preferred_name, "); sql.append( " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) "); sql.append(" staff_avatar, "); sql.append(" a.client_uuid, "); sql.append(" a.org_level_uuid, "); sql.append(" a.dept_uuid, "); sql.append(" a.staff_code, "); sql.append(" job_post_uuid, "); sql.append(" staff_status, "); sql.append(" job_post_name, "); sql.append(" b.uuid uuid1 "); sql.append(" FROM "); sql.append(" product_sys_staffs a "); sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid "); sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid "); sql.append(" WHERE "); sql.append(" staff_status <= 5 "); sql.append(" and a.direct_leader_code=(select tricode FROM product_sys_staffs where uuid=? ) and a.direct_leader_code is not null "); staffs = baseDao.listTable(sql.toString(), new Object[]{Global.getSystemConfig("upload.key", ""), staffUuid}); } Map org_level_uuids = new HashMap<>(); List uuids = new ArrayList<>(); StringBuilder b = new StringBuilder(); if (staffs != null && staffs.getRows() > 0) { staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1"); // 国际化 baseDao.listInternationDataTable(staffs, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); b.append(" uuid in ("); for (int i = 0; i < staffs.getRows(); i++) { if (org_level_uuids.get(staffs.getString(i, "org_level_uuid")) == null) { org_level_uuids.put(staffs.getString(i, "org_level_uuid"), staffs.getString(i, "org_level_uuid")); if (uuids.size() > 0) { b.append(","); } b.append("?"); uuids.add(staffs.getString(i, "org_level_uuid")); } if (org_level_uuids.get(staffs.getString(i, "dept_uuid")) == null) { org_level_uuids.put(staffs.getString(i, "dept_uuid"), staffs.getString(i, "dept_uuid")); if (uuids.size() > 0) { b.append(","); } b.append("?"); uuids.add(staffs.getString(i, "dept_uuid")); } } b.append(")"); } DataTableEntity coms = null; if (!uuids.isEmpty()) { // 查询所有指定组织机构下的组织机构 coms = baseDao.listTable("product_sys_org_levels", b.toString(), uuids.toArray()); // 国际化 baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); } if (coms == null || coms.getRows() == 0) { return new ArrayList<>(); } else { Map code = new HashMap<>(); for (int i = 0; i < coms.getRows(); i++) { getParentCode(coms.getString(i, "org_level_code"), code); } b.delete(0, b.length()); for (Object key : code.keySet()) { if (b.length() > 0) { b.append(","); } b.append("?"); } b.insert(0, " org_level_code in ("); b.append(")"); coms = baseDao.listTable("product_sys_org_levels", b.toString(), code.keySet().toArray()); } return convertOrgStaffInternation(coms, staffs); } /** * 获取当前人的所有下属 * * @param fse * @param userUuid 指定用户 * @param functionUuid 指定功能 * @param client_type 客户端类型 * @param language_code 语言编码 * @return * @throws BaseException */ public List> listAllSubordinateStaffs(String staffCode, Object client_type, Object language_code) throws BaseException { // 查询所有指定组织机构下的所有人员 StringBuilder sql = new StringBuilder(); DataTableEntity staffs = new DataTableEntity(); if (!StringUtils.isEmpty(staffCode)) { sql.append("select tricode uuid FROM product_sys_staffs where leader_tricode like '"); sql.append(staffCode); sql.append("%'"); sql.append(" AND leader_tricode !=?"); DataTableEntity c = baseDao.listTable(sql.toString(), new String[]{staffCode}); String b = staffCode; Object[] uuid = c.getUuids(); if (c != null && c.getRows() > 0 && uuid != null) { b = org.apache.commons.lang3.StringUtils.join(uuid, ","); } Object vs[] = BaseUtil.buildQuestionMarkFilter(" a.tricode ", " in ", b); if (vs != null && vs.length > 1 && vs[1] != null) { String filter = vs[0].toString(); List paras = (List) vs[1]; // 查询所有指定组织机构下的所有人员 sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.uuid, "); sql.append(" user_id staff_id, "); sql.append(" tricode, "); sql.append(" preferred_name, "); sql.append( " concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) "); sql.append(" staff_avatar, "); sql.append(" a.client_uuid, "); sql.append(" a.org_level_uuid, "); sql.append(" a.dept_uuid, "); sql.append(" job_post_uuid, "); sql.append(" a.staff_code, "); sql.append(" staff_status, "); sql.append(" job_post_name, "); sql.append(" b.uuid uuid1 "); sql.append(" FROM "); sql.append(" product_sys_staffs a "); sql.append(" JOIN product_sys_job_posts b ON a.job_post_uuid = b.uuid "); sql.append(" left join product_sys_attachments c on a.staff_avatar=c.uuid "); sql.append(" WHERE "); sql.append(" staff_status <= 5 "); sql.append(" and a.tricode <>? "); sql.append(" and ").append(filter); paras.add(0, staffCode); paras.add(0, Global.getSystemConfig("upload.key", "")); staffs = baseDao.listTable(sql.toString(), paras.toArray()); } } Map org_level_uuids = new HashMap<>(); List uuids = new ArrayList<>(); StringBuilder b = new StringBuilder(); if (staffs != null && staffs.getRows() > 0) { staffs.getMeta().addAliasField("product_sys_job_posts.uuid", "uuid1"); // 国际化 baseDao.listInternationDataTable(staffs, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); b.append(" uuid in ("); for (int i = 0; i < staffs.getRows(); i++) { if (org_level_uuids.get(staffs.getString(i, "org_level_uuid")) == null) { org_level_uuids.put(staffs.getString(i, "org_level_uuid"), staffs.getString(i, "org_level_uuid")); if (uuids.size() > 0) { b.append(","); } b.append("?"); uuids.add(staffs.getString(i, "org_level_uuid")); } if (org_level_uuids.get(staffs.getString(i, "dept_uuid")) == null) { org_level_uuids.put(staffs.getString(i, "dept_uuid"), staffs.getString(i, "dept_uuid")); if (uuids.size() > 0) { b.append(","); } b.append("?"); uuids.add(staffs.getString(i, "dept_uuid")); } } b.append(")"); } DataTableEntity coms = null; if (!uuids.isEmpty()) { // 查询所有指定组织机构下的组织机构 coms = baseDao.listTable("product_sys_org_levels", b.toString(), uuids.toArray()); // 国际化 baseDao.listInternationDataTable(coms, CoreConst.CLIENT_TYPE_WEB.equals(client_type) ? null : language_code.toString()); } if (coms == null || coms.getRows() == 0) { return new ArrayList<>(); } else { Map code = new HashMap<>(); for (int i = 0; i < coms.getRows(); i++) { getParentCode(coms.getString(i, "org_level_code"), code); } b.delete(0, b.length()); for (Object key : code.keySet()) { if (b.length() > 0) { b.append(","); } b.append("?"); } b.insert(0, " org_level_code in ("); b.append(")"); coms = baseDao.listTable("product_sys_org_levels", b.toString(), code.keySet().toArray()); } return convertOrgStaffInternation(coms, staffs); } /** * 菜单国际化转换 * * @param orgs 组织机构 * @param staffs 人员 * @return */ private List> convertOrgStaffInternation(DataTableEntity orgs, DataTableEntity staffs) throws BaseException { List> org_staff = new ArrayList<>(); // 封装上下级菜单 Map> parent_org = new HashMap<>(); // 封装部门 Map> parent_dept = new HashMap<>(); if (orgs != null && orgs.getRows() > 0) { for (int j = 0; j < orgs.getRows(); j++) { FieldSetEntity org = orgs.getFieldSetEntity(j); Map o = JsonUtil.parseJsonFieldSetToMap(org); String pcode = org.getString("org_level_code_parent"); if (StringUtils.isEmpty(pcode) || parent_org.get(pcode) == null) { org_staff.add(o); } else {// 上级菜单 Map pm = parent_org.get(pcode); Object subs = pm.get("son_org"); List> submenus = null; if (subs == null) { submenus = new ArrayList<>(); pm.put("son_org", submenus); } else { submenus = (List>) subs; } submenus.add(o); } parent_org.put(org.getString("org_level_code"), o); if (org.getInteger("org_level_type") == 1) { parent_dept.put(org.getString("uuid"), o); } } } if (staffs != null && staffs.getRows() > 0) { for (int j = 0; j < staffs.getRows(); j++) { FieldSetEntity staff = staffs.getFieldSetEntity(j); Map o = JsonUtil.parseJsonFieldSetToMap(staff); String dept_uuid = staff.getString("dept_uuid"); if (parent_dept.get(dept_uuid) != null) { // 部门 Map pm = parent_dept.get(dept_uuid); Object subs = pm.get("staff"); List> submenus = null; if (subs == null) { submenus = new ArrayList<>(); pm.put("staff", submenus); } else { submenus = (List>) subs; } submenus.add(o); } } } return org_staff; } /** * 员工信息详情(移动端) * * @param uuid * @return * @throws BaseException */ public FieldSetEntity findStaffInfoByMobile() throws BaseException { String uuid = null; FieldSetEntity fseCurrentStaff = SpringMVCContextHolder.getCurrentUser().getCurrentStaff(); if (fseCurrentStaff != null) { uuid = fseCurrentStaff.getUUID(); } else { throw new BaseException(SystemCode.SYSTEM_STAFF_INFO_NO_EXIST.getValue(), SystemCode.SYSTEM_STAFF_INFO_NO_EXIST.getText(), this.getClass(), "findStaffInfoByMobile"); } StringBuilder sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" a.child_name,a.christian_name,a.client_uuid,a.cost_center_uuid,a.created_by,a.created_utc_datetime,a.dept_uuid,a.direct_leader_code, "); sql.append(" a.entry_datetime,a.family_name,a.given_name,a.is_dept_manage,a.is_org_admin,a.is_org_manager,a.job_post_grade_uuid,a.job_post_uuid, "); sql.append(" a.org_level_uuid,a.preferred_name,a.probation_end,a.role_uuids,a.show_name,a.staff_code,a.staff_email,a.staff_id,a.staff_image, "); sql.append(" a.staff_status,a.tricode,a.updated_by,a.updated_utc_datetime,a.user_id,a.uuid, "); sql.append(" b.status, "); sql.append(" c.attachment_url,concat(c.attachment_domain,'/',c.attachment_container,'/',c.module_uuid,'/',c.attachment_title,?) staff_avatar "); sql.append(" FROM product_sys_staffs a "); sql.append(" LEFT JOIN product_sys_users b ON a.user_id=b.user_id "); sql.append(" LEFT JOIN product_sys_attachments c ON a.staff_avatar=c.uuid where a.uuid=? "); String sostoken = Global.getSystemConfig("upload.key", ""); FieldSetEntity fseStaff = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{sostoken, uuid}, false); baseDao.listInternationDataTable(fseStaff, null); return fseStaff; } private void getParentCode(String code, Map newCode) { String cs[] = code.split("-"); List codes = new ArrayList<>(); codes.add(cs[0]); newCode.put(cs[0], cs[0]); for (int i = 1; i < cs.length; i++) { codes.add(codes.get(i - 1) + "-" + cs[i]); newCode.put(codes.get(i - 1) + "-" + cs[i], codes.get(i - 1) + "-" + cs[i]); } } /** * 初始化员工leader_tricode数据 * * @return * @throws Ez */ public void initStaffLeaderTricode() throws Exception { System.out.println(new Date()); //获取所有无上级领导员工 DataTableEntity dtStaffInfo = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, "direct_leader_code is null or direct_leader_code =''"); if (!BaseUtil.dataTableIsEmpty(dtStaffInfo)) { String virtualCode = "000"; for (int i = 0; i < dtStaffInfo.getRows(); i++) { FieldSetEntity fseStaffInfo = dtStaffInfo.getFieldSetEntity(i); fseStaffInfo.remove("show_name"); fseStaffInfo.remove("family_name"); fseStaffInfo.remove("given_name"); fseStaffInfo.remove("christian_name"); fseStaffInfo.remove("child_name"); fseStaffInfo.remove("preferred_name"); String leader_tricode = ""; if (i == 0) { leader_tricode = virtualCode; } else { leader_tricode = SingletonUtil.makeSameLevelCode(virtualCode); virtualCode = leader_tricode; } fseStaffInfo.setValue(CmnConst.LEADER_TRICODE, leader_tricode); //Fri Apr 16 03:55:34 UTC 2021 // baseDao.update(fseStaffInfo); // DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE); // Thread.currentThread().sleep(4000); createStaffLeaderTricode(fseStaffInfo.getString(CmnConst.TRICODE), leader_tricode); } baseDao.update(dtStaffInfo); DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, CmnConst.LEADER_TRICODE); } System.out.println(new Date()); } /** * 自动创建下级员工leader_tricode数据 * * @param tricode * @param leader_tricode */ public void createStaffLeaderTricode(String tricode, String leader_tricode) { DataTableEntity dtSubStaffInfo = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, "direct_leader_code=?", new Object[]{tricode}); if (!BaseUtil.dataTableIsEmpty(dtSubStaffInfo)) { String virtualCode = leader_tricode + "-000"; for (int i = 0; i < dtSubStaffInfo.getRows(); i++) { FieldSetEntity fseSubStaffInfo = dtSubStaffInfo.getFieldSetEntity(i); fseSubStaffInfo.remove("show_name"); fseSubStaffInfo.remove("family_name"); fseSubStaffInfo.remove("given_name"); fseSubStaffInfo.remove("christian_name"); fseSubStaffInfo.remove("child_name"); fseSubStaffInfo.remove("preferred_name"); String sub_leader_tricode = ""; if (i == 0) { sub_leader_tricode = virtualCode; } else { sub_leader_tricode = SingletonUtil.makeSameLevelCode(virtualCode); virtualCode = sub_leader_tricode; } fseSubStaffInfo.setValue(CmnConst.LEADER_TRICODE, sub_leader_tricode); // baseDao.update(fseSubStaffInfo); createStaffLeaderTricode(fseSubStaffInfo.getString(CmnConst.TRICODE), sub_leader_tricode); } baseDao.update(dtSubStaffInfo); } } }