Commit 84e9a1d3 by 罗绍泽

增加portlet布局保存的方法

详见:http://localhost:8080/jfV5portal/jwAppsPortletView_portletApi
parent f2a8eefd
...@@ -14,6 +14,8 @@ jwAppPortletModel.prototype.listAllPTemplateByUser = function(){}; ...@@ -14,6 +14,8 @@ jwAppPortletModel.prototype.listAllPTemplateByUser = function(){};
jwAppPortletModel.prototype.listAllPortletColumns = function(){}; jwAppPortletModel.prototype.listAllPortletColumns = function(){};
//获取所有的资源列表 //获取所有的资源列表
jwAppPortletModel.prototype.listAllPTemplate = function(){}; jwAppPortletModel.prototype.listAllPTemplate = function(){};
//保存用户的资源列表
jwAppPortletModel.prototype.saveLayout = function(){};
//创建一个数据操作对象,然后再后续使用 //创建一个数据操作对象,然后再后续使用
......
...@@ -39,7 +39,7 @@ table { ...@@ -39,7 +39,7 @@ table {
width: 100%; width: 100%;
} }
table tr td pre { table tr td .pre {
width: 100%; width: 100%;
height: 200px; height: 200px;
overflow: auto; overflow: auto;
...@@ -65,9 +65,9 @@ table tr td pre { ...@@ -65,9 +65,9 @@ table tr td pre {
</tr> </tr>
<tr> <tr>
<td>调用</td> <td>调用</td>
<td>jwAppPortletModel.jwAppsPortletDataAction.listAllPTemplateByUser({<br /> <td><pre>var result = jwAppPortletModel.jwAppsPortletDataAction.listAllPTemplateByUser({
&nbsp;&nbsp;&nbsp;&nbsp; FIELD_COLUMN_ID:'d6926714-c220-4a7e-9ec0-3a23caebb179' <br /> FIELD_COLUMN_ID: 'd6926714-c220-4a7e-9ec0-3a23caebb179'
})</td> })</pre></td>
</tr> </tr>
<tr> <tr>
<td>参数备注</td> <td>参数备注</td>
...@@ -75,7 +75,7 @@ table tr td pre { ...@@ -75,7 +75,7 @@ table tr td pre {
</tr> </tr>
<tr> <tr>
<td><span class="look">结果查看</span></td> <td><span class="look">结果查看</span></td>
<td><pre></pre></td> <td><pre class="pre"></pre></td>
</tr> </tr>
</table> </table>
...@@ -90,7 +90,7 @@ table tr td pre { ...@@ -90,7 +90,7 @@ table tr td pre {
</tr> </tr>
<tr> <tr>
<td>调用</td> <td>调用</td>
<td>jwAppPortletModel.jwAppsPortletDataAction.listAllPortletColumns()</td> <td><pre>var result = jwAppPortletModel.jwAppsPortletDataAction.listAllPortletColumns()</pre></td>
</tr> </tr>
<tr> <tr>
<td>参数备注</td> <td>参数备注</td>
...@@ -98,7 +98,7 @@ table tr td pre { ...@@ -98,7 +98,7 @@ table tr td pre {
</tr> </tr>
<tr> <tr>
<td><span class="look">结果查看</span></td> <td><span class="look">结果查看</span></td>
<td><pre></pre></td> <td><pre class="pre"></pre></td>
</tr> </tr>
</table> </table>
...@@ -113,9 +113,9 @@ table tr td pre { ...@@ -113,9 +113,9 @@ table tr td pre {
</tr> </tr>
<tr> <tr>
<td>调用</td> <td>调用</td>
<td>jwAppPortletModel.jwAppsPortletDataAction.listAllPTemplate({<br /> <td><pre>var result = jwAppPortletModel.jwAppsPortletDataAction.listAllPTemplate({
&nbsp;&nbsp;&nbsp;&nbsp; FIELD_COLUMN_ID:'d6926714-c220-4a7e-9ec0-3a23caebb179' <br /> FIELD_COLUMN_ID: 'd6926714-c220-4a7e-9ec0-3a23caebb179'
})</td> })</pre></td>
</tr> </tr>
<tr> <tr>
<td>参数备注</td> <td>参数备注</td>
...@@ -123,7 +123,42 @@ table tr td pre { ...@@ -123,7 +123,42 @@ table tr td pre {
</tr> </tr>
<tr> <tr>
<td><span class="look">结果查看</span></td> <td><span class="look">结果查看</span></td>
<td><pre></pre></td> <td><pre class="pre"></pre></td>
</tr>
</table>
<table id="tbl_004">
<tr>
<td>编号</td>
<td>004</td>
</tr>
<tr>
<td>描述</td>
<td>保存用户的资源列表</td>
</tr>
<tr>
<td>调用</td>
<td><pre>var layout = {
columnsId: 'd6926714-c220-4a7e-9ec0-3a23caebb179',
portlets: [{
"PORTLET_ID": "a9a27fe8-8215-44a1-8e65-f93c74962240"
},
{
"PORTLET_ID": "8538986b-f177-4f70-a525-59f78d557c6b"
}]
};
layout = JSON.stringify(layout);
var result = jwAppPortletModel.jwAppsPortletActAction.saveLayout({
layout: layout
});</pre></td>
</tr>
<tr>
<td>参数备注</td>
<td>FIELD_COLUMN_ID:栏目id</td>
</tr>
<tr>
<td><span class="look">结果查看</span></td>
<td><pre class="pre"></pre></td>
</tr> </tr>
</table> </table>
</body> </body>
...@@ -133,8 +168,8 @@ table tr td pre { ...@@ -133,8 +168,8 @@ table tr td pre {
var $table = $(this); var $table = $(this);
var tr4 = $(this).find('tr').eq(4); var tr4 = $(this).find('tr').eq(4);
tr4.find('td').eq(0).find('span').click(function() { tr4.find('td').eq(0).find('span').click(function() {
var click = $table.find('tr').eq(2).find('td').eq(1).text(); var click = $table.find('tr').eq(2).find('td').eq(1).find('pre').text();
eval('var result=' + click); eval(click);
tr4.find('td').eq(1).find('pre').html(syntaxHighlight(result)); tr4.find('td').eq(1).find('pre').html(syntaxHighlight(result));
}); });
}); });
......
...@@ -15,4 +15,6 @@ public interface PortletBusiness { ...@@ -15,4 +15,6 @@ public interface PortletBusiness {
List<Map<String,Object>> list_portlet_template(Map<String, Object> query) throws BusinessException ; List<Map<String,Object>> list_portlet_template(Map<String, Object> query) throws BusinessException ;
List<Map<String,Object>> list_portlet_columns(Map<String, Object> query) throws BusinessException ; List<Map<String,Object>> list_portlet_columns(Map<String, Object> query) throws BusinessException ;
void saveLayout(String columnsId,List<Map<String, Object>> list) throws BusinessException ;
} }
...@@ -2,9 +2,13 @@ package com.jw.app.business.portlet; ...@@ -2,9 +2,13 @@ package com.jw.app.business.portlet;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import com.gaowj.business.exception.BusinessException; import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.SessionUtil; import com.gaowj.business.util.SessionUtil;
...@@ -13,6 +17,11 @@ import com.jw.app.business.utils.QueryParamUtil; ...@@ -13,6 +17,11 @@ import com.jw.app.business.utils.QueryParamUtil;
public class PortletBusinessImpl implements PortletBusiness { public class PortletBusinessImpl implements PortletBusiness {
/**
* 默认模板的标识符
*/
private static final String DEFAULT="default";
private PortletDAO portletDAO; private PortletDAO portletDAO;
public PortletDAO getPortletDAO() { public PortletDAO getPortletDAO() {
...@@ -29,10 +38,11 @@ public class PortletBusinessImpl implements PortletBusiness { ...@@ -29,10 +38,11 @@ public class PortletBusinessImpl implements PortletBusiness {
throws BusinessException { throws BusinessException {
List<Map<String, Object>> listData=null; List<Map<String, Object>> listData=null;
try { try {
query.put("USER_ID", SessionUtil.getEmid());
listData = QueryParamUtil.ClobToString(portletDAO.list_portlet_template_user(query)); listData = QueryParamUtil.ClobToString(portletDAO.list_portlet_template_user(query));
if(listData.size()==0){ if(listData.size()==0){
//如果当前登陆人还没有设置自定义的资源,则显示默认的资源 //如果当前登陆人还没有设置自定义的资源,则显示默认的资源
query.put("USER_ID", "default"); query.put("USER_ID", DEFAULT);
listData = QueryParamUtil.ClobToString(portletDAO.list_portlet_template_user(query)); listData = QueryParamUtil.ClobToString(portletDAO.list_portlet_template_user(query));
} }
for(Map<String, Object> map:listData){ for(Map<String, Object> map:listData){
...@@ -94,4 +104,72 @@ public class PortletBusinessImpl implements PortletBusiness { ...@@ -94,4 +104,72 @@ public class PortletBusinessImpl implements PortletBusiness {
return listData; return listData;
} }
@Override
public void saveLayout(String columnsId,List<Map<String, Object>> list) throws BusinessException {
String userId=SessionUtil.getEmid();
List<Map<String, Object>> listData=null;
try {
Map<String,Object> query=new HashMap<String, Object>();
query.put("USER_ID", userId);
query.put("COLUMN_ID", columnsId);
listData = QueryParamUtil.ClobToString(portletDAO.list_portlet_template_user(query));
if(listData.size()==0){
//如果当前登陆人没有设置自己的模板布局,则查询默认的布局
query.put("USER_ID", DEFAULT);
listData = QueryParamUtil.ClobToString(portletDAO.list_portlet_template_user(query));
}
//验证用户传过来的布局和数据库中的布局是否一致,默认为一致
boolean same=true;
if(listData.size()!=list.size()){
same=false;
}else{
//长度一致的情况下,判断每一个索引所在位置的portletId是否一致
for(int i=0;i<listData.size();i++){
//只要有一个不满足,则设置same为false
if(!listData.get(i).get("PORTLET_ID").equals(list.get(i).get("PORTLET_ID"))){
same=false;
break;
}
}
}
if(!same){
//如果不一致,则将用户的自定义模板布局删除,重新添加新布局进行保存
Map<String,Object> deleteQuery=new HashMap<String, Object>();
deleteQuery.put("USER_ID", userId);
portletDAO.delete_portlet_template_user(deleteQuery);
//重新添加
int index=0;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now=formatter.format(new Date());
for(Map<String, Object> map:list){
map.put("ID", UUID.randomUUID().toString());
map.put("USER_ID", userId);
map.put("ORDER_NUM", index++);
map.put("IS_DELETE", 0);
map.put("CREATE_USER", userId);
map.put("CREATE_TIME", now);
portletDAO.insert_portlet_template_user(mapToList(map));
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private List<Map<String,Object>> mapToList(Map<String, Object> map){
List<Map<String,Object>> entity=new ArrayList<Map<String,Object>>();
for (Map.Entry<String,Object> entry : map.entrySet()) {
Map<String,Object> field=new HashMap<String, Object>();
field.put("key", entry.getKey());
field.put("value", entry.getValue());
entity.add(field);
}
return entity;
}
} }
...@@ -17,4 +17,8 @@ public interface PortletDAO { ...@@ -17,4 +17,8 @@ public interface PortletDAO {
List<Map<String,Object>> list_portlet_content(Map<String,Object> query) throws BusinessException ; List<Map<String,Object>> list_portlet_content(Map<String,Object> query) throws BusinessException ;
List<Map<String,Object>> list_app_acount(Map<String,Object> query) throws BusinessException ; List<Map<String,Object>> list_app_acount(Map<String,Object> query) throws BusinessException ;
void delete_portlet_template_user(Map<String,Object> query) throws BusinessException ;
void insert_portlet_template_user(List<Map<String,Object>> entity) throws BusinessException ;
} }
...@@ -120,4 +120,24 @@ ...@@ -120,4 +120,24 @@
on btua.APP_ID=btumu.APP_ID on btua.APP_ID=btumu.APP_ID
WHERE btumu.USER_ID=#{USER_ID} AND btua.APP_ID=#{APP_ID} WHERE btumu.USER_ID=#{USER_ID} AND btua.APP_ID=#{APP_ID}
</select> </select>
<delete id="delete_portlet_template_user" parameterType="map">
delete from portlet_template_user where user_id=#{USER_ID}
</delete>
<insert id="insert_portlet_template_user" parameterType="java.util.List">
insert into portlet_template_user(
<trim prefix="" suffixOverrides=",">
<foreach collection="list" item="field">
${field.key},
</foreach>
</trim>
<![CDATA[ ) values( ]]>
<trim prefix="" suffixOverrides=",">
<foreach collection="list" item="field">
#{field.value},
</foreach>
</trim>
<![CDATA[ ) ]]>
</insert>
</mapper> </mapper>
\ No newline at end of file
package com.jw.app.portlet.action; package com.jw.app.portlet.action;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.gaowj.business.action.BasicAction; import com.gaowj.business.action.BasicAction;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.exception.BusinessException;
import com.gaowj.business.util.RequestUtils;
import com.jw.app.business.PortletBusiness;
import com.jw.app.business.utils.Status;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;
public class actAction extends BasicAction { public class actAction extends BasicAction {
...@@ -20,5 +32,25 @@ public class actAction extends BasicAction { ...@@ -20,5 +32,25 @@ public class actAction extends BasicAction {
public void setJsonObject(JSONObject jsonObject) { public void setJsonObject(JSONObject jsonObject) {
this.jsonObject = jsonObject; this.jsonObject = jsonObject;
} }
public String saveLayout() throws BusinessException{
String layout=RequestUtils.getString(request, "layout");
//layout="{columnsId:'d6926714-c220-4a7e-9ec0-3a23caebb179',portlets:[{\"PORTLET_ID\":\"a9a27fe8-8215-44a1-8e65-f93c74962240\"},{\"PORTLET_ID\":\"8538986b-f177-4f70-a525-59f78d557c6b\"}]}";
JSONObject json=JSONObject.fromObject(layout);
//获取栏目id
String columnsId=json.get("columnsId").toString();
//解析protlets
JSONArray array=JSONArray.fromObject(json.get("portlets"));
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
for(Iterator iter = array.iterator(); iter.hasNext();){
JSONObject jsonObject = (JSONObject)iter.next();
list.add((Map<String, Object>) JSONObject.toBean(jsonObject, Map.class));
}
PortletBusiness business = BusinessManager.getBusiness(PortletBusiness.class);
business.saveLayout(columnsId, list);
jsonObject.putAll(Status.getStatus(Status.UPDATE_OK));
return "json";
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment