Compare commits
No commits in common. 'master' and '0.0.1-SNAPSHOT' have entirely different histories.
master
...
0.0.1-SNAP
Binary file not shown.
Binary file not shown.
@ -1,108 +0,0 @@
|
|||||||
package xyz.wbsite.action.ajax.admin;
|
|
||||||
|
|
||||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import xyz.wbsite.frame.base.Error;
|
|
||||||
import xyz.wbsite.frame.excel.WExcel;
|
|
||||||
import xyz.wbsite.frame.utils.LogUtil;
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.base.ErrorType;
|
|
||||||
import xyz.wbsite.frame.utils.MapperUtil;
|
|
||||||
import xyz.wbsite.frame.base.BaseResponse;
|
|
||||||
import xyz.wbsite.frame.utils.ResponseUtil;
|
|
||||||
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
||||||
import xyz.wbsite.frame.excel.exception.TemplateNotMatchException;
|
|
||||||
import xyz.wbsite.module.admin.ent.ConfigData;
|
|
||||||
import xyz.wbsite.module.admin.mgr.ConfigDataManager;
|
|
||||||
import xyz.wbsite.module.admin.req.ConfigDataCreateRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.ConfigDataDeleteRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.ConfigDataFindRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.ConfigDataUpdateRequest;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ConfigDataCreateResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ConfigDataDeleteResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ConfigDataFindResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ConfigDataUpdateResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConfigDataAjax{
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConfigDataManager configDataManager;
|
|
||||||
|
|
||||||
public ConfigDataCreateResponse create(ConfigDataCreateRequest request) {
|
|
||||||
return configDataManager.create(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigDataDeleteResponse delete(ConfigDataDeleteRequest request) {
|
|
||||||
return configDataManager.delete(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigDataUpdateResponse update(ConfigDataUpdateRequest request) {
|
|
||||||
return configDataManager.update(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigDataFindResponse find(ConfigDataFindRequest request) {
|
|
||||||
return configDataManager.find(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object template(){
|
|
||||||
return ResponseUtil.apply(new WExcel<>(ConfigData.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object exports(ConfigDataFindRequest request) {
|
|
||||||
ConfigDataFindResponse response = configDataManager.find(request, LocalData.getToken());
|
|
||||||
if (response.hasError()) {
|
|
||||||
return response;
|
|
||||||
} else if (response.getTotalCount() == 0) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
return ResponseUtil.apply(new WExcel<>(ConfigData.class).addDatas(response.getResult()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object imports(MultipartFile file) {
|
|
||||||
BaseResponse baseResponse = new BaseResponse();
|
|
||||||
try {
|
|
||||||
// 检查文件格式
|
|
||||||
String originalFilename = file.getOriginalFilename() != null ? file.getOriginalFilename() : "";
|
|
||||||
if (!originalFilename.matches(".+(.xlsx?|.XLSX?)$")) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件格式错误!");
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
// 兼容2003以前老版本.xls
|
|
||||||
ExcelTypeEnum excelTypeEnum = originalFilename.matches(".+(.xlsx|.XLSX)$") ? ExcelTypeEnum.XLSX : ExcelTypeEnum.XLS;
|
|
||||||
WExcel sheet = new WExcel<>(ConfigData.class).read(file.getBytes(), excelTypeEnum, new WExcel.Processor<ConfigData>() {
|
|
||||||
@Override
|
|
||||||
public List<String> exec(ConfigData o, int index) {
|
|
||||||
ConfigDataCreateRequest request = MapperUtil.map(o, ConfigDataCreateRequest.class);
|
|
||||||
List<String> validate = ValidationUtil.validate(request);
|
|
||||||
if (validate == null || validate.size() == 0) {
|
|
||||||
ConfigDataCreateResponse configDataCreateResponse = configDataManager.create(request, LocalData.getToken());
|
|
||||||
if (configDataCreateResponse.hasError()) {
|
|
||||||
for (Error error : configDataCreateResponse.getErrors()) {
|
|
||||||
validate.add(error.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 当导入出现错误时可以将存在标注错误的Excel返回给用户改正
|
|
||||||
if (sheet.hasError()) {
|
|
||||||
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
|
||||||
} else {
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtil.dumpException(e);
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
|
|
||||||
} catch (TemplateNotMatchException e) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
package xyz.wbsite.action.ajax.admin;
|
|
||||||
|
|
||||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import xyz.wbsite.frame.base.Error;
|
|
||||||
import xyz.wbsite.frame.excel.WExcel;
|
|
||||||
import xyz.wbsite.frame.utils.LogUtil;
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.base.ErrorType;
|
|
||||||
import xyz.wbsite.frame.utils.MapperUtil;
|
|
||||||
import xyz.wbsite.frame.base.BaseResponse;
|
|
||||||
import xyz.wbsite.frame.utils.ResponseUtil;
|
|
||||||
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
||||||
import xyz.wbsite.frame.excel.exception.TemplateNotMatchException;
|
|
||||||
import xyz.wbsite.module.admin.ent.Locations;
|
|
||||||
import xyz.wbsite.module.admin.mgr.LocationsManager;
|
|
||||||
import xyz.wbsite.module.admin.req.LocationsCreateRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.LocationsDeleteRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.LocationsFindRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.LocationsUpdateRequest;
|
|
||||||
import xyz.wbsite.module.admin.rsp.LocationsCreateResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.LocationsDeleteResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.LocationsFindResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.LocationsUpdateResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LocationsAjax{
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LocationsManager locationsManager;
|
|
||||||
|
|
||||||
public LocationsCreateResponse create(LocationsCreateRequest request) {
|
|
||||||
return locationsManager.create(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocationsDeleteResponse delete(LocationsDeleteRequest request) {
|
|
||||||
return locationsManager.delete(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocationsUpdateResponse update(LocationsUpdateRequest request) {
|
|
||||||
return locationsManager.update(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocationsFindResponse find(LocationsFindRequest request) {
|
|
||||||
return locationsManager.find(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object template(){
|
|
||||||
return ResponseUtil.apply(new WExcel<>(Locations.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object exports(LocationsFindRequest request) {
|
|
||||||
LocationsFindResponse response = locationsManager.find(request, LocalData.getToken());
|
|
||||||
if (response.hasError()) {
|
|
||||||
return response;
|
|
||||||
} else if (response.getTotalCount() == 0) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
return ResponseUtil.apply(new WExcel<>(Locations.class).addDatas(response.getResult()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object imports(MultipartFile file) {
|
|
||||||
BaseResponse baseResponse = new BaseResponse();
|
|
||||||
try {
|
|
||||||
// 检查文件格式
|
|
||||||
String originalFilename = file.getOriginalFilename() != null ? file.getOriginalFilename() : "";
|
|
||||||
if (!originalFilename.matches(".+(.xlsx?|.XLSX?)$")) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件格式错误!");
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
// 兼容2003以前老版本.xls
|
|
||||||
ExcelTypeEnum excelTypeEnum = originalFilename.matches(".+(.xlsx|.XLSX)$") ? ExcelTypeEnum.XLSX : ExcelTypeEnum.XLS;
|
|
||||||
WExcel sheet = new WExcel<>(Locations.class).read(file.getBytes(), excelTypeEnum, new WExcel.Processor<Locations>() {
|
|
||||||
@Override
|
|
||||||
public List<String> exec(Locations o, int index) {
|
|
||||||
LocationsCreateRequest request = MapperUtil.map(o, LocationsCreateRequest.class);
|
|
||||||
List<String> validate = ValidationUtil.validate(request);
|
|
||||||
if (validate == null || validate.size() == 0) {
|
|
||||||
LocationsCreateResponse locationsCreateResponse = locationsManager.create(request, LocalData.getToken());
|
|
||||||
if (locationsCreateResponse.hasError()) {
|
|
||||||
for (Error error : locationsCreateResponse.getErrors()) {
|
|
||||||
validate.add(error.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 当导入出现错误时可以将存在标注错误的Excel返回给用户改正
|
|
||||||
if (sheet.hasError()) {
|
|
||||||
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
|
||||||
} else {
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtil.dumpException(e);
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
|
|
||||||
} catch (TemplateNotMatchException e) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
package xyz.wbsite.action.ajax.admin;
|
|
||||||
|
|
||||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import xyz.wbsite.frame.base.Error;
|
|
||||||
import xyz.wbsite.frame.excel.WExcel;
|
|
||||||
import xyz.wbsite.frame.utils.LogUtil;
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.base.ErrorType;
|
|
||||||
import xyz.wbsite.frame.utils.MapperUtil;
|
|
||||||
import xyz.wbsite.frame.base.BaseResponse;
|
|
||||||
import xyz.wbsite.frame.utils.ResponseUtil;
|
|
||||||
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
||||||
import xyz.wbsite.frame.excel.exception.TemplateNotMatchException;
|
|
||||||
import xyz.wbsite.module.admin.ent.Rules;
|
|
||||||
import xyz.wbsite.module.admin.mgr.RulesManager;
|
|
||||||
import xyz.wbsite.module.admin.req.RulesCreateRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.RulesDeleteRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.RulesFindRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.RulesUpdateRequest;
|
|
||||||
import xyz.wbsite.module.admin.rsp.RulesCreateResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.RulesDeleteResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.RulesFindResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.RulesUpdateResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class RulesAjax{
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RulesManager rulesManager;
|
|
||||||
|
|
||||||
public RulesCreateResponse create(RulesCreateRequest request) {
|
|
||||||
return rulesManager.create(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public RulesDeleteResponse delete(RulesDeleteRequest request) {
|
|
||||||
return rulesManager.delete(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public RulesUpdateResponse update(RulesUpdateRequest request) {
|
|
||||||
return rulesManager.update(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public RulesFindResponse find(RulesFindRequest request) {
|
|
||||||
return rulesManager.find(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object template(){
|
|
||||||
return ResponseUtil.apply(new WExcel<>(Rules.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object exports(RulesFindRequest request) {
|
|
||||||
RulesFindResponse response = rulesManager.find(request, LocalData.getToken());
|
|
||||||
if (response.hasError()) {
|
|
||||||
return response;
|
|
||||||
} else if (response.getTotalCount() == 0) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
return ResponseUtil.apply(new WExcel<>(Rules.class).addDatas(response.getResult()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object imports(MultipartFile file) {
|
|
||||||
BaseResponse baseResponse = new BaseResponse();
|
|
||||||
try {
|
|
||||||
// 检查文件格式
|
|
||||||
String originalFilename = file.getOriginalFilename() != null ? file.getOriginalFilename() : "";
|
|
||||||
if (!originalFilename.matches(".+(.xlsx?|.XLSX?)$")) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件格式错误!");
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
// 兼容2003以前老版本.xls
|
|
||||||
ExcelTypeEnum excelTypeEnum = originalFilename.matches(".+(.xlsx|.XLSX)$") ? ExcelTypeEnum.XLSX : ExcelTypeEnum.XLS;
|
|
||||||
WExcel sheet = new WExcel<>(Rules.class).read(file.getBytes(), excelTypeEnum, new WExcel.Processor<Rules>() {
|
|
||||||
@Override
|
|
||||||
public List<String> exec(Rules o, int index) {
|
|
||||||
RulesCreateRequest request = MapperUtil.map(o, RulesCreateRequest.class);
|
|
||||||
List<String> validate = ValidationUtil.validate(request);
|
|
||||||
if (validate == null || validate.size() == 0) {
|
|
||||||
RulesCreateResponse rulesCreateResponse = rulesManager.create(request, LocalData.getToken());
|
|
||||||
if (rulesCreateResponse.hasError()) {
|
|
||||||
for (Error error : rulesCreateResponse.getErrors()) {
|
|
||||||
validate.add(error.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 当导入出现错误时可以将存在标注错误的Excel返回给用户改正
|
|
||||||
if (sheet.hasError()) {
|
|
||||||
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
|
||||||
} else {
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtil.dumpException(e);
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
|
|
||||||
} catch (TemplateNotMatchException e) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
package xyz.wbsite.action.ajax.admin;
|
|
||||||
|
|
||||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import xyz.wbsite.frame.base.Error;
|
|
||||||
import xyz.wbsite.frame.excel.WExcel;
|
|
||||||
import xyz.wbsite.frame.utils.LogUtil;
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.base.ErrorType;
|
|
||||||
import xyz.wbsite.frame.utils.MapperUtil;
|
|
||||||
import xyz.wbsite.frame.base.BaseResponse;
|
|
||||||
import xyz.wbsite.frame.utils.ResponseUtil;
|
|
||||||
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
||||||
import xyz.wbsite.frame.excel.exception.TemplateNotMatchException;
|
|
||||||
import xyz.wbsite.module.admin.ent.Services;
|
|
||||||
import xyz.wbsite.module.admin.mgr.ServicesManager;
|
|
||||||
import xyz.wbsite.module.admin.req.ServicesCreateRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.ServicesDeleteRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.ServicesFindRequest;
|
|
||||||
import xyz.wbsite.module.admin.req.ServicesUpdateRequest;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ServicesCreateResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ServicesDeleteResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ServicesFindResponse;
|
|
||||||
import xyz.wbsite.module.admin.rsp.ServicesUpdateResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ServicesAjax{
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ServicesManager servicesManager;
|
|
||||||
|
|
||||||
public ServicesCreateResponse create(ServicesCreateRequest request) {
|
|
||||||
return servicesManager.create(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServicesDeleteResponse delete(ServicesDeleteRequest request) {
|
|
||||||
return servicesManager.delete(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServicesUpdateResponse update(ServicesUpdateRequest request) {
|
|
||||||
return servicesManager.update(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServicesFindResponse find(ServicesFindRequest request) {
|
|
||||||
return servicesManager.find(request, LocalData.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object template(){
|
|
||||||
return ResponseUtil.apply(new WExcel<>(Services.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object exports(ServicesFindRequest request) {
|
|
||||||
ServicesFindResponse response = servicesManager.find(request, LocalData.getToken());
|
|
||||||
if (response.hasError()) {
|
|
||||||
return response;
|
|
||||||
} else if (response.getTotalCount() == 0) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
return ResponseUtil.apply(new WExcel<>(Services.class).addDatas(response.getResult()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object imports(MultipartFile file) {
|
|
||||||
BaseResponse baseResponse = new BaseResponse();
|
|
||||||
try {
|
|
||||||
// 检查文件格式
|
|
||||||
String originalFilename = file.getOriginalFilename() != null ? file.getOriginalFilename() : "";
|
|
||||||
if (!originalFilename.matches(".+(.xlsx?|.XLSX?)$")) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件格式错误!");
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
// 兼容2003以前老版本.xls
|
|
||||||
ExcelTypeEnum excelTypeEnum = originalFilename.matches(".+(.xlsx|.XLSX)$") ? ExcelTypeEnum.XLSX : ExcelTypeEnum.XLS;
|
|
||||||
WExcel sheet = new WExcel<>(Services.class).read(file.getBytes(), excelTypeEnum, new WExcel.Processor<Services>() {
|
|
||||||
@Override
|
|
||||||
public List<String> exec(Services o, int index) {
|
|
||||||
ServicesCreateRequest request = MapperUtil.map(o, ServicesCreateRequest.class);
|
|
||||||
List<String> validate = ValidationUtil.validate(request);
|
|
||||||
if (validate == null || validate.size() == 0) {
|
|
||||||
ServicesCreateResponse servicesCreateResponse = servicesManager.create(request, LocalData.getToken());
|
|
||||||
if (servicesCreateResponse.hasError()) {
|
|
||||||
for (Error error : servicesCreateResponse.getErrors()) {
|
|
||||||
validate.add(error.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return validate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 当导入出现错误时可以将存在标注错误的Excel返回给用户改正
|
|
||||||
if (sheet.hasError()) {
|
|
||||||
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
|
||||||
} else {
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
LogUtil.dumpException(e);
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
|
|
||||||
} catch (TemplateNotMatchException e) {
|
|
||||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
return baseResponse;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,60 @@
|
|||||||
|
package xyz.wbsite.action.ajax.conf;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import xyz.wbsite.frame.auth.LocalData;
|
||||||
|
import xyz.wbsite.module.conf.mgr.MappingManager;
|
||||||
|
import xyz.wbsite.module.conf.req.MappingCreateRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.MappingDeleteRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.MappingFindRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.MappingGetRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.MappingUpdateRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.NginxReloadRequest;
|
||||||
|
import xyz.wbsite.module.conf.rsp.MappingCreateResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.MappingDeleteResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.MappingFindResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.MappingGetResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.MappingUpdateResponse;
|
||||||
|
|
||||||
|
public class MappingAjax {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MappingManager mappingManager;
|
||||||
|
|
||||||
|
public MappingCreateResponse create(MappingCreateRequest request) {
|
||||||
|
MappingCreateResponse response = mappingManager.create(request, LocalData.getToken());
|
||||||
|
if (!response.hasError()) {
|
||||||
|
NginxAjax nginxAjax = LocalData.getBean(NginxAjax.class);
|
||||||
|
nginxAjax.flushConfig();
|
||||||
|
nginxAjax.reload(new NginxReloadRequest());
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingDeleteResponse delete(MappingDeleteRequest request) {
|
||||||
|
MappingDeleteResponse response = mappingManager.delete(request, LocalData.getToken());
|
||||||
|
if (!response.hasError()) {
|
||||||
|
NginxAjax nginxAjax = LocalData.getBean(NginxAjax.class);
|
||||||
|
nginxAjax.flushConfig();
|
||||||
|
nginxAjax.reload(new NginxReloadRequest());
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingUpdateResponse update(MappingUpdateRequest request) {
|
||||||
|
MappingUpdateResponse response = mappingManager.update(request, LocalData.getToken());
|
||||||
|
if (!response.hasError()) {
|
||||||
|
NginxAjax nginxAjax = LocalData.getBean(NginxAjax.class);
|
||||||
|
nginxAjax.flushConfig();
|
||||||
|
nginxAjax.reload(new NginxReloadRequest());
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingFindResponse find(MappingFindRequest request) {
|
||||||
|
return mappingManager.find(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingGetResponse get(MappingGetRequest request) {
|
||||||
|
return mappingManager.get(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,119 @@
|
|||||||
|
package xyz.wbsite.action.ajax.conf;
|
||||||
|
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import freemarker.template.TemplateException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||||
|
import xyz.wbsite.frame.auth.LocalData;
|
||||||
|
import xyz.wbsite.frame.base.ErrorType;
|
||||||
|
import xyz.wbsite.frame.base.SortType;
|
||||||
|
import xyz.wbsite.frame.utils.ProcessUtil;
|
||||||
|
import xyz.wbsite.module.conf.ent.Mapping;
|
||||||
|
import xyz.wbsite.module.conf.ent.NginxCtrl;
|
||||||
|
import xyz.wbsite.module.conf.mgr.MappingManager;
|
||||||
|
import xyz.wbsite.module.conf.req.MappingFindRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.NginxReloadRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.NginxStartRequest;
|
||||||
|
import xyz.wbsite.module.conf.req.NginxStopRequest;
|
||||||
|
import xyz.wbsite.module.conf.rsp.MappingFindResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.NginxReloadResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.NginxStartResponse;
|
||||||
|
import xyz.wbsite.module.conf.rsp.NginxStopResponse;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NginxAjax {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NginxCtrl nginxCtrl;
|
||||||
|
@Autowired
|
||||||
|
private MappingManager mappingManager;
|
||||||
|
@Autowired
|
||||||
|
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||||
|
|
||||||
|
public NginxStartResponse start(NginxStartRequest request) {
|
||||||
|
NginxStartResponse response = new NginxStartResponse();
|
||||||
|
if (nginxCtrl.isRunning()) {
|
||||||
|
response.addError(ErrorType.BUSINESS_ERROR, "程序已经运行");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
ProcessUtil.execBat(nginxCtrl.getStartCmd());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NginxStopResponse stop(NginxStopRequest request) {
|
||||||
|
NginxStopResponse response = new NginxStopResponse();
|
||||||
|
if (!nginxCtrl.isRunning()) {
|
||||||
|
response.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
ProcessUtil.execBat(nginxCtrl.getStopCmd());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NginxReloadResponse reload(NginxReloadRequest request) {
|
||||||
|
NginxReloadResponse response = new NginxReloadResponse();
|
||||||
|
if (!nginxCtrl.isRunning()) {
|
||||||
|
response.addError(ErrorType.BUSINESS_ERROR, "程序尚未运行");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
// 刷新配置文件
|
||||||
|
flushConfig();
|
||||||
|
// 重新加载配置文件
|
||||||
|
ProcessUtil.execBat(nginxCtrl.getReloadCmd());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void flushConfig() {
|
||||||
|
Writer wr = null;
|
||||||
|
try {
|
||||||
|
File config = nginxCtrl.getConfig();
|
||||||
|
HashMap<String, Object> context = new HashMap<>();
|
||||||
|
|
||||||
|
MappingFindRequest mappingFindRequest = new MappingFindRequest();
|
||||||
|
mappingFindRequest.setPageSize(0);
|
||||||
|
mappingFindRequest.setSortKey("PORT");
|
||||||
|
mappingFindRequest.setSortType(SortType.ASC);
|
||||||
|
MappingFindResponse mappingFindResponse = mappingManager.find(mappingFindRequest, LocalData.getSysToken());
|
||||||
|
|
||||||
|
Map<String, List<Mapping>> services = new HashMap<>();
|
||||||
|
|
||||||
|
for (Mapping mapping : mappingFindResponse.getResult()) {
|
||||||
|
|
||||||
|
List<Mapping> mappings = services.get(mapping.getPort());
|
||||||
|
|
||||||
|
if (mappings == null) {
|
||||||
|
mappings = new ArrayList<>();
|
||||||
|
services.put(mapping.getPort(), mappings);
|
||||||
|
}
|
||||||
|
mappings.add(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.put("services", services);
|
||||||
|
Template template = freeMarkerConfigurer.getConfiguration().getTemplate("nginx.conf.ftl");
|
||||||
|
wr = new OutputStreamWriter(new FileOutputStream(config), "UTF-8");
|
||||||
|
//写入
|
||||||
|
template.process(context, wr);
|
||||||
|
//关闭流
|
||||||
|
wr.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (TemplateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
wr.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package xyz.wbsite.action.ajax.system;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import xyz.wbsite.frame.auth.LocalData;
|
||||||
|
import xyz.wbsite.frame.auth.Token;
|
||||||
|
import xyz.wbsite.frame.base.ErrorType;
|
||||||
|
import xyz.wbsite.frame.utils.CookieUtil;
|
||||||
|
import xyz.wbsite.frame.utils.IDgenerator;
|
||||||
|
import xyz.wbsite.frame.utils.MD5Util;
|
||||||
|
import xyz.wbsite.frame.utils.ValidationUtil;
|
||||||
|
import xyz.wbsite.module.system.req.UserLoginRequest;
|
||||||
|
import xyz.wbsite.module.system.req.UserLogoutRequest;
|
||||||
|
import xyz.wbsite.module.system.rsp.UserLoginResponse;
|
||||||
|
import xyz.wbsite.module.system.rsp.UserLogoutResponse;
|
||||||
|
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class UserAjax {
|
||||||
|
|
||||||
|
@Value("${web.url.auth.admin}")
|
||||||
|
private String admin;
|
||||||
|
@Value("${web.url.auth.pwd}")
|
||||||
|
private String pwd;
|
||||||
|
|
||||||
|
public UserLoginResponse login(UserLoginRequest request, Token token, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||||
|
UserLoginResponse response = new UserLoginResponse();
|
||||||
|
|
||||||
|
ValidationUtil.validate(request, response);
|
||||||
|
if (response.hasError()) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getUsername().equals(admin)) {//超级管理员登录
|
||||||
|
String generatePwd = MD5Util.generatePwd(request.getPassword());
|
||||||
|
if (!generatePwd.equals(pwd)) {
|
||||||
|
response.addError(ErrorType.BUSINESS_ERROR, "用户名或密码错误!");
|
||||||
|
} else {
|
||||||
|
Date current = new Date();
|
||||||
|
Calendar instance = Calendar.getInstance();
|
||||||
|
instance.setTime(current);
|
||||||
|
instance.add(Calendar.HOUR_OF_DAY, 1);//默认一个小时内有效
|
||||||
|
|
||||||
|
Token sysToken = LocalData.getSysToken();
|
||||||
|
sysToken.setToken(IDgenerator.nextUUID());
|
||||||
|
|
||||||
|
Cookie cookie = CookieUtil.newCookie("token", sysToken.getToken());
|
||||||
|
httpServletResponse.addCookie(cookie);
|
||||||
|
response.setToken(sysToken.getToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserLogoutResponse logout(UserLogoutRequest request, Token token) {
|
||||||
|
UserLogoutResponse response = new UserLogoutResponse();
|
||||||
|
CookieUtil.clearCookie("token");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
@ -1,124 +0,0 @@
|
|||||||
package xyz.wbsite.action.ajax.wframe;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import xyz.wbsite.config.CacheConfig;
|
|
||||||
import xyz.wbsite.frame.base.ErrorType;
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.base.LoginRequest;
|
|
||||||
import xyz.wbsite.frame.base.LoginResponse;
|
|
||||||
import xyz.wbsite.frame.base.LogoutRequest;
|
|
||||||
import xyz.wbsite.frame.base.LogoutResponse;
|
|
||||||
import xyz.wbsite.frame.base.Token;
|
|
||||||
import xyz.wbsite.frame.base.UserEntity;
|
|
||||||
import xyz.wbsite.frame.base.VerifyCodeRequest;
|
|
||||||
import xyz.wbsite.frame.base.VerifyCodeResponse;
|
|
||||||
import xyz.wbsite.frame.provider.FrameProvider;
|
|
||||||
import xyz.wbsite.frame.provider.TokenProvider;
|
|
||||||
import xyz.wbsite.frame.provider.UserProvider;
|
|
||||||
import xyz.wbsite.frame.utils.CookieUtil;
|
|
||||||
import xyz.wbsite.frame.utils.IDgenerator;
|
|
||||||
import xyz.wbsite.frame.utils.MD5Util;
|
|
||||||
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
||||||
import xyz.wbsite.frame.utils.VerifyCodeUtil;
|
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
public class AuthAjax {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CacheConfig cacheConfig;
|
|
||||||
|
|
||||||
public VerifyCodeResponse verifyCode(VerifyCodeRequest request) {
|
|
||||||
VerifyCodeResponse response = new VerifyCodeResponse();
|
|
||||||
VerifyCodeUtil.Builder builder = new VerifyCodeUtil.Builder().build();
|
|
||||||
response.setVerifyCodeId(IDgenerator.nextId());
|
|
||||||
response.setVerifyCodeBase64(builder.toBase64());
|
|
||||||
cacheConfig.put(response.getVerifyCodeId(), builder.toCode(), 3 * 60 * 1000);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginResponse login(LoginRequest request, HttpServletResponse httpServletResponse) {
|
|
||||||
LoginResponse response = new LoginResponse();
|
|
||||||
|
|
||||||
ValidationUtil.validate(request, response);
|
|
||||||
if (response.hasError()) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取验证码
|
|
||||||
String o = cacheConfig.remove(request.getVerifyCodeId(), String.class);
|
|
||||||
if (o == null) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "验证码已过期!");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证验证码
|
|
||||||
if (!request.getVerifyCodeCode().toLowerCase().equals(o.toLowerCase())) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "验证码错误!");
|
|
||||||
cacheConfig.remove(request.getVerifyCodeId());
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取用户提供者
|
|
||||||
UserProvider userProvider = FrameProvider.getInstance().getUserProvider();
|
|
||||||
if (userProvider == null) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "用户提供者未实现!");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取用户信息
|
|
||||||
UserEntity userEntity = userProvider.getUser(request.getUsername());
|
|
||||||
if (userEntity == null) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "用户名或密码错误!");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证密码
|
|
||||||
String generatePwd = MD5Util.generatePwd(request.getPassword());
|
|
||||||
if (!generatePwd.equals(userEntity.getPassword())) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "用户名或密码错误!");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取通行证提供者
|
|
||||||
TokenProvider tokenProvider = FrameProvider.getInstance().getTokenProvider();
|
|
||||||
if (tokenProvider == null) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "通行证提供者未实现!");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建通行证
|
|
||||||
Token token = tokenProvider.build(userEntity);
|
|
||||||
if (token == null) {
|
|
||||||
response.addError(ErrorType.BUSINESS_ERROR, "通行证构建失败!");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
response.setToken(token.getToken());
|
|
||||||
Cookie cookie = CookieUtil.newCookie("token", response.getToken());
|
|
||||||
httpServletResponse.addCookie(cookie);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogoutResponse logout(LogoutRequest request) {
|
|
||||||
LogoutResponse response = new LogoutResponse();
|
|
||||||
|
|
||||||
Token token = LocalData.getToken();
|
|
||||||
if (token != null) {
|
|
||||||
cacheConfig.clear(token.getToken());
|
|
||||||
}
|
|
||||||
CookieUtil.clearCookie("token");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogoutResponse changePwd(LogoutRequest request) {
|
|
||||||
LogoutResponse response = new LogoutResponse();
|
|
||||||
|
|
||||||
Token token = LocalData.getToken();
|
|
||||||
if (token != null) {
|
|
||||||
cacheConfig.clear(token.getToken());
|
|
||||||
}
|
|
||||||
CookieUtil.clearCookie("token");
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package xyz.wbsite.action.ajax.wframe;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.DictLoadRequest;
|
|
||||||
import xyz.wbsite.frame.base.DictLoadResponse;
|
|
||||||
import xyz.wbsite.frame.provider.DictProvider;
|
|
||||||
import xyz.wbsite.frame.provider.FrameProvider;
|
|
||||||
import xyz.wbsite.frame.utils.ValidationUtil;
|
|
||||||
|
|
||||||
public class DictAjax {
|
|
||||||
|
|
||||||
public DictLoadResponse load(DictLoadRequest request) {
|
|
||||||
DictLoadResponse response = new DictLoadResponse();
|
|
||||||
|
|
||||||
ValidationUtil.validate(request, response);
|
|
||||||
if (response.hasError()) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
DictProvider dictProvider = FrameProvider.getInstance().getDictProvider();
|
|
||||||
response.setResult(dictProvider.getDict(request.getDictName()));
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,33 @@
|
|||||||
|
package xyz.wbsite.action.api.conf;
|
||||||
|
|
||||||
|
import xyz.wbsite.frame.auth.LocalData;
|
||||||
|
import xyz.wbsite.module.conf.mgr.MappingManager;
|
||||||
|
import xyz.wbsite.module.conf.req.*;
|
||||||
|
import xyz.wbsite.module.conf.rsp.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
public class MappingApi{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MappingManager mappingManager;
|
||||||
|
|
||||||
|
public MappingCreateResponse create(MappingCreateRequest request) {
|
||||||
|
return mappingManager.create(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingDeleteResponse delete(MappingDeleteRequest request) {
|
||||||
|
return mappingManager.delete(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingUpdateResponse update(MappingUpdateRequest request) {
|
||||||
|
return mappingManager.update(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingFindResponse find(MappingFindRequest request) {
|
||||||
|
return mappingManager.find(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MappingGetResponse get(MappingGetRequest request) {
|
||||||
|
return mappingManager.get(request, LocalData.getToken());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package xyz.wbsite.action.control;
|
||||||
|
|
||||||
|
import xyz.wbsite.frame.base.Control;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
public class Header extends Control {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exec(Model model, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package xyz.wbsite.action.screen;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import xyz.wbsite.frame.base.Screen;
|
||||||
|
import xyz.wbsite.module.conf.ent.NginxCtrl;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
public class Home extends Screen {
|
||||||
|
@Autowired
|
||||||
|
private NginxCtrl nginxCtrl;
|
||||||
|
@Value("${mapping.default.port}")
|
||||||
|
private String serverPort;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exec(Model model, HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
model.addAttribute("run", nginxCtrl.isRunning() ? "true" : "false");
|
||||||
|
model.addAttribute("serverPort", serverPort);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package xyz.wbsite.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.system.ApplicationHome;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import xyz.wbsite.frame.utils.FileUtil;
|
||||||
|
import xyz.wbsite.frame.utils.ZipUtil;
|
||||||
|
import xyz.wbsite.module.conf.ent.NginxCtrl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class NginxConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public NginxCtrl initNginx() {
|
||||||
|
String property = environment.getProperty("nginx-path");
|
||||||
|
File nginxHome = null;
|
||||||
|
if (StringUtils.isEmpty(property)) {
|
||||||
|
ApplicationHome home = new ApplicationHome(getClass());
|
||||||
|
// 当前运行jar文件
|
||||||
|
File jarFile = home.getSource() != null ? home.getSource() : home.getDir();
|
||||||
|
|
||||||
|
//jar同目录
|
||||||
|
nginxHome = new File(jarFile.getParent(), "nginx");
|
||||||
|
|
||||||
|
if (!nginxHome.exists()) {
|
||||||
|
ClassPathResource classPathResource = new ClassPathResource("nginx-1.16.1.zip");
|
||||||
|
try {
|
||||||
|
InputStream inputStream = classPathResource.getInputStream();
|
||||||
|
File nginxDir = new File(jarFile.getParent(), "nginx");
|
||||||
|
File nginxZip = new File(jarFile.getParent(), "nginx.zip");
|
||||||
|
FileUtil.inputStream2File(inputStream, nginxZip);
|
||||||
|
ZipUtil.unZip(nginxZip, nginxDir);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nginxHome = new File(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nginxHome.exists()) {
|
||||||
|
throw new RuntimeException("nginx home not exists!");
|
||||||
|
}
|
||||||
|
|
||||||
|
File start = new File(nginxHome, "start.bat");
|
||||||
|
File stop = new File(nginxHome, "stop.bat");
|
||||||
|
File reload = new File(nginxHome, "reload.bat");
|
||||||
|
|
||||||
|
NginxCtrl nginxCtrl = new NginxCtrl();
|
||||||
|
nginxCtrl.setStartCmd(start.getAbsolutePath());
|
||||||
|
nginxCtrl.setStopCmd(stop.getAbsolutePath());
|
||||||
|
nginxCtrl.setReloadCmd(reload.getAbsolutePath());
|
||||||
|
nginxCtrl.setVersionCmd(nginxHome.getAbsolutePath() + " -v ");
|
||||||
|
nginxCtrl.setConfig(new File(new File(nginxHome, "conf"), "nginx.conf"));
|
||||||
|
return nginxCtrl;
|
||||||
|
}
|
||||||
|
}
|
@ -1,63 +0,0 @@
|
|||||||
package xyz.wbsite.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
|
||||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
|
||||||
import xyz.wbsite.frame.schedule.RunTask;
|
|
||||||
import xyz.wbsite.frame.schedule.Scheduler;
|
|
||||||
import xyz.wbsite.frame.utils.LogUtil;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class TaskConfig {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private Scheduler scheduler;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Scheduler registerScheduler() {
|
|
||||||
return new Scheduler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void registryTask() {
|
|
||||||
{// 扫描类任务
|
|
||||||
String aPackage = this.getClass().getPackage().getName();
|
|
||||||
Pattern compile = Pattern.compile("(.*)\\.config");
|
|
||||||
Matcher matcher = compile.matcher(aPackage);
|
|
||||||
if (matcher.find()) {
|
|
||||||
DefaultListableBeanFactory simpleBeanDefinitionRegistry = new DefaultListableBeanFactory();
|
|
||||||
ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(simpleBeanDefinitionRegistry);
|
|
||||||
classPathBeanDefinitionScanner.resetFilters(false);
|
|
||||||
classPathBeanDefinitionScanner.addIncludeFilter(new AssignableTypeFilter(RunTask.class));
|
|
||||||
classPathBeanDefinitionScanner.setBeanNameGenerator(new BeanNameGenerator() {
|
|
||||||
@Override
|
|
||||||
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry) {
|
|
||||||
String beanClassName = beanDefinition.getBeanClassName();
|
|
||||||
try {
|
|
||||||
Class<?> aClass = Class.forName(beanClassName);
|
|
||||||
Object instance = aClass.newInstance();
|
|
||||||
RunTask task = (RunTask) instance;
|
|
||||||
scheduler.createOrRepeat(task);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
LogUtil.i("registry task " + beanClassName);
|
|
||||||
return beanClassName;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
classPathBeanDefinitionScanner.scan(matcher.group(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
|
|
||||||
public class DictLoadRequest extends BaseRequest{
|
|
||||||
|
|
||||||
@NotEmpty(message = "字典名称不能为空")
|
|
||||||
private String dictName;
|
|
||||||
|
|
||||||
public String getDictName() {
|
|
||||||
return dictName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDictName(String dictName) {
|
|
||||||
this.dictName = dictName;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.DictEntity;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DictLoadResponse extends BaseResponse {
|
|
||||||
|
|
||||||
private List<DictEntity> result = new ArrayList<>();
|
|
||||||
|
|
||||||
public List<DictEntity> getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResult(List<DictEntity> result) {
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(DictEntity entity) {
|
|
||||||
this.result.add(entity);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class LogTaskEntity implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TASK_ID - 任务主键
|
|
||||||
*/
|
|
||||||
private String taskId;
|
|
||||||
/**
|
|
||||||
* TASK_NAME - 任务名称
|
|
||||||
*/
|
|
||||||
private String taskName;
|
|
||||||
/**
|
|
||||||
* START_TIME - 开始时间
|
|
||||||
*/
|
|
||||||
private Date startTime;
|
|
||||||
/**
|
|
||||||
* END_TIME - 结束时间
|
|
||||||
*/
|
|
||||||
private Date endTime;
|
|
||||||
/**
|
|
||||||
* EXEC_TIME - 执行耗时
|
|
||||||
*/
|
|
||||||
private Integer execTime;
|
|
||||||
/**
|
|
||||||
* EXEC_STATE - 执行状态
|
|
||||||
*/
|
|
||||||
private String execState;
|
|
||||||
/**
|
|
||||||
* EXEC_RESULT - 执行结果
|
|
||||||
*/
|
|
||||||
private String execResult;
|
|
||||||
|
|
||||||
public String getTaskId() {
|
|
||||||
return taskId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskId(String taskId) {
|
|
||||||
this.taskId = taskId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTaskName() {
|
|
||||||
return taskName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskName(String taskName) {
|
|
||||||
this.taskName = taskName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getStartTime() {
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartTime(Date startTime) {
|
|
||||||
this.startTime = startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getEndTime() {
|
|
||||||
return endTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndTime(Date endTime) {
|
|
||||||
this.endTime = endTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getExecTime() {
|
|
||||||
return execTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExecTime(Integer execTime) {
|
|
||||||
this.execTime = execTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExecState() {
|
|
||||||
return execState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExecState(String execState) {
|
|
||||||
this.execState = execState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExecResult() {
|
|
||||||
return execResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExecResult(String execResult) {
|
|
||||||
this.execResult = execResult;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.BaseRequest;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LoginRequest - 登录
|
|
||||||
*
|
|
||||||
* @author wangbing
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 2017-01-01
|
|
||||||
*/
|
|
||||||
public class LoginRequest extends BaseRequest {
|
|
||||||
|
|
||||||
@NotBlank(message = "[username]用户名不能为空")
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@NotBlank(message = "[password]用户密码不能为空")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@NotNull(message = "[verifyCodeId]验证码ID不能为空")
|
|
||||||
private Long verifyCodeId;
|
|
||||||
|
|
||||||
@NotBlank(message = "[verifyCodeCode]验证码不能为空")
|
|
||||||
private String verifyCodeCode;
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getVerifyCodeId() {
|
|
||||||
return verifyCodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVerifyCodeId(Long verifyCodeId) {
|
|
||||||
this.verifyCodeId = verifyCodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVerifyCodeCode() {
|
|
||||||
return verifyCodeCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVerifyCodeCode(String verifyCodeCode) {
|
|
||||||
this.verifyCodeCode = verifyCodeCode;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.BaseRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LogoutRequest - 用户登出
|
|
||||||
*
|
|
||||||
* @author wangbing
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 2017-01-01
|
|
||||||
*/
|
|
||||||
public class LogoutRequest extends BaseRequest {
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.BaseResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LogoutResponse - 用户登出
|
|
||||||
*
|
|
||||||
* @author wangbing
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 2017-01-01
|
|
||||||
*/
|
|
||||||
public class LogoutResponse extends BaseResponse {
|
|
||||||
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class SqlTaskEntity implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TASK_NAME - 任务名称
|
|
||||||
*/
|
|
||||||
private String taskName;
|
|
||||||
/**
|
|
||||||
* TASK_NOTE - 详细注释
|
|
||||||
*/
|
|
||||||
private String taskNote;
|
|
||||||
/**
|
|
||||||
* 任务类型.
|
|
||||||
* Cron:Cron表达式
|
|
||||||
* DelayRepeat:间隔重复(秒)
|
|
||||||
* FixRepeat:绝对重复(秒)
|
|
||||||
*/
|
|
||||||
private String taskType;
|
|
||||||
/**
|
|
||||||
* TYPE_VALUE - 任务类型值
|
|
||||||
*/
|
|
||||||
private String typeValue;
|
|
||||||
/**
|
|
||||||
* TASK_SQL - 任务SQL
|
|
||||||
*/
|
|
||||||
private String taskSql;
|
|
||||||
|
|
||||||
public String getTaskName() {
|
|
||||||
return taskName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskName(String taskName) {
|
|
||||||
this.taskName = taskName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTaskNote() {
|
|
||||||
return taskNote;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskNote(String taskNote) {
|
|
||||||
this.taskNote = taskNote;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTaskType() {
|
|
||||||
return taskType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskType(String taskType) {
|
|
||||||
this.taskType = taskType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTypeValue() {
|
|
||||||
return typeValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeValue(String typeValue) {
|
|
||||||
this.typeValue = typeValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTaskSql() {
|
|
||||||
return taskSql;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskSql(String taskSql) {
|
|
||||||
this.taskSql = taskSql;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class UserEntity extends BaseEntity {
|
|
||||||
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
private String userAlias;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
private Set<String> resSet = new HashSet<>();
|
|
||||||
|
|
||||||
public String getUserName() {
|
|
||||||
return userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserName(String userName) {
|
|
||||||
this.userName = userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserAlias() {
|
|
||||||
return userAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserAlias(String userAlias) {
|
|
||||||
this.userAlias = userAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getResSet() {
|
|
||||||
return resSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResSet(Set<String> resSet) {
|
|
||||||
this.resSet = resSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putRes(String resource) {
|
|
||||||
resSet.add(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putRes(Set<String> resourceSet) {
|
|
||||||
this.resSet.addAll(resourceSet);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.BaseRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* VerifyCodeRequest - 请求验证码
|
|
||||||
*
|
|
||||||
* @author wangbing
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 2020-12-24
|
|
||||||
*/
|
|
||||||
public class VerifyCodeRequest extends BaseRequest {
|
|
||||||
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.BaseResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* VerifyCodeResponse - 请求验证码
|
|
||||||
*
|
|
||||||
* @author wangbing
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 2020-12-24
|
|
||||||
*/
|
|
||||||
public class VerifyCodeResponse extends BaseResponse {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码ID
|
|
||||||
*/
|
|
||||||
private Long verifyCodeId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码base64
|
|
||||||
*/
|
|
||||||
private String verifyCodeBase64;
|
|
||||||
|
|
||||||
public Long getVerifyCodeId() {
|
|
||||||
return verifyCodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVerifyCodeId(Long verifyCodeId) {
|
|
||||||
this.verifyCodeId = verifyCodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVerifyCodeBase64() {
|
|
||||||
return verifyCodeBase64;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVerifyCodeBase64(String verifyCodeBase64) {
|
|
||||||
this.verifyCodeBase64 = verifyCodeBase64;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
package xyz.wbsite.frame.base;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class VisitorEntity implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APP_NAME - 应用名称
|
|
||||||
*/
|
|
||||||
private String appName;
|
|
||||||
/**
|
|
||||||
* APP_NOTE - 应用简介
|
|
||||||
*/
|
|
||||||
private String appNote;
|
|
||||||
/**
|
|
||||||
* APP_KEY - 应用码
|
|
||||||
*/
|
|
||||||
private String appKey;
|
|
||||||
/**
|
|
||||||
* APP_SECRET - 安全码
|
|
||||||
*/
|
|
||||||
private String appSecret;
|
|
||||||
|
|
||||||
public String getAppName() {
|
|
||||||
return appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppName(String appName) {
|
|
||||||
this.appName = appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppNote() {
|
|
||||||
return appNote;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppNote(String appNote) {
|
|
||||||
this.appNote = appNote;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppKey() {
|
|
||||||
return appKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppKey(String appKey) {
|
|
||||||
this.appKey = appKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppSecret() {
|
|
||||||
return appSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppSecret(String appSecret) {
|
|
||||||
this.appSecret = appSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> resSet = new HashSet<>();
|
|
||||||
|
|
||||||
public Set<String> getResSet() {
|
|
||||||
return resSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResSet(Set<String> resSet) {
|
|
||||||
this.resSet = resSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putRes(String resource) {
|
|
||||||
resSet.add(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putRes(Set<String> resourceSet) {
|
|
||||||
this.resSet.addAll(resourceSet);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,17 @@
|
|||||||
|
package xyz.wbsite.frame.excel.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel文件读取失败异常
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class ReadErrorException extends Exception {
|
||||||
|
public ReadErrorException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadErrorException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package xyz.wbsite.frame.excel.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 值转换异常
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 2017-01-01
|
||||||
|
*/
|
||||||
|
public class ValueConverterException extends Exception {
|
||||||
|
|
||||||
|
public ValueConverterException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package xyz.wbsite.frame.excel.handler;
|
|
||||||
|
|
||||||
import com.alibaba.excel.metadata.CellData;
|
|
||||||
import com.alibaba.excel.metadata.Head;
|
|
||||||
import com.alibaba.excel.write.handler.AbstractCellWriteHandler;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class HeadWriteHandler extends AbstractCellWriteHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
|
|
||||||
super.afterCellDispose(writeSheetHolder, writeTableHolder, cellDataList, cell, head, relativeRowIndex, isHead);
|
|
||||||
if (isHead) {
|
|
||||||
handlerHead(head);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void handlerHead(Head head);
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package xyz.wbsite.frame.excel.handler;
|
|
||||||
|
|
||||||
import com.alibaba.excel.metadata.CellData;
|
|
||||||
import com.alibaba.excel.metadata.Head;
|
|
||||||
import com.alibaba.excel.write.handler.CellWriteHandler;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import xyz.wbsite.frame.excel.WHead;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class WCellWriteHandler implements CellWriteHandler {
|
|
||||||
private CellStyle[] styles;
|
|
||||||
|
|
||||||
private Map<Integer, List<String>> errMap;
|
|
||||||
|
|
||||||
public WCellWriteHandler(List<WHead> wHeads, CellStyle[] styles, Map<Integer, List<String>> errMap) {
|
|
||||||
this.styles = styles;
|
|
||||||
this.errMap = errMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean isHead) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean isHead) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData, Cell cell, Head head, Integer integer, Boolean isHead) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> list, Cell cell, Head head, Integer rowIndex, Boolean isHead) {
|
|
||||||
if (isHead) {
|
|
||||||
cell.setCellStyle(styles[0]);
|
|
||||||
} else if (errMap.get(rowIndex) != null) {
|
|
||||||
cell.setCellStyle(styles[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package xyz.wbsite.frame.excel.handler;
|
|
||||||
|
|
||||||
import com.alibaba.excel.metadata.Head;
|
|
||||||
import com.alibaba.excel.write.handler.RowWriteHandler;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
import org.apache.poi.ss.usermodel.Comment;
|
|
||||||
import org.apache.poi.ss.usermodel.Drawing;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
|
||||||
import xyz.wbsite.frame.excel.WHead;
|
|
||||||
import xyz.wbsite.frame.utils.StringUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class WRowWriteHandler implements RowWriteHandler {
|
|
||||||
private List<WHead> wHeads;
|
|
||||||
private Map<Integer, List<String>> errMap;
|
|
||||||
|
|
||||||
public WRowWriteHandler(List<WHead> wHeads, Map<Integer, List<String>> errMap) {
|
|
||||||
this.wHeads = wHeads;
|
|
||||||
this.errMap = errMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer integer, Integer integer1, Boolean isHead) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer integer, Boolean isHead) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer rowIndex, Boolean isHead) {
|
|
||||||
if (isHead && getHeadMaxRow() == rowIndex) {
|
|
||||||
for (int i = 0; i < wHeads.size(); i++) {
|
|
||||||
WHead wHead = wHeads.get(i);
|
|
||||||
if (StringUtil.isNotEmpty(wHead.getNote())) {
|
|
||||||
Drawing<?> drawingPatriarch = writeSheetHolder.getSheet().createDrawingPatriarch();
|
|
||||||
// 创建一个批注
|
|
||||||
int headRow = getHeadRow(wHead.getHead());
|
|
||||||
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) i, headRow, (short) i + 1, headRow + 3));
|
|
||||||
// 输入批注信息
|
|
||||||
comment.setString(new XSSFRichTextString(wHead.getNote()));
|
|
||||||
// 将批注添加到标题对象中
|
|
||||||
writeSheetHolder.getSheet().getRow(headRow).getCell(i).setCellComment(comment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isHead && errMap.get(rowIndex) != null) {
|
|
||||||
Cell cell = row.createCell(wHeads.size());
|
|
||||||
cell.getCellStyle().setWrapText(true);
|
|
||||||
List<String> errs = errMap.get(rowIndex);
|
|
||||||
cell.setCellValue(String.join("\r\n", errs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeadMaxRow() {
|
|
||||||
int r = 0;
|
|
||||||
for (WHead wHead : wHeads) {
|
|
||||||
if (wHead.getHead().getHeadNameList().size() - 1 > r) r = wHead.getHead().getHeadNameList().size() - 1;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeadRow(Head head) {
|
|
||||||
List<String> nameList = head.getHeadNameList();
|
|
||||||
if (nameList.size() == 1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int r = nameList.size() - 1;
|
|
||||||
String last = nameList.get(r);
|
|
||||||
for (int i = nameList.size() - 2; i >= 0; i--) {
|
|
||||||
String s = nameList.get(i);
|
|
||||||
if (s.equals(last)) {
|
|
||||||
r--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package xyz.wbsite.frame.excel.handler;
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.excel.write.handler.SheetWriteHandler;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
|
||||||
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
|
|
||||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
||||||
import xyz.wbsite.frame.excel.WHead;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class WSheetWriteHandler implements SheetWriteHandler {
|
|
||||||
private List<WHead> wHeads;
|
|
||||||
private CellStyle[] styles;
|
|
||||||
|
|
||||||
public WSheetWriteHandler(List<WHead> wHeads, CellStyle[] styles) {
|
|
||||||
this.wHeads = wHeads;
|
|
||||||
this.styles = styles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
|
|
||||||
{
|
|
||||||
styles[1] = writeWorkbookHolder.getWorkbook().createCellStyle();
|
|
||||||
styles[1].setFillForegroundColor(IndexedColors.RED.getIndex());
|
|
||||||
styles[1].setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
styles[0] = writeWorkbookHolder.getWorkbook().createCellStyle();
|
|
||||||
styles[0].setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
||||||
styles[0].setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
||||||
styles[0].setBorderBottom(BorderStyle.THIN);
|
|
||||||
styles[0].setBorderLeft(BorderStyle.THIN);
|
|
||||||
styles[0].setBorderRight(BorderStyle.THIN);
|
|
||||||
styles[0].setBorderTop(BorderStyle.THIN);
|
|
||||||
styles[0].setAlignment(HorizontalAlignment.CENTER);
|
|
||||||
Font font = writeWorkbookHolder.getWorkbook().createFont();
|
|
||||||
font.setColor(IndexedColors.BLACK.getIndex());
|
|
||||||
font.setFontHeightInPoints((short) 12);
|
|
||||||
font.setBold(true);
|
|
||||||
styles[0].setFont(font);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
|
|
||||||
for (int i = 0; i < wHeads.size(); i++) {
|
|
||||||
WHead col = wHeads.get(i);
|
|
||||||
if (col.getSelectList() != null && col.getSelectList().length > 0) {
|
|
||||||
CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(0, 500, i, i);
|
|
||||||
DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper();
|
|
||||||
DataValidationConstraint constraint = helper.createExplicitListConstraint(col.getSelectList());
|
|
||||||
DataValidation dataValidation = helper.createValidation(constraint, cellRangeAddressList);
|
|
||||||
writeSheetHolder.getSheet().addValidationData(dataValidation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package xyz.wbsite.frame.excel.listener;
|
|
||||||
|
|
||||||
import com.alibaba.excel.context.AnalysisContext;
|
|
||||||
import com.alibaba.excel.event.AnalysisEventListener;
|
|
||||||
import xyz.wbsite.frame.excel.WHead;
|
|
||||||
import xyz.wbsite.frame.excel.exception.TemplateNotMatchException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class WReadListener<T> extends AnalysisEventListener<T> {
|
|
||||||
private List<WHead> wHeads;
|
|
||||||
private TemplateNotMatchException[] es;
|
|
||||||
private boolean isHead;
|
|
||||||
|
|
||||||
public WReadListener(List<WHead> wHeads, TemplateNotMatchException[] es) {
|
|
||||||
this.wHeads = wHeads;
|
|
||||||
this.es = es;
|
|
||||||
this.isHead = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invokeHeadMap(Map headMap, AnalysisContext context) {
|
|
||||||
if (wHeads.size() != headMap.size()) {
|
|
||||||
es[0] = new TemplateNotMatchException("文件列数量与模板不一致!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
es[0] = null;
|
|
||||||
for (int i = 0; i < wHeads.size(); i++) {
|
|
||||||
WHead wCol = wHeads.get(i);
|
|
||||||
String cellValue = headMap.get(i).toString();
|
|
||||||
if (!wCol.getName().equals(cellValue)) {
|
|
||||||
es[0] = new TemplateNotMatchException(String.format("第 %d 列应为[ %s ]", i + 1, wCol.getName()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(T o, AnalysisContext analysisContext) {
|
|
||||||
isHead = false;
|
|
||||||
invoke(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void invoke(T o);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext(AnalysisContext context) {
|
|
||||||
// 请求head
|
|
||||||
if (isHead) {//多级表头,头部未结束
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!isHead && es[0] == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,57 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class BaseCellStyle {
|
||||||
|
/**
|
||||||
|
* 样式
|
||||||
|
*/
|
||||||
|
protected CellStyle style;
|
||||||
|
|
||||||
|
public BaseCellStyle(Workbook workbook) {
|
||||||
|
style = workbook.createCellStyle();
|
||||||
|
style.setFillPattern(CellStyle.NO_FILL);
|
||||||
|
//下边框
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//下边框颜色
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//左边框
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//左边框颜色
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//右边框
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//右边框颜色
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
//上边框
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND);
|
||||||
|
//上边框颜色
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||||
|
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //上下居中
|
||||||
|
style.setBorderBottom(CellStyle.SOLID_FOREGROUND); //下边框
|
||||||
|
style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); //下边框颜色
|
||||||
|
style.setBorderLeft(CellStyle.SOLID_FOREGROUND); //左边框
|
||||||
|
style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); //左边框颜色
|
||||||
|
style.setBorderRight(CellStyle.SOLID_FOREGROUND); //右边框
|
||||||
|
style.setRightBorderColor(IndexedColors.BLACK.getIndex()); //右边框颜色
|
||||||
|
style.setBorderTop(CellStyle.SOLID_FOREGROUND); //上边框
|
||||||
|
style.setTopBorderColor(IndexedColors.BLACK.getIndex()); //上边框颜色
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellStyle getStyle() {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyle(CellStyle style) {
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class BaseFont {
|
||||||
|
/**
|
||||||
|
* 字体
|
||||||
|
*/
|
||||||
|
protected Font font;
|
||||||
|
|
||||||
|
public BaseFont(Workbook workbook) {
|
||||||
|
font = workbook.createFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Font getFont() {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFont(Font font) {
|
||||||
|
this.font = font;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
public class DataCellStyle extends BaseCellStyle {
|
||||||
|
|
||||||
|
public DataCellStyle(Workbook workbook, short align, boolean error) {
|
||||||
|
super(workbook);
|
||||||
|
style.setAlignment(align);
|
||||||
|
if (error) {
|
||||||
|
style.setFillForegroundColor(HSSFColor.RED.index); //背景颜色红色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); //设置单元格填充样式
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataCellStyle(Workbook workbook, short align) {
|
||||||
|
this(workbook, align, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataCellStyle(Workbook workbook, boolean error) {
|
||||||
|
this(workbook, CellStyle.ALIGN_LEFT, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataCellStyle(Workbook workbook) {
|
||||||
|
this(workbook, CellStyle.ALIGN_LEFT, false);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
public class ErrorCellStyle extends BaseCellStyle {
|
||||||
|
|
||||||
|
public ErrorCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillForegroundColor(HSSFColor.RED.index); //背景颜色红色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); //设置单元格填充样式
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellStyle getStyle() {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyle(CellStyle style) {
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
public class HeadCellStyle extends BaseCellStyle {
|
||||||
|
public HeadCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); //背景颜色-灰色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 设置单元格填充样式
|
||||||
|
style.setAlignment(CellStyle.ALIGN_CENTER); // 居中
|
||||||
|
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//上下居中
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通字体.颜色黑
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class NormalFont extends BaseFont {
|
||||||
|
public NormalFont(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
font.setColor(HSSFColor.BLACK.index); //字体颜色-黑色
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通字体.颜色黑
|
||||||
|
* Created on 2015/1/29.
|
||||||
|
*
|
||||||
|
* @author
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class RedFont extends BaseFont {
|
||||||
|
public RedFont(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
font.setColor(HSSFColor.RED.index); //字体颜色-黑色
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.wbsite.frame.excel.style;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
|
public class SuccessCellStyle extends BaseCellStyle {
|
||||||
|
|
||||||
|
public SuccessCellStyle(Workbook workbook) {
|
||||||
|
super(workbook);
|
||||||
|
style.setFillForegroundColor(HSSFColor.GREEN.index); //背景颜色红色
|
||||||
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND); //设置单元格填充样式
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellStyle getStyle() {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStyle(CellStyle style) {
|
||||||
|
this.style = style;
|
||||||
|
}
|
||||||
|
}
|
@ -1,46 +0,0 @@
|
|||||||
package xyz.wbsite.frame.listener;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class FrameListener {
|
|
||||||
|
|
||||||
private static FrameListener ourInstance = new FrameListener();
|
|
||||||
|
|
||||||
public static FrameListener getInstance() {
|
|
||||||
return ourInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FrameListener() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRes(String res) {
|
|
||||||
Map<String, IResListener> beansOfType = LocalData.getApplicationContext().getBeansOfType(IResListener.class);
|
|
||||||
for (IResListener resListener : beansOfType.values()) {
|
|
||||||
resListener.onRes(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onError(Throwable throwable) {
|
|
||||||
Map<String, IErrorListener> beansOfType = LocalData.getApplicationContext().getBeansOfType(IErrorListener.class);
|
|
||||||
for (IErrorListener errorListener : beansOfType.values()) {
|
|
||||||
errorListener.error(throwable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onError(String message) {
|
|
||||||
onError(new RuntimeException(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTaskError(Throwable error) {
|
|
||||||
Map<String, IErrorListener> beansOfType = LocalData.getApplicationContext().getBeansOfType(IErrorListener.class);
|
|
||||||
for (IErrorListener errorListener : beansOfType.values()) {
|
|
||||||
errorListener.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTaskError(String message) {
|
|
||||||
onTaskError(new RuntimeException(message));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package xyz.wbsite.frame.listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统错误监听器
|
|
||||||
*/
|
|
||||||
public interface IErrorListener {
|
|
||||||
|
|
||||||
void error(Throwable error);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package xyz.wbsite.frame.listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源收集监听器
|
|
||||||
*/
|
|
||||||
public interface IResListener {
|
|
||||||
|
|
||||||
void onRes(String res);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package xyz.wbsite.frame.listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务错误监听器
|
|
||||||
*/
|
|
||||||
public interface ITaskErrorListener {
|
|
||||||
|
|
||||||
void error(Throwable error);
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.DictEntity;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface DictProvider {
|
|
||||||
|
|
||||||
List<DictEntity> getDict(@NotNull String dictName);
|
|
||||||
|
|
||||||
boolean isExist(@NotNull String dictName);
|
|
||||||
|
|
||||||
boolean isExistValue(@NotNull String dictName, @NotNull String dictKey);
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class FrameProvider {
|
|
||||||
|
|
||||||
private static FrameProvider ourInstance = new FrameProvider();
|
|
||||||
|
|
||||||
public static FrameProvider getInstance() {
|
|
||||||
return ourInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FrameProvider() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserProvider getUserProvider() {
|
|
||||||
Map<String, UserProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(UserProvider.class);
|
|
||||||
if (beansOfType.size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Iterator<String> iterator = beansOfType.keySet().iterator();
|
|
||||||
String name = iterator.next();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String next = iterator.next();
|
|
||||||
name = !"simpleUserProvider".equals(next) ? next : name;
|
|
||||||
}
|
|
||||||
return beansOfType.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TokenProvider getTokenProvider() {
|
|
||||||
Map<String, TokenProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(TokenProvider.class);
|
|
||||||
if (beansOfType.size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Iterator<String> iterator = beansOfType.keySet().iterator();
|
|
||||||
String name = iterator.next();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String next = iterator.next();
|
|
||||||
name = !"simpleTokenProvider".equals(next) ? next : name;
|
|
||||||
}
|
|
||||||
return beansOfType.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProfileProvider getProfileProvider() {
|
|
||||||
Map<String, ProfileProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(ProfileProvider.class);
|
|
||||||
if (beansOfType.size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Iterator<String> iterator = beansOfType.keySet().iterator();
|
|
||||||
String name = iterator.next();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String next = iterator.next();
|
|
||||||
name = !"simpleProfileProvider".equals(next) ? next : name;
|
|
||||||
}
|
|
||||||
return beansOfType.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DictProvider getDictProvider() {
|
|
||||||
Map<String, DictProvider> beansOfType = LocalData.getApplicationContext().getBeansOfType(DictProvider.class);
|
|
||||||
if (beansOfType.size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Iterator<String> iterator = beansOfType.keySet().iterator();
|
|
||||||
String name = iterator.next();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String next = iterator.next();
|
|
||||||
name = !"simpleDictProvider".equals(next) ? next : name;
|
|
||||||
}
|
|
||||||
return beansOfType.get(name);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.LogTaskEntity;
|
|
||||||
|
|
||||||
public interface LogTaskCollector {
|
|
||||||
void collector(LogTaskEntity entity);
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
public interface ProfileProvider {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得当前环境配置
|
|
||||||
*
|
|
||||||
* @param key 配置项名
|
|
||||||
* @param defaultValue 默认值
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String getString(String key, String defaultValue);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得当前环境配置
|
|
||||||
*
|
|
||||||
* @param key 配置项名
|
|
||||||
* @param defaultValue 默认值
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int getInt(String key, int defaultValue);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得当前环境配置
|
|
||||||
*
|
|
||||||
* @param key 配置项名
|
|
||||||
* @param defaultValue 默认值
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
long getLong(String key, long defaultValue);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得当前环境配置
|
|
||||||
*
|
|
||||||
* @param key 配置项名
|
|
||||||
* @param defaultValue 默认值
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean getBoolean(String key, boolean defaultValue);
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.utils.StringUtil;
|
|
||||||
|
|
||||||
public class SimpleProfileProvider implements ProfileProvider {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getString(String key, String defaultValue) {
|
|
||||||
return LocalData.getProperty(key, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInt(String key, int defaultValue) {
|
|
||||||
String string = getString(key, String.valueOf(defaultValue));
|
|
||||||
if (!StringUtil.isEmpty(string)) {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(string);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLong(String key, long defaultValue) {
|
|
||||||
String string = this.getString(key, String.valueOf(defaultValue));
|
|
||||||
if (!StringUtil.isEmpty(string)) {
|
|
||||||
try {
|
|
||||||
return Long.parseLong(string);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getBoolean(String key, boolean defaultValue) {
|
|
||||||
String string = this.getString(key, String.valueOf(defaultValue));
|
|
||||||
if (!StringUtil.isEmpty(string)) {
|
|
||||||
try {
|
|
||||||
return Boolean.parseBoolean(string);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import xyz.wbsite.config.CacheConfig;
|
|
||||||
import xyz.wbsite.frame.base.Token;
|
|
||||||
import xyz.wbsite.frame.base.UserEntity;
|
|
||||||
import xyz.wbsite.frame.utils.IDgenerator;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class SimpleTokenProvider implements TokenProvider {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CacheConfig cacheConfig;
|
|
||||||
|
|
||||||
public Token build(@NotNull UserEntity userEntity) {
|
|
||||||
Token token = new Token();
|
|
||||||
token.setId(IDgenerator.nextId());
|
|
||||||
token.setUserId(userEntity.getId());
|
|
||||||
token.setToken(IDgenerator.nextUUID());
|
|
||||||
token.setUserName(userEntity.getUserName());
|
|
||||||
token.setUserAlias(userEntity.getUserAlias());
|
|
||||||
token.putRes(userEntity.getResSet());
|
|
||||||
cacheConfig.put(token.getToken(), token, 3 * 60 * 60 * 1000);
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Token build(@NotNull String token) {
|
|
||||||
// 检索缓存Token
|
|
||||||
Object o = cacheConfig.get(token);
|
|
||||||
if (o != null && o instanceof Token) {
|
|
||||||
return (Token) o;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import xyz.wbsite.frame.base.LocalData;
|
|
||||||
import xyz.wbsite.frame.base.UserEntity;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class SimpleUserProvider implements UserProvider {
|
|
||||||
|
|
||||||
public UserEntity getUser(String username) {
|
|
||||||
String admin = LocalData.getProperty("web.url.auth.admin", "");
|
|
||||||
if (!username.equals(admin)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
UserEntity userEntity = new UserEntity();
|
|
||||||
userEntity.setId(0L);
|
|
||||||
userEntity.setUserName(username);
|
|
||||||
userEntity.setUserAlias("超级管理员");
|
|
||||||
userEntity.setPassword(LocalData.getProperty("web.url.auth.pwd", ""));
|
|
||||||
userEntity.putRes(".*");
|
|
||||||
return userEntity;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.SqlTaskEntity;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface SqlTaskProvider {
|
|
||||||
List<SqlTaskEntity> getSqlTask();
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.Token;
|
|
||||||
import xyz.wbsite.frame.base.UserEntity;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public interface TokenProvider {
|
|
||||||
|
|
||||||
Token build(@NotNull UserEntity userEntity);
|
|
||||||
|
|
||||||
Token build(@NotNull String token);
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.UserEntity;
|
|
||||||
|
|
||||||
public interface UserProvider {
|
|
||||||
|
|
||||||
UserEntity getUser(String username);
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package xyz.wbsite.frame.provider;
|
|
||||||
|
|
||||||
import xyz.wbsite.frame.base.VisitorEntity;
|
|
||||||
|
|
||||||
public interface VisitorProvider {
|
|
||||||
|
|
||||||
VisitorEntity getVisitor(String appKey);
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue