【fix sonar】 JobGroupController.java文件

This commit is contained in:
tianwenbo
2023-03-10 13:45:25 +08:00
parent b5e60923aa
commit 4f818cbde1
@@ -33,6 +33,8 @@ public class JobGroupController {
@Resource
private XxlJobRegistryDao xxlJobRegistryDao;
private String systemPleaseInput= "system_please_input";
@RequestMapping
public String index(Model model) {
return "jobgroup/jobgroup.index";
@@ -47,12 +49,12 @@ public class JobGroupController {
// page query
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
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("recordsTotal", list_count); // 总记录数
maps.put("recordsFiltered", list_count); // 过滤后的总记录数
Map<String, Object> maps = new HashMap<>();
maps.put("recordsTotal", listCount); // 总记录数
maps.put("recordsFiltered", listCount); // 过滤后的总记录数
maps.put("data", list); // 分页列表
return maps;
}
@@ -63,22 +65,22 @@ public class JobGroupController {
// valid
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) {
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) {
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.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(",");
for (String item: addresss) {
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){
// valid
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) {
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) {
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) {
// 0=自动注册
List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppname());
String addressListStr = null;
StringBuilder addressListStr = new StringBuilder();
if (registryList!=null && !registryList.isEmpty()) {
Collections.sort(registryList);
addressListStr = "";
addressListStr = new StringBuilder();
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 {
// 1=手动录入
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(",");
for (String item: addresss) {
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){
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());
if (list != null) {
for (XxlJobRegistry item: list) {
@@ -139,7 +141,7 @@ public class JobGroupController {
String appname = item.getRegistryKey();
List<String> registryList = appAddressMap.get(appname);
if (registryList == null) {
registryList = new ArrayList<String>();
registryList = new ArrayList<>();
}
if (!registryList.contains(item.getRegistryValue())) {
@@ -159,12 +161,12 @@ public class JobGroupController {
// valid
int count = xxlJobInfoDao.pageListCount(0, 10, id, -1, null, null, null);
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();
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);
@@ -175,7 +177,7 @@ public class JobGroupController {
@ResponseBody
public ReturnT<XxlJobGroup> loadById(int 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);
}
}