com.fhs.pagex.service.xsimpl.PagexAddService Maven / Gradle / Ivy
The newest version!
package com.fhs.pagex.service.xsimpl;
import com.fhs.common.utils.CheckUtils;
import com.fhs.common.utils.ConverterUtils;
import com.fhs.common.utils.Logger;
import com.fhs.core.config.EConfig;
import com.fhs.pagex.common.BeetlUtil;
import com.fhs.pagex.dto.PagexAddDTO;
import com.fhs.pagex.service.HandelPageXService;
import com.fhs.pagex.service.IPageXService;
import com.fhs.pagex.service.PagexDataService;
import com.fhs.pagex.tag.form.BaseFormTag;
import com.fhs.pagex.tag.form.FormTagFactory;
import com.fhs.pagex.tag.form.IOne2XTag;
import com.mybatis.jpa.common.ColumnNameUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.script.ScriptException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 处理添加,修改,详细页面的服务
*
* @ProjectName: framework_v2_idea2
* @Package: com.fhs.pagex
* @ClassName: PagexAddService
* @Author: JackWang
* @CreateDate: 2018/11/30 0030 20:07
* @UpdateUser: JackWang
* @UpdateDate: 2018/11/30 0030 20:07
* @Version: 1.0
*/
@Component
public class PagexAddService implements IPageXService, InitializingBean {
private static final Logger LOG = Logger.getLogger(PagexAddService.class);
/**
* 向html传递的Map
*/
private Map paramMap;
/**
* 拼接html
*
* @param request request
* @param response response
* @param js js配置
* @param namespace 命名空间
* @return 列表页HTML
*/
public String service(HttpServletRequest request, HttpServletResponse response, String js, String namespace) throws NoSuchMethodException, ScriptException {
// 如果有缓存直接在缓存取
/*if (PagexDataService.SIGNEL.getAddPageHtmlCache().containsKey(namespace)) {
return PagexDataService.SIGNEL.getAddPageHtmlCache().get(namespace);
}*/
PagexAddDTO pageAddSett = PagexDataService.SIGNEL.getPagexAddDTOFromCache(namespace);
//formHtml
paramMap = new HashMap<>();
String formHtml = createFormHtml(request, response, pageAddSett);
//save_url
if(!pageAddSett.getModelConfig().containsKey("saveUrl"))
{
pageAddSett.getModelConfig().put("saveUrl", EConfig.getPathPropertiesValue("basePath") +
"/ms/x/" + namespace + "/add");
}
if(!pageAddSett.getModelConfig().containsKey("updateUrl"))
{
pageAddSett.getModelConfig().put("updateUrl", EConfig.getPathPropertiesValue("basePath") +
"/ms/x/" + namespace + "/update/");
}
if(!pageAddSett.getModelConfig().containsKey("infoUrl"))
{
pageAddSett.getModelConfig().put("infoUrl", EConfig.getPathPropertiesValue("basePath") +
"/ms/x/" + namespace + "/info/");
}
String resultHtml = null;
try {
paramMap.put("formHtml",formHtml);
paramMap.put("modelConfig",pageAddSett.getModelConfig());
paramMap.put("otherFunctions",pageAddSett.getOtherFunctions());
if(PagexDataService.SIGNEL.getAddPageExtendsHtmlPathMap().containsKey(namespace)) {
paramMap.put("extendsHtml", BeetlUtil.renderBeelt(PagexDataService.SIGNEL.getAddPageExtendsHtmlPathMap().get(namespace), new HashMap<>()));
}
resultHtml = BeetlUtil.renderBeelt("/pagex/add_update_template.html",paramMap);
return resultHtml;
} catch (Exception e) {
e.printStackTrace();
return "code:500,message:" +e.getMessage();
}
}
/**
* 拼接表单内容 结束
* 此处代码是本系统最复杂的一块
*
* @param pageAddSett 添加页配置
* @return 表单内容
*/
public String createFormHtml(HttpServletRequest request, HttpServletResponse response, PagexAddDTO pageAddSett) {
String type = null;
Class fromTagClass = null;
BaseFormTag formTag = null;
StringBuilder formFieldBuilder = new StringBuilder();
List readyJsListList = new ArrayList<>();
List loadSuccessList = new ArrayList<>();
List onSaveList = new ArrayList<>();
List overallJsList = new ArrayList<>();
//上一个tag
BaseFormTag preTag = null;
// 上一个tag是否包含endDiv
Boolean preHasEndDiv = true;
// 获取所有的表单字段
for (Map field : pageAddSett.getFormFieldSett()) {
type = ConverterUtils.toString(field.get("type"));
if (CheckUtils.isNullOrEmpty(type))
{
continue;
}
if("one2x".equals(type))
{
formFieldBuilder.append(handelOne2X( readyJsListList ,loadSuccessList, onSaveList, overallJsList,
pageAddSett, field, request, response));
continue;
}
fromTagClass = FormTagFactory.getTag(type);
if (fromTagClass == null) {
LOG.error("系统不支持的列表type:" + type);
continue;
}
try {
formTag = (BaseFormTag) fromTagClass.newInstance();
Map fieldSettMap = new HashMap<>();
fieldSettMap.putAll(field);
fieldSettMap.put("name", ColumnNameUtil.underlineToCamel(ConverterUtils.toString(fieldSettMap.get("name"))));
formTag.setTagSett(fieldSettMap, request, response);
// 如果是新起一行
if (formTag.isNewRow()) {
if (preHasEndDiv) {
formFieldBuilder.append(formTag.getContentHtml());
} else{
formFieldBuilder.append("
"+formTag.getContentHtml());
preHasEndDiv = false;
} else { // 如果上一个不为空
if (preHasEndDiv) {
formFieldBuilder.append(" readyJsListList ,List loadSuccessList, List onSaveList, List overallJsList,
PagexAddDTO pageAddSett,Map field,HttpServletRequest request, HttpServletResponse response){
// 头处理
// template处理
// load数据处理
// 保存数据处理
// 初始化
String xnamespace = ConverterUtils.toString(field.get("namespace"));
readyJsListList.add(xnamespace + "_ready()");
loadSuccessList.add(xnamespace + "_onload(info)");
onSaveList.add(xnamespace + "_onsave()");
//找到需要关联的dto
PagexAddDTO xAddDTO = PagexDataService.SIGNEL.getPagexAddDTOFromCache(xnamespace);
String type = null;
Class extends IOne2XTag> fromTagClass = null;
IOne2XTag tag = null;
List
"+formTag.getContentHtml());
preHasEndDiv = false;
} else{
formFieldBuilder.append( formTag.getContentHtml()+"
");
preHasEndDiv = true;
}
}
}
preTag = formTag;
// 获取readyJsList
if (!CheckUtils.isNullOrEmpty(formTag.readyJs())){
readyJsListList.add(formTag.readyJs());
}
// 获取loadSuccessList
if (!CheckUtils.isNullOrEmpty(formTag.loadSuccessJs())){
loadSuccessList.add(formTag.loadSuccessJs());
}
// 获取onSaveList
if (!CheckUtils.isNullOrEmpty(formTag.saveJs())){
onSaveList.add(formTag.saveJs());
}
// 获取overallJsList
if (!CheckUtils.isNullOrEmpty(formTag.overallJs())){
overallJsList.add(formTag.overallJs());
}
} catch (InstantiationException e) {
LOG.error(this, e);
} catch (IllegalAccessException e) {
LOG.error(this, e);
}
}
request.setAttribute("tagReadyJsList",readyJsListList);
request.setAttribute("tagLoadSuccessList",loadSuccessList);
request.setAttribute("tagOnSaveList",onSaveList);
request.setAttribute("tagOverallJsList",overallJsList);
paramMap.put("tagReadyJsList",readyJsListList);
paramMap.put("tagLoadSuccessList",loadSuccessList);
paramMap.put("tagOnSaveList",onSaveList);
paramMap.put("tagOverallJsList",overallJsList);
return formFieldBuilder.toString();
}
@Override
public void afterPropertiesSet() throws Exception {
HandelPageXService.SIGEL.registerPageXService("add_update.jsp",this);
}
private String handelOne2X(List© 2015 - 2024 Weber Informatics LLC | Privacy Policy