【添加】添加3个文件

This commit is contained in:
zer0Black
2021-03-12 10:39:22 +08:00
parent 4fc12b9524
commit ad440643a9
4 changed files with 530 additions and 9 deletions
@@ -0,0 +1,21 @@
package com.jero.generater.interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class OnlineConfiguration implements WebMvcConfigurer {
@Bean
public OnlineInterceptor onlineInterceptor() {
return new OnlineInterceptor();
}
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(onlineInterceptor())
.excludePathPatterns(new String[]{"/*.html", "/html/**", "/js/**", "/css/**", "/images/**"})
.addPathPatterns(new String[]{"/online/cgform/api/**"});
}
}
@@ -0,0 +1,123 @@
package com.jero.generater.interceptor;
import com.alibaba.fastjson.JSON;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jero.common.api.dto.OnlineAuthDTO;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.OnlineAuth;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.util.JwtUtil;
import com.jero.common.util.SpringContextUtils;
import com.jero.common.util.oConvertUtils;
import com.jero.generater.modules.online.cgform.service.IOnlineBaseAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
public class OnlineInterceptor implements HandlerInterceptor {
private static final Logger a = LoggerFactory.getLogger(OnlineInterceptor.class);
private IOnlineBaseAPI b;
private ISysBaseAPI sysBaseAPI;
private static final String d = "/online/cgform";
private static final String[] e = new String[]{"/online/cgformInnerTableList",
"/online/cgformErpList",
"/online/cgformList",
"/online/cgformTreeList",
"/online/cgformTabList"};
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
boolean bool = handler.getClass().isAssignableFrom(HandlerMethod.class);
if (bool) {
OnlineAuth onlineAuth = (OnlineAuth) ((HandlerMethod) handler).getMethodAnnotation(OnlineAuth.class);
if (onlineAuth != null) {
a.debug("===== online 菜单访问拦截器 =====");
String str1 = request.getRequestURI().substring(request.getContextPath().length());
str1 = a(str1);
String str2 = onlineAuth.value();
String str3 = str1.substring(str1.lastIndexOf(str2) + str2.length());
a.debug("拦截请求(" + request.getMethod() + ")" + str1 + ",");
if ("form".equals(str2) && "DELETE".equals(request.getMethod())) {
str3 = str3.substring(0, str3.lastIndexOf("/"));
}
String str4 = request.getParameter("tabletype");
if (this.b == null) {
this.b = (IOnlineBaseAPI) SpringContextUtils.getBean(IOnlineBaseAPI.class);
}
str3 = this.b.getOnlineErpCode(str3, str4);
ArrayList<String> arrayList = new ArrayList();
for (String str : e) {
arrayList.add(str + str3);
}
if (this.sysBaseAPI == null) {
this.sysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
}
String str5 = JwtUtil.getUserNameByToken(request);
OnlineAuthDTO onlineAuthDTO = new OnlineAuthDTO(str5, arrayList, "/online/cgform");
boolean bool1 = this.sysBaseAPI.hasOnlineAuth(onlineAuthDTO);
if (!bool1) {
a.info("请求无权限(" + request.getMethod() + ")" + str1);
a(response, str2);
return false;
}
}
}
return true;
}
private String a(String paramString) {
String str = "";
if (oConvertUtils.isNotEmpty(paramString)) {
str = paramString.replace("\\", "/")
.replace("//", "/");
if (str.indexOf("//") >= 0) {
str = a(str);
}
}
return str;
}
private void a(HttpServletResponse paramHttpServletResponse, String paramString) {
PrintWriter printWriter = null;
paramHttpServletResponse.setCharacterEncoding("UTF-8");
paramHttpServletResponse.setContentType("application/json; charset=utf-8");
paramHttpServletResponse.setHeader("auth", "fail");
try {
printWriter = paramHttpServletResponse.getWriter();
if ("exportXls".equals(paramString)) {
printWriter.print("");
} else {
Result result = Result.error("无权限访问(操作)");
printWriter.print(JSON.toJSON(result));
}
} catch (IOException iOException) {
a.error(iOException.getMessage());
} finally {
if (printWriter != null)
printWriter.close();
}
}
}
@@ -0,0 +1,386 @@
package com.jero.generater.modules.online.auth.a;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jero.common.api.vo.Result;
import com.jero.common.util.oConvertUtils;
import com.jero.generater.modules.online.auth.entity.OnlAuthData;
import com.jero.generater.modules.online.auth.entity.OnlAuthPage;
import com.jero.generater.modules.online.auth.entity.OnlAuthRelation;
import com.jero.generater.modules.online.auth.service.IOnlAuthDataService;
import com.jero.generater.modules.online.auth.service.IOnlAuthPageService;
import com.jero.generater.modules.online.auth.service.IOnlAuthRelationService;
import com.jero.generater.modules.online.auth.vo.AuthColumnVO;
import com.jero.generater.modules.online.auth.vo.AuthPageVO;
import com.jero.generater.modules.online.cgform.entity.OnlCgformButton;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import com.jero.generater.modules.online.cgform.entity.OnlCgformHead;
import com.jero.generater.modules.online.cgform.service.IOnlCgformButtonService;
import com.jero.generater.modules.online.cgform.service.IOnlCgformFieldService;
import com.jero.generater.modules.online.cgform.service.IOnlCgformHeadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController("onlCgformAuthController")
@RequestMapping({"/online/cgform/api"})
public class OnlCgformAuthController {
private static final Logger a = LoggerFactory.getLogger(OnlCgformAuthController.class);
@Autowired
private IOnlCgformFieldService onlCgformFieldService;
@Autowired
private IOnlAuthDataService onlAuthDataService;
@Autowired
private IOnlAuthPageService onlAuthPageService;
@Autowired
private IOnlCgformButtonService onlCgformButtonService;
@Autowired
private IOnlAuthRelationService onlAuthRelationService;
@Autowired
private IOnlCgformHeadService onlCgformHeadService;
@GetMapping({"/authData/{cgformId}"})
public Result<List<OnlAuthData>> a(@PathVariable("cgformId") String paramString) {
Result<List<OnlAuthData>> result = new Result();
LambdaQueryWrapper<OnlAuthData> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.eq(OnlAuthData::getCgformId, paramString);
List list = this.onlAuthDataService.list((Wrapper) lambdaQueryWrapper);
result.setResult(list);
result.setSuccess(true);
return result;
}
@PostMapping({"/authData"})
public Result<OnlAuthData> a(@RequestBody OnlAuthData paramOnlAuthData) {
Result<OnlAuthData> result = new Result();
try {
this.onlAuthDataService.save(paramOnlAuthData);
result.success("添加成功!");
} catch (Exception exception) {
a.error(exception.getMessage(), exception);
result.error500("操作失败");
}
return result;
}
@PutMapping({"/authData"})
public Result<OnlAuthData> b(@RequestBody OnlAuthData paramOnlAuthData) {
Result<OnlAuthData> result = new Result();
this.onlAuthDataService.updateById(paramOnlAuthData);
return result;
}
@DeleteMapping({"/authData/{id}"})
public Result<?> b(@PathVariable("id") String paramString) {
this.onlAuthDataService.deleteOne(paramString);
return Result.ok("删除成功!");
}
@GetMapping({"/authButton/{cgformId}"})
public Result<Map<String, Object>> c(@PathVariable("cgformId") String paramString) {
Result<Map<String, Object>> result = new Result();
LambdaQueryWrapper<OnlCgformButton> buttonLambdaQueryWrapper = new LambdaQueryWrapper();
buttonLambdaQueryWrapper.eq(OnlCgformButton::getCgformHeadId, paramString)
.eq(OnlCgformButton::getButtonStatus, Integer.valueOf(1))
.select(OnlCgformButton::getButtonCode, OnlCgformButton::getButtonName, OnlCgformButton::getButtonStyle);
List buttonList = this.onlCgformButtonService.list((Wrapper) buttonLambdaQueryWrapper);
LambdaQueryWrapper<OnlAuthPage> authPageLambdaQueryWrapper = new LambdaQueryWrapper();
authPageLambdaQueryWrapper.eq(OnlAuthPage::getCgformId, paramString)
.eq(OnlAuthPage::getType, Integer.valueOf(2));
List authPageList = this.onlAuthPageService.list((Wrapper) authPageLambdaQueryWrapper);
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("buttonList", buttonList);
hashMap.put("authList", authPageList);
result.setResult(hashMap);
result.setSuccess(true);
return result;
}
@PostMapping({"/authButton"})
public Result<OnlAuthPage> a(@RequestBody OnlAuthPage paramOnlAuthPage) {
Result<OnlAuthPage> result = new Result();
try {
String str = paramOnlAuthPage.getId();
boolean bool = false;
if (oConvertUtils.isNotEmpty(str)) {
OnlAuthPage onlAuthPage = (OnlAuthPage) this.onlAuthPageService.getById(str);
if (onlAuthPage != null) {
bool = true;
onlAuthPage.setStatus(Integer.valueOf(1));
this.onlAuthPageService.updateById(onlAuthPage);
}
}
if (!bool) {
paramOnlAuthPage.setStatus(Integer.valueOf(1));
this.onlAuthPageService.save(paramOnlAuthPage);
}
result.setResult(paramOnlAuthPage);
result.success("操作成功!");
} catch (Exception exception) {
a.error(exception.getMessage(), exception);
result.error500("操作失败");
}
return result;
}
@PutMapping({"/authButton/{id}"})
public Result<?> d(@PathVariable("id") String paramString) {
LambdaUpdateWrapper<OnlAuthPage> lambdaUpdateWrapper = new LambdaUpdateWrapper();
lambdaUpdateWrapper.eq(OnlAuthPage::getId, paramString).set(OnlAuthPage::getStatus, Integer.valueOf(0));
this.onlAuthPageService.update((Wrapper) lambdaUpdateWrapper);
return Result.OK("操作成功");
}
@GetMapping({"/authColumn/{cgformId}"})
public Result<List<AuthColumnVO>> e(@PathVariable("cgformId") String paramString) {
Result<List<AuthColumnVO>> result = new Result();
LambdaQueryWrapper<OnlCgformField> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.eq(OnlCgformField::getCgformHeadId, paramString);
lambdaQueryWrapper.orderByAsc(OnlCgformField::getOrderNum);
List<OnlCgformField> list = this.onlCgformFieldService.list((Wrapper) lambdaQueryWrapper);
if (list == null || list.size() == 0) {
Result.error("未找到对应字段信息!");
}
LambdaQueryWrapper<OnlAuthPage> pageLambdaQueryWrapper = new LambdaQueryWrapper();
pageLambdaQueryWrapper.eq(OnlAuthPage::getCgformId, paramString).eq(OnlAuthPage::getType, Integer.valueOf(1));
List<OnlAuthPage> pageList = this.onlAuthPageService.list((Wrapper) pageLambdaQueryWrapper);
ArrayList<AuthColumnVO> arrayList = new ArrayList();
for (OnlCgformField onlCgformField : list) {
AuthColumnVO authColumnVO = new AuthColumnVO(onlCgformField);
Integer integer = Integer.valueOf(0);
boolean bool1 = false, bool2 = false, bool3 = false;
for (int b = 0; b < pageList.size(); b++) {
OnlAuthPage onlAuthPage = pageList.get(b);
if (onlCgformField.getDbFieldName().equals(onlAuthPage.getCode())) {
integer = onlAuthPage.getStatus();
if (onlAuthPage.getPage().intValue() == 3 && onlAuthPage.getControl().intValue() == 5) {
bool1 = true;
}
if (onlAuthPage.getPage().intValue() == 5) {
if (onlAuthPage.getControl().intValue() == 5) {
bool2 = true;
} else if (onlAuthPage.getControl().intValue() == 3) {
bool3 = true;
}
}
}
}
authColumnVO.setStatus(integer);
authColumnVO.setListShow(bool1);
authColumnVO.setFormShow(bool2);
authColumnVO.setFormEditable(bool3);
arrayList.add(authColumnVO);
}
result.setResult(arrayList);
Result.OK("加载字段权限数据完成");
return result;
}
@PutMapping({"/authColumn"})
public Result<?> a(@RequestBody AuthColumnVO paramAuthColumnVO) {
Result<?> result = new Result();
try {
if (paramAuthColumnVO.getStatus().intValue() == 1) {
this.onlAuthPageService.enableAuthColumn(paramAuthColumnVO);
} else {
this.onlAuthPageService.disableAuthColumn(paramAuthColumnVO);
}
result.success("操作成功!");
} catch (Exception exception) {
a.error(exception.getMessage(), exception);
result.error500("操作失败");
}
return result;
}
@PostMapping({"/authColumn"})
public Result<?> b(@RequestBody AuthColumnVO paramAuthColumnVO) {
Result<?> result = new Result();
try {
this.onlAuthPageService.switchAuthColumn(paramAuthColumnVO);
result.success("操作成功!");
} catch (Exception exception) {
a.error(exception.getMessage(), exception);
result.error500("操作失败");
}
return result;
}
@GetMapping({"/authPage/{cgformId}/{type}"})
public Result<List<AuthPageVO>> a(@PathVariable("cgformId") String paramString, @PathVariable("type") Integer paramInteger) {
Result<List<AuthPageVO>> result = new Result();
List list = this.onlAuthPageService.queryAuthByFormId(paramString, paramInteger.intValue());
result.setResult(list);
result.setSuccess(true);
return result;
}
@GetMapping({"/validAuthData/{cgformId}"})
public Result<List<OnlAuthData>> f(@PathVariable("cgformId") String paramString) {
Result<List<OnlAuthData>> result = new Result();
LambdaQueryWrapper<OnlAuthData> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.eq(OnlAuthData::getCgformId, paramString)
.eq(OnlAuthData::getStatus, Integer.valueOf(1))
.select(OnlAuthData::getId, OnlAuthData::getRuleName);
List list = this.onlAuthDataService.list((Wrapper) lambdaQueryWrapper);
result.setResult(list);
result.setSuccess(true);
return result;
}
@GetMapping({"/roleAuth"})
public Result<List<OnlAuthRelation>> a(@RequestParam("roleId") String paramString1, @RequestParam("cgformId") String paramString2, @RequestParam("type") Integer paramInteger) {
Result<List<OnlAuthRelation>> result = new Result();
LambdaQueryWrapper<OnlAuthRelation> lambdaQueryWrapper = new LambdaQueryWrapper();
lambdaQueryWrapper.eq(OnlAuthRelation::getRoleId, paramString1)
.eq(OnlAuthRelation::getCgformId, paramString2)
.eq(OnlAuthRelation::getType, paramInteger)
.select(OnlAuthRelation::getAuthId);
List list = this.onlAuthRelationService.list((Wrapper) lambdaQueryWrapper);
result.setResult(list);
result.setSuccess(true);
return result;
}
@PostMapping({"/roleColumnAuth/{roleId}/{cgformId}"})
public Result<?> a(@PathVariable("roleId") String paramString1, @PathVariable("cgformId") String paramString2, @RequestBody JSONObject paramJSONObject) {
Result<?> result = new Result();
JSONArray jSONArray = paramJSONObject.getJSONArray("authId");
List list = jSONArray.toJavaList(String.class);
this.onlAuthRelationService.saveRoleAuth(paramString1, paramString2, 1, list);
result.setSuccess(true);
return result;
}
@PostMapping({"/roleButtonAuth/{roleId}/{cgformId}"})
public Result<?> b(@PathVariable("roleId") String paramString1, @PathVariable("cgformId") String paramString2, @RequestBody JSONObject paramJSONObject) {
Result<?> result = new Result();
JSONArray jSONArray = paramJSONObject.getJSONArray("authId");
List list = jSONArray.toJavaList(String.class);
this.onlAuthRelationService.saveRoleAuth(paramString1, paramString2, 2, list);
result.setSuccess(true);
return result;
}
@PostMapping({"/roleDataAuth/{roleId}/{cgformId}"})
public Result<?> c(@PathVariable("roleId") String paramString1, @PathVariable("cgformId") String paramString2, @RequestBody JSONObject paramJSONObject) {
Result<?> result = new Result();
JSONArray jSONArray = paramJSONObject.getJSONArray("authId");
List list = jSONArray.toJavaList(String.class);
this.onlAuthRelationService.saveRoleAuth(paramString1, paramString2, 3, list);
result.setSuccess(true);
return result;
}
@GetMapping({"/getAuthColumn/{desformCode}"})
public Result<List<AuthColumnVO>> g(@PathVariable("desformCode") String paramString) {
LambdaQueryWrapper<OnlCgformHead> cgformHeadLambdaQueryWrapper = new LambdaQueryWrapper();
cgformHeadLambdaQueryWrapper.eq(OnlCgformHead::getTableName, paramString);
OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getOne((Wrapper) (cgformHeadLambdaQueryWrapper));
if (onlCgformHead == null) {
Result.error("未找到对应字段信息!");
}
Result<List<AuthColumnVO>> result = new Result();
LambdaQueryWrapper<OnlCgformField> cgformFieldLambdaQueryWrapper = new LambdaQueryWrapper();
cgformFieldLambdaQueryWrapper.eq(OnlCgformField::getCgformHeadId, onlCgformHead.getId());
cgformFieldLambdaQueryWrapper.orderByAsc(OnlCgformField::getOrderNum);
List<OnlCgformField> list = this.onlCgformFieldService.list((Wrapper) cgformFieldLambdaQueryWrapper);
if (list == null || list.size() == 0) {
Result.error("未找到对应字段信息!");
}
ArrayList<AuthColumnVO> arrayList = new ArrayList();
for (OnlCgformField onlCgformField : list) {
AuthColumnVO authColumnVO = new AuthColumnVO(onlCgformField);
authColumnVO.setTableName(onlCgformHead.getTableName());
authColumnVO.setTableNameTxt(onlCgformHead.getTableTxt());
arrayList.add(authColumnVO);
}
if (oConvertUtils.isNotEmpty(onlCgformHead.getSubTableStr()))
for (String str : onlCgformHead.getSubTableStr().split(",")) {
OnlCgformHead onlCgformHead1 = (OnlCgformHead) this.onlCgformHeadService.getOne((Wrapper) (
new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, str)
);
if (onlCgformHead1 != null) {
LambdaQueryWrapper lambdaQueryWrapper1 = (LambdaQueryWrapper) (
new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, onlCgformHead1.getId()
);
List<OnlCgformField> fieldList = this.onlCgformFieldService.list((Wrapper) lambdaQueryWrapper1);
if (fieldList != null) {
for (OnlCgformField onlCgformField : fieldList) {
AuthColumnVO authColumnVO = new AuthColumnVO(onlCgformField);
authColumnVO.setTableName(onlCgformHead1.getTableName());
authColumnVO.setTableNameTxt(onlCgformHead1.getTableTxt());
arrayList.add(authColumnVO);
}
}
}
}
result.setResult(arrayList);
Result.OK("加载字段权限数据完成");
return result;
}
}
@@ -1,9 +0,0 @@
package com.jero.generater;
/**
* @Description TODO
* @Author zero
* @Date 2021/3/11
**/
public class placeholder {
}