|
|
@@ -1,11 +1,10 @@
|
|
|
package easydo.technology.system.rest;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import easydo.technology.annotation.WebLog;
|
|
|
+import easydo.technology.components.JdbcClient;
|
|
|
import easydo.technology.system.domain.SysDept;
|
|
|
import easydo.technology.system.dto.SysDeptDto;
|
|
|
-import easydo.technology.system.mapper.SysDeptMapper;
|
|
|
-import easydo.technology.system.service.ISysDeptService;
|
|
|
+import easydo.technology.utils.SecurityUtils;
|
|
|
import easydo.technology.utils.StringUtil;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
@@ -14,7 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.sql.DataSource;
|
|
|
+import java.sql.Connection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -25,56 +27,77 @@ import java.util.List;
|
|
|
@RequestMapping("/dept")
|
|
|
public class DeptController {
|
|
|
@Resource
|
|
|
- SysDeptMapper sysDeptMapper;
|
|
|
+ JdbcClient jdbcClient;
|
|
|
@Resource
|
|
|
- ISysDeptService sysDeptService;
|
|
|
+ DataSource dataSource;
|
|
|
|
|
|
@WebLog
|
|
|
@RequestMapping("/getList")
|
|
|
- public Object getList(@RequestBody SysDeptDto dto) {
|
|
|
- QueryWrapper<SysDept> wrapper = new QueryWrapper<>();
|
|
|
- if (StringUtil.isNotEmpty(dto.getPid())) {
|
|
|
- if (dto.getPid() == 0) {
|
|
|
- wrapper.isNull("pid");
|
|
|
- } else {
|
|
|
- wrapper.eq("pid", dto.getPid());
|
|
|
- }
|
|
|
- }
|
|
|
- if(StringUtil.isNotEmpty(dto.getName())){
|
|
|
- wrapper.like("name", dto.getName());
|
|
|
- }
|
|
|
- if (StringUtil.isNotEmpty(dto.getEnabled())) {
|
|
|
- wrapper.eq("enabled", dto.getEnabled());
|
|
|
- }
|
|
|
- if (StringUtil.isNotEmpty(dto.getBeginCreateTime())) {
|
|
|
- wrapper.gt("create_time", dto.getBeginCreateTime());
|
|
|
- }
|
|
|
- if (StringUtil.isNotEmpty(dto.getEndCreateTime())) {
|
|
|
- wrapper.lt("create_time", dto.getEndCreateTime());
|
|
|
- }
|
|
|
- List<SysDept> deptList = sysDeptMapper.selectList(wrapper);
|
|
|
+ public Object getList(@RequestBody Map<String, Object> map) throws Exception {
|
|
|
+ List<SysDept> deptList = jdbcClient.getJdbcList(map, SysDept.class);
|
|
|
return new ResponseEntity<>(deptList, HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@WebLog
|
|
|
@RequestMapping("/save")
|
|
|
- public Object save(@RequestBody SysDept dept) {
|
|
|
- sysDeptService.saveDept(dept);
|
|
|
- return new ResponseEntity<>(dept, HttpStatus.OK);
|
|
|
+ public Object save(@RequestBody SysDept model) throws Exception {
|
|
|
+ Connection connection = null;
|
|
|
+ try {
|
|
|
+ connection = dataSource.getConnection();
|
|
|
+ connection.setAutoCommit(false);
|
|
|
+
|
|
|
+ model.setDeptId((long) 0);
|
|
|
+ String username = SecurityUtils.getCurrentUsername();
|
|
|
+ model.setCreateBy(username);
|
|
|
+ model.setUpdateBy(username);
|
|
|
+ jdbcClient.jdbcInsert(model, connection);
|
|
|
+
|
|
|
+ if (StringUtil.isNotEmpty(model.getPid())) {
|
|
|
+ SysDept pDept = new SysDept();
|
|
|
+ pDept.setDeptId(model.getPid());
|
|
|
+ pDept = jdbcClient.getJdbcModel(pDept, connection);
|
|
|
+ pDept.setSubCount(pDept.getSubCount() + 1);
|
|
|
+ jdbcClient.jdbcUpdateById(pDept, connection);
|
|
|
+ }
|
|
|
+
|
|
|
+ connection.commit();
|
|
|
+ return new ResponseEntity<>(model, HttpStatus.OK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ connection.rollback();
|
|
|
+ throw new Exception(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ jdbcClient.finallyExecute(connection);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@WebLog
|
|
|
@RequestMapping("/update")
|
|
|
public Object update(@RequestBody SysDept dept) throws Exception {
|
|
|
- sysDeptService.updateDept(dept);
|
|
|
+ String username = SecurityUtils.getCurrentUsername();
|
|
|
+ dept.setUpdateBy(username);
|
|
|
+ jdbcClient.jdbcUpdateById(dept);
|
|
|
return new ResponseEntity<>(dept, HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@WebLog
|
|
|
@RequestMapping("/remove")
|
|
|
- public Object remove(@RequestBody SysDeptDto dept) throws Exception {
|
|
|
- sysDeptService.verification(dept.getIds());
|
|
|
- sysDeptService.removeByIds(dept.getIds());
|
|
|
- return new ResponseEntity<>(dept, HttpStatus.OK);
|
|
|
+ public Object remove(@RequestBody SysDept model) throws Exception {
|
|
|
+ Connection connection = null;
|
|
|
+ try {
|
|
|
+ connection = dataSource.getConnection();
|
|
|
+
|
|
|
+ SysDept dept = new SysDept();
|
|
|
+ dept.setPid(model.getDeptId());
|
|
|
+ int count = jdbcClient.getJdbcCount(dept, connection);
|
|
|
+ if (count > 0) {
|
|
|
+ throw new Exception("该组织存在下级组织,请勿删除");
|
|
|
+ }
|
|
|
+ jdbcClient.jdbcRemoveById(model,connection);
|
|
|
+ return new ResponseEntity<>(model, HttpStatus.OK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ jdbcClient.finallyExecute(connection);
|
|
|
+ }
|
|
|
}
|
|
|
}
|