【fix sonar】 JobGroupController.java文件
This commit is contained in:
+26
-24
@@ -33,6 +33,8 @@ public class JobGroupController {
|
|||||||
@Resource
|
@Resource
|
||||||
private XxlJobRegistryDao xxlJobRegistryDao;
|
private XxlJobRegistryDao xxlJobRegistryDao;
|
||||||
|
|
||||||
|
private String systemPleaseInput= "system_please_input";
|
||||||
|
|
||||||
@RequestMapping
|
@RequestMapping
|
||||||
public String index(Model model) {
|
public String index(Model model) {
|
||||||
return "jobgroup/jobgroup.index";
|
return "jobgroup/jobgroup.index";
|
||||||
@@ -47,12 +49,12 @@ public class JobGroupController {
|
|||||||
|
|
||||||
// page query
|
// page query
|
||||||
List<XxlJobGroup> list = xxlJobGroupDao.pageList(start, length, appname, title);
|
List<XxlJobGroup> list = xxlJobGroupDao.pageList(start, length, appname, title);
|
||||||
int list_count = xxlJobGroupDao.pageListCount(start, length, appname, title);
|
int listCount = xxlJobGroupDao.pageListCount(start, length, appname, title);
|
||||||
|
|
||||||
// package result
|
// package result
|
||||||
Map<String, Object> maps = new HashMap<String, Object>();
|
Map<String, Object> maps = new HashMap<>();
|
||||||
maps.put("recordsTotal", list_count); // 总记录数
|
maps.put("recordsTotal", listCount); // 总记录数
|
||||||
maps.put("recordsFiltered", list_count); // 过滤后的总记录数
|
maps.put("recordsFiltered", listCount); // 过滤后的总记录数
|
||||||
maps.put("data", list); // 分页列表
|
maps.put("data", list); // 分页列表
|
||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
@@ -63,22 +65,22 @@ public class JobGroupController {
|
|||||||
|
|
||||||
// valid
|
// valid
|
||||||
if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
|
if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
|
||||||
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
|
return new ReturnT<>(500, (I18nUtil.getString(systemPleaseInput)+"AppName") );
|
||||||
}
|
}
|
||||||
if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
|
if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_appname_length") );
|
||||||
}
|
}
|
||||||
if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
|
if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
|
||||||
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
|
return new ReturnT<>(500, (I18nUtil.getString(systemPleaseInput) + I18nUtil.getString("jobgroup_field_title")) );
|
||||||
}
|
}
|
||||||
if (xxlJobGroup.getAddressType()!=0) {
|
if (xxlJobGroup.getAddressType()!=0) {
|
||||||
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
||||||
}
|
}
|
||||||
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
||||||
for (String item: addresss) {
|
for (String item: addresss) {
|
||||||
if (item==null || item.trim().length()==0) {
|
if (item==null || item.trim().length()==0) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,36 +94,36 @@ public class JobGroupController {
|
|||||||
public ReturnT<String> update(XxlJobGroup xxlJobGroup){
|
public ReturnT<String> update(XxlJobGroup xxlJobGroup){
|
||||||
// valid
|
// valid
|
||||||
if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
|
if (xxlJobGroup.getAppname()==null || xxlJobGroup.getAppname().trim().length()==0) {
|
||||||
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
|
return new ReturnT<>(500, (I18nUtil.getString(systemPleaseInput)+"AppName") );
|
||||||
}
|
}
|
||||||
if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
|
if (xxlJobGroup.getAppname().length()<4 || xxlJobGroup.getAppname().length()>64) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appname_length") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_appname_length") );
|
||||||
}
|
}
|
||||||
if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
|
if (xxlJobGroup.getTitle()==null || xxlJobGroup.getTitle().trim().length()==0) {
|
||||||
return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
|
return new ReturnT<>(500, (I18nUtil.getString(systemPleaseInput) + I18nUtil.getString("jobgroup_field_title")) );
|
||||||
}
|
}
|
||||||
if (xxlJobGroup.getAddressType() == 0) {
|
if (xxlJobGroup.getAddressType() == 0) {
|
||||||
// 0=自动注册
|
// 0=自动注册
|
||||||
List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppname());
|
List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppname());
|
||||||
String addressListStr = null;
|
StringBuilder addressListStr = new StringBuilder();
|
||||||
if (registryList!=null && !registryList.isEmpty()) {
|
if (registryList!=null && !registryList.isEmpty()) {
|
||||||
Collections.sort(registryList);
|
Collections.sort(registryList);
|
||||||
addressListStr = "";
|
addressListStr = new StringBuilder();
|
||||||
for (String item:registryList) {
|
for (String item:registryList) {
|
||||||
addressListStr += item + ",";
|
addressListStr.append(item).append(",");
|
||||||
}
|
}
|
||||||
addressListStr = addressListStr.substring(0, addressListStr.length()-1);
|
addressListStr = new StringBuilder(addressListStr.substring(0, addressListStr.length() - 1));
|
||||||
}
|
}
|
||||||
xxlJobGroup.setAddressList(addressListStr);
|
xxlJobGroup.setAddressList(addressListStr.toString());
|
||||||
} else {
|
} else {
|
||||||
// 1=手动录入
|
// 1=手动录入
|
||||||
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
if (xxlJobGroup.getAddressList()==null || xxlJobGroup.getAddressList().trim().length()==0) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
|
||||||
}
|
}
|
||||||
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
String[] addresss = xxlJobGroup.getAddressList().split(",");
|
||||||
for (String item: addresss) {
|
for (String item: addresss) {
|
||||||
if (item==null || item.trim().length()==0) {
|
if (item==null || item.trim().length()==0) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +133,7 @@ public class JobGroupController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<String> findRegistryByAppName(String appnameParam){
|
private List<String> findRegistryByAppName(String appnameParam){
|
||||||
HashMap<String, List<String>> appAddressMap = new HashMap<String, List<String>>();
|
HashMap<String, List<String>> appAddressMap = new HashMap<>();
|
||||||
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
|
List<XxlJobRegistry> list = xxlJobRegistryDao.findAll(RegistryConfig.DEAD_TIMEOUT, new Date());
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (XxlJobRegistry item: list) {
|
for (XxlJobRegistry item: list) {
|
||||||
@@ -139,7 +141,7 @@ public class JobGroupController {
|
|||||||
String appname = item.getRegistryKey();
|
String appname = item.getRegistryKey();
|
||||||
List<String> registryList = appAddressMap.get(appname);
|
List<String> registryList = appAddressMap.get(appname);
|
||||||
if (registryList == null) {
|
if (registryList == null) {
|
||||||
registryList = new ArrayList<String>();
|
registryList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!registryList.contains(item.getRegistryValue())) {
|
if (!registryList.contains(item.getRegistryValue())) {
|
||||||
@@ -159,12 +161,12 @@ public class JobGroupController {
|
|||||||
// valid
|
// valid
|
||||||
int count = xxlJobInfoDao.pageListCount(0, 10, id, -1, null, null, null);
|
int count = xxlJobInfoDao.pageListCount(0, 10, id, -1, null, null, null);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_del_limit_0") );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
|
List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
|
||||||
if (allList.size() == 1) {
|
if (allList.size() == 1) {
|
||||||
return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1") );
|
return new ReturnT<>(500, I18nUtil.getString("jobgroup_del_limit_1") );
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = xxlJobGroupDao.remove(id);
|
int ret = xxlJobGroupDao.remove(id);
|
||||||
@@ -175,7 +177,7 @@ public class JobGroupController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ReturnT<XxlJobGroup> loadById(int id){
|
public ReturnT<XxlJobGroup> loadById(int id){
|
||||||
XxlJobGroup jobGroup = xxlJobGroupDao.load(id);
|
XxlJobGroup jobGroup = xxlJobGroupDao.load(id);
|
||||||
return jobGroup!=null?new ReturnT<XxlJobGroup>(jobGroup):new ReturnT<XxlJobGroup>(ReturnT.FAIL_CODE, null);
|
return jobGroup!=null?new ReturnT<>(jobGroup):new ReturnT<>(ReturnT.FAIL_CODE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user