新增 sys.office.notAllowDeleteIfUserExists 和 sys.company.notAllowDeleteIfUserExists 参数,增加删除机构和公司数据的时候校验是否有用户
This commit is contained in:
Binary file not shown.
@@ -11,8 +11,10 @@ import com.jeesite.common.idgen.IdGen;
|
|||||||
import com.jeesite.common.lang.StringUtils;
|
import com.jeesite.common.lang.StringUtils;
|
||||||
import com.jeesite.common.web.BaseController;
|
import com.jeesite.common.web.BaseController;
|
||||||
import com.jeesite.modules.sys.entity.Company;
|
import com.jeesite.modules.sys.entity.Company;
|
||||||
|
import com.jeesite.modules.sys.entity.EmpUser;
|
||||||
import com.jeesite.modules.sys.entity.Office;
|
import com.jeesite.modules.sys.entity.Office;
|
||||||
import com.jeesite.modules.sys.service.CompanyService;
|
import com.jeesite.modules.sys.service.CompanyService;
|
||||||
|
import com.jeesite.modules.sys.service.EmpUserService;
|
||||||
import com.jeesite.modules.sys.service.OfficeService;
|
import com.jeesite.modules.sys.service.OfficeService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@@ -43,9 +45,10 @@ public class CompanyController extends BaseController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CompanyService companyService;
|
private CompanyService companyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OfficeService officeService;
|
private OfficeService officeService;
|
||||||
|
@Autowired
|
||||||
|
private EmpUserService empUserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取公司
|
* 获取公司
|
||||||
@@ -208,6 +211,14 @@ public class CompanyController extends BaseController {
|
|||||||
@RequestMapping(value = "delete")
|
@RequestMapping(value = "delete")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String delete(Company company) {
|
public String delete(Company company) {
|
||||||
|
if (Global.getConfigToBoolean("sys.company.notAllowDeleteIfUserExists", "false")) {
|
||||||
|
EmpUser empUserWhere = new EmpUser();
|
||||||
|
empUserWhere.getEmployee().getCompany().setIsQueryChildren(true);
|
||||||
|
empUserWhere.getEmployee().getCompany().setCompanyCode(company.getCompanyCode());
|
||||||
|
if (empUserService.findCount(empUserWhere) > 0) {
|
||||||
|
return renderResult(Global.FALSE, text("不允许删除包含用户的公司"));
|
||||||
|
}
|
||||||
|
}
|
||||||
companyService.delete(company);
|
companyService.delete(company);
|
||||||
return renderResult(Global.TRUE, text("删除公司''{0}''成功", company.getCompanyName()));
|
return renderResult(Global.TRUE, text("删除公司''{0}''成功", company.getCompanyName()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import com.jeesite.common.lang.StringUtils;
|
|||||||
import com.jeesite.common.utils.excel.ExcelExport;
|
import com.jeesite.common.utils.excel.ExcelExport;
|
||||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
||||||
import com.jeesite.common.web.BaseController;
|
import com.jeesite.common.web.BaseController;
|
||||||
|
import com.jeesite.modules.sys.entity.EmpUser;
|
||||||
import com.jeesite.modules.sys.entity.Office;
|
import com.jeesite.modules.sys.entity.Office;
|
||||||
|
import com.jeesite.modules.sys.service.EmpUserService;
|
||||||
import com.jeesite.modules.sys.service.OfficeService;
|
import com.jeesite.modules.sys.service.OfficeService;
|
||||||
import com.jeesite.modules.sys.web.user.EmpUserController;
|
import com.jeesite.modules.sys.web.user.EmpUserController;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -46,7 +48,8 @@ public class OfficeController extends BaseController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OfficeService officeService;
|
private OfficeService officeService;
|
||||||
|
@Autowired
|
||||||
|
private EmpUserService empUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmpUserController empUserController;
|
private EmpUserController empUserController;
|
||||||
|
|
||||||
@@ -260,6 +263,14 @@ public class OfficeController extends BaseController {
|
|||||||
@RequestMapping(value = "delete")
|
@RequestMapping(value = "delete")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String delete(Office office) {
|
public String delete(Office office) {
|
||||||
|
if (Global.getConfigToBoolean("sys.office.notAllowDeleteIfUserExists", "false")) {
|
||||||
|
EmpUser empUserWhere = new EmpUser();
|
||||||
|
empUserWhere.getEmployee().getOffice().setIsQueryChildren(true);
|
||||||
|
empUserWhere.getEmployee().getOffice().setOfficeCode(office.getOfficeCode());
|
||||||
|
if (empUserService.findCount(empUserWhere) > 0) {
|
||||||
|
return renderResult(Global.FALSE, text("不允许删除包含用户的机构"));
|
||||||
|
}
|
||||||
|
}
|
||||||
officeService.delete(office);
|
officeService.delete(office);
|
||||||
return renderResult(Global.TRUE, text("删除机构''{0}''成功", office.getOfficeName()));
|
return renderResult(Global.TRUE, text("删除机构''{0}''成功", office.getOfficeName()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user