package cn.autoform.web.controller.datamanagement;
|
|
import cn.autoform.bean.BudgetData;
|
import cn.autoform.bean.BudgetTitle;
|
import cn.autoform.bean.CodeAndValueBean;
|
import cn.autoform.bean.ProcessBudget;
|
import cn.autoform.bean.form.FormDataBase;
|
import cn.autoform.bean.form.JoinFormData;
|
import cn.autoform.bean.form.RequestFormBase;
|
import cn.autoform.bean.page.PageResult;
|
import cn.autoform.bean.seache.SeacheConditions;
|
import cn.autoform.db.entity.FieldPropertyEntity;
|
import cn.autoform.db.entity.FormBaseEntity;
|
import cn.autoform.db.entity.FormDataMangerEntity;
|
import cn.autoform.db.entity.FormFieldEntity;
|
import cn.autoform.db.exten.AllFormData;
|
import cn.autoform.db.exten.MasterValue;
|
import cn.autoform.factory.FormFactory;
|
import cn.autoform.factory.product.ProductMethod;
|
import cn.autoform.fw.exception.FormClientException;
|
import cn.autoform.fw.exception.RestResult;
|
import cn.autoform.fw.utility.ConstMap;
|
import cn.autoform.fw.utility.RestResultGenerator;
|
import cn.autoform.log.bean.OperationLog;
|
import cn.autoform.log.bean.OperationLogConst;
|
import cn.autoform.util.OperationLogTool;
|
import cn.autoform.util.UUIDUtil;
|
import cn.autoform.util.form.entity.FormDataParam;
|
import cn.autoform.util.form.paramap.FormDataEditMap;
|
import cn.autoform.util.thread.Keys;
|
import cn.autoform.util.thread.ThreadData;
|
import cn.autoform.util.tool.CodeToNameTool;
|
import cn.autoform.util.tool.JSONTool;
|
import cn.autoform.util.tool.RequestContext;
|
import cn.autoform.web.client.FormClient;
|
import cn.autoform.web.client.MasterClient;
|
import cn.autoform.web.client.util.auto.OnlyCharacters;
|
import cn.autoform.web.controller.formbase.FormBaseController;
|
import cn.autoform.web.request.FormBaseUpdateRequestForm;
|
import cn.autoform.web.service.FormInfoService;
|
import cn.autoform.web.service.datamanagement.DataManagementService;
|
import cn.autoform.web.service.datasource.DatasourceService;
|
import cn.autoform.web.service.formbase.FormBaseService;
|
import cn.autoform.web.service.formtending.FormTendingService;
|
import cn.autoform.web.service.masterdata.MasterDataService;
|
import com.alibaba.fastjson.TypeReference;
|
import lombok.extern.slf4j.Slf4j;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.io.BufferedReader;
|
import java.io.IOException;
|
import java.io.InputStreamReader;
|
import java.net.HttpURLConnection;
|
import java.net.URL;
|
import java.util.*;
|
import java.util.concurrent.TimeoutException;
|
|
@RestController
|
@Slf4j
|
public class DataManagementController implements OperationLogConst {
|
|
private static final Logger logger = LoggerFactory.getLogger(DataManagementController.class);
|
|
private static final Map<String, String> DBTYPEARRAY = new HashMap<>();
|
|
private static final Map<String, String> DBTYPE = new HashMap<>();
|
|
@Resource
|
private FormClient formClient;
|
|
@Autowired
|
private FormFactory formFactory;
|
|
@Autowired
|
CodeToNameTool codeToNameTool;
|
|
@Autowired
|
private MasterClient masterClient;
|
|
@Resource
|
private FormDataEditMap formDataEditMap;
|
|
@Autowired
|
private FormBaseService formBaseService = null;
|
|
@Autowired
|
private FormBaseController formBaseController;
|
@Autowired
|
private OperationLogTool operationLogTool;
|
|
static {
|
// 单选按钮
|
DBTYPEARRAY.put("radio", "");
|
// 下拉列表框
|
DBTYPEARRAY.put("dropdownlist", "");
|
// 复选框
|
DBTYPEARRAY.put("checkbox", "");
|
// 数型控件
|
DBTYPEARRAY.put("tree", "");
|
|
// 单行文本
|
DBTYPE.put("text", ConstMap.VARCHAR150);
|
// 单选按钮
|
DBTYPE.put("radio", ConstMap.VARCHAR50);
|
// 下拉列表框
|
DBTYPE.put("dropdownlist", ConstMap.LONGTEXT);
|
// 日期控件
|
DBTYPE.put("calendar", ConstMap.VARCHAR30);
|
// 复选框
|
DBTYPE.put("checkbox", ConstMap.LONGTEXT);
|
// 子表单
|
DBTYPE.put("subform", ConstMap.VARCHAR30);
|
// 数字
|
DBTYPE.put("number", ConstMap.VARCHAR30);
|
// 多行文本
|
DBTYPE.put("textarea", ConstMap.LONGTEXT);
|
// HTML
|
DBTYPE.put("htmlediter", ConstMap.LONGTEXT);
|
// 条码
|
DBTYPE.put("barcode", ConstMap.VARCHAR30);
|
// 二维码
|
DBTYPE.put("qrcode", ConstMap.VARCHAR200);
|
// 图片
|
DBTYPE.put("image", ConstMap.LONGTEXT);
|
// 文件上传
|
DBTYPE.put("fileupload", ConstMap.LONGTEXT);
|
// 数型控件
|
DBTYPE.put("tree", ConstMap.LONGTEXT);
|
// 金额组件
|
DBTYPE.put("amount", ConstMap.LONGTEXT);
|
//自定义控件
|
DBTYPE.put("mytext", ConstMap.VARCHAR150);
|
//生成编号控件
|
DBTYPE.put("auto", ConstMap.VARCHAR50);
|
|
}
|
|
@Autowired
|
private DataManagementService dataManagementService = null;
|
|
@Autowired
|
private MasterDataService masterDataService = null;
|
|
@Autowired
|
private DatasourceService datasourceService = null;
|
|
@Resource
|
private FormInfoService formInfoService;
|
|
/**
|
* 获取主表单字段的值
|
*
|
* @param formID
|
* @param tenantID
|
* @return List<String>
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datamanagement09}", method = RequestMethod.GET)
|
public RestResult<List<String>> getFormFieldMainValue(String formID, String tenantID, String flag) throws Exception {
|
tenantID = ThreadData.get(Keys.TENANT_ID);
|
String tableName = this.dataManagementService.getBaseTableName(formID, tenantID);
|
ProductMethod productMethod = this.formFactory.createFormMethod();
|
List<String> fieldList = productMethod.getFormFieldMainValue(formID, tenantID, ThreadData.get(Keys.IO_FLAG).toString(), tableName);
|
|
return RestResultGenerator.genSuccessResult(fieldList);
|
|
}
|
|
@RequestMapping("/form/select/operationLog")
|
public RestResult<PageResult<List<OperationLog>>> queryFormDataPage(@RequestBody Map<String, Object> operationLog) {
|
try {
|
log.debug("开始分页查询----------");
|
PageResult<List<OperationLog>> o = formClient.selectOperationLog(operationLog);
|
log.debug("分页查询内容----------{}",o);
|
return RestResultGenerator.genSuccessResult(o);
|
} catch (Exception e) {
|
log.debug("分页查询错误----------");
|
}
|
return RestResultGenerator.genErrorResult("10002");
|
}
|
|
|
/**
|
* 获取主表单字段
|
*
|
* @return
|
*/
|
@RequestMapping(value = "${requset.datamanagement08}", method = RequestMethod.POST)
|
public RestResult<List<FormFieldEntity>> getFormFieldMain(@RequestBody String jsonStr) throws IOException {
|
JSONObject jSONObject = JSONObject.fromObject(jsonStr);
|
String formID = (String) jSONObject.get("formID");
|
String tenantID = ThreadData.get(Keys.TENANT_ID);
|
List<FormFieldEntity> rsList = dataManagementService.getFormFieldMain(formID, tenantID);
|
List<FormFieldEntity> realRsList = new ArrayList<>();
|
for (FormFieldEntity tempEntity : rsList) {
|
if (DBTYPEARRAY.containsKey(tempEntity.getFieldtype())) {
|
Map<String, FieldPropertyEntity> fieldPropertyMap = dataManagementService
|
.queryFormFieldsAboutData(formID, tenantID, tempEntity.getColumnOrderNum());
|
String dataSourceType = fieldPropertyMap.get("datasourcetype").getValue();
|
String realMasterData = fieldPropertyMap.get("masterData").getValue();
|
// 主数据
|
if (ConstMap.MASTERDATA.equals(dataSourceType) && !"".equals(realMasterData)) {
|
masterDataSetUp(fieldPropertyMap, tempEntity, tenantID);
|
} else if (ConstMap.DATASOURCE.equals(dataSourceType)) {
|
dataSourceSetUp(fieldPropertyMap, tempEntity, tenantID, formID);
|
} else if (ConstMap.CUSTOM.equals(dataSourceType)) {
|
customSetUp(fieldPropertyMap, tempEntity);
|
} else if (ConstMap.APIURL.equals(dataSourceType)) {
|
apiUrlSetUp(fieldPropertyMap, tempEntity);
|
}
|
tempEntity.setDataSourceType(dataSourceType);
|
realRsList.add(tempEntity);
|
} else {
|
realRsList.add(tempEntity);
|
}
|
tempEntity.setTitle(dataManagementService.getTitleProperty(formID, tenantID, tempEntity.getColumnOrderNum()));
|
}
|
|
return RestResultGenerator.genSuccessResult(realRsList);
|
}
|
|
@Autowired
|
private FormTendingService formTendingService = null;
|
|
@RequestMapping(value = "/copy/form")
|
public RestResult<Object> copyForm(
|
@RequestParam String sourceFormId
|
, @RequestParam String sourceTenantId
|
, @RequestParam String targetTenantId) throws Exception {
|
RequestContext.setThreadData(Keys.TENANT_ID, sourceTenantId);
|
RequestContext.setThreadData(Keys.FORM_ID, sourceFormId);
|
FormBaseEntity formBaseEntity = formBaseService.getFormBaseInfo(sourceTenantId, sourceFormId, null);
|
|
//创建表单
|
String formId, formSetId, formName;
|
|
Map<String, Object> jsonObject = new HashMap<>();
|
jsonObject.put("formVer", formBaseEntity.getFormVer());
|
jsonObject.put("formSetID", formSetId = UUID.randomUUID().toString().replace("-", ""));
|
jsonObject.put("tenantID", targetTenantId);
|
jsonObject.put("templateID", formBaseEntity.getTemplateID());
|
jsonObject.put("formMode", "2");
|
jsonObject.put("filedset", formBaseEntity.getFieldset());
|
jsonObject.put("formName", formName = formBaseEntity.getFormName() + new Random().nextInt(999));
|
jsonObject.put("formid", formId = UUIDUtil.shortUuid());
|
jsonObject.put("flag", ProductMethod.IOType.services.toString());
|
jsonObject.put("accountingRule", formBaseEntity.getAccountingRule());
|
jsonObject.put("description", formBaseEntity.getDescription());
|
jsonObject.put("validationRuleGroupID", "");
|
jsonObject.put("designMode", formBaseEntity.getDesignMode());
|
jsonObject.put("formLayout", formBaseEntity.getFormLayout());
|
jsonObject.put("resultForm", formBaseEntity.getResultForm());
|
jsonObject.put("linkage", formBaseEntity.getLinkage());
|
jsonObject.put("fromwidth", formBaseEntity.getFormWidth());
|
jsonObject.put("fromheigh", formBaseEntity.getFormHeight());
|
jsonObject.put("userName", formBaseEntity.getCreateUser());
|
RequestContext.setThreadData(Keys.TENANT_ID, targetTenantId);
|
RequestContext.setThreadData(Keys.FORM_ID, formId);
|
RestResult<Object> res = formBaseController.saveformService(JSONTool.toJson(jsonObject));
|
|
// 复制自定义按钮、自定义js
|
formInfoService.copyFormInfo(sourceFormId, sourceTenantId, formId, targetTenantId);
|
|
// 启用表单
|
FormBaseUpdateRequestForm formBaseUpdateRequestForm = new FormBaseUpdateRequestForm();
|
formBaseUpdateRequestForm.setTenantID(targetTenantId);
|
formBaseUpdateRequestForm.setFormID(formId);
|
formBaseUpdateRequestForm.setFormSetID(formSetId);
|
formBaseUpdateRequestForm.setFormVer(formBaseEntity.getFormVer());
|
formBaseUpdateRequestForm.setEnablesetting("1");
|
formBaseUpdateRequestForm.setDesignMode("2");
|
formBaseUpdateRequestForm.setFormName(formName);
|
formBaseUpdateRequestForm.setDeleteFlg("0");
|
|
formTendingService.updateFormBaseInfo(formBaseUpdateRequestForm);
|
return res;
|
}
|
|
/**
|
* 获取表单字段
|
*
|
* @param formID 表单ID
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datamanagement01}", method = RequestMethod.GET)
|
public RestResult<List<FormFieldEntity>> getFormFieldListService(String formID) throws Exception {
|
return RestResultGenerator.genSuccessResult(
|
formBaseService.getFormFieldEntitys(ThreadData.get(Keys.TENANT_ID), formID));
|
}
|
|
/**
|
* API装载
|
*
|
* @param fieldPropertyMap
|
* @param tempEntity
|
*/
|
private void apiUrlSetUp(Map<String, FieldPropertyEntity> fieldPropertyMap, FormFieldEntity tempEntity) throws IOException {
|
String apiUrl = fieldPropertyMap.get("apiUrl").getValue();
|
String code = fieldPropertyMap.get("apiIdKey").getValue();
|
String text = fieldPropertyMap.get("apiPIdKey").getValue();
|
BufferedReader reader = null;
|
try {
|
URL url = new URL(apiUrl);
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
con.setRequestMethod("GET");
|
con.connect();
|
reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
|
String line;
|
StringBuilder buffer = new StringBuilder();
|
while ((line = reader.readLine()) != null) {
|
buffer.append(line);
|
}
|
reader.close();
|
con.disconnect();
|
String res = buffer.toString();
|
JSONArray jsonObjAPi = JSONArray.fromObject(res);
|
if (jsonObjAPi.isEmpty()) {
|
List<CodeAndValueBean> addList = new ArrayList<>();
|
for (Object jsonObjSub : jsonObjAPi) {
|
JSONObject jsonObjSubcov = (JSONObject) jsonObjSub;
|
String codeRs = jsonObjSubcov.getString(code);
|
String textRs = jsonObjSubcov.getString(text);
|
CodeAndValueBean codeAndvaule = new CodeAndValueBean();
|
codeAndvaule.setCode(codeRs);
|
codeAndvaule.setValue(textRs);
|
addList.add(codeAndvaule);
|
}
|
tempEntity.setDataSourceData(addList);
|
}
|
} catch (Exception e) {
|
logger.error("---------> API URL ERROR!", e);
|
} finally {
|
if (reader != null) {
|
reader.close();
|
}
|
}
|
}
|
|
/**
|
* 自定义装载
|
*
|
* @param fieldPropertyMap
|
* @param tempEntity
|
*/
|
private void customSetUp(Map<String, FieldPropertyEntity> fieldPropertyMap, FormFieldEntity tempEntity) {
|
try {
|
// 自定义
|
String custom = fieldPropertyMap.get("custom").getValue();
|
JSONArray jsArray = JSONArray.fromObject(custom);
|
List<CodeAndValueBean> addList = new ArrayList<>();
|
for (Object jsonObjSub : jsArray) {
|
JSONObject jsonObjSubcov = (JSONObject) jsonObjSub;
|
String value = jsonObjSubcov.getString("itemtext");
|
String code = jsonObjSubcov.getString("code");
|
CodeAndValueBean codeAndvaule = new CodeAndValueBean();
|
codeAndvaule.setCode(code);
|
codeAndvaule.setValue(value);
|
addList.add(codeAndvaule);
|
}
|
tempEntity.setDataSourceData(addList);
|
} catch (Exception e) {
|
logger.error("---------> 自定义数据源 ERROR!", e);
|
}
|
}
|
|
/**
|
* 数据源装载
|
*
|
* @param fieldPropertyMap
|
* @param tempEntity
|
* @param tenantID
|
* @param formID
|
*/
|
private void dataSourceSetUp(Map<String, FieldPropertyEntity> fieldPropertyMap, FormFieldEntity tempEntity,
|
String tenantID, String formID) {
|
try {
|
// 数据源
|
System.err.println(JSONTool.toJson(fieldPropertyMap));
|
String datasource = fieldPropertyMap.get("datasource").getValue();
|
String text = fieldPropertyMap.get("textcolumn").getValue();
|
String value = fieldPropertyMap.get("valuecolumn").getValue();
|
|
StringBuilder sendSearchCol = new StringBuilder();
|
sendSearchCol.append(text);
|
sendSearchCol.append(ConstMap.COMMA);
|
sendSearchCol.append(value);
|
|
Map<String, List<String>> datasourceList = datasourceService.getColumnsValues(tenantID, formID, datasource,
|
sendSearchCol.toString());
|
List<String> codeList = datasourceList.get(text);
|
List<String> textList = datasourceList.get(value);
|
List<CodeAndValueBean> addList = new ArrayList<>();
|
for (int i = 0; i < codeList.size(); i++) {
|
CodeAndValueBean codeAndvaule = new CodeAndValueBean();
|
codeAndvaule.setCode(codeList.get(i));
|
codeAndvaule.setValue(textList.get(i));
|
addList.add(codeAndvaule);
|
}
|
tempEntity.setDataSourceData(addList);
|
} catch (Exception e) {
|
logger.error("---------> 数据源 ERROR!", e);
|
}
|
}
|
|
/**
|
* 主数据装载
|
*
|
* @param fieldPropertyMap
|
* @param tempEntity
|
* @param tenantID
|
*/
|
private void masterDataSetUp(Map<String, FieldPropertyEntity> fieldPropertyMap, FormFieldEntity tempEntity,
|
String tenantID) {
|
try {
|
String masterDataId = fieldPropertyMap.get("masterData").getValue();
|
JSONObject jsonObj = JSONObject.fromObject(masterDataId);
|
String defindCode = null;
|
String eleCode = null;
|
if (jsonObj.has("defindCode")) {
|
defindCode = jsonObj.getString("defindCode");
|
}
|
if (jsonObj.has("eleCode")) {
|
eleCode = jsonObj.getString("eleCode");
|
}
|
|
if (defindCode != null && eleCode != null) {
|
String eleName = null;
|
if (jsonObj.has(ConstMap.ELENAME)) {
|
eleName = jsonObj.getString(ConstMap.ELENAME);
|
}
|
String parentCode = null;
|
|
if (jsonObj.has("parentCode")) {
|
parentCode = jsonObj.getString("parentCode");
|
}
|
|
MasterValue MasterValue = new MasterValue();
|
MasterValue.setTenantID(tenantID);
|
MasterValue.setDefineCode(defindCode);
|
MasterValue.setELE_CODE(eleCode);
|
MasterValue.setParentCode(parentCode);
|
MasterValue.setEleName(eleName);
|
List<CodeAndValueBean> result = this.masterClient.queryClientMasterValues(MasterValue);
|
tempEntity.setDataSourceData(result);
|
}
|
|
|
//yuezhw 2017-12-16注释掉
|
// List<MasterValueEntity> masterDataCode = this.formFactory.createFormMethod().queryMasterValues(tenantID,
|
// jsonObj.getString("defindCode"), jsonObj.getString("eleCode"));
|
// List<MasterValueEntity> masterDataName = this.formFactory.createFormMethod().queryMasterValues(tenantID,
|
// jsonObj.getString("defindCode"), jsonObj.getString("eleName"));
|
// //下面注释方法为之前的
|
//// List<MasterValueEntity> masterDataCode = masterDataService.queryMasterValues(tenantID,
|
//// jsonObj.getString("defindCode"), jsonObj.getString("eleCode"));
|
//// List<MasterValueEntity> masterDataName = masterDataService.queryMasterValues(tenantID,
|
//// jsonObj.getString("defindCode"), jsonObj.getString("eleName"));
|
// if (masterDataCode.size() == masterDataName.size()) {
|
// List<CodeAndValueBean> addList = new ArrayList<>();
|
// for (int i = 0; i < masterDataCode.size(); i++) {
|
// CodeAndValueBean codeAndvaule = new CodeAndValueBean();
|
// codeAndvaule.setCode(masterDataCode.get(i).getEle_value());
|
// codeAndvaule.setValue(masterDataName.get(i).getEle_value());
|
// addList.add(codeAndvaule);
|
// }
|
// }
|
} catch (Exception e) {
|
logger.error("---------> 主数据 ERROR!", e);
|
}
|
}
|
|
/**
|
* 获取表单字段
|
*
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datamanagement02}", method = {RequestMethod.POST, RequestMethod.GET})
|
public RestResult<PageResult<Map<String, Object>>> getFormDataListService(
|
@RequestParam(name = SeacheConditions.PARAM_KEY, required = false) String seacheParam) {
|
List<SeacheConditions> seacheCondition = null;
|
if (StringUtils.isNotBlank(seacheParam)) {
|
seacheCondition = JSONTool.toObj(seacheParam, new TypeReference<List<SeacheConditions>>() {
|
});
|
}
|
return RestResultGenerator.genSuccessResult(this.formFactory.createFormMethod().queryFormDataPage(seacheCondition));
|
}
|
|
|
@RequestMapping(value = "${requset.datamanagement10}", method = {RequestMethod.POST, RequestMethod.GET})
|
public RestResult<PageResult<Map<String, Object>>> getAssociatedFormDataService(@RequestBody JoinFormData joinFormData) throws Exception {
|
PageResult<Map<String, Object>> pageResult = this.formFactory.createFormMethod()
|
.queryFormDataPage(joinFormData.getSearch(), joinFormData.getScreenCondition(), joinFormData.getDataRowNum());
|
return RestResultGenerator.genSuccessResult(pageResult);
|
}
|
|
/**
|
* 添加表单数据
|
*
|
* @return 执行结果
|
* @throws TimeoutException
|
* @throws FormClientException
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
@RequestMapping(value = "${requset.datamanagement03}", method = RequestMethod.POST)
|
public RestResult<Object> addFormDataService(@RequestBody FormDataParam jsonStr) throws TimeoutException, FormClientException {
|
jsonStr.setTenantID(ThreadData.get(Keys.TENANT_ID));
|
RestResult<Object> result = RestResultGenerator.genSuccessResult(
|
this.formFactory.createFormMethod().addFormData(
|
new AllFormData(formDataEditMap.apply(jsonStr))));
|
// String formID = jsonStr.getFormID();
|
//
|
// HashMap<String, String> modelMap = new HashMap<>();
|
// modelMap.put("formId", formID);
|
// modelMap.put("operationNum", OperationLogConst.OPERATION_ADD);
|
// try {
|
// //>>>>>>>>>>>>>>>>>>添加日志
|
// log.debug("插入添加日志记录----{}", formID);
|
// formClient.addOperationLog(modelMap);
|
// }
|
// log.debug("插入删除日志记录----{}", formID);
|
// //>>>>>>>>>>>>>>>>>>添加删除日志
|
// } catch (Exception e) {
|
// log.error("删除数据异常-------{}", e.getMessage());
|
// }
|
//
|
// if (i > 0) {
|
// try {
|
// log.debug("准备记录添加日志guo:---------->");
|
// initCompanyApi.addOperationLog(Objects.toString(formData.getFormId(),""),Objects.toString(formData.getDataRowNum(),""),OperationLogConst.OPERATION_ADD,formData.getUserName());
|
// }catch (Exception e){
|
// log.error("----------远程调用----------操作日志添加异常:{}",e.getMessage());
|
// }
|
// }
|
return result;
|
}
|
|
@RequestMapping(value = "${requset.datamanagement21}", method = RequestMethod.POST)
|
public RestResult<String> getAutoNumber(@RequestBody Map<String, Object> param) {
|
return RestResultGenerator.genSuccessResult(dataManagementService.getAutoNumber(param.get("formID").toString()
|
, ThreadData.get(Keys.TENANT_ID)
|
, param.get("field").toString()
|
, Integer.parseInt(param.get("id").toString())));
|
|
}
|
|
/**
|
* 删除表单数据
|
*
|
* @return 执行结果
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datamanagement04}", method = RequestMethod.POST)
|
public RestResult<Object> removeFormDataListService(@RequestBody String jsonStr) throws Exception {
|
|
// 表单数据格式化成JSON
|
JSONObject jsonObj = JSONObject.fromObject(jsonStr);
|
String formID = jsonObj.getString(ConstMap.FORMIDKEY);
|
String tenantID = ThreadData.get(Keys.TENANT_ID);
|
String userName = jsonObj.getString("userName");
|
JSONArray jSONArray = jsonObj.getJSONArray("datarowNumArray");
|
//将JSON对象封装到实体中
|
HashMap<String, String> modelMap = new HashMap<>();
|
modelMap.put("formId", formID);
|
modelMap.put("operationNum", OperationLogConst.OPERATION_DELETE);
|
modelMap.put("userName",userName);
|
// modelMap.put("dataRowNum",jSONArray.toString());
|
this.formFactory.createFormMethod().removeFormData(formID, tenantID, jSONArray, userName);
|
try {
|
//>>>>>>>>>>>>>>>>>>添加删除日志
|
log.debug("插入删除日志记录----{}", formID);
|
for (Object s:jSONArray){
|
modelMap.put("dataRowNum", s.toString());
|
formClient.addOperationLog(modelMap);
|
}
|
log.debug("插入删除日志记录----{}", formID);
|
//>>>>>>>>>>>>>>>>>>添加删除日志
|
} catch (Exception e) {
|
log.error("删除数据异常-------{}", e.getMessage());
|
}
|
return RestResultGenerator.genSuccessResult(null);
|
}
|
|
|
/**
|
* 更改表单控件状态 true 前端显示,false 前端不显示
|
*
|
* @return 执行结果
|
* @throws TimeoutException
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
@RequestMapping(value = "${request.datamanagement11}", method = RequestMethod.POST)
|
public void updateFormFieldService(@RequestBody String jsonStr) {
|
// 表单数据格式化成JSON
|
JSONObject jsonObj = JSONObject.fromObject(jsonStr);
|
String formID = jsonObj.getString(ConstMap.FORMIDKEY);
|
String tenantID = ThreadData.get(Keys.TENANT_ID);
|
String fieldIsShow = jsonObj.getString(ConstMap.FIELDISSHOW);
|
String alias = jsonObj.getString(ConstMap.ALIAS);
|
FormFieldEntity formFieldentity = new FormFieldEntity();
|
formFieldentity.setFormID(formID);
|
formFieldentity.setTenantID(tenantID);
|
formFieldentity.setFieldIsShow(fieldIsShow);
|
formFieldentity.setFieldKey(alias);
|
dataManagementService.updateFormFieldState(formFieldentity);
|
|
}
|
|
/**
|
* 更改表单控件状态 true 前端显示,false 前端不显示
|
*
|
* @return 执行结果
|
* @throws TimeoutException
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
@RequestMapping(value = "${request.datamanagement12}", method = RequestMethod.POST)
|
public void updateMainFormFieldService(@RequestBody String jsonStr) {
|
// 表单数据格式化成JSON
|
JSONObject jsonObj = JSONObject.fromObject(jsonStr);
|
String formID = jsonObj.getString(ConstMap.FORMIDKEY);
|
String tenantID = ThreadData.get(Keys.TENANT_ID);
|
String searchIsShow = jsonObj.getString(ConstMap.SEARCHISSHOW);
|
String alias = jsonObj.getString(ConstMap.ALIAS);
|
FormFieldEntity formFieldentity = new FormFieldEntity();
|
formFieldentity.setFormID(formID);
|
formFieldentity.setTenantID(tenantID);
|
formFieldentity.setSearchIsShow(searchIsShow);
|
formFieldentity.setFieldKey(alias);
|
dataManagementService.updateMainFormFieldService(formFieldentity);
|
}
|
|
|
/**
|
* 添加表单数据
|
*
|
* @return 执行结果
|
* @throws TimeoutException
|
* @throws FormClientException
|
*/
|
@Transactional(rollbackFor = Exception.class)
|
@RequestMapping(value = "${requset.datamanagement06}", method = RequestMethod.POST)
|
public RestResult<Object> updateFormDataService(@RequestBody FormDataParam jsonStr) throws TimeoutException, FormClientException {
|
jsonStr.setTenantID(ThreadData.get(Keys.TENANT_ID));
|
this.formFactory.createFormMethod().updataFormData(
|
new AllFormData(formDataEditMap.apply(jsonStr)));
|
String formId = jsonStr.getFormID();
|
String userName = jsonStr.getUserName();
|
HashMap<String, String> modelMap = new HashMap<>();
|
modelMap.put("formId", formId);
|
modelMap.put("operationNum", OperationLogConst.OPERATION_EDIT);
|
modelMap.put("userName",userName);
|
modelMap.put("dataRowNum",jsonStr.getDataRowNum().toString());
|
try {
|
//>>>>>>>>>>>>>>>>>>添加编辑日志
|
log.debug("插入修改日志记录----{}", formId);
|
formClient.addOperationLog(modelMap);
|
log.debug("插入修改日志记录----{}", formId);
|
//>>>>>>>>>>>>>>>>>>添加删除日志
|
} catch (Exception e) {
|
log.error("修改数据异常-------{}", e.getMessage());
|
}
|
return RestResultGenerator.genSuccessResult(null);
|
}
|
|
|
/**
|
* 更新表单数据
|
*
|
* @param formID 表单ID
|
* @param tenantID 租户ID
|
* @param formdataNum 子表单顺番
|
* @param datarowNum 数据行番
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datamanagement05}", method = RequestMethod.GET)
|
public RestResult<List<Map<String, Object>>> getSubFormDataListService(String formID, String tenantID,
|
Integer formdataNum, Integer datarowNum) throws Exception {
|
tenantID = ThreadData.get(Keys.TENANT_ID);
|
System.out.println("get请求参数为:" + formID + "---" + tenantID + "----" + formdataNum + "---" + datarowNum);
|
List<Map<String, Object>> rsMap = this.formFactory.createFormMethod().getSubFormDataListService(formID, tenantID, formdataNum, datarowNum);
|
// dataManagementService.querySubFormDataList(formID, tenantID, formdataNum,
|
// datarowNum);
|
return RestResultGenerator.genSuccessResult(rsMap);
|
}
|
|
/**
|
* 更新表单数据
|
*
|
* @param formID 表单ID
|
* @param formdataNum 子表单顺番
|
* @param datarowNum 数据行番
|
* @return
|
* @throws Exception
|
*/
|
@RequestMapping(value = "${requset.datamanagement07}", method = RequestMethod.GET)
|
public RestResult<Map<String, Object>> getSingleFormDataService(String formID, String formdataNum,
|
Integer datarowNum) throws Exception {
|
String tenantID = ThreadData.get(Keys.TENANT_ID);
|
ProductMethod productMethod = this.formFactory.createFormMethod();
|
Map<String, Object> sf = productMethod.queryFormDataList(formID, tenantID, datarowNum, formdataNum);
|
return RestResultGenerator.genSuccessResult(sf);
|
}
|
|
|
/**
|
* 生成主表单SQL文
|
*
|
* @param insertFields 插入的列
|
* @param insertvalues 插入的值
|
* @return
|
*/
|
private String genInsertSqlMain(List<String> insertFields, List<String> insertvalues, Integer dataRowNum,
|
String userName) {
|
StringBuilder sbSql = new StringBuilder(
|
"/*!mycat:sql=select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ INSERT INTO %s ( ");
|
sbSql.append("DATAROWNUM");
|
sbSql.append(ConstMap.COMMA);
|
sbSql.append(ConstMap.TENANTIDKEY);
|
sbSql.append(ConstMap.COMMA);
|
sbSql.append("SUBDATAROWNUM");
|
sbSql.append(ConstMap.COMMA);
|
for (String insertField : insertFields) {
|
sbSql.append(insertField);
|
sbSql.append(ConstMap.COMMA);
|
}
|
sbSql.append(" DELETEFLG,CREATEUSER,CREATEDATETIME,UPDATEUSER,UPDATEDATETIME ");
|
sbSql.append(") VALUES (");
|
// DATAROWNUM
|
sbSql.append(dataRowNum);
|
sbSql.append(ConstMap.COMMA);
|
// TENANTID
|
sbSql.append("'%s'");
|
sbSql.append(ConstMap.COMMA);
|
// subdatarowNum
|
sbSql.append(0);
|
sbSql.append(ConstMap.COMMA);
|
for (String insertValue : insertvalues) {
|
insertValue = insertValue.replace("%", "%%");//后加上来的。
|
sbSql.append("'");
|
sbSql.append(insertValue);
|
sbSql.append("'");
|
sbSql.append(ConstMap.COMMA);
|
}
|
sbSql.append("'0','");
|
sbSql.append(userName);
|
sbSql.append("',");
|
sbSql.append("CURRENT_TIMESTAMP(),'");
|
sbSql.append(userName);
|
sbSql.append("',");
|
sbSql.append("CURRENT_TIMESTAMP()");
|
sbSql.append(");");
|
return sbSql.toString();
|
}
|
|
/**
|
* 生成主表单SQL文
|
*
|
* @param insertFields 插入的列
|
* @param insertvalues 插入的值
|
* @return
|
*/
|
private String genUpdateSqlMain(List<String> insertFields, List<String> insertvalues, Integer dataRowNum,
|
String userName) {
|
StringBuilder sbSql = new StringBuilder(
|
"/*!mycat:sql=select tenantid from FORMDATAMANAGER WHERE TENANTID = '%s' AND FROMID = '%s' */ UPDATE %s ");
|
sbSql.append(" SET ");
|
int index = 0;
|
for (String insertField : insertFields) {
|
sbSql.append(insertField);
|
sbSql.append(" = '");
|
String insertValues = insertvalues.get(index);
|
insertValues = insertValues.replace("%", "%%");
|
sbSql.append(insertValues);
|
sbSql.append("'");
|
sbSql.append(ConstMap.COMMA);
|
index++;
|
}
|
sbSql.append(" UPDATEUSER = '");
|
sbSql.append(userName);
|
sbSql.append("' ,UPDATEDATETIME = CURRENT_TIMESTAMP() ");
|
|
sbSql.append("WHERE DATAROWNUM = ");
|
sbSql.append(dataRowNum);
|
sbSql.append(" AND TENANTID = ");
|
sbSql.append(" '%s';");
|
return sbSql.toString();
|
}
|
|
/**
|
* 生成子表单SQL文
|
*
|
* @param insertFieldsSub 插入的列
|
* @param insertvaluesSub 插入的值
|
* @return
|
*/
|
private List<String> genInsertSqlSub(Map<Integer, List<List<String>>> insertFieldsSub,
|
Map<Integer, List<List<String>>> insertvaluesSub, Map<Integer, FormDataMangerEntity> tableNamsMap,
|
String tenantID, String formID, Integer dataRowNum, String userName) {
|
Iterator<Integer> keys = insertFieldsSub.keySet().iterator();
|
List<String> allList = new ArrayList<>();
|
while (keys.hasNext()) {
|
Integer key = keys.next();
|
List<String> sql = genSubSql(tableNamsMap.get(key).getFormdatatable(), insertFieldsSub.get(key),
|
insertvaluesSub.get(key), tenantID, formID, dataRowNum, userName);
|
allList.addAll(sql);
|
}
|
return allList;
|
}
|
|
/**
|
* @param tableName
|
* @param insertFieldsBig
|
* @param insertvaluesBig
|
* @param tenantID
|
* @param formID
|
* @param dataRowNum
|
* @return
|
*/
|
private List<String> genSubSql(String tableName, List<List<String>> insertFieldsBig,
|
List<List<String>> insertvaluesBig, String tenantID, String formID, Integer dataRowNum, String userName) {
|
List<String> sqlList = new ArrayList<>();
|
for (int i = 0; i < insertFieldsBig.size(); i++) {
|
StringBuilder sbSql = new StringBuilder();
|
List<String> insertFields = insertFieldsBig.get(i);
|
List<String> insertvalues = insertvaluesBig.get(i);
|
sbSql.append("/*!mycat:sql=select tenantid from FORMDATAMANAGER WHERE TENANTID = '");
|
sbSql.append(tenantID);
|
sbSql.append("' AND FROMID = '");
|
sbSql.append(formID);
|
sbSql.append("' */ ");
|
sbSql.append(" INSERT INTO ");
|
sbSql.append(tableName);
|
sbSql.append("( ");
|
|
sbSql.append("DATAROWNUM");
|
sbSql.append(ConstMap.COMMA);
|
sbSql.append(ConstMap.TENANTIDKEY);
|
sbSql.append(ConstMap.COMMA);
|
sbSql.append("SUBDATAROWNUM");
|
sbSql.append(ConstMap.COMMA);
|
|
for (String insertField : insertFields) {
|
sbSql.append(insertField);
|
sbSql.append(ConstMap.COMMA);
|
}
|
sbSql.append(" DELETEFLG,CREATEUSER,CREATEDATETIME,UPDATEUSER,UPDATEDATETIME ");
|
sbSql.append(" ) VALUES (");
|
// DATAROWNUM
|
sbSql.append(dataRowNum);
|
sbSql.append(ConstMap.COMMA);
|
// TENANTID
|
sbSql.append("'");
|
sbSql.append(tenantID);
|
sbSql.append("'");
|
sbSql.append(ConstMap.COMMA);
|
// subdatarowNum
|
sbSql.append(i + 1);
|
sbSql.append(ConstMap.COMMA);
|
for (String insertValue : insertvalues) {
|
sbSql.append("'");
|
sbSql.append(insertValue);
|
sbSql.append("'");
|
sbSql.append(ConstMap.COMMA);
|
}
|
sbSql.append("'0','");
|
sbSql.append(userName);
|
sbSql.append("',");
|
sbSql.append("CURRENT_TIMESTAMP(),'");
|
sbSql.append(userName);
|
sbSql.append("',");
|
sbSql.append("CURRENT_TIMESTAMP()");
|
sbSql.append(");");
|
sqlList.add(sbSql.toString());
|
}
|
return sqlList;
|
}
|
|
@RequestMapping(value = "${requset.datamanagement13}", method = RequestMethod.POST)
|
public RestResult<String> getGenerateRandomNumService(@RequestBody String jsonStr) {
|
JSONObject jsonObj = JSONObject.fromObject(jsonStr);
|
String rule = jsonObj.getString("prefix");
|
if (rule.contains("$in"))
|
return RestResultGenerator.genSuccessResult(ConstMap.AUTOINCREMENT);
|
String onlyStr = OnlyCharacters.getOnlyStr(rule);
|
return RestResultGenerator.genSuccessResult(onlyStr);
|
}
|
|
@RequestMapping(value = "${requset.datamanagement14}", method = RequestMethod.POST)
|
public RestResult<Integer> addFormStateData(@RequestBody Map<String, String> formState) {
|
return RestResultGenerator.genSuccessResult(dataManagementService.addFormStateData(formState));
|
|
}
|
|
@RequestMapping(value = "${requset.datamanagement15}", method = RequestMethod.POST)
|
public RestResult<Map<String, Object>> getAssociateData(@RequestBody BudgetData budgetData) throws TimeoutException, FormClientException {
|
return RestResultGenerator.genSuccessResult(dataManagementService.getAssociateData(budgetData));
|
}
|
|
@RequestMapping(value = "${requset.datamanagement16}", method = RequestMethod.POST)
|
public RestResult<List<BudgetTitle>> getAssociateTitle(@RequestBody Map<String, Object> key) throws TimeoutException, FormClientException {
|
return RestResultGenerator.genSuccessResult(dataManagementService.getAssociateTitle(key));
|
}
|
|
@RequestMapping(value = "${requset.datamanagement17}", method = RequestMethod.POST)
|
public RestResult<Map<String, Object>> getFormContext(@RequestBody FormDataBase formDataBase) {
|
return RestResultGenerator.genSuccessResult(dataManagementService.getFormContext(formDataBase.getFormID(), formDataBase.getTenantID()));
|
}
|
|
@RequestMapping(value = "${requset.datamanagement18}", method = RequestMethod.POST)
|
public RestResult<Map<String, Object>> getFormDataContext(@RequestBody RequestFormBase requestFormBase) {
|
return RestResultGenerator.genSuccessResult(dataManagementService.getFormDataContext(requestFormBase));
|
}
|
|
@RequestMapping(value = "${requset.datamanagement19}", method = RequestMethod.POST)
|
public RestResult<Object> getBudget(@RequestBody ProcessBudget processBudget) throws TimeoutException, FormClientException {
|
return RestResultGenerator.genSuccessResult(dataManagementService.getBudget(processBudget));
|
}
|
|
@RequestMapping(value = "${requset.datamanagement20}", method = RequestMethod.POST)
|
public List<Map<String, Object>> queryFormFiled(FormDataBase formDataBase) throws TimeoutException, FormClientException {
|
return dataManagementService.queryFormFiled(formDataBase.getFormID(), formDataBase.getTenantID());
|
}
|
}
|