|
@@ -0,0 +1,268 @@
|
|
|
+package com.jpsoft.supervision.modules.base.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.supervision.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.supervision.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.supervision.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.supervision.modules.base.entity.Organization;
|
|
|
+import com.jpsoft.supervision.modules.base.service.OrganizationService;
|
|
|
+import com.jpsoft.supervision.modules.sys.entity.DataDictionary;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/organization")
|
|
|
+@Api(description = "组织机构管理")
|
|
|
+public class OrganizationController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationService organizationService;
|
|
|
+
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<Organization> create(){
|
|
|
+ MessageResult<Organization> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Organization organization = new Organization();
|
|
|
+
|
|
|
+ msgResult.setData(organization);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
+ @PostMapping("add")
|
|
|
+ public MessageResult<Organization> add(@RequestBody Organization organization,@RequestAttribute String subject){
|
|
|
+ MessageResult<Organization> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ organization.setId(UUID.randomUUID().toString());
|
|
|
+ organization.setDelFlag(false);
|
|
|
+ organization.setCreateBy(subject);
|
|
|
+ organization.setCreateTime(new Date());
|
|
|
+
|
|
|
+ Organization org = organizationService.get(organization.getParentId());
|
|
|
+ if(org != null){
|
|
|
+ organization.setCode(org.getCode() + "," + organization.getId());
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ organization.setCode(organization.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ int affectCount = organizationService.insert(organization);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(organization);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult<Organization> edit(@PathVariable("id") String id){
|
|
|
+ MessageResult<Organization> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Organization organization = organizationService.get(id);
|
|
|
+
|
|
|
+ if (organization != null) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(organization);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="更新用户")
|
|
|
+ @PostMapping("update")
|
|
|
+ public MessageResult<Organization> update(@RequestBody Organization organization,@RequestAttribute String subject){
|
|
|
+ MessageResult<Organization> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ organization.setUpdateBy(subject);
|
|
|
+ organization.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = organizationService.update(organization);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(organization);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="删除")
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Organization organization = organizationService.get(id);
|
|
|
+ organization.setDelFlag(true);
|
|
|
+ organization.setUpdateBy(subject);
|
|
|
+ organization.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = organizationService.update(organization);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="批量删除")
|
|
|
+ @PostMapping("batchDelete")
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ int affectCount = 0;
|
|
|
+
|
|
|
+ for (String id : idList) {
|
|
|
+ Organization organization = organizationService.get(id);
|
|
|
+ organization.setDelFlag(true);
|
|
|
+ organization.setUpdateBy(subject);
|
|
|
+ organization.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += organizationService.update(organization);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="列表")
|
|
|
+ @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
+ String name,
|
|
|
+ String parentId,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+
|
|
|
+ //当前用户ID
|
|
|
+ System.out.println(subject);
|
|
|
+
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("id_","asc"));
|
|
|
+
|
|
|
+ if (!"null".equals(parentId) && StringUtils.isNotEmpty(parentId)) {
|
|
|
+ searchParams.put("parentId",parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ searchParams.put("name","%" + name + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<Organization> page = organizationService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询")
|
|
|
+ @RequestMapping(value = "query", method = RequestMethod.POST)
|
|
|
+ public MessageResult<List> query(
|
|
|
+ String keywords,
|
|
|
+ String excludeId,
|
|
|
+ @RequestAttribute String subject) {
|
|
|
+ MessageResult<List> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("a.create_time", "asc"));
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(keywords)) {
|
|
|
+ searchParams.put("name", "%" + keywords + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(excludeId)) {
|
|
|
+ searchParams.put("excludeId", excludeId);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<Organization> page = organizationService.pageSearch(searchParams,1,1000,false,sortList);
|
|
|
+ List<Organization> organizationList = page.getResult();
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(organizationList);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|