package com.bonus.sys.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.bonus.sys.AjaxRes; import com.bonus.sys.BaseController; import com.bonus.sys.GlobalConst; import com.bonus.sys.Page; import com.bonus.sys.beans.OrgBean; import com.bonus.sys.beans.ZNode; import com.bonus.sys.service.OrgService; import com.bonus.sys.service.UserService; @Controller @RequestMapping("/backstage/org/") public class OrgController extends BaseController { @Autowired private OrgService service; @Autowired private UserService userService; @RequestMapping("list") public String index(Model model) { return "/sys/orglist"; } @RequestMapping("orgManagement") public String orgManagement(Model model) { return "/sys/orgManagement"; } @RequestMapping("toOrgForm") public String toOrgForm(Model model,OrgBean org) { try { OrgBean o = service.findOrgById(org); String opt = org.getOpt(); o.setOpt(opt); if("add".equals(opt)){ String code = service.getNextCode(o); org.setCode(code); org.setParent(o); model.addAttribute("org", org); }else{ model.addAttribute("org", o); } model.addAttribute("emps", userService.findInternalEmp()); } catch (Exception e) { e.printStackTrace(); } return "/sys/orgForm"; } @RequestMapping(value = "findAll", method = RequestMethod.POST) @ResponseBody public AjaxRes findAll() { AjaxRes ar = getAjaxRes(); try { List list = userService.getOrgBeans(); List emps = userService.findAllInternalEmp(); for (ZNode bean : emps) { bean.setIcon(getRequest().getContextPath() + "/static/image/emp.png"); } ar.setSucceed(list); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } @RequestMapping(value = "findAllList", method = RequestMethod.POST) @ResponseBody public AjaxRes findAllList() { AjaxRes ar = getAjaxRes(); try { List list = userService.getOrgBeansList(); ar.setSucceed(list); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } @RequestMapping(value = "findOrgTree", method = RequestMethod.POST) @ResponseBody public AjaxRes findOrgTree() { AjaxRes ar = getAjaxRes(); try { List list = service.getOrgTree(); if (list != null) { for (ZNode bean : list) { if ("0".equals(bean.getpId())) { bean.setOpen(true); } } } ar.setSucceed(list); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } /** * @Author 无畏 * @Date 2019-09-12 * @function 获得机具列表 * @param o * @return */ @RequestMapping("findByPage") public String getApplyList(@RequestBody Page page,OrgBean o,Model model) { try { o = page.getObj(); page = service.findByPage(o, page); model.addAttribute("page", page); } catch (Exception e) { e.printStackTrace(); } return "/sys/orgManagementList"; } @RequestMapping(value = "update", method = RequestMethod.POST) @ResponseBody public AjaxRes update(OrgBean o) { AjaxRes ar = getAjaxRes(); try { service.updateOrgBean(o); ar.setSucceedMsg(GlobalConst.UPDATE_SUCCEED); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.UPDATE_FAIL); } return ar; } @RequestMapping(value = "add", method = RequestMethod.POST) @ResponseBody public AjaxRes add(OrgBean o) { AjaxRes ar = getAjaxRes(); try { service.insertOrgBean(o); ar.setSucceedMsg(GlobalConst.SAVE_SUCCEED); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.SAVE_FAIL); } return ar; } @RequestMapping(value = "checkNameIsExist", method = RequestMethod.POST) @ResponseBody public AjaxRes checkNameIsExist(OrgBean o) { AjaxRes ar = getAjaxRes(); try { List list = service.checkNameIsExist(o); if(list.size() > 0){ ar.setFailMsg("该部门名在当前上级部门下已经存在,请您仔细校验核对!"); }else{ ar.setRes(GlobalConst.SUCCEED); } } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } @RequestMapping(value = "addOrg", method = RequestMethod.POST) @ResponseBody public AjaxRes addOrg(@RequestBody OrgBean o) { AjaxRes ar = getAjaxRes(); try { o.setCode(service.getNextCode(o.getParent()));; int result = service.addOrg(o); if(result == 0){ ar.setFailMsg("部门添加失败!"); }else{ ar.setSucceedMsg("部门添加成功!"); } } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } @RequestMapping(value = "updateOrg", method = RequestMethod.POST) @ResponseBody public AjaxRes updateOrg(@RequestBody OrgBean o) { AjaxRes ar = getAjaxRes(); try { int result = service.updateOrg(o); if(result == 0){ ar.setFailMsg("部门更新失败!"); }else{ ar.setSucceedMsg("部门更新成功!"); } } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } @RequestMapping(value = "del", method = RequestMethod.POST) @ResponseBody public AjaxRes del(OrgBean o) { AjaxRes ar = getAjaxRes(); try { service.delete(o.getId()); ar.setSucceedMsg(GlobalConst.DEL_SUCCEED); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DEL_FAIL); } return ar; } @RequestMapping(value = "findRepairGroup", method = RequestMethod.POST) @ResponseBody public AjaxRes findRepairGroup(OrgBean o) { AjaxRes ar = getAjaxRes(); try { List list = service.findRepairGroup(o); ar.setSucceed(list); } catch (Exception e) { logger.error(e.toString(), e); ar.setFailMsg(GlobalConst.DATA_FAIL); } return ar; } }