| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- package cn.com.lzt.common.service.impl;
- import cn.com.lzt.process.roledepartmap.entity.ProcessRoleDepartMapEntity;
- import cn.com.lzt.useractiviti.data.dao.UseractivitiDataDao;
- import cn.com.lzt.useractiviti.data.service.UseractivitiDataServiceI;
- import cn.com.lzt.warehouse.entity.WarehouseEntity;
- import org.apache.commons.lang3.StringUtils;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.core.util.oConvertUtils;
- import org.jeecgframework.web.system.pojo.base.*;
- import org.jeecgframework.web.system.service.SystemService;
- import org.jeecgframework.web.system.service.UserService;
- import org.jeecgframework.workflow.service.CustomerUserSelectServiceI;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Map;
- @Service("customerUserSelectServiceI")
- @Transactional
- public class CustomerUserSelectServiceImpl extends CommonServiceImpl implements CustomerUserSelectServiceI {
- private static String temp = "";
-
- @Autowired
- private SystemService systemService;
- @Autowired
- private UseractivitiDataServiceI useractivitiDataService;
- @Autowired
- private UseractivitiDataDao useractivitiDataDao;
- @Autowired
- private UserService userService;
- @SuppressWarnings("unchecked")
- @Override
- public List<String> customerUserSelect(String tableName, String id, String customercode) {
- List<String> list = new ArrayList<String>();
- if (oConvertUtils.isEmpty(tableName) || oConvertUtils.isEmpty(id)) {
- throw new BusinessException("传入的参数有问题,请联系管理员");
- }
- Map<String,Object> map = systemService.findOneForJdbc("select * from "+tableName+" where id = ?",id);
- String userid = (String)map.get("userid");
- String username = (String)map.get("create_by");
- String createUserId = null;
- if (username != null) {
- Map<String, Object> mapresult = systemService.findOneForJdbc(
- "select * from t_s_base_user where username=? ", username);
- createUserId = (String) mapresult.get("id");
- }
- // TSBaseUser t = null;
- if(userid != null && userid.length()>0) {
- // t = systemService.get(TSBaseUser.class,userid);
- }else {
- if(StringUtils.equals("t_bus_activiti_user_personnel",tableName)){//入职审批
- userid="-1";
- }else {
- userid = createUserId;
- }
- }
- if(Globals.TYPE_CREATE_DEPART_MANAGER.toString().equals(customercode)) {//创建者组织机构负责人
- TSUser createUser = userService.getUserByUserName(username);
- TSDepart depart = useractivitiDataDao.getUserDep(createUser.getId());
- List<TSUser> userlist= useractivitiDataService.getDepManager(depart.getId());
- if(userlist.isEmpty()){
- throw new BusinessException("申请人的申请没有对应的处理人,请联系管理员!申请人:"+userid+"_"+username);
- }
- List<String> returnList= new ArrayList<>(userlist.size());
- for(TSUser user :userlist){
- returnList.add(user.getUserName());
- }
- return returnList;
- }
- if(oConvertUtils.isNotEmpty(userid)){
- //createBy gjs 组织机构负责人 start
- if(Globals.TYPE_DEPART_MANAGER.toString().equals(customercode)) {
- String departId = (String) map.get("depart_id");
- if(StringUtils.isBlank(departId)){
- departId = (String) map.get("projectid");
- }
- if(StringUtils.equals("t_bus_activiti_samelevel_transfer", tableName)){//平级调动
- departId = (String) map.get("in_unitid");
- }
- if(StringUtils.isBlank(departId)){
- TSDepart depart = useractivitiDataDao.getUserDep(userid);
- departId = depart.getId();
- }
- List<TSUser> userlist= useractivitiDataService.getDepManager(departId);
- if(userlist.isEmpty()){
- throw new BusinessException("申请人的申请没有对应的处理人,请联系管理员!申请人:"+userid+"_"+username);
- }
- List<String> returnList= new ArrayList<>(userlist.size());
- for(TSUser user :userlist){
- returnList.add(user.getUserName());
- }
- return returnList;
- }
- //createBy gjs 组织机构负责人 end
- //分管副总
- if("FGFZ".equals(customercode)) {
- TSDepart depart = useractivitiDataDao.getUserDep(createUserId);
- String departId = depart.getId();
- List<ProcessRoleDepartMapEntity> entityList = findHql("from ProcessRoleDepartMapEntity where departId like ?"
- ,"%"+departId+"%");
- List<String> returnList= new ArrayList<>();
- if(!entityList.isEmpty()){
- for(ProcessRoleDepartMapEntity entity:entityList){
- String roleId = entity.getRoleId();
- String sql = "select user.username from t_s_role_user ru,t_s_base_user user where ru.roleid=? and ru.userid=user.id";
- List<String> userIdList = findListbySql(sql,roleId);
- returnList.addAll(userIdList);
- }
- if(!returnList.isEmpty()) return returnList;
- }
- }
- List<TSUserOrg> roleUser = systemService.getSession().createSQLQuery("select * from t_s_user_org where user_id = '" + userid + "' and ifpluralism = 0 and status = 0 ").addEntity(TSUserOrg.class).list();
- TSDepart ts = null;
- if(Globals.TYPE_WAREHOUSE.toString().equals(customercode)){//领料点部门
- String warehouseid = oConvertUtils.getString(map.get("warehouseid"));
- WarehouseEntity warehouseEntity=systemService.getEntity(WarehouseEntity.class,warehouseid);
- ts = systemService.getEntity(TSDepart.class, warehouseEntity.getProjectId());
- }else {
- if (roleUser.size() > 0) {
- ts = roleUser.get(0).getTsDepart();
- }
- }
- //createBy gjs 员工入职审批逻辑 start
- if(!oConvertUtils.isNotEmpty(ts)){
- String depart_id = (String) map.get("depart_id");
- if(StringUtils.isNotBlank(depart_id)){
- ts = systemService.getEntity(TSDepart.class, depart_id);
- }
- }
- //createBy gjs 员工入职审批逻辑 end
- if(oConvertUtils.isNotEmpty(ts)){
- TSRole tsRole = null;
- String type = "";
- String idString = "";
- //项目经理
- if(Globals.TYPE_SUPERIOR.toString().equals(customercode) || Globals.TYPE_WAREHOUSE.toString().equals(customercode)){
- type = Globals.POSITION_TYPE_PRO.toString();
- if(ts.getTSPDepart() == null || StringUtil.isEmpty(ts.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(ts.getTSPDepart().getId())) {
- // 上级所属部门是公司总部或者空,取当前所属部门
- idString = ts.getId();
- }else {
- idString = selectById("3", ts.getTSPDepart().getId());
- }
- //区域经理
- }else if(Globals.TYPE_SUPERIORS.toString().equals(customercode)){
- type = Globals.POSITION_TYPE_RE.toString();
- if(Globals.org_type_4.equals(ts.getOrgType())){
- idString = ts.getId();
- }else{
- idString = selectById("4", ts.getTSPDepart().getId());
- }
- //老板
- }else if(Globals.TYPE_BOSS.toString().equals(customercode)){
- type = Globals.POSITION_TYPE_BOSS.toString();
- if(Globals.org_type_1.equals(ts.getOrgType())){
- idString = ts.getId();
- }else{
- idString = selectById("1",ts.getTSPDepart().getId());
-
- }
- }else if(Globals.TYPE_CREATE_SUPERIOR.toString().equals(customercode)){//创建者项目经理
- type = Globals.POSITION_TYPE_PRO.toString();
- TSUser createUser = systemService.findUniqueByProperty(TSUser.class, "userName",username);
- List<TSUserOrg> createUserOrg = systemService.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+createUser.getId()+"' and ifpluralism = 0 and status = 0 ").addEntity(TSUserOrg.class).list();
- TSDepart createUserTs = null;
- if(createUserOrg.size()>0){
- createUserTs = createUserOrg.get(0).getTsDepart();
- }
- if(createUserTs !=null ) {
- if (createUserTs.getTSPDepart() == null || StringUtil.isEmpty(createUserTs.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(createUserTs.getTSPDepart().getId())) {
- // 上级所属部门是公司总部或者空,取当前所属部门
- idString = createUserTs.getId();
- } else {
- idString = selectById("3", createUserTs.getTSPDepart().getId());
- }
- }
- }else if(Globals.TYPE_NQ.toString().equals(customercode)){//项目内勤
- type = Globals.POSITION_TYPE_NQ.toString();
- if(ts.getTSPDepart() == null || StringUtil.isEmpty(ts.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(ts.getTSPDepart().getId())) {
- // 上级所属部门是公司总部或者空,取当前所属部门
- idString = ts.getId();
- }else {
- idString = selectById("3", ts.getTSPDepart().getId());
- }
- }
- // 根据不同tablename 重新设置
- idString = retrieveProjectId(idString,tableName, map, ts, roleUser, userid);
-
- if(StringUtils.isEmpty(idString)){
- if(map.containsKey("project_id")) {
- idString = (String)map.get("project_id");
- }
- }
-
- if(StringUtils.isNotEmpty(type)){
- tsRole = systemService.findUniqueByProperty(TSRole.class, "roleCode", type);
- List<TSRoleUser> reRoleUsers = systemService.findByProperty(TSRoleUser.class, "TSRole.id", tsRole.getId());
- if(oConvertUtils.isNotEmpty(reRoleUsers)){
- for (TSRoleUser tsRoleUser : reRoleUsers) {
- TSBaseUser sts = tsRoleUser.getTSUser();
- List<TSUserOrg> ro = systemService.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+sts.getId()+"' and status = 0").addEntity(TSUserOrg.class).list();
- for (TSUserOrg tsUserOrg : ro) {
- TSDepart de = tsUserOrg.getTsDepart();
- if(de.getId().equals(idString)){
- list.add(sts.getUserName());
- }
- }
- }
- }
- }else{
- /*if(StringUtils.isNotEmpty(ts.getSupervisorId())){
- TSBaseUser tb = get(TSBaseUser.class,ts.getSupervisorId());
- list.add(tb.getUserName());
- }*/
- //找同部门的部门经理
- if(Globals.TYPE_GUARD.toString().equals(customercode)){
- List<TSUserOrg> orgUser = systemService.getSession().createSQLQuery("select * from t_s_user_org where org_id = '"+ts.getId()+"' and status = 0 ").addEntity(TSUserOrg.class).list();
- if(orgUser != null){
- for (int i = 0; i < orgUser.size(); i++) {
- TSBaseUser s = orgUser.get(i).getTsUser();
- List<TSRoleUser> roluserList = systemService.getSession().createSQLQuery("select * from t_s_role_user where userid = '"+s.getId()+"'").addEntity(TSRoleUser.class).list();
- if(!roluserList.isEmpty()){
- for (TSRoleUser tsRoleUser : roluserList) {
- TSRole tRole = tsRoleUser.getTSRole();
- if(Arrays.asList(Globals.POSITION_TYPE_SECTION).contains(tRole.getRoleCode())){
- list.add(s.getUserName());
- }
- }
- }
-
- }
- }
- //找直属项目的项目负责人
- }else if(Globals.TYPE_PERGUARD.toString().equals(customercode)){
- if(StringUtils.isNotEmpty(ts.getSupervisorId())){
- TSBaseUser tb = get(TSBaseUser.class,ts.getSupervisorId());
- list.add(tb.getUserName());
- }else{
- temp = selectByName(ts.getTSPDepart().getId());
- TSDepart tsDepart = systemService.getEntity(TSDepart.class,temp);
- if(StringUtils.isNotEmpty(tsDepart.getSupervisorId())){
- TSBaseUser tb = get(TSBaseUser.class,tsDepart.getSupervisorId());
- list.add(tb.getUserName());
- }
- }
- }
- }
- }
- }
-
- if(list.isEmpty()){
- throw new BusinessException("申请人的申请没有对应的处理人,请联系管理员!申请人:"+userid+"_"+username);
- }
- return list;
- }
-
- /**
- * @param projectid
- * @param tableName
- * @param map
- * @param ts
- * @param roleUser
- * @param userid
- * @return
- */
- private String retrieveProjectId(String projectid, String tableName, Map<String, Object> map, TSDepart ts, List<TSUserOrg> roleUser,
- String userid) {
- if("t_b_orders".equals(tableName)) {
- if(map.containsKey("warehouse_id")){
- String warehouse_id = (String)map.get("warehouse_id");
- WarehouseEntity warehouse = systemService.get(WarehouseEntity.class, warehouse_id);
- if(warehouse != null) {
- projectid = warehouse.getProjectId();
- }
- }
- }
-
- return projectid;
- }
- private String selectById(String code,String id){
- TSDepart tsDepart = systemService.getEntity(TSDepart.class,id);
- 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;
- }
-
- private String selectByName(String id){
- TSDepart tsDepart = systemService.getEntity(TSDepart.class,id);
- if(StringUtils.isNotEmpty(tsDepart.getSupervisorId())){
- temp = tsDepart.getId();
- }else{
- if(tsDepart.getTSPDepart() != null){
- selectByName(tsDepart.getTSPDepart().getId());
- }
- }
- return temp;
- }
-
- }
|