SysDeptController.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package com.boman.system.controller;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import java.util.List;
  8. import com.alibaba.fastjson.JSONObject;
  9. import org.apache.commons.lang3.ArrayUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.validation.annotation.Validated;
  12. import org.springframework.web.bind.annotation.DeleteMapping;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.PathVariable;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.PutMapping;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import com.boman.domain.constant.UserConstants;
  21. import com.boman.common.core.utils.SecurityUtils;
  22. import com.boman.common.core.utils.StringUtils;
  23. import com.boman.common.core.web.controller.BaseController;
  24. import com.boman.domain.dto.AjaxResult;
  25. import com.boman.common.log.annotation.Log;
  26. import com.boman.common.log.enums.BusinessType;
  27. import com.boman.common.security.annotation.PreAuthorize;
  28. import com.boman.domain.SysDept;
  29. import com.boman.system.service.ISysDeptService;
  30. /**
  31. * 部门信息
  32. *
  33. * @author ruoyi
  34. */
  35. @RestController
  36. @RequestMapping("/dept")
  37. public class SysDeptController extends BaseController
  38. {
  39. @Autowired
  40. private ISysDeptService deptService;
  41. /**
  42. * 获取部门列表
  43. */
  44. // @PreAuthorize(hasPermi = "system:dept:list")
  45. @GetMapping("/list")
  46. public AjaxResult list(SysDept dept) {
  47. List<SysDept> depts = deptService.selectDeptList(dept);
  48. return AjaxResult.success(depts);
  49. }
  50. /**
  51. * 获取部门列表
  52. */
  53. @GetMapping("/deptList")
  54. public AjaxResult deptList(SysDept dept) {
  55. List<SysDept> depts = deptService.selectDepts(dept);
  56. return AjaxResult.success(depts);
  57. }
  58. /**
  59. * 查询部门列表(排除节点)
  60. */
  61. @PreAuthorize(hasPermi = "system:dept:list")
  62. @GetMapping("/list/exclude/{id}")
  63. public AjaxResult excludeChild(@PathVariable(value = "id", required = false) Long id)
  64. {
  65. List<SysDept> depts = deptService.selectDeptList(new SysDept());
  66. Iterator<SysDept> it = depts.iterator();
  67. while (it.hasNext())
  68. {
  69. SysDept d = (SysDept) it.next();
  70. if (d.getId().intValue() == id
  71. || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), id + ""))
  72. {
  73. it.remove();
  74. }
  75. }
  76. return AjaxResult.success(depts);
  77. }
  78. /**
  79. * 功能描述: 拿到部门下所有的部门, 包含传过来的deptId
  80. *
  81. * @param deptId deptId
  82. * @return com.boman.domain.dto.AjaxResult
  83. */
  84. @GetMapping("/list/children/depts/{deptId}")
  85. public List<SysDept> listChildrenDepts(@PathVariable(value = "deptId") Long deptId) {
  86. return deptService.listChildrenDepts(deptId);
  87. }
  88. /**
  89. * 根据部门编号获取详细信息
  90. */
  91. @PreAuthorize(hasPermi = "system:dept:query")
  92. @GetMapping(value = "/{id}")
  93. public AjaxResult getInfo(@PathVariable Long id)
  94. {
  95. return AjaxResult.success(deptService.selectDeptById(id));
  96. }
  97. /**
  98. * 根据部门编号获取详细信息
  99. */
  100. @PreAuthorize(hasPermi = "system:dept:query")
  101. @GetMapping(value = "/getById/{id}")
  102. public SysDept getById(@PathVariable("id") Long id)
  103. {
  104. return deptService.selectDeptById(id);
  105. }
  106. /**
  107. * 根据部门名称获取该用户属于哪一个部门(疫苗新增/修改时使用)
  108. */
  109. @GetMapping(value = "/selectByDeptName/{deptName}")
  110. public List<SysDept> selectByDeptName(@PathVariable("deptName") String deptName)
  111. {
  112. return deptService.selectByDeptName(deptName);
  113. }
  114. /**
  115. * 获取部门下拉树列表
  116. */
  117. @GetMapping("/treeselect")
  118. public AjaxResult treeselect(SysDept dept)
  119. {
  120. List<SysDept> depts = deptService.selectDeptList(dept);
  121. return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
  122. }
  123. /**
  124. * 获取部门下拉树列表
  125. */
  126. @GetMapping("/depts")
  127. public AjaxResult depts(SysDept dept)
  128. {
  129. List<SysDept> depts = deptService.selectDepts(dept);
  130. return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
  131. }
  132. /**
  133. * 加载对应角色部门列表树
  134. */
  135. @GetMapping(value = "/roleDeptTreeselect/{roleId}")
  136. public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
  137. {
  138. List<SysDept> depts = deptService.selectDeptList(new SysDept());
  139. AjaxResult ajax = AjaxResult.success();
  140. ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
  141. ajax.put("depts", deptService.buildDeptTreeSelect(depts));
  142. return ajax;
  143. }
  144. /**
  145. * 新增部门
  146. */
  147. @PreAuthorize(hasPermi = "system:dept:add")
  148. @Log(title = "部门管理", businessType = BusinessType.INSERT)
  149. @PostMapping
  150. public AjaxResult add(@Validated @RequestBody SysDept dept)
  151. {
  152. if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
  153. {
  154. return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
  155. }
  156. dept.setCreateBy(SecurityUtils.getUsername());
  157. return toAjax(deptService.insertDept(dept));
  158. }
  159. /**
  160. * 修改部门
  161. */
  162. @PreAuthorize(hasPermi = "system:dept:edit")
  163. @Log(title = "部门管理", businessType = BusinessType.UPDATE)
  164. @PutMapping
  165. public AjaxResult edit(@Validated @RequestBody SysDept dept)
  166. {
  167. if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
  168. {
  169. return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
  170. }
  171. else if (dept.getParentId().equals(dept.getId()))
  172. {
  173. return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
  174. }
  175. else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
  176. && deptService.selectNormalChildrenDeptById(dept.getId()) > 0)
  177. {
  178. return AjaxResult.error("该部门包含未停用的子部门!");
  179. }
  180. dept.setUpdateBy(SecurityUtils.getUsername());
  181. return toAjax(deptService.updateDept(dept));
  182. }
  183. /**
  184. * 删除部门
  185. */
  186. @PreAuthorize(hasPermi = "system:dept:remove")
  187. @Log(title = "部门管理", businessType = BusinessType.DELETE)
  188. @DeleteMapping("/{id}")
  189. public AjaxResult remove(@PathVariable Long id)
  190. {
  191. if (deptService.hasChildById(id))
  192. {
  193. return AjaxResult.error("存在下级部门,不允许删除");
  194. }
  195. if (deptService.checkDeptExistUser(id))
  196. {
  197. return AjaxResult.error("部门存在用户,不允许删除");
  198. }
  199. return toAjax(deptService.deleteDeptById(id));
  200. }
  201. @GetMapping("/moveData/{limit}/{offset}")
  202. public String moveYmjzData(@PathVariable("limit") int limit, @PathVariable("offset") int offset) throws Exception {
  203. // List<String> idCardList = mapper.listIdCard(limit, offset);
  204. List<JSONObject> ymjzList = deptService.syncData();
  205. int moveData = 0;
  206. StringBuilder stringBuilder = new StringBuilder();
  207. List<String> enpty = new ArrayList<>();
  208. for (int i = 0; i < ymjzList.size(); i++) {
  209. JSONObject ymjz = ymjzList.get(i);
  210. String idCard = ymjz.getString("id_card");
  211. Long deptId = ymjz.getLong("dept_id");
  212. String sql = "";
  213. if(deptId == null) {
  214. enpty.add(idCard);
  215. }else {
  216. sql = String.format("UPDATE vaccine_info set dept_id = %s where id_card = '%s'; -- %s \r\n", deptId, idCard, i);
  217. stringBuilder.append(sql);
  218. }
  219. System.err.println("count: " + i + ", " + sql);
  220. moveData++;
  221. }
  222. File file = new File("E:\\\\work\\vainfo.sql");
  223. // File file = new File("//home//vainfo_update.sql");
  224. if (!file.exists()) {
  225. file.createNewFile();
  226. }
  227. FileWriter fileWriter = new FileWriter(file, true);
  228. BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
  229. bufferedWriter.write(stringBuilder.toString());
  230. bufferedWriter.close();
  231. for (String s : enpty) {
  232. System.out.println(s);
  233. }
  234. return "循环了 " + moveData + " 条";
  235. }
  236. /**
  237. * 查找子部门,不递归
  238. */
  239. @GetMapping("/parentId/{parentId}")
  240. public List<SysDept> getByParentId(@PathVariable("parentId") Long parentId) {
  241. return deptService.getByParentId(parentId);
  242. }
  243. }