CustomerUserSelectServiceImpl.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package cn.com.lzt.common.service.impl;
  2. import cn.com.lzt.process.roledepartmap.entity.ProcessRoleDepartMapEntity;
  3. import cn.com.lzt.useractiviti.data.dao.UseractivitiDataDao;
  4. import cn.com.lzt.useractiviti.data.service.UseractivitiDataServiceI;
  5. import cn.com.lzt.warehouse.entity.WarehouseEntity;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.jeecgframework.core.common.exception.BusinessException;
  8. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  9. import org.jeecgframework.core.constant.Globals;
  10. import org.jeecgframework.core.util.StringUtil;
  11. import org.jeecgframework.core.util.oConvertUtils;
  12. import org.jeecgframework.web.system.pojo.base.*;
  13. import org.jeecgframework.web.system.service.SystemService;
  14. import org.jeecgframework.web.system.service.UserService;
  15. import org.jeecgframework.workflow.service.CustomerUserSelectServiceI;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.List;
  22. import java.util.Map;
  23. @Service("customerUserSelectServiceI")
  24. @Transactional
  25. public class CustomerUserSelectServiceImpl extends CommonServiceImpl implements CustomerUserSelectServiceI {
  26. private static String temp = "";
  27. @Autowired
  28. private SystemService systemService;
  29. @Autowired
  30. private UseractivitiDataServiceI useractivitiDataService;
  31. @Autowired
  32. private UseractivitiDataDao useractivitiDataDao;
  33. @Autowired
  34. private UserService userService;
  35. @SuppressWarnings("unchecked")
  36. @Override
  37. public List<String> customerUserSelect(String tableName, String id, String customercode) {
  38. List<String> list = new ArrayList<String>();
  39. if (oConvertUtils.isEmpty(tableName) || oConvertUtils.isEmpty(id)) {
  40. throw new BusinessException("传入的参数有问题,请联系管理员");
  41. }
  42. Map<String,Object> map = systemService.findOneForJdbc("select * from "+tableName+" where id = ?",id);
  43. String userid = (String)map.get("userid");
  44. String username = (String)map.get("create_by");
  45. String createUserId = null;
  46. if (username != null) {
  47. Map<String, Object> mapresult = systemService.findOneForJdbc(
  48. "select * from t_s_base_user where username=? ", username);
  49. createUserId = (String) mapresult.get("id");
  50. }
  51. // TSBaseUser t = null;
  52. if(userid != null && userid.length()>0) {
  53. // t = systemService.get(TSBaseUser.class,userid);
  54. }else {
  55. if(StringUtils.equals("t_bus_activiti_user_personnel",tableName)){//入职审批
  56. userid="-1";
  57. }else {
  58. userid = createUserId;
  59. }
  60. }
  61. if(Globals.TYPE_CREATE_DEPART_MANAGER.toString().equals(customercode)) {//创建者组织机构负责人
  62. TSUser createUser = userService.getUserByUserName(username);
  63. TSDepart depart = useractivitiDataDao.getUserDep(createUser.getId());
  64. List<TSUser> userlist= useractivitiDataService.getDepManager(depart.getId());
  65. if(userlist.isEmpty()){
  66. throw new BusinessException("申请人的申请没有对应的处理人,请联系管理员!申请人:"+userid+"_"+username);
  67. }
  68. List<String> returnList= new ArrayList<>(userlist.size());
  69. for(TSUser user :userlist){
  70. returnList.add(user.getUserName());
  71. }
  72. return returnList;
  73. }
  74. if(oConvertUtils.isNotEmpty(userid)){
  75. //createBy gjs 组织机构负责人 start
  76. if(Globals.TYPE_DEPART_MANAGER.toString().equals(customercode)) {
  77. String departId = (String) map.get("depart_id");
  78. if(StringUtils.isBlank(departId)){
  79. departId = (String) map.get("projectid");
  80. }
  81. if(StringUtils.equals("t_bus_activiti_samelevel_transfer", tableName)){//平级调动
  82. departId = (String) map.get("in_unitid");
  83. }
  84. if(StringUtils.isBlank(departId)){
  85. TSDepart depart = useractivitiDataDao.getUserDep(userid);
  86. departId = depart.getId();
  87. }
  88. List<TSUser> userlist= useractivitiDataService.getDepManager(departId);
  89. if(userlist.isEmpty()){
  90. throw new BusinessException("申请人的申请没有对应的处理人,请联系管理员!申请人:"+userid+"_"+username);
  91. }
  92. List<String> returnList= new ArrayList<>(userlist.size());
  93. for(TSUser user :userlist){
  94. returnList.add(user.getUserName());
  95. }
  96. return returnList;
  97. }
  98. //createBy gjs 组织机构负责人 end
  99. //分管副总
  100. if("FGFZ".equals(customercode)) {
  101. TSDepart depart = useractivitiDataDao.getUserDep(createUserId);
  102. String departId = depart.getId();
  103. List<ProcessRoleDepartMapEntity> entityList = findHql("from ProcessRoleDepartMapEntity where departId like ?"
  104. ,"%"+departId+"%");
  105. List<String> returnList= new ArrayList<>();
  106. if(!entityList.isEmpty()){
  107. for(ProcessRoleDepartMapEntity entity:entityList){
  108. String roleId = entity.getRoleId();
  109. String sql = "select user.username from t_s_role_user ru,t_s_base_user user where ru.roleid=? and ru.userid=user.id";
  110. List<String> userIdList = findListbySql(sql,roleId);
  111. returnList.addAll(userIdList);
  112. }
  113. if(!returnList.isEmpty()) return returnList;
  114. }
  115. }
  116. 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();
  117. TSDepart ts = null;
  118. if(Globals.TYPE_WAREHOUSE.toString().equals(customercode)){//领料点部门
  119. String warehouseid = oConvertUtils.getString(map.get("warehouseid"));
  120. WarehouseEntity warehouseEntity=systemService.getEntity(WarehouseEntity.class,warehouseid);
  121. ts = systemService.getEntity(TSDepart.class, warehouseEntity.getProjectId());
  122. }else {
  123. if (roleUser.size() > 0) {
  124. ts = roleUser.get(0).getTsDepart();
  125. }
  126. }
  127. //createBy gjs 员工入职审批逻辑 start
  128. if(!oConvertUtils.isNotEmpty(ts)){
  129. String depart_id = (String) map.get("depart_id");
  130. if(StringUtils.isNotBlank(depart_id)){
  131. ts = systemService.getEntity(TSDepart.class, depart_id);
  132. }
  133. }
  134. //createBy gjs 员工入职审批逻辑 end
  135. if(oConvertUtils.isNotEmpty(ts)){
  136. TSRole tsRole = null;
  137. String type = "";
  138. String idString = "";
  139. //项目经理
  140. if(Globals.TYPE_SUPERIOR.toString().equals(customercode) || Globals.TYPE_WAREHOUSE.toString().equals(customercode)){
  141. type = Globals.POSITION_TYPE_PRO.toString();
  142. if(ts.getTSPDepart() == null || StringUtil.isEmpty(ts.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(ts.getTSPDepart().getId())) {
  143. // 上级所属部门是公司总部或者空,取当前所属部门
  144. idString = ts.getId();
  145. }else {
  146. idString = selectById("3", ts.getTSPDepart().getId());
  147. }
  148. //区域经理
  149. }else if(Globals.TYPE_SUPERIORS.toString().equals(customercode)){
  150. type = Globals.POSITION_TYPE_RE.toString();
  151. if(Globals.org_type_4.equals(ts.getOrgType())){
  152. idString = ts.getId();
  153. }else{
  154. idString = selectById("4", ts.getTSPDepart().getId());
  155. }
  156. //老板
  157. }else if(Globals.TYPE_BOSS.toString().equals(customercode)){
  158. type = Globals.POSITION_TYPE_BOSS.toString();
  159. if(Globals.org_type_1.equals(ts.getOrgType())){
  160. idString = ts.getId();
  161. }else{
  162. idString = selectById("1",ts.getTSPDepart().getId());
  163. }
  164. }else if(Globals.TYPE_CREATE_SUPERIOR.toString().equals(customercode)){//创建者项目经理
  165. type = Globals.POSITION_TYPE_PRO.toString();
  166. TSUser createUser = systemService.findUniqueByProperty(TSUser.class, "userName",username);
  167. 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();
  168. TSDepart createUserTs = null;
  169. if(createUserOrg.size()>0){
  170. createUserTs = createUserOrg.get(0).getTsDepart();
  171. }
  172. if(createUserTs !=null ) {
  173. if (createUserTs.getTSPDepart() == null || StringUtil.isEmpty(createUserTs.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(createUserTs.getTSPDepart().getId())) {
  174. // 上级所属部门是公司总部或者空,取当前所属部门
  175. idString = createUserTs.getId();
  176. } else {
  177. idString = selectById("3", createUserTs.getTSPDepart().getId());
  178. }
  179. }
  180. }else if(Globals.TYPE_NQ.toString().equals(customercode)){//项目内勤
  181. type = Globals.POSITION_TYPE_NQ.toString();
  182. if(ts.getTSPDepart() == null || StringUtil.isEmpty(ts.getTSPDepart().getId()) || "4028e4a55f6c84ec015f6ca5c6ab0001".equals(ts.getTSPDepart().getId())) {
  183. // 上级所属部门是公司总部或者空,取当前所属部门
  184. idString = ts.getId();
  185. }else {
  186. idString = selectById("3", ts.getTSPDepart().getId());
  187. }
  188. }
  189. // 根据不同tablename 重新设置
  190. idString = retrieveProjectId(idString,tableName, map, ts, roleUser, userid);
  191. if(StringUtils.isEmpty(idString)){
  192. if(map.containsKey("project_id")) {
  193. idString = (String)map.get("project_id");
  194. }
  195. }
  196. if(StringUtils.isNotEmpty(type)){
  197. tsRole = systemService.findUniqueByProperty(TSRole.class, "roleCode", type);
  198. List<TSRoleUser> reRoleUsers = systemService.findByProperty(TSRoleUser.class, "TSRole.id", tsRole.getId());
  199. if(oConvertUtils.isNotEmpty(reRoleUsers)){
  200. for (TSRoleUser tsRoleUser : reRoleUsers) {
  201. TSBaseUser sts = tsRoleUser.getTSUser();
  202. List<TSUserOrg> ro = systemService.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+sts.getId()+"' and status = 0").addEntity(TSUserOrg.class).list();
  203. for (TSUserOrg tsUserOrg : ro) {
  204. TSDepart de = tsUserOrg.getTsDepart();
  205. if(de.getId().equals(idString)){
  206. list.add(sts.getUserName());
  207. }
  208. }
  209. }
  210. }
  211. }else{
  212. /*if(StringUtils.isNotEmpty(ts.getSupervisorId())){
  213. TSBaseUser tb = get(TSBaseUser.class,ts.getSupervisorId());
  214. list.add(tb.getUserName());
  215. }*/
  216. //找同部门的部门经理
  217. if(Globals.TYPE_GUARD.toString().equals(customercode)){
  218. List<TSUserOrg> orgUser = systemService.getSession().createSQLQuery("select * from t_s_user_org where org_id = '"+ts.getId()+"' and status = 0 ").addEntity(TSUserOrg.class).list();
  219. if(orgUser != null){
  220. for (int i = 0; i < orgUser.size(); i++) {
  221. TSBaseUser s = orgUser.get(i).getTsUser();
  222. List<TSRoleUser> roluserList = systemService.getSession().createSQLQuery("select * from t_s_role_user where userid = '"+s.getId()+"'").addEntity(TSRoleUser.class).list();
  223. if(!roluserList.isEmpty()){
  224. for (TSRoleUser tsRoleUser : roluserList) {
  225. TSRole tRole = tsRoleUser.getTSRole();
  226. if(Arrays.asList(Globals.POSITION_TYPE_SECTION).contains(tRole.getRoleCode())){
  227. list.add(s.getUserName());
  228. }
  229. }
  230. }
  231. }
  232. }
  233. //找直属项目的项目负责人
  234. }else if(Globals.TYPE_PERGUARD.toString().equals(customercode)){
  235. if(StringUtils.isNotEmpty(ts.getSupervisorId())){
  236. TSBaseUser tb = get(TSBaseUser.class,ts.getSupervisorId());
  237. list.add(tb.getUserName());
  238. }else{
  239. temp = selectByName(ts.getTSPDepart().getId());
  240. TSDepart tsDepart = systemService.getEntity(TSDepart.class,temp);
  241. if(StringUtils.isNotEmpty(tsDepart.getSupervisorId())){
  242. TSBaseUser tb = get(TSBaseUser.class,tsDepart.getSupervisorId());
  243. list.add(tb.getUserName());
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. if(list.isEmpty()){
  251. throw new BusinessException("申请人的申请没有对应的处理人,请联系管理员!申请人:"+userid+"_"+username);
  252. }
  253. return list;
  254. }
  255. /**
  256. * @param projectid
  257. * @param tableName
  258. * @param map
  259. * @param ts
  260. * @param roleUser
  261. * @param userid
  262. * @return
  263. */
  264. private String retrieveProjectId(String projectid, String tableName, Map<String, Object> map, TSDepart ts, List<TSUserOrg> roleUser,
  265. String userid) {
  266. if("t_b_orders".equals(tableName)) {
  267. if(map.containsKey("warehouse_id")){
  268. String warehouse_id = (String)map.get("warehouse_id");
  269. WarehouseEntity warehouse = systemService.get(WarehouseEntity.class, warehouse_id);
  270. if(warehouse != null) {
  271. projectid = warehouse.getProjectId();
  272. }
  273. }
  274. }
  275. return projectid;
  276. }
  277. private String selectById(String code,String id){
  278. TSDepart tsDepart = systemService.getEntity(TSDepart.class,id);
  279. if(code.equals("3")){
  280. if(code.equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){
  281. temp = tsDepart.getId();
  282. }else{
  283. if(tsDepart.getTSPDepart() != null){
  284. selectById(code, tsDepart.getTSPDepart().getId());
  285. }
  286. }
  287. }else{
  288. if(code.equals(tsDepart.getOrgType())){
  289. temp = tsDepart.getId();
  290. }else{
  291. if(tsDepart.getTSPDepart() != null){
  292. selectById(code, tsDepart.getTSPDepart().getId());
  293. }
  294. }
  295. }
  296. return temp;
  297. }
  298. private String selectByName(String id){
  299. TSDepart tsDepart = systemService.getEntity(TSDepart.class,id);
  300. if(StringUtils.isNotEmpty(tsDepart.getSupervisorId())){
  301. temp = tsDepart.getId();
  302. }else{
  303. if(tsDepart.getTSPDepart() != null){
  304. selectByName(tsDepart.getTSPDepart().getId());
  305. }
  306. }
  307. return temp;
  308. }
  309. }