package com.yc.action.customControl;
|
|
import com.yc.entity.customControl.*;
|
import com.yc.multiData.SpObserver;
|
import com.yc.service.customControl.ControlLayoutIfc;
|
import com.yc.utils.SessionKey;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
import java.io.File;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* @BelongsProject: eCoWorksV3
|
* @BelongsPackage: com.yc.action.controlLayout
|
* @author: xinyb
|
* @CreateTime: 2023-06-12 15:57
|
* @Description:
|
*/
|
@CrossOrigin
|
@RestController
|
@RequestMapping("/custom")
|
@ResponseBody
|
public class ControlLayoutAction {
|
@Autowired
|
ControlLayoutIfc controlLayoutIfc;
|
|
/**
|
* 获取用户自定义的页面布局(自定义控件信息)
|
*
|
* @param customParam
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/controlLayout.do")
|
public CustomBack getControlLayout(@RequestBody CustomParam param, HttpServletRequest request, HttpServletResponse response) {
|
CustomBack back = new CustomBack();
|
try {
|
if (param.getFormId() == null) {
|
back.fail("缺少功能号,无法自定义布局");
|
return back;
|
}
|
if (param.getFormType() == null) {
|
back.fail("缺少功能类型,无法自定义布局");
|
return back;
|
}
|
String userAgent = request.getHeader("User-Agent");
|
HttpSession session = request.getSession();
|
if (StringUtils.isBlank(param.getUserCode())) {//没userCode就拿登录的会话userCode
|
param.setUserCode((String) session.getAttribute(SessionKey.USERCODE));
|
}
|
String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
|
SpObserver.setDBtoInstance("_" + dbId);
|
List<MenuEntity> menuList = controlLayoutIfc.getMenu(param.getFormId(), param.getFormType());
|
if (menuList == null) {
|
back.fail("获取不到9810设置的功能号信息");
|
return back;
|
}
|
List<CustomJson> json = new ArrayList<>();
|
for (MenuEntity menu : menuList) {//遍历功能号(多表需要遍历)
|
CustomJson customJson = new CustomJson();
|
customJson.setFormId(menu.getFormId());
|
customJson.setFormName(menu.getFormName());
|
customJson.setTabId(menu.getTabId());
|
customJson.setMainFormId(menu.getMainFormId());
|
getCustomJson(param, menu, customJson, json);
|
json.add(customJson);
|
}
|
|
//最终返回的数据格式
|
Map<String, List<CustomJson>> backJson = new HashMap<String, List<CustomJson>>();
|
for (CustomJson j : json) {
|
if (backJson.get(j.getTabId()) == null || backJson.get(j.getTabId()).size() == 0) {//
|
List<CustomJson> customJsons = json.stream().filter(c -> c.getTabId().equals(j.getTabId())).collect(Collectors.toList());
|
backJson.put(j.getTabId(), customJsons);
|
}
|
}
|
back.success(backJson);
|
} catch (Exception e) {
|
back.fail(e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return back;
|
}
|
|
/**
|
* 保存控件布局信息
|
*
|
* @param json
|
* @param request
|
* @param response
|
* @return
|
*/
|
@PostMapping("/saveControlLayout.do")
|
public CustomBack saveControlLayout(@RequestBody List<CustomAttribute> json, HttpServletRequest request, HttpServletResponse response) {
|
CustomBack back = new CustomBack();
|
try {
|
if (json == null || json.size() == 0) {
|
back.fail("获取不到页面需要保存的内容");
|
return back;
|
}
|
HttpSession session = request.getSession();
|
String userCode = "";
|
Set<String> userCodes = json.stream().map(CustomAttribute::getUserCode).collect(Collectors.toSet());
|
if (userCodes.size() > 1) {//前端出现多个userCode,这种情况不能进行保存操作
|
back.fail("保存的布局出现多个用户账号设置,账号:" + String.join(";", userCodes));
|
return back;
|
}
|
userCode = String.join(",", userCodes);
|
if (StringUtils.isBlank(userCode)) {//前端没有userCode值传过来的时候拿当前登录的userCode值
|
userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
}
|
Set<Integer> formIds = json.stream().map(CustomAttribute::getFormId).collect(Collectors.toSet());
|
if (formIds.size() == 0) {
|
back.fail("布局的功能号不能为空,请检查");
|
return back;
|
}
|
String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
|
SpObserver.setDBtoInstance("_" + dbId);
|
Integer count = controlLayoutIfc.saveCustomLayout(json, formIds, userCode);
|
if (count > 0) {
|
back.saveOk("保存成功");
|
}
|
return back;
|
} catch (Exception e) {
|
back.fail(e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return back;
|
}
|
|
/**
|
* 删除自定义控件布局
|
*
|
* @param formId
|
* @param formType
|
* @param request
|
* @param response
|
* @return
|
*/
|
@RequestMapping(value = "/deleteControlLayout.do")
|
public CustomBack deleteControlLayout(@RequestBody List<CustomAttribute> json, Integer fromIdAage, Integer formType,
|
HttpServletRequest request, HttpServletResponse response) {
|
CustomBack back = new CustomBack();
|
HttpSession session = request.getSession();
|
try {
|
String userCode = (String) session.getAttribute(SessionKey.USERCODE);
|
if (StringUtils.isBlank(userCode)) {
|
back.fail("获取不到当前用户名");
|
return back;
|
}
|
|
String dbId = (String) session.getAttribute(SessionKey.DATA_BASE_ID);
|
SpObserver.setDBtoInstance("_" + dbId);
|
Set<Integer> formIds = json.stream().map(CustomAttribute::getFormId).collect(Collectors.toSet());
|
Set<Integer> formTypes = json.stream().map(CustomAttribute::getFormType).collect(Collectors.toSet());
|
int cont = controlLayoutIfc.deleteCustomLayout(userCode, formIds, formTypes);
|
if (cont > 0) {
|
File file = null;
|
String url = "";
|
url = request.getServletContext().getRealPath("/app/" + dbId + "/0/cnzh/" + fromIdAage + "/" + formType + "/");
|
for (Integer formId : formIds) {
|
String[] fileNames={
|
userCode + "_panel.jsp",
|
userCode +"_panelControl"+formId+".jsp",
|
userCode + "_grid.jsp",
|
formId + "_" + userCode + "_panel.jsp",
|
formId + "_" + userCode +"_panelControl"+formId+".jsp",
|
formId + "_" + userCode + "_grid.jsp"
|
};
|
for (String fileName : fileNames) {
|
file = new File(url +fileName);
|
if (file.exists()) {
|
file.delete();
|
}
|
}
|
}
|
back.success("已初始化");
|
return back;
|
}
|
} catch (Exception e) {
|
back.fail(e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return back;
|
}
|
|
/**
|
* 获取每个功能号在9802设置的参数(行 列 高 宽等)
|
*
|
* @param param
|
* @param menu
|
* @param json
|
* @return
|
*/
|
private void getCustomJson(CustomParam param, MenuEntity menu, CustomJson customJson, List<CustomJson> json) throws Exception {
|
try {
|
List<CustomAttribute> customAttributes = controlLayoutIfc.getCustomAttributes(param.getUserCode(), menu.getFormId(), menu.getFormType());//取本身的formtype
|
if (customAttributes == null) {
|
throw new Exception("获取不到功能号:" + menu.getFormId() + "的参数设置,返回内容:null");
|
}
|
int PanelHeadFlag=0;
|
int GridHeadFlag=1;
|
if(menu.getFormType()==1||menu.getFormType()==3||menu.getFormType()==7||menu.getFormType()==18||menu.getFormType()==19){
|
//面板,表格的主从表和其他类型相反
|
PanelHeadFlag=1;
|
GridHeadFlag=0;
|
}
|
final int finalPanelHeadFlag=PanelHeadFlag;
|
final int finalGridHeadFlag=GridHeadFlag;
|
|
//获取是主表的全部参数设置 headFlag=0
|
List<CustomAttribute> masterAll = customAttributes.stream().filter(c -> c.getHeadFlag() == finalPanelHeadFlag).collect(Collectors.toList());
|
//获取是主表的参数设置(表格之前) headFlag=0 && masterFieldShowLocation==0
|
List<CustomAttribute> master = masterAll.stream().filter(c -> c.getMasterFieldShowLocation() == 0).collect(Collectors.toList());
|
customJson.getMaster().setList(master);
|
//获取是从表的参数设置 headFlag=1
|
List<CustomAttribute> slave = customAttributes.stream().filter(c -> c.getHeadFlag() == finalGridHeadFlag).collect(Collectors.toList());
|
customJson.getSlave().setList(slave);
|
//获取是主表的参数设置(表格之前) headFlag=0 && masterFieldShowLocation==1
|
List<CustomAttribute> master1 = masterAll.stream().filter(c -> c.getMasterFieldShowLocation() == 1).collect(Collectors.toList());
|
customJson.getMaster1().setList(master1);
|
String where = "";
|
//获取当前页面单据查询条件信息(主功能号和功能号相同)
|
if (menu.getMainFormId().equals(menu.getFormId())) {
|
if (StringUtils.isNotBlank(param.getDocCode())) {
|
where = "docCode='" + param.getDocCode() + "'";
|
}
|
if (StringUtils.isBlank(where) && StringUtils.isNotBlank(param.getQueryString())) {
|
String[] params = param.getQueryString().split(";");
|
for (int p = 0; p < params.length; p++) {
|
where += params[p];
|
if (p + 1 < params.length) {
|
where += " and ";
|
}
|
}
|
}
|
} else {
|
//主功能号和功能号不相同说明是多表存在子功能号,where条件就要根据设置的参数进行组装
|
List<CustomJson> jsonData = json.stream().filter(j -> j.getFormId().equals(menu.getMainFormId())).collect(Collectors.toList());
|
if (jsonData.size() == 1) {//主功能号有数据
|
Map<String, Object> mapData = (Map<String, Object>) jsonData.get(0).getMaster().getData();//获取到主功能单据值(字段都是小写)
|
if (mapData != null && !mapData.isEmpty()) {
|
String[] fks = menu.getFk().split(";");
|
String[] seekGroupIds = menu.getSeekGroupId().split(";");
|
if (fks.length > 0 && fks.length == seekGroupIds.length) {//设置的参数相等时候才组装where
|
for (int i = 0; i < fks.length; i++) {
|
String value = mapData.get(fks[i].toLowerCase()) != null ? (String) mapData.get(fks[i].toLowerCase()) : "";//DBHelper.getValue(mapData, fks[i]);
|
where += seekGroupIds[i] + "='" + value + "'";
|
if (i + 1 < fks.length) {
|
where += " and ";
|
}
|
}
|
}
|
}
|
}
|
}
|
if (StringUtils.isBlank(where)) {
|
where = "docCode=''";
|
}
|
//获取单据数据信息 主表
|
if (masterAll.size() > 0 && StringUtils.isNotBlank(menu.getHdTable())) {
|
//获取到要查询data数据的字段ID(主表)
|
List<String> fieldId = masterAll.stream().map(CustomAttribute::getFieldId).collect(Collectors.toList());
|
String fieldIds = String.join(",", fieldId);
|
if (StringUtils.isBlank(fieldIds)) {
|
fieldIds = "*";//查询全部
|
}
|
if (menu.getFormType() == 1) {//1类型窗体处理
|
fieldIds = "top 1 " + fieldIds;
|
}
|
Map<String, Object> map = controlLayoutIfc.getFormData(fieldIds, menu.getHdTable(), where);
|
customJson.getMaster().setData(map);//填充数据值到data(表格之前)
|
customJson.getMaster1().setData(map);//填充数据值到data(表格之后)
|
}
|
//获取单据数据信息 从表
|
if (slave.size() > 0 && StringUtils.isNotBlank(menu.getDtTable())) {
|
//获取到要查询data数据的字段ID(从表)
|
List<String> fieldId = slave.stream().map(CustomAttribute::getFieldId).collect(Collectors.toList());
|
String fieldIds = String.join(",", fieldId);
|
if (StringUtils.isBlank(fieldIds)) {
|
fieldIds = "*";//查询全部
|
}
|
Map<String, Object> map = controlLayoutIfc.getFormData("top 1 " + fieldIds, menu.getDtTable(), where);
|
customJson.getSlave().setData(map);
|
}
|
if (";9;15;17;499;497;".contains(";" + param.getFormType() + ";") || menu.getFormType() == 1) {//这些是清单列表或者是多表的 1类型 设置成表格显示
|
customJson.getMaster().setGrid(true);
|
customJson.getMaster1().setList(new ArrayList<>());//是列表清单面板不需要显示 xin 2024-3-28 10:06:24
|
customJson.getMaster1().setData(null);
|
}
|
if(menu.getFormType()!=20) {
|
//20的从表也是面板
|
customJson.getSlave().setGrid(true);//从表就直接是表格显示
|
}
|
//下面是针对18类型窗体的特殊处理
|
if (param.getFormType() == 18) {
|
|
}
|
} catch (Exception e) {
|
throw e;
|
}
|
}
|
}
|