| | |
| | | package com.vci.frameworkcore.controller; |
| | | |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.dto.OrgDepartmentDTO; |
| | | import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI; |
| | | import com.vci.frameworkcore.pagemodel.OrgDepartmentVO; |
| | | import com.vci.constant.FrameWorkLangCodeConstant; |
| | | import com.vci.pagemodel.OrgDepartmentVO; |
| | | import com.vci.starter.web.annotation.controller.VciUnCheckRight; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.pagemodel.*; |
| | | import com.vci.starter.web.util.ControllerUtil; |
| | | import com.vci.starter.web.util.LangBaseUtil; |
| | | import com.vci.starter.web.util.LocalFileUtil; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import com.vci.web.util.Func; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | 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 org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/departmentQueryController") |
| | | @Slf4j |
| | | public class OrgDepartmentQueryController { |
| | | |
| | | /** |
| | |
| | | private OrgDeptQueryServiceI deptQueryService; |
| | | |
| | | /** |
| | | * 部门的树形参照 |
| | | * 日志 |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | /** |
| | | * 部门的树形参照,部门管理也用的这个查询接口 |
| | | * @param treeQueryObject 树形数据的查询对象,包括查询条件,上级主键,是否多选等,(extandParamsMap中添加"showAllDepartmentNode"为"true"时,并且parentOid为空,返回结果中会包含“所有部门”这个节点) |
| | | * @return 部门的树形参照,已经转换了上下级关系 |
| | | * @throws VciBaseException 查询出错的时候会抛出异常,如果是老的项目里不抛出异常 |
| | | */ |
| | | @RequestMapping(value = "/refTree",method = RequestMethod.GET) |
| | | public BaseResult<Tree> refTree(TreeQueryObject treeQueryObject) throws VciBaseException{ |
| | | List<Tree> deptTreeList = deptQueryService.refTreeDept(treeQueryObject); |
| | | return BaseResult.tree(deptTreeList); |
| | | //老的项目依然是添加try catch,方法里不抛出异常 |
| | | //BaseResult.fail("这里返回前端的错误信息"); |
| | | try { |
| | | List<Tree> deptTreeList = deptQueryService.refTreeDept(treeQueryObject); |
| | | return BaseResult.tree(deptTreeList); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "部门树查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 部门查询,带分页 |
| | | * 部门列表查询,带分页 |
| | | * @param queryObject |
| | | * @return |
| | | * @return 返回的list不是tree结构的 |
| | | */ |
| | | @RequestMapping(value = "/refDataGrid",method = RequestMethod.GET) |
| | | public BaseResult<OrgDepartmentVO> refDataGrid(BaseQueryObject queryObject){ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 保存部门角色关联信息,带查重功能 |
| | | * @param userOIds 用户id |
| | | * 保存部门用户关联信息,平台自带查重功能 |
| | | * @param userOids 用户id |
| | | * @param deptId 部门oid |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/saveUsersDepts",method = RequestMethod.POST) |
| | | public BaseResult saveUsersDepts(String[] userOIds, String deptId){ |
| | | public BaseResult saveUsersDepts(String[] userOids, String deptId){ |
| | | //不能同时为空 |
| | | if(Func.isEmpty(userOids) && Func.isBlank(deptId)){ |
| | | return BaseResult.fail("角色主键和部门主键,参数不能同时为空!"); |
| | | } |
| | | try { |
| | | return deptQueryService.saveUsersDept(userOIds,deptId) ? BaseResult.success("角色分配成功!"):BaseResult.fail("角色分配失败!"); |
| | | return deptQueryService.saveUsersDept(userOids,deptId) ? BaseResult.success("部门分配成功!"):BaseResult.fail("部门分配失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | String exceptionMessage = "关联的部门时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新增单条部门 |
| | | * @param orgDepartmentDTO |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/addDept",method = RequestMethod.POST) |
| | | public BaseResult addDept(@RequestBody OrgDepartmentDTO orgDepartmentDTO){ |
| | | try { |
| | | return deptQueryService.addDept(orgDepartmentDTO) ? BaseResult.success("部门添加成功!"):BaseResult.fail("部门添加失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "添加部门时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改部门信息 |
| | | * @param orgDepartmentDTO |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/updateDept",method = RequestMethod.PUT) |
| | | public BaseResult updateRole(@RequestBody OrgDepartmentDTO orgDepartmentDTO){ |
| | | try { |
| | | return deptQueryService.updateDept(orgDepartmentDTO) ? BaseResult.success("部门修改成功!"):BaseResult.fail("部门修改失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "修改部门时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除部门 |
| | | * @param ids 要删除的部门主键 |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/deleteDept",method = RequestMethod.DELETE) |
| | | public BaseResult deleteDept(String[] ids){ |
| | | try { |
| | | return deptQueryService.deleteDept(ids) ? BaseResult.success("删除部门成功!"):BaseResult.fail("删除部门失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "添加部门时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | return BaseResult.fail(exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载人员导入模板 |
| | | * @param downloadFileName |
| | | * @param response |
| | | */ |
| | | @RequestMapping(value = "/downloadImportTemplate",method = RequestMethod.GET) |
| | | public void downloadImportTemplate(String downloadFileName, HttpServletResponse response){ |
| | | try { |
| | | String excelPath = deptQueryService.downloadImportTemplate(downloadFileName); |
| | | ControllerUtil.writeFileToResponse(response,excelPath); |
| | | } catch (Exception e) { |
| | | String msg = "下载部门导入模板时出现错误,原因:" + LangBaseUtil.getErrorMsg(e); |
| | | try { |
| | | e.printStackTrace(); |
| | | ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null); |
| | | } catch (IOException ioException) { |
| | | ioException.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 部门导入 |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/importDept",method = RequestMethod.POST) |
| | | @VciUnCheckRight |
| | | public BaseResult importUser(MultipartFile file){ |
| | | String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename()); |
| | | File file1 = new File(excelFileName); |
| | | try { |
| | | file.transferTo(new File(excelFileName)); |
| | | if (file != null) { |
| | | return deptQueryService.importDept(file1); |
| | | } else { |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"}); |
| | | } |
| | | }catch (Throwable e) { |
| | | throw new VciBaseException(e.getMessage(),new String[0],e); |
| | | }finally { |
| | | file1.delete(); |
| | | } |
| | | } |
| | | |