You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
10 KiB
Java
223 lines
10 KiB
Java
package com.glxp.api.controller.auth;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.beust.jcommander.internal.Lists;
|
|
import com.beust.jcommander.internal.Maps;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
import com.glxp.api.annotation.Log;
|
|
import com.glxp.api.common.enums.ResultEnum;
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
import com.glxp.api.constant.BusinessType;
|
|
import com.glxp.api.controller.BaseController;
|
|
import com.glxp.api.entity.auth.SysCustomConfigDetailEntity;
|
|
import com.glxp.api.entity.auth.SysCustomConfigEntity;
|
|
import com.glxp.api.req.auth.SysCustomConfigDetailRequest;
|
|
import com.glxp.api.req.auth.SysCustomConfigRequest;
|
|
import com.glxp.api.req.system.DeleteRequest;
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
import com.glxp.api.res.auth.SysCustomConfigFromDetailResponse;
|
|
import com.glxp.api.res.auth.SysCustomConfigResponse;
|
|
import com.glxp.api.service.auth.ISysCustomConfigDetailService;
|
|
import com.glxp.api.service.auth.ISysCustomConfigService;
|
|
import com.glxp.api.util.StringUtils;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.validation.Valid;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 用户信息
|
|
*
|
|
*/
|
|
@Validated
|
|
@RequiredArgsConstructor
|
|
@RestController
|
|
@RequestMapping("/system/custom/config")
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class SysCustomConfigController extends BaseController {
|
|
|
|
private final ISysCustomConfigService sysCustomConfigService;
|
|
|
|
private final ISysCustomConfigDetailService sysCustomConfigDetailService;
|
|
|
|
@GetMapping("/list")
|
|
public BaseResponse list(SysCustomConfigRequest request, BindingResult bindingResult) {
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
List<SysCustomConfigEntity> list = sysCustomConfigService.filterSysCustomConfig(request);
|
|
PageInfo<SysCustomConfigEntity> authAdminPageInfo = new PageInfo<>(list);
|
|
PageSimpleResponse<SysCustomConfigEntity> authAdminPageSimpleResponse = new PageSimpleResponse<>();
|
|
authAdminPageSimpleResponse.setTotal(authAdminPageInfo.getTotal());
|
|
authAdminPageSimpleResponse.setList(list);
|
|
|
|
return ResultVOUtils.success(authAdminPageSimpleResponse);
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/save")
|
|
@Log(title = "界面配置管理", businessType = BusinessType.INSERT)
|
|
public BaseResponse save(@RequestBody SysCustomConfigEntity entity,
|
|
BindingResult bindingResult) {
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
|
|
boolean b = sysCustomConfigService.insertSysCustomConfig(entity);
|
|
if (!b) {
|
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
|
}
|
|
return ResultVOUtils.success("添加成功!");
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/edit")
|
|
@Log(title = "界面配置管理", businessType = BusinessType.UPDATE)
|
|
public BaseResponse edit(@RequestBody @Valid SysCustomConfigEntity entity,
|
|
BindingResult bindingResult) {
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
if (entity.getId() == null) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
|
|
}
|
|
SysCustomConfigEntity originEntity = sysCustomConfigService.selectById(entity.getId());
|
|
if (originEntity == null) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
|
|
}
|
|
boolean b = sysCustomConfigService.updateSysCustomConfig(entity);
|
|
if (!b) {
|
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
|
}
|
|
|
|
return ResultVOUtils.success("修改成功!");
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/delete")
|
|
@Log(title = "界面配置管理", businessType = BusinessType.DELETE)
|
|
public BaseResponse delete(@RequestBody DeleteRequest deleteRequest) {
|
|
|
|
if (StringUtils.isEmpty(deleteRequest.getId())) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
|
|
}
|
|
boolean b = sysCustomConfigService.deleteById(deleteRequest.getId());
|
|
sysCustomConfigDetailService.deleteByConfigId(deleteRequest.getId());
|
|
if (!b) {
|
|
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
|
|
}
|
|
return ResultVOUtils.success();
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/getConfigs")
|
|
@Log(title = "界面配置管理")
|
|
public BaseResponse getConfigs(@RequestBody SysCustomConfigRequest request,BindingResult bindingResult) {
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
}
|
|
List<SysCustomConfigEntity> list = sysCustomConfigService.filterSysCustomConfig(request);
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
return ResultVOUtils.error(ResultEnum.DATA_NOT);
|
|
}
|
|
SysCustomConfigEntity sysCustomConfigEntity = list.get(0);
|
|
SysCustomConfigDetailRequest detailRequest = new SysCustomConfigDetailRequest();
|
|
detailRequest.setConfigId(sysCustomConfigEntity.getId().toString());
|
|
detailRequest.setIsShow("1");
|
|
// detailRequest.setType(request.getType());
|
|
List<SysCustomConfigDetailEntity> detailList = sysCustomConfigDetailService.filterSysCustomConfigDetail(detailRequest);
|
|
Map<String,List<SysCustomConfigDetailEntity>> map = detailList.stream().collect(
|
|
Collectors.groupingBy(SysCustomConfigDetailEntity::getType));
|
|
List<SysCustomConfigDetailEntity> tableList = map.get("1") == null? Lists.newArrayList():map.get("1");
|
|
List<SysCustomConfigDetailEntity> queryList = map.get("2") == null? Lists.newArrayList():map.get("2");
|
|
List<SysCustomConfigDetailEntity> fromList = map.get("3") == null? Lists.newArrayList():map.get("3");
|
|
|
|
List<SysCustomConfigDetailEntity> fromSortList = fromList.stream().sorted(Comparator.comparing(SysCustomConfigDetailEntity::getLineNumber)).collect(Collectors.toList());
|
|
|
|
Map<Integer,List<SysCustomConfigDetailEntity>> fromMap = fromSortList.stream().collect(
|
|
Collectors.groupingBy(SysCustomConfigDetailEntity::getLineNumber,LinkedHashMap::new,Collectors.toList()));
|
|
List<SysCustomConfigFromDetailResponse> fromDetailList = Lists.newArrayList();
|
|
for (Map.Entry<Integer, List<SysCustomConfigDetailEntity>> entry : fromMap.entrySet()) {
|
|
SysCustomConfigFromDetailResponse sysCustomConfigFromDetailResponse = new SysCustomConfigFromDetailResponse();
|
|
sysCustomConfigFromDetailResponse.setNumber(entry.getKey());
|
|
List<SysCustomConfigDetailEntity> entities = entry.getValue();
|
|
entities.stream().forEach(s->{
|
|
if(StringUtils.isNotEmpty(s.getCheckRules())){
|
|
String replacedJsonString = s.getCheckRules().replaceAll("(\\w+)(\\s*:\\s*)", "\"$1\"$2");
|
|
JSONArray object = JSONArray.parseArray(replacedJsonString);
|
|
s.setCheckRulesObj(object);
|
|
}
|
|
if(StringUtils.isNotEmpty(s.getLableRule())){
|
|
JSONObject objectLaber = JSONObject.parseObject(s.getLableRule());
|
|
List<Map> mapList = Lists.newArrayList();
|
|
Iterator<String> it = objectLaber.keySet().iterator();
|
|
String inputType = s.getInputType();
|
|
while(it.hasNext()) {
|
|
Map<String,Object> mapTemp = Maps.newHashMap();
|
|
String key = (String) it.next();
|
|
String value = objectLaber.getString(key);
|
|
mapTemp.put("label", value);
|
|
if("number".equals(inputType)){
|
|
mapTemp.put("value", Integer.parseInt(key));
|
|
}else{
|
|
mapTemp.put("value", key);
|
|
}
|
|
mapList.add(mapTemp);
|
|
}
|
|
s.setLableRuleObj(mapList);
|
|
}
|
|
});
|
|
sysCustomConfigFromDetailResponse.setList(entities);
|
|
fromDetailList.add(sysCustomConfigFromDetailResponse);
|
|
}
|
|
|
|
tableList.stream().forEach(s->{
|
|
if(StringUtils.isNotEmpty(s.getLableRule())) {
|
|
JSONObject objectLaber = JSONObject.parseObject(s.getLableRule());
|
|
s.setLableRuleObj(objectLaber);
|
|
}
|
|
if(StringUtils.isNotEmpty(s.getButtonRule())){
|
|
JSONArray objectButton = JSONArray.parseArray(s.getButtonRule());
|
|
s.setButtonRulObj(objectButton);
|
|
}
|
|
});
|
|
queryList.stream().forEach(s->{
|
|
if(StringUtils.isNotEmpty(s.getLableRule())){
|
|
JSONObject objectLaber = JSONObject.parseObject(s.getLableRule());
|
|
List<Map> mapList = Lists.newArrayList();
|
|
Iterator<String> it = objectLaber.keySet().iterator();
|
|
while(it.hasNext()) {
|
|
Map<String,String> mapTemp = Maps.newHashMap();
|
|
String key = (String) it.next();
|
|
String value = objectLaber.getString(key);
|
|
mapTemp.put("label", value);
|
|
mapTemp.put("value", key);
|
|
mapList.add(mapTemp);
|
|
}
|
|
s.setLableRuleObj(mapList);
|
|
}
|
|
});
|
|
SysCustomConfigResponse sysCustomConfigResponse = new SysCustomConfigResponse();
|
|
BeanUtil.copyProperties(sysCustomConfigEntity, sysCustomConfigResponse);
|
|
sysCustomConfigResponse.setTableList(tableList);
|
|
sysCustomConfigResponse.setQueryList(queryList);
|
|
sysCustomConfigResponse.setFromList(fromDetailList);
|
|
return ResultVOUtils.success(sysCustomConfigResponse);
|
|
}
|
|
}
|