OfficeController.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. /**
  2. * Copyright &copy; 2013-2017 <a href="http://www.rhcncpa.com/">瑞华会计师事务所</a> All rights reserved.
  3. */
  4. package com.jeeplus.modules.sys.web;
  5. import java.io.UnsupportedEncodingException;
  6. import java.net.URLDecoder;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import javax.servlet.http.HttpSession;
  14. import com.jeeplus.common.json.AjaxJson;
  15. import com.jeeplus.common.persistence.Page;
  16. import com.jeeplus.common.utils.MyBeanUtils;
  17. import com.jeeplus.modules.sys.dao.CompanyDao;
  18. import com.jeeplus.modules.sys.dao.OfficeDao;
  19. import com.jeeplus.modules.sys.dao.RoleDao;
  20. import com.jeeplus.modules.sys.dao.UserDao;
  21. import com.jeeplus.modules.sys.entity.*;
  22. import com.jeeplus.modules.sys.service.CompanyService;
  23. import com.jeeplus.modules.sys.service.SystemService;
  24. import com.jeeplus.modules.sysuseroffice.entity.Useroffice;
  25. import com.jeeplus.modules.workclientinfo.entity.WorkClientLinkman;
  26. import com.jeeplus.modules.workstaff.entity.WorkStaffBasicInfo;
  27. import com.jeeplus.modules.workstaff.service.WorkStaffBasicInfoService;
  28. import org.apache.shiro.authz.annotation.Logical;
  29. import org.apache.shiro.authz.annotation.RequiresPermissions;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.stereotype.Controller;
  32. import org.springframework.ui.Model;
  33. import org.springframework.web.bind.annotation.ModelAttribute;
  34. import org.springframework.web.bind.annotation.RequestMapping;
  35. import org.springframework.web.bind.annotation.RequestParam;
  36. import org.springframework.web.bind.annotation.ResponseBody;
  37. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  38. import com.google.common.collect.Lists;
  39. import com.google.common.collect.Maps;
  40. import com.jeeplus.common.config.Global;
  41. import com.jeeplus.common.utils.StringUtils;
  42. import com.jeeplus.common.web.BaseController;
  43. import com.jeeplus.modules.sys.service.OfficeService;
  44. import com.jeeplus.modules.sys.utils.DictUtils;
  45. import com.jeeplus.modules.sys.utils.UserUtils;
  46. /**
  47. * 机构Controller
  48. *
  49. * @author jeeplus
  50. * @version 2013-5-15
  51. */
  52. @Controller
  53. @RequestMapping(value = "${adminPath}/sys/office")
  54. public class OfficeController extends BaseController {
  55. @Autowired
  56. private OfficeService officeService;
  57. @Autowired
  58. private SystemService systemService;
  59. @Autowired
  60. private CompanyService companyService;
  61. @Autowired
  62. private RoleDao roleDao;
  63. @Autowired
  64. private CompanyDao companyDao;
  65. @Autowired
  66. private WorkStaffBasicInfoService workStaffBasicInfoService;
  67. @Autowired
  68. private OfficeDao officeDao;
  69. @ModelAttribute("office")
  70. public Office get(@RequestParam(required = false) String id) {
  71. if (StringUtils.isNotBlank(id)) {
  72. return officeService.get(id);
  73. } else {
  74. return new Office();
  75. }
  76. }
  77. @RequiresPermissions("sys:office:index")
  78. @RequestMapping(value = {"list",""})
  79. public String index(Office office, Model model) {
  80. User user=UserUtils.get(UserUtils.getUser().getId());
  81. List<Office> offices = new ArrayList<>();
  82. if (office == null || office.getParentIds() == null || office.getParentIds().equals("")) {
  83. offices = officeService.findListIndex(office);
  84. if (offices!=null && offices.size()!=0){
  85. boolean b = true;
  86. for (Office office1:offices){
  87. if (office1.getType().equals("1")){
  88. office1.setParent(new Office("0"));
  89. b = false;
  90. break;
  91. }
  92. }
  93. List<Role> roleList = roleDao.getManagerRoleList(UserUtils.getUser().getId(),UserUtils.getSelectCompany().getId());
  94. if(roleList!=null&&roleList.size()>0){
  95. for (Office office1:offices){
  96. if (office1.getType().equals("3") && b){
  97. for(Role role:roleList){
  98. if(office1.getId().equals(role.getOffice().getId())){
  99. office1.setParent(new Office("0"));
  100. }
  101. }
  102. }
  103. }
  104. }else{
  105. for (Office office1:offices){
  106. if (office1.getType().equals("3") && b){
  107. office1.setParent(new Office("0"));
  108. }
  109. }
  110. }
  111. }
  112. } else {
  113. offices = officeService.findListt(office);
  114. }
  115. model.addAttribute("list", offices);
  116. return "modules/sys/officeList";
  117. }
  118. /* @RequiresPermissions("sys:office:index")
  119. @RequestMapping(value = {"list"})
  120. public String list(Office office, Model model) {
  121. if (office == null || office.getParentIds() == null || office.getParentIds().equals("")) {
  122. model.addAttribute("list", officeService.findList(false));
  123. } else {
  124. model.addAttribute("list", officeService.findListt(office));
  125. }
  126. return "modules/sys/officeList";
  127. }*/
  128. @RequiresPermissions(value = {"sys:office:view", "sys:office:add", "sys:office:edit"}, logical = Logical.OR)
  129. @RequestMapping(value = "form")
  130. public String form(Office office, Model model, HttpSession session, HttpServletRequest request) {
  131. String view = request.getParameter("view");
  132. if (!StringUtils.isBlank(view)) {
  133. if (view.equals("view")) {
  134. if (StringUtils.isNotBlank(office.getMaster())) {
  135. office.setMasterName(UserUtils.get(office.getMaster()).getName());
  136. }
  137. return "modules/sys/officeView";
  138. }
  139. }
  140. User user = UserUtils.getUser();
  141. if (office.getParent() == null || office.getParent().getId() == null) {
  142. office.setParent(user.getOffice());
  143. }
  144. office.setParent(officeService.get(office.getParent().getId()));
  145. if (office.getArea() == null) {
  146. office.setArea(user.getOffice().getArea());
  147. }
  148. if (!UserUtils.getSelectRole().get(0).getId().equals("1") && !user.getId().equals("1")) {
  149. Office selectCompany = UserUtils.getSelectCompany();
  150. if(!isSelectComp(selectCompany,office)){
  151. office.setParent(selectCompany);//非admin 只能创建部门 以及 当前公司的分公司
  152. }
  153. }
  154. if (StringUtils.isNotBlank(office.getMaster())) {
  155. office.setMasterName(UserUtils.get(office.getMaster()).getName());
  156. }
  157. // 自动获取排序号
  158. if (StringUtils.isBlank(office.getId()) && office.getParent() != null) {
  159. int size = 0;
  160. List<Office> list = officeService.findAll();
  161. for (int i = 0; i < list.size(); i++) {
  162. Office e = list.get(i);
  163. if (e.getParent() != null && e.getParent().getId() != null
  164. && e.getParent().getId().equals(office.getParent().getId())) {
  165. size++;
  166. }
  167. }
  168. office.setCode(office.getParent().getCode() + StringUtils.leftPad(String.valueOf(size > 0 ? size + 1 : 1), 3, "0"));
  169. }
  170. if (StringUtils.isBlank(office.getId())) {
  171. office.setType(null);
  172. } else if (StringUtils.isNotBlank(office.getId())) {
  173. session.setAttribute("state", "disabled");//禁止修改类型级别
  174. /*if(office.getParentIds().equals("0")||office.getCode().equals("100000")||office.getParentIds().equals("0,")){
  175. session.setAttribute("cname","no");//禁止修改公司名称
  176. }*/
  177. }
  178. model.addAttribute("office", office);
  179. return "modules/sys/officeForm";
  180. }
  181. private boolean isSelectComp(Office selectCompany, Office office) {
  182. if (office.getParent()==null||StringUtils.isBlank(office.getParent().getId())) {
  183. return false;
  184. }
  185. if (office.getParent().getId()==selectCompany.getId())return true;
  186. if(StringUtils.isNotBlank(office.getParent().getParentIds())){
  187. String[] split = office.getParent().getParentIds().split(",");
  188. for (String s : split) {
  189. if (s.equals(selectCompany.getId()))return true;
  190. }
  191. }
  192. return false;
  193. }
  194. @RequiresPermissions(value = {"sys:office:add", "sys:office:edit"}, logical = Logical.OR)
  195. @RequestMapping(value = "save")
  196. public String save(Office office, Model model, RedirectAttributes redirectAttributes, HttpSession session, HttpServletRequest request) throws Exception {
  197. if (Global.isDemoMode()) {
  198. addMessage(redirectAttributes, "演示模式,不允许操作!");
  199. return "redirect:" + adminPath + "/sys/office/";
  200. }
  201. Office office1 = office.getParent();
  202. if(office1 != null && office1.getName() != null) {
  203. Office o = officeService.get(office.getParent().getId());
  204. if (o.getType().equals("2")) {
  205. if (!"2".equals(office.getType())) {
  206. addMessage(redirectAttributes, "部门下不能添加分公司!");
  207. return "redirect:" + adminPath + "/sys/office/";
  208. }
  209. }
  210. }
  211. if (!beanValidator(model, office)) {
  212. return form(office, model, session, request);
  213. }
  214. Office c = UserUtils.getSelectCompany();
  215. if (office.getType().equals("1")) {
  216. if (office.getParent() == null || office.getParent().getId() == null) {
  217. office.setGrade("1");
  218. } else {
  219. office.setGrade("2");//分公司等级
  220. }
  221. } else if (office.getType().equals("2")) {
  222. office.setGrade("2");
  223. } else if (office.getType().equals("3")) {
  224. office.setGrade("2");
  225. } else {
  226. office.setGrade("3");
  227. }
  228. if (!office.getIsNewRecord()) {//编辑表单保存
  229. Office t = officeService.get(office.getId());//从数据库取出记录的值
  230. MyBeanUtils.copyBeanNotNull2Bean(office, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
  231. t.setIsSon(c.getIsSon());
  232. officeService.save(t);
  233. addMessage(redirectAttributes, "修改成功");
  234. String id = "0".equals(office.getParentId()) ? "" : office.getParentId();
  235. return "redirect:" + adminPath + "/sys/office/list";
  236. } else {//新增表单保存
  237. office.setIsSon(c.getIsSon());
  238. officeService.save(office);//保存
  239. }
  240. String str = "0";
  241. //如果是添加分公司,则分配相应部门和岗位
  242. try {
  243. Company company = new Company();
  244. company.setName(office.getTopCompany());
  245. company.setEmail(office.getEmail());
  246. company.setPhone(office.getPhone());
  247. company.setTuser(new User(office.getMaster()));
  248. company.setUSEABLE("1");
  249. String logo = "";
  250. if (office.getLogo() != null) {
  251. logo = office.getLogo();
  252. }
  253. company.setLogo(logo);
  254. if (office.getType().equals("1")) {
  255. str = companyService.applyCompanyOR(office, company, request);
  256. } else if (office.getType().equals("2")){
  257. Boolean b = companyService.applyOffice(office);
  258. } else if (office.getType().equals("3")) {
  259. Office com = new Office();
  260. if (!UserUtils.getUser().isAdmin()) {
  261. com = UserUtils.getSelectCompany();
  262. } else {
  263. com = office.getParent();
  264. }
  265. str = companyService.applyCompanyAnd(com, office, company, request);
  266. }
  267. if (office.getChildDeptList() != null) {
  268. Office childOffice = null;
  269. for (String id : office.getChildDeptList()) {
  270. childOffice = new Office();
  271. childOffice.setName(DictUtils.getDictLabel(id, "sys_office_common", "未知"));
  272. childOffice.setParent(office);
  273. childOffice.setArea(office.getArea());
  274. childOffice.setType("2");
  275. childOffice.setGrade(String.valueOf(Integer.valueOf(office.getGrade()) + 1));
  276. childOffice.setUseable(Global.YES);
  277. officeService.save(childOffice);
  278. }
  279. }
  280. if (str != null && "1".equals(str)) {
  281. addMessage(redirectAttributes, "保存机构'" + office.getTopCompany() + "'成功");
  282. logger.info("添加成功");
  283. } else if ("2".equals(str)) {
  284. addMessage(redirectAttributes, "创建公司管理员岗位失败");
  285. logger.info("创建公司管理员岗位失败");
  286. } else if ("3".equals(str)) {
  287. addMessage(redirectAttributes, "所选负责人数据异常");
  288. } else if ("0".equals(str)) {
  289. addMessage(redirectAttributes, "保存机构'" + office.getTopCompany() + "'成功");
  290. } else {
  291. logger.info("添加失败");
  292. }
  293. } catch (Exception e) {
  294. logger.info("Exception e:"+e);
  295. officeService.delete(office);
  296. addMessage(redirectAttributes, "创建公司管理员岗位失败");
  297. }
  298. String id = "0".equals(office.getParentId()) ? "" : office.getParentId();
  299. /*if(UserUtils.getUser().getId().equals(office.getMaster())&&office.getType().equals("1")){
  300. request.getSession().invalidate();
  301. }*/
  302. return "redirect:" + adminPath + "/sys/office/?repage";
  303. }
  304. @RequiresPermissions("sys:office:del")
  305. @RequestMapping(value = "delete")
  306. public String delete(Office office, RedirectAttributes redirectAttributes, HttpServletRequest request) {
  307. if (Global.isDemoMode()) {
  308. addMessage(redirectAttributes, "演示模式,不允许操作!");
  309. return "redirect:" + adminPath + "/sys/office/list";
  310. }
  311. if ("1".equals(office.getId())||"1".equals(office.getParentId())) {
  312. addMessage(redirectAttributes, "删除机构失败,不能删除当前机构!");
  313. //return "redirect:" + adminPath + "/sys/office/list?id=" + office.getParentId() + "&parentIds=" + office.getParentIds();
  314. return "redirect:" + Global.getAdminPath() + "/sys/office/?repage";
  315. }
  316. int cou = systemService.countByOffice(office);
  317. if (cou > 0) {
  318. addMessage(redirectAttributes, "删除机构失败,当前机构下存在用户!");
  319. return "redirect:" + Global.getAdminPath() + "/sys/office/?repage";
  320. }
  321. officeService.logicDelete(office);
  322. if(UserUtils.getSelectCompany().getId().equals(office.getId())){
  323. systemService.removeSession(UserUtils.getUser());
  324. return "modules/sys/sysLogin";
  325. }
  326. addMessage(redirectAttributes, "删除机构成功");
  327. return "redirect:" + Global.getAdminPath() + "/sys/office/?repage";
  328. }
  329. @RequiresPermissions("sys:office:del")
  330. @RequestMapping(value = "deleteUseable")
  331. public String deleteUseable(Office office, RedirectAttributes redirectAttributes, HttpServletRequest request) {
  332. try{
  333. Office company = UserUtils.getSelectCompany();
  334. if ("1".equals(company.getId())) {
  335. if (UserUtils.getUser().isAdmin()) {
  336. String[] ids = office.getParentIds().split(",");
  337. if (ids.length>1) {
  338. int lenght = ids.length - 1;
  339. for (int i = lenght; i > 0; i--) {
  340. Office o = officeService.get(ids[1]);
  341. if (o.getType().equals("1")) {
  342. company = o;
  343. break;
  344. }
  345. }
  346. }else{
  347. company = new Office("1");
  348. }
  349. }else {
  350. addMessage(redirectAttributes, "无操作权限!");
  351. }
  352. }
  353. String str = "成功";
  354. if ("1".equals(office.getUseable())){
  355. officeService.updateUseable(office);
  356. addMessage(redirectAttributes, "该机构及所有子机构项启用"+str);
  357. }else {
  358. List<User> users = systemService.findUserByOffices(office,company);
  359. if (users==null||users.size()==0){
  360. officeService.updateUseable(office);
  361. }else {
  362. str = "失败,机构下存在用户不能禁用!";
  363. }
  364. addMessage(redirectAttributes, "该机构及所有子机构项禁用"+str);
  365. }
  366. }catch (Exception e){
  367. logger.error("Exception e:"+e);
  368. if ("1".equals(office.getUseable())){
  369. addMessage(redirectAttributes, "该机构及所有子机构项启用失败");
  370. }else {
  371. addMessage(redirectAttributes, "该机构及所有子机构项禁用失败");
  372. }
  373. }
  374. return "redirect:" + Global.getAdminPath() + "/sys/office/?repage";
  375. }
  376. @ResponseBody
  377. @RequestMapping(value = "userCompany")
  378. public List<Map<String, Object>> userCompany(@RequestParam(required = false) String extId, HttpServletResponse response){
  379. List<Map<String, Object>> maps = new ArrayList<>();
  380. User user = UserUtils.getUser();
  381. List<Office> offices = officeService.findByUserId(user.getId());
  382. for (Office office : offices){
  383. Map<String, Object> map = new HashMap<>();
  384. map.put("companyId",office.getId());
  385. map.put("companyName",office.getTopCompany());
  386. if (office.getId().equals(user.getComId())){
  387. map.put("is",true);
  388. }else {
  389. map.put("is",false);
  390. }
  391. maps.add(map);
  392. }
  393. return maps;
  394. }
  395. /**
  396. * 获取机构JSON数据。
  397. *
  398. * @param extId 排除的ID
  399. * @param type 类型(1:公司;2:部门/小组/其它:3:用户)
  400. * @param grade 显示级别
  401. * @param response
  402. * @return
  403. */
  404. @RequiresPermissions("user")
  405. @ResponseBody
  406. @RequestMapping(value = "treeData")
  407. public List<Map<String, Object>> treeData(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  408. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  409. List<Map<String, Object>> mapList = Lists.newArrayList();
  410. List<Office> list = officeService.findList(isAll);
  411. for (int i = 0; i < list.size(); i++) {
  412. Office e = list.get(i);
  413. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  414. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  415. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  416. && Global.YES.equals(e.getUseable())) {
  417. Map<String, Object> map = Maps.newHashMap();
  418. map.put("id", e.getId());
  419. map.put("pId", e.getParentId());
  420. map.put("pIds", e.getParentIds());
  421. map.put("name", e.getTopCompany());
  422. map.put("type", e.getType());
  423. if (type != null && "3".equals(type)) {
  424. map.put("isParent", true);
  425. }
  426. mapList.add(map);
  427. }
  428. }
  429. return mapList;
  430. }
  431. /**
  432. * 获取机构JSON数据。
  433. *
  434. * @param extId 排除的ID
  435. * @param type 类型(1:公司;2:部门/小组/其它:3:用户)
  436. * @param grade 显示级别
  437. * @param response
  438. * @return
  439. */
  440. @RequiresPermissions("user")
  441. @ResponseBody
  442. @RequestMapping(value = "treeDataAll")
  443. public List<Map<String, Object>> treeDataAll(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  444. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  445. List<Map<String, Object>> mapList = Lists.newArrayList();
  446. Office office = new Office();
  447. office.setParentIds(UserUtils.getSelectCompany().getId());
  448. List<Office> list = officeService.findByParentIdsLike(office);
  449. for (int i = 0; i < list.size(); i++) {
  450. Office e = list.get(i);
  451. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  452. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  453. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  454. && Global.YES.equals(e.getUseable())) {
  455. Map<String, Object> map = Maps.newHashMap();
  456. map.put("id", e.getId());
  457. map.put("pId", e.getParentId());
  458. map.put("pIds", e.getParentIds());
  459. map.put("name", e.getTopCompany());
  460. if (type != null && "3".equals(type)) {
  461. map.put("isParent", true);
  462. }
  463. mapList.add(map);
  464. }
  465. }
  466. return mapList;
  467. }
  468. /**
  469. * 获取机构JSON数据。
  470. *
  471. * @param extId 排除的ID
  472. * @param type 类型 公司
  473. * @param grade 显示级别
  474. * @param response
  475. * @return
  476. */
  477. @RequiresPermissions("user")
  478. @ResponseBody
  479. @RequestMapping(value = "treeDataAlls")
  480. public List<Map<String, Object>> treeDataAlls(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  481. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  482. List<Map<String, Object>> mapList = Lists.newArrayList();
  483. Office office = new Office();
  484. User u = UserUtils.getUser();
  485. office.setParent(UserUtils.getSelectOffice().getParent());
  486. List<Office> list = officeService.findByParentId(office);
  487. for (int i = 0; i < list.size(); i++) {
  488. Office e = list.get(i);
  489. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  490. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  491. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  492. && Global.YES.equals(e.getUseable())) {
  493. Map<String, Object> map = Maps.newHashMap();
  494. map.put("id", e.getId());
  495. map.put("pId", e.getParentId());
  496. map.put("pIds", e.getParentIds());
  497. map.put("name", e.getTopCompany());
  498. if (type != null && "3".equals(type)) {
  499. map.put("isParent", true);
  500. }
  501. mapList.add(map);
  502. }
  503. }
  504. return mapList;
  505. }
  506. /**
  507. * 获取机构JSON数据。
  508. *
  509. * @param extId 排除的ID
  510. * @param type 类型(1:公司;2:部门/小组/其它:3:用户)
  511. * @param grade 显示级别
  512. * @param response
  513. * @return
  514. */
  515. @RequiresPermissions("user")
  516. @ResponseBody
  517. @RequestMapping(value = "treeDataCompany")
  518. public List<Map<String, Object>> treeDataCompany(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  519. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  520. List<Map<String, Object>> mapList = Lists.newArrayList();
  521. Office office = new Office();
  522. office.setParentIds(UserUtils.getSelectCompany().getId());
  523. List<Office> list = officeService.findByCompany(office);
  524. for (int i = 0; i < list.size(); i++) {
  525. Office e = list.get(i);
  526. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  527. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  528. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  529. && Global.YES.equals(e.getUseable())) {
  530. Map<String, Object> map = Maps.newHashMap();
  531. map.put("id", e.getId());
  532. map.put("pId", e.getParentId());
  533. map.put("pIds", e.getParentIds());
  534. map.put("name", e.getTopCompany());
  535. if (type != null && "3".equals(type)) {
  536. map.put("isParent", true);
  537. }
  538. mapList.add(map);
  539. }
  540. }
  541. return mapList;
  542. }
  543. /**
  544. * 获取机构JSON数据。
  545. *
  546. * @param extId 排除的ID
  547. * @param type 类型(1:公司;2:部门/小组/其它:3:用户)
  548. * @param grade 显示级别
  549. * @param response
  550. * @return
  551. */
  552. @RequiresPermissions("user")
  553. @ResponseBody
  554. @RequestMapping(value = "treeDataCompanyDSF")
  555. public List<Map<String, Object>> treeDataCompanyDSF(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  556. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  557. List<Map<String, Object>> mapList = Lists.newArrayList();
  558. Office office = new Office();
  559. List<Office> list = officeService.findByCompanyDSF(office);
  560. for (int i = 0; i < list.size(); i++) {
  561. Office e = list.get(i);
  562. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  563. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  564. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  565. && Global.YES.equals(e.getUseable())) {
  566. Map<String, Object> map = Maps.newHashMap();
  567. map.put("id", e.getId());
  568. map.put("pIds", e.getParentIds());
  569. map.put("pId", e.getParentId());
  570. map.put("name", e.getTopCompany());
  571. if (type != null && "3".equals(type)) {
  572. map.put("isParent", true);
  573. }
  574. mapList.add(map);
  575. }
  576. }
  577. return mapList;
  578. }
  579. /**
  580. * 获取岗位JSON数据。
  581. *
  582. * @param response
  583. * @return
  584. */
  585. @RequiresPermissions("user")
  586. @ResponseBody
  587. @RequestMapping(value = "treeDataRole")
  588. public List<Map<String, Object>> treeDataRole(@RequestParam(required = false) String userId,@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  589. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  590. List<Map<String, Object>> mapList = Lists.newArrayList();
  591. List<Office> list = new ArrayList<>();
  592. Office userOffice = UserUtils.getSelectOffice();
  593. if (UserUtils.getUser().isAdmin()){
  594. list = officeService.findAll();
  595. }else {
  596. Office office = new Office();
  597. if (StringUtils.isBlank(userOffice.getBranchOffice())){
  598. office.setParentIds(UserUtils.getSelectCompany().getId());
  599. list = officeService.findByParentIdsLike(office);
  600. }else {
  601. office.setParentIds(userOffice.getBranchOffice());
  602. list = officeService.findByParentIdsLike(office);
  603. }
  604. }
  605. for (int i = 0; i < list.size(); i++) {
  606. Office e = list.get(i);
  607. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  608. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  609. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  610. && Global.YES.equals(e.getUseable())) {
  611. Map<String, Object> map = Maps.newHashMap();
  612. map.put("id", e.getId());
  613. map.put("pIds", e.getParentIds());
  614. map.put("pId", e.getParentId());
  615. map.put("name", e.getTopCompany());
  616. if (type != null && "3".equals(type)) {
  617. map.put("isParent", true);
  618. }
  619. map.put("look", false);
  620. mapList.add(map);
  621. }
  622. }
  623. Office company = new Office();
  624. if (StringUtils.isNotBlank(userId)) {
  625. company = UserUtils.get(userId).getCompany();
  626. } else {
  627. company = UserUtils.getSelectCompany();
  628. }
  629. Role roles = new Role();
  630. if (!UserUtils.getUser().isAdmin()){
  631. roles.setCompany(company);
  632. roles.setBranchCompany(new Office(userOffice.getBranchOffice()));
  633. }
  634. List<Role> roleList = UserUtils.getRoleListByCompanys(roles);
  635. for (int i = 0; i < roleList.size(); i++) {
  636. Role e = roleList.get(i);
  637. Map<String, Object> map = Maps.newHashMap();
  638. map.put("id", e.getId());
  639. map.put("name", e.getName());
  640. map.put("pId", e.getOffice().getId());
  641. map.put("pIds", e.getOffice().getParentIds()+e.getOffice().getId()+",");
  642. map.put("isParent", false);
  643. map.put("look", true);
  644. mapList.add(map);
  645. }
  646. return mapList;
  647. /*Office company = new Office();
  648. if (StringUtils.isNotBlank(userId)) {
  649. company = UserUtils.get(userId).getCompany();
  650. } else {
  651. company = UserUtils.getSelectCompany();
  652. }
  653. Role roles = new Role();
  654. roles.setCompany(company);
  655. List<Role> roleList = UserUtils.getRoleListByCompany(roles);
  656. for (int i = 0; i < roleList.size(); i++) {
  657. Role e = roleList.get(i);
  658. Map<String, Object> map = Maps.newHashMap();
  659. map.put("id", e.getId());
  660. map.put("name", e.getTopCompany());
  661. map.put("isParent", false);
  662. mapList.add(map);
  663. }*/
  664. }
  665. /**
  666. * 获取角色JSON数据。
  667. *
  668. * @param response
  669. * @return
  670. */
  671. @RequiresPermissions("user")
  672. @ResponseBody
  673. @RequestMapping(value = "treeDataRoleActivity")
  674. public List<Map<String, Object>> treeDataRoleActivity(HttpServletResponse response) {
  675. List<Map<String, Object>> mapList = Lists.newArrayList();
  676. Office company = UserUtils.getSelectCompany();
  677. SysRoleActivity roleActivity = new SysRoleActivity();
  678. roleActivity.setCompanyId(company.getId());
  679. List<SysRoleActivity> roleList = UserUtils.getRoleActivityListByCompany(roleActivity);
  680. if (roleList!=null && roleList.size()!=0){
  681. for (int i = 0; i < roleList.size(); i++) {
  682. SysRoleActivity e = roleList.get(i);
  683. Map<String, Object> map = Maps.newHashMap();
  684. map.put("id", e.getId());
  685. map.put("isParent", false);
  686. map.put("name", e.getName());
  687. mapList.add(map);
  688. }
  689. }
  690. return mapList;
  691. }
  692. /**
  693. * 获取角色JSON数据。
  694. *
  695. * @param response
  696. * @return
  697. */
  698. @RequiresPermissions("user")
  699. @RequestMapping(value = "treeDataRoleActivitys")
  700. public String treeDataRoleActivitys(SysRoleActivity sysRoleActivity,String url,boolean isAll,String type,boolean isSingle,HttpServletRequest request, HttpServletResponse response, Model model) {
  701. Office company = UserUtils.getSelectCompany();
  702. sysRoleActivity.setCompanyId(company.getId());
  703. List<SysRoleActivity> roleList = UserUtils.getRoleActivityListByCompany(sysRoleActivity);
  704. //model.addAttribute("sysRoleActivity", sysRoleActivity);
  705. model.addAttribute("isSingle", isSingle);
  706. model.addAttribute("url", url);
  707. model.addAttribute("isAll", isAll);
  708. model.addAttribute("type", type);
  709. model.addAttribute("roleList", roleList);
  710. return "modules/sys/gridSelectRole";
  711. }
  712. /**
  713. * 获取角色JSON数据。
  714. *
  715. * @param response
  716. * @return
  717. */
  718. @RequiresPermissions("user")
  719. @ResponseBody
  720. @RequestMapping(value = "treeDataRoleActivityEnname")
  721. public List<Map<String, Object>> treeDataRoleActivityEnname(HttpServletResponse response) {
  722. List<Map<String, Object>> mapList = Lists.newArrayList();
  723. Office company = UserUtils.getSelectCompany();
  724. SysRoleActivity roleActivity = new SysRoleActivity();
  725. roleActivity.setCompanyId(company.getId());
  726. List<SysRoleActivity> roleList = UserUtils.getRoleActivityListByCompany(roleActivity);
  727. for (int i = 0; i < roleList.size(); i++) {
  728. SysRoleActivity e = roleList.get(i);
  729. Map<String, Object> map = Maps.newHashMap();
  730. map.put("id", e.getEnname());
  731. map.put("name", e.getName());
  732. map.put("isParent", false);
  733. mapList.add(map);
  734. }
  735. return mapList;
  736. }
  737. @RequestMapping("compInfo")
  738. @ResponseBody
  739. public Office queryCompInfo(String id){
  740. Office office = officeService.get(id);
  741. if(office!=null) {
  742. office.setSimpleName(UserUtils.getSysParamByCompany("company_shortname",office.getId()));
  743. office.setBranchSimpleName(UserUtils.getSysParamByCompany("branch_shortname",office.getId()));
  744. }
  745. return office;
  746. }
  747. @RequestMapping(value = "gridSelectUser")
  748. public String gridSelectUser(WorkStaffBasicInfo workStaffBasicInfo,String url,boolean isAll,String type,boolean isSingle, HttpServletRequest request, HttpServletResponse response, Model model){
  749. List<Office> list =new ArrayList<>();
  750. Office office=UserUtils.getSelectOffice();
  751. if(StringUtils.isNotBlank(office.getBranchOffice())){
  752. Office branchOffice=officeDao.get(office.getBranchOffice());
  753. workStaffBasicInfo.setBranchOffice(branchOffice);
  754. }else{
  755. workStaffBasicInfo.setBranchOffice(UserUtils.getSelectCompany());
  756. }
  757. Page<WorkStaffBasicInfo> page=new Page<>();
  758. if("1".equals(type)){//列表没有转正申请的员工,单选
  759. workStaffBasicInfo.setStatus("试用");
  760. page = workStaffBasicInfoService.findUserApplyPage(new Page<WorkStaffBasicInfo>(request, response), workStaffBasicInfo);
  761. }else if("2".equals(type)){//劳动关系员工
  762. page = workStaffBasicInfoService.findUserShipList(new Page<WorkStaffBasicInfo>(request, response), workStaffBasicInfo);
  763. }else if("3".equals(type)){
  764. workStaffBasicInfo.setUserId(UserUtils.getUser().getId());
  765. page = workStaffBasicInfoService.findUserListPage(new Page<WorkStaffBasicInfo>(request, response), workStaffBasicInfo);
  766. }else if("5".equals(type)){
  767. //人员信息库引用
  768. page = workStaffBasicInfoService.findAchivePage(new Page<WorkStaffBasicInfo>(request, response), workStaffBasicInfo);
  769. }else if("4".equals(type)){
  770. //人员信息库引用
  771. workStaffBasicInfo.setBranchOffice(null);
  772. workStaffBasicInfo.setSqlStr("AND a.status in ('正式','试用','劳务') and a.office_id in ( SELECT ss.id FROM sys_office ss where ss.id='"+UserUtils.getSelectBranchOffice()+"' or ss.parent_ids like concat('%','"+UserUtils.getSelectBranchOffice()+"','%')) ");
  773. page = workStaffBasicInfoService.findUserListPage(new Page<WorkStaffBasicInfo>(request, response), workStaffBasicInfo);
  774. }else{
  775. workStaffBasicInfo.setSqlStr("AND a.status in ('正式','试用','劳务')");
  776. page = workStaffBasicInfoService.findUserListPage(new Page<WorkStaffBasicInfo>(request, response), workStaffBasicInfo);
  777. }
  778. model.addAttribute("workStaffBasicInfo", workStaffBasicInfo);
  779. model.addAttribute("isSingle", isSingle);
  780. model.addAttribute("url", url);
  781. model.addAttribute("isAll", isAll);
  782. model.addAttribute("type", type);
  783. model.addAttribute("page", page);
  784. return "modules/sys/gridSelectUser";
  785. }
  786. /**
  787. * 获取机构JSON数据。
  788. *
  789. * @param extId 排除的ID
  790. * @param type 类型(1:公司;2:部门/小组/其它:3:用户)
  791. * @param grade 显示级别
  792. * @param response
  793. * @return
  794. */
  795. @RequiresPermissions("user")
  796. @ResponseBody
  797. @RequestMapping(value = "treeDataBranchOffice")
  798. public List<Map<String, Object>> treeDataBranchOffice(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  799. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll,@RequestParam(required = false) String branchOffice, HttpServletResponse response) {
  800. List<Map<String, Object>> mapList = Lists.newArrayList();
  801. List<Office> list = new ArrayList<>();
  802. if (StringUtils.isBlank(branchOffice)){
  803. list = officeService.findByBranchOffice();
  804. }else {
  805. list = officeService.findByBranchOfficeInfo(branchOffice);
  806. }
  807. for (int i = 0; i < list.size(); i++) {
  808. Office e = list.get(i);
  809. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  810. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  811. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  812. && Global.YES.equals(e.getUseable())) {
  813. Map<String, Object> map = Maps.newHashMap();
  814. map.put("id", e.getId());
  815. map.put("pId", e.getParentId());
  816. map.put("pIds", e.getParentIds());
  817. map.put("name", e.getTopCompany());
  818. if (type != null && "3".equals(type)) {
  819. map.put("isParent", true);
  820. }
  821. mapList.add(map);
  822. }
  823. }
  824. return mapList;
  825. }
  826. /**
  827. * 获取机构JSON数据。
  828. *
  829. * @param extId 排除的ID
  830. * @param type 类型(1:公司;2:部门/小组/其它:3:用户)
  831. * @param grade 显示级别
  832. * @param response
  833. * @return
  834. */
  835. @RequiresPermissions("user")
  836. @ResponseBody
  837. @RequestMapping(value = "treeDataAllOffice")
  838. public List<Map<String, Object>> treeDataAllOffice(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
  839. @RequestParam(required = false) Long grade, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
  840. List<Map<String, Object>> mapList = Lists.newArrayList();
  841. Office office=UserUtils.getSelectOffice();
  842. // Office branchOffice=officeDao.get(office.getBranchOffice());
  843. List<Office> list = officeService.treeDataAllOffice(office);
  844. for (int i = 0; i < list.size(); i++) {
  845. Office e = list.get(i);
  846. if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
  847. && (type == null || (type != null && (type.equals("1") ? type.equals(e.getType()) : true)))
  848. && (grade == null || (grade != null && Integer.parseInt(e.getGrade()) <= grade.intValue()))
  849. && Global.YES.equals(e.getUseable())) {
  850. Map<String, Object> map = Maps.newHashMap();
  851. map.put("id", e.getId());
  852. map.put("pId", e.getParentId());
  853. map.put("pIds", e.getParentIds());
  854. map.put("name", e.getTopCompany());
  855. if (type != null && "3".equals(type)) {
  856. map.put("isParent", true);
  857. }
  858. mapList.add(map);
  859. }
  860. }
  861. return mapList;
  862. }
  863. @RequiresPermissions("user")
  864. @ResponseBody
  865. @RequestMapping(value = "validate")
  866. public AjaxJson validate(String id) {
  867. AjaxJson ajaxJson = new AjaxJson();
  868. boolean inUse = officeService.validate(id);
  869. ajaxJson.getBody().put("inUse",inUse);
  870. return ajaxJson;
  871. }
  872. }