黎星凯
2024-04-15 62b6a7fac3f2acde70b578431147c4a01f19c182
consum-base/src/main/java/com/consum/base/controller/FinSysTenantDepartmentController.java
@@ -1,6 +1,17 @@
package com.consum.base.controller;
import java.util.List;
import cn.hutool.core.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.consum.base.BaseController;
import com.consum.base.core.type.StatesType;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.pojo.FinSysTenantDepartmentParam;
import com.consum.base.service.FinSysTenantDepartmentService;
@@ -9,14 +20,11 @@
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @Description 部门管理
@@ -38,8 +46,7 @@
     */
    @ApiOperation(value = "新增", notes = "新增")
    @ApiImplicitParams(value = {
        @ApiImplicitParam(name = "param", value = "部门信息", required = true, dataType = "FinSysTenantDepartmentParam")
    })
        @ApiImplicitParam(name = "param", value = "部门信息", required = true, dataType = "FinSysTenantDepartmentParam")})
    @PostMapping("/add")
    public ResponseValue add() {
        FinSysTenantDepartmentParam param = CommonUtil.getObjFromReqBody(FinSysTenantDepartmentParam.class);
@@ -53,16 +60,24 @@
        if (StringUtils.isEmpty(param.getCode())) {
            return ResponseValue.error("编号为空");
        }
        FinSysTenantDepartment tenantDepartment = this.departmentService.selectByCode(param.getCode(),param.getId());
        FinSysTenantDepartment tenantDepartment =
            departmentService.getTenantDepartment(null, param.getTenantId(), param.getCode());
        if (tenantDepartment != null) {
            return ResponseValue.error("部门编号已存在");
        }
        //判断同一机构id下 部门名称 是否重复
        FinSysTenantDepartment department = this.departmentService.getByNameAndTenantId(param.getName(), param.getTenantId());
        // 判断同一机构id下 部门名称 是否重复
        FinSysTenantDepartment department =
            departmentService.getTenantDepartment(param.getName(), param.getTenantId(), null);
        if (department != null) {
            return ResponseValue.error("部门名称已存在");
        }
        // 部门编号
        FinSysTenantDepartmentParam finSysTenantDepartmentParam1 = new FinSysTenantDepartmentParam();
        finSysTenantDepartmentParam1.setCode(param.getCode());
        List<FinSysTenantDepartment> datas = departmentService.queryDataList(finSysTenantDepartmentParam1);
        if(!CollectionUtil.isEmpty(datas)){
            return ResponseValue.error("此编号已存在");
        }
        int result = this.departmentService.add(param, this.getSysInfo());
        if (result > 0) {
            return ResponseValue.success();
@@ -75,7 +90,7 @@
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
    //如果不传机构id,默认查省级机构的部门
    // 如果不传机构id,默认查省级机构的部门
    @GetMapping("/list")
    public ResponseValue queryList() {
        FinSysTenantDepartmentParam param = CommonUtil.getObjFromReq(FinSysTenantDepartmentParam.class);
@@ -91,11 +106,9 @@
        return ResponseValue.success(pager);
    }
    @ApiOperation(value = "根据机构id查询所有部门列表信息", notes = "根据机构id查询所有部门列表信息")
    @ApiImplicitParams(value = {
        @ApiImplicitParam(name = "param", value = "部门信息", required = true, dataType = "FinSysTenantDepartmentParam")
    })
        @ApiImplicitParam(name = "param", value = "部门信息", required = true, dataType = "FinSysTenantDepartmentParam")})
    @GetMapping("/list/all")
    public ResponseValue queryAllDepartment(Long tenantId) {
        FinSysTenantUser sysInfo = this.getSysInfo();
@@ -104,6 +117,7 @@
        }
        FinSysTenantDepartment finSysTenantDepartment = new FinSysTenantDepartment();
        finSysTenantDepartment.setTenantId(tenantId);
        finSysTenantDepartment.setStatus(StatesType.NORMAL.getValue());
        List<FinSysTenantDepartment> finSysTenantDepartments = this.departmentService.select(finSysTenantDepartment);
        return ResponseValue.success(finSysTenantDepartments);
    }
@@ -134,9 +148,20 @@
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        FinSysTenantDepartment tenantDepartment = this.departmentService.selectByCode(param.getCode(),param.getId());
        FinSysTenantDepartment tenantDepartment =
            this.departmentService.getTenantDepartment(null, param.getTenantId(), param.getCode());
        if (tenantDepartment != null) {
            return ResponseValue.error("部门编号已存在");
            //return ResponseValue.error("部门编号已存在");
        }
        // 部门编号
        FinSysTenantDepartmentParam finSysTenantDepartmentParam1 = new FinSysTenantDepartmentParam();
        finSysTenantDepartmentParam1.setCode(param.getCode());
        List<FinSysTenantDepartment> datas = departmentService.queryDataList(finSysTenantDepartmentParam1);
        if(!CollectionUtil.isEmpty(datas)){
            FinSysTenantDepartment finSysTenantDepartment1 = datas.get(0);
            if(!finSysTenantDepartment1.getId().equals(param.getId())){
                return ResponseValue.error("此编号已存在");
            }
        }
        int num = this.departmentService.updateFinSysTenantDepartment(param, sysInfo);
        return num > 0 ? ResponseValue.success() : ResponseValue.error("编辑失败!");
@@ -184,6 +209,4 @@
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("删除失败!");
    }
}