| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package cn.com.lzt.common.util;
- import org.apache.commons.lang3.StringUtils;
- import org.jeecgframework.core.common.dao.jdbc.JdbcDao;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.core.util.*;
- import org.jeecgframework.web.system.pojo.base.TSDepart;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.jeecgframework.web.system.pojo.base.TSUserOrg;
- import org.jeecgframework.web.system.service.SystemService;
- import java.util.List;
- import java.util.Map;
- public class DepartUtil {
- private static SystemService systemService;
- public static final String HR_ID="00000000610f6b0d01610f7078050007";//人事部门id
- public static final String XXB="00000000614594980161462963290d31";//信息发展部
- public static final String GENERALMANAGEROFFICE="00000000610f6afa01611cd2da0b0094";//总经理办公室
- static {
- systemService = ApplicationContextUtil.getContext().getBean(SystemService.class);
- }
- /**
- * 判断所属部门是项目还是职能部门
- * @param departId
- * @return
- */
- public static DepartType departType(String departId){
- SystemService service = ApplicationContextUtil.getContext().getBean(SystemService.class);
- departId = getQueryDepIdByDepId(departId);
- TSDepart depart = service.getEntity(TSDepart.class,departId);
- return departType(depart);
- }
- public static DepartType departType(TSDepart depart){
- if(StringUtils.equals(depart.getOrgType(),"2")&&depart.getOrgCode().length()==6){//职能部门
- return DepartType.department;
- }else{//项目
- return DepartType.project;
- }
- }
- public static enum DepartType{
- project(1)//项目
- ,department(2);//职能部门
- private int typeCode;
- private DepartType(int typeCode){
- this.typeCode=typeCode;
- }
- public int getTypeCode() {
- return typeCode;
- }
- public void setTypeCode(int typeCode) {
- this.typeCode = typeCode;
- }
- }
- /**
- * 获得用于查询的部门id
- * @param userid
- * @return
- */
- public static String getQueryDepIdByUserId(String userid){
- SystemService service = ApplicationContextUtil.getContext().getBean(SystemService.class);
- List<TSUserOrg> userorgList = service.findHql("from TSUserOrg where tsUser.id=? and ifpluralism=? ", userid, Globals.PLURALISM_NO.toString());
- if(userorgList.size() > 0) {
- TSDepart depart = userorgList.get(0).getTsDepart();
- return getQueryDepId(depart);
- }
- return null;
- }
- public static String getQueryDepIdByDepId(String depid){
- SystemService service = ApplicationContextUtil.getContext().getBean(SystemService.class);
- TSDepart depart = service.getEntity(TSDepart.class,depid);
- if(depart==null){//处理projectid 问题
- String findProjectDepartHql = "from TSDepart where projectid=? and length(orgCode)=6";
- List<TSDepart> list = service.findHql(findProjectDepartHql,depid);
- if(!list.isEmpty()){
- depart =list.get(0);
- }
- }
- return getQueryDepId(depart);
- }
- /**
- * 获得用于查询的部门id
- * @param dep
- * @return
- */
- public static String getQueryDepId(TSDepart dep){
- String depId ;
- if (dep.getTSPDepart() == null || StringUtil.isEmpty(dep.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(dep.getTSPDepart().getId())) {
- // 上级所属部门是公司总部或者空,取当前所属部门
- depId = dep.getId();
- } else {
- depId = selectById("3", dep.getTSPDepart().getId());
- }
- return depId;
- }
- private static String selectById(String code,String id){
- TSDepart tsDepart = systemService.getEntity(TSDepart.class,id);
- String temp = "";
- if(code.equals("3")){
- if(code.equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){
- temp = tsDepart.getId();
- }else{
- if(tsDepart.getTSPDepart() != null){
- selectById(code, tsDepart.getTSPDepart().getId());
- }
- }
- }else{
- if(code.equals(tsDepart.getOrgType())){
- temp = tsDepart.getId();
- }else{
- if(tsDepart.getTSPDepart() != null){
- selectById(code, tsDepart.getTSPDepart().getId());
- }
- }
- }
- return temp;
- }
- public static synchronized String getMaxLocalCode(String parentCode){
- if(oConvertUtils.isEmpty(parentCode)){
- parentCode = "";
- }
- int localCodeLength = parentCode.length() + YouBianCodeUtil.zhanweiLength;
- StringBuilder sb = new StringBuilder();
- sb.append("SELECT org_code FROM t_s_depart");
- //-update-begin--author:scott--date:20160414--for:数据库兼容性修改---
- if(ResourceUtil.getJdbcUrl().indexOf(JdbcDao.DATABSE_TYPE_SQLSERVER)!=-1){
- sb.append(" where LEN(org_code) = ").append(localCodeLength);
- }else{
- sb.append(" where LENGTH(org_code) = ").append(localCodeLength);
- }
- //-update-end--author:scott--date:20160414--for:数据库兼容性修改---
- if(oConvertUtils.isNotEmpty(parentCode)){
- sb.append(" and org_code like '").append(parentCode).append("%'");
- }
- //update-begin-Alex 20160310 for:去除LIMIT,解决数据库兼容性问题
- sb.append(" ORDER BY org_code DESC");
- List<Map<String, Object>> objMapList = systemService.findForJdbc(sb.toString(), 1, 1);
- String returnCode = null;
- if(objMapList!=null && objMapList.size()>0){
- returnCode = (String)objMapList.get(0).get("org_code");
- }
- //update-end-Alex 20160310 for:去除LIMIT,解决数据库兼容性问题
- return returnCode;
- }
- /**
- * 根据项目id转换成组织机构
- * */
- public static TSDepart getDepartFromProject(String projectid) {
- String hql = "from TSDepart where projectid =? and LENGTH(org_code ) = 6";
- List<TSDepart> departList = systemService.findHql(hql, projectid);
- if(departList != null && departList.size() > 0) {
- return departList.get(0);
- }else {
- return null;
- }
- }
- /**
- * 判断用户是否属于总经办
- * */
- public static boolean userWhetherBelongToGeneralManagerOffice(TSUser user) {
- StringBuffer sql = new StringBuffer();
- sql.append(" SELECT ");
- sql.append(" dep.* ");
- sql.append(" FROM ");
- sql.append(" t_s_depart dep, ");
- sql.append(" t_s_user_org org ");
- sql.append(" WHERE ");
- sql.append(" dep.id = org.org_id ");
- sql.append(" AND org.ifpluralism = '0' ");
- sql.append(" AND org.STATUS = 0 ");
- sql.append(" AND org.user_id = '");
- sql.append(user.getId());
- sql.append("' ");
- List<Map<String,Object>> list = systemService.findForJdbc(sql.toString());
- if(GENERALMANAGEROFFICE.equals(list.get(0).get("ID"))){
- return true;
- }else{
- return false;
- }
- }
- }
|