码迷,mamicode.com
首页 > 移动开发 > 详细

手机端参照写法

时间:2015-10-31 17:10:09      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:

一、需求:要求在手机端页面新增一个参照:
技术分享
怎么在手机页面新增一个参照节点?第一步:我们肯定要明白手机端这个页面是怎么展现的?
其实手机端展现的原理很简单,手机端是通过加载在portal界面配置好的手机模板,我们知道,
portal可以配置手机、pc、pad三种终端的界面,这里我们需要配置在手机端的模板,具体看图:
浏览器输入127.0.0.1/portal输入管理员账号即可进入管理员界面,
技术分享
选择系统管理->表单配置
技术分享
选择main
技术分享
然后就会跳转到"个性化设置",里面的说明看清楚。
技术分享
下面看“增加项”,如果不用这个,请跳过
技术分享技术分享
手动编写一个唯一的"编号"与"名称"即可。这里只做一个内容展现功能,并没有实际的操作。
这里我们重点了解一下“编辑‘
技术分享技术分享
点击”编辑“就会跳转到这个界面
我们注意到左边就是我们的数据集,什么是数据集,(⊙﹏⊙)b这点基础应该有吧?我们点击那个”+“即可展现我们数据集中的属性
这里因为我们是新增一个显示在手机端的参照,所以涉及到数据的操作,我们肯定要选择一个可以关联数据库的字段,这时候预留自
定义属性就起到作用了,因为”vdef1~n“当初设计元数据的时候就是为了将来做功能拓展,这里派上用场了,
友情提示:将左边的属性移动到右边时,要关注这个字段是不是已经被使用,因为不能排除这个应用已经做了别的拓展,对吧?
另外,勾上”是否可见“,让它显示在模板。
技术分享
我这里选择vdef11,因为前面的被其他使用了,然后选择这个节点,调整属性
技术分享
因为这里是参照,我们一定要选择到参照,另外引用的参照,就是之前我们在UAP-Studio中模式化生成的参照。
关于怎么模式化生成参照,我这里只做简单的说明,具体请参考相关文档,
1.模式化生成参照,关注有没有生成”xxxModel与xxxControlor“这两个类,
2.查询数据库,关注参照有没有新增到数据库select * from bd_refinfo order by ts desc;
3.具体的逻辑请在xxxControlor中完成,我这里只做了一个简单的查询,大家可以参考其他参照的xxxControlor类怎么写的。
  1. package nc.ref.cacoverplan.control;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import nc.uap.lfw.core.data.Dataset;
  6. import nc.uap.lfw.core.data.PaginationInfo;
  7. import nc.uap.lfw.core.event.DataLoadEvent;
  8. import nc.uap.lfw.core.refnode.IRefNode;
  9. import nc.uap.lfw.core.serializer.impl.List2DatasetSerializer;
  10. import uap.lfw.ref.ctrl.LfwSqlGridReferenceController;
  11. import uap.lfw.ref.sqlvo.ILfwRefSqlVO;
  12. import uap.lfw.ref.sqlvo.LfwReferenceSqlVO;
  13. import uap.lfw.ref.util.LfwReferenceUtil;
  14. public class CacoverplanCAGridRefController extends LfwSqlGridReferenceController {
  15. private String getMultilangTextSql(String fieldCodeInRef, String fieldCodeWithTable) {
  16. StringBuilder sb = new StringBuilder();
  17. sb.append(fieldCodeWithTable).append(‘ ‘).append(fieldCodeInRef);
  18. for (int i = 2; i < 7; i++) {
  19. sb.append(‘,‘).append(fieldCodeWithTable).append(i).append(‘ ‘).append(fieldCodeInRef).append(i);
  20. }
  21. return sb.toString();
  22. }
  23. @Override
  24. public ILfwRefSqlVO getGridSqlVO() {

  25. LfwReferenceSqlVO sqlvo = new LfwReferenceSqlVO();
  26. StringBuilder selSql = new StringBuilder();
  27. selSql.append("select a.pk_group,a.pk_org,a.pk_org_v,a.pk_dept,a.pk_plan,a.pk_salesman, ");
  28. selSql.append(getMultilangTextSql("pk_account_vname", "b.vname")).append(‘,‘);
  29. selSql.append(" a.vmemo from cuma_fugaiplan a ");
  30. selSql.append("inner join cuma_account b on a.customer=b.pk_account ");
  31. // String sql = "select b.vname,a.vmemo from cuma_fugaiplan a inner join cuma_account b on a.customer=b.pk_account";
  32. //虚拟表(可以是单个数据库表,也可以是多个表联合查询的虚拟表)
  33. sqlvo.setTableName("(" + selSql + ") cuma_fugaiplan");
  34. //真实数据库表(虚拟表中包含的所有表的集合)
  35. sqlvo.setRealTableNames("cuma_fugaiplan");
  36. //设置虚拟表排序字段
  37. sqlvo.setOrderByPart("");
  38. return sqlvo;
  39. }
  40. @Override
  41. public void onDataLoad(DataLoadEvent e) {
  42. Dataset ds = (Dataset) e.getSource();
  43. ILfwRefSqlVO vo = getMainRefSqlVO();
  44. if (vo == null) {
  45. return;
  46. }
  47. Map values = new HashMap(2);
  48. values.put("KEY_LOCATE_WP", new Object[] { getFilterValue() });
  49. Map sqlMap = vo.getSql(ds.getFieldSet().getFields(), values, null);
  50. String sql = (String) sqlMap.get("KEY_SQL");
  51. String countSql = (String) sqlMap.get("KEY_COUNT_SQL");
  52. List params = (List) sqlMap.get("KEY_SQL_PARAM_VALUES");
  53. sql=sql.replaceAll("realfinishtime", "dplanfinishtime");
  54. countSql=countSql.replaceAll("realfinishtime", "dplanfinishtime");
  55. PaginationInfo pInfo = ds.getCurrentRowSet().getPaginationInfo();
  56. IRefNode refNode = LfwReferenceUtil.getRefNodeFromParentWindow(null);
  57. List vec = getRefResult(refNode, vo, sql, countSql, params, pInfo);
  58. //ds.getFieldSet().addField(new field);
  59. new List2DatasetSerializer().serialize(ds.getCurrentKey(), pInfo, vec,
  60. ds);
  61. }
  62. }

技术分享技术分享
好了,我们的初期设置工作已经做好了,基本上可以在手机上显示那个参照了,如果没有成功,只能说你不够细心了

下面是具体代码的调整,这个根据具体的业务,可以做一个参考。
移动CRM客户端所有关于前端页面交互都会走这个类,我们先找到这个类”MobileAdapterServiceImpl
怎么找到这个类,试试Ctrl+shift+T,很方便的一个快捷键。
相信聪明的你早就找到了,我们关注getReferToSrvMap()这个方法。
  1. private Map<String, String> getReferToSrvMap() {
  2. Map<String, String> referToMap = new HashMap<String, String>();
  3. referToMap.put(MobileConsts.REFER_TO_ACCOUNT, MobileConsts.ACCOUNT_QRY_SERVICE);
  4. referToMap.put(MobileConsts.REFER_TO_LEAD, MobileConsts.LEAD_QRY_SERVICE);
  5. referToMap.put(MobileConsts.REFER_TO_BO, MobileConsts.BO_QRY_SERVICE);
  6. referToMap.put(MobileConsts.REFER_TO_CONTACT, MobileConsts.CONTACT_QRY_SERVICE);
  7. referToMap.put(MobileConsts.REFER_TO_INVENTORY, MobileConsts.INVENTORY_QRY_SERVICE);
  8. referToMap.put(MobileConsts.REFER_TO_INVENTORY_WEB, MobileConsts.INVENTORY_QRY_SERVICE);
  9. referToMap.put(MobileConsts.REFER_TO_INVENTORYCLASS, MobileConsts.INVENTORYCLASS_QRY_SERVICE);
  10. referToMap.put(MobileConsts.REFER_TO_ACTIVITY, MobileConsts.ACTIVITY_QRY_SERVICE);
  11. referToMap.put(MobileConsts.REFER_TO_COVERPLAN, MobileConsts.ACCOUNT_COVERPLAN_SERVICE);
  12. return referToMap;
  13. }
referToMap.put(MobileConsts.REFER_TO_COVERPLAN, MobileConsts.ACCOUNT_COVERPLAN_SERVICE);这个是我自己手动加的,
目的就是把自己的服务给注册到这个类中,我们看下MobileConsts.REFER_TO_COVERPLAN 指定的 MobileConsts.ACCOUNT_COVERPLAN_SERVICE我们跟进去看下是什么。
  1. /**
  2. * 移动覆盖计划查询服务
  3. */
  4. public static final String ACCOUNT_COVERPLAN_SERVICE = "nc.pubitf.ca.cuma.account.ma.IMACoverPlanService";
我们看到它实际上就是一个服务类的接口,它会根据这个接口找到相应的实现类。
写完这个之后,我们下一个关注便是
  1. public List<Map> getReferValues(String groupId, String userId, String orgId, String referto, String condition,
  2. String startline, String count, String ispaging)
getReferValues这个方法顾名思义它是得到参照的值的,所以我们要在自己的服务中复写这个方法,写上自己的业务,尽量不要使用这个通用的方法。
  1. package nc.impl.ca.cuma.account.ma;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import nc.bs.ca.capub.mobile.common.MobileCommon;
  7. import nc.bs.ca.capub.mobile.common.MobileConsts;
  8. import nc.bs.ca.capub.mobile.data.handler.MobileReferListHandler;
  9. import nc.bs.ca.capub.mobile.service.MobilePubService;
  10. import nc.bs.ca.capub.mobile.template.MobileTemplateManager;
  11. import nc.bs.ca.capub.service.NCLocatorFactory;
  12. import nc.bs.ca.capub.util.ArrayUtils;
  13. import nc.bs.ca.capub.util.CommonUtils;
  14. import nc.bs.ca.capub.util.QuerySchemeUtils;
  15. import nc.bs.ca.capub.util.QueryUtils;
  16. import nc.bs.ca.capub.vo.CrmLoginContext;
  17. import nc.bs.ca.capub.vo.CrmQueryCondVO;
  18. import nc.bs.framework.common.NCLocator;
  19. import nc.itf.ca.capub.commonfunc.activity.IActivityService;
  20. import nc.itf.ca.cuma.account.IAccountService;
  21. import nc.itf.ca.cuma.account.account.coverplan.ICoverplanService;
  22. import nc.pubitf.ca.cuma.account.ma.IMACoverPlanService;
  23. import nc.uap.cpb.org.vos.CpUserVO;
  24. import nc.uap.ctrl.tpl.qry.FromWhereSQLImpl;
  25. import nc.uap.ctrl.tpl.qry.base.QuerySchemeVO;
  26. import nc.uap.lfw.core.data.PaginationInfo;
  27. import nc.uap.lfw.core.exception.LfwBusinessException;
  28. import nc.vo.ca.capub.commonfunc.activity.ActivityVO;
  29. import nc.vo.ca.cuma.account.AccountVO;
  30. import nc.vo.cuma.fugaiplan.FugaiPlanVO;
  31. import nc.vo.org.DeptVO;
  32. import nc.vo.pub.SuperVO;
  33. import nc.vo.pub.VOStatus;
  34. import nc.vo.pub.lang.UFDate;
  35. import nc.vo.pub.lang.UFDateTime;
  36. import org.apache.commons.lang.StringUtils;
  37. import uap.lfw.imp.query.base.QuerySchemeUtil;
  38. public class MACoverPlanServiceImpl extends MobilePubService implements IMACoverPlanService {
  39. private ICoverplanService service;
  40. private ICoverplanService getService() {
  41. if (null == this.service) {
  42. this.service = NCLocatorFactory.getInstance().getCANCLocator()
  43. .lookup(ICoverplanService.class);
  44. }
  45. return this.service;
  46. }
  47. @Override
  48. public List<Map> getReferValues(String groupId, String userId, String pk_org, String referTo, String condition,
  49. String startline, String count, String ispaging) {
  50. CrmLoginContext crmLoginContext = new CrmLoginContext();
  51. crmLoginContext.setPk_group(groupId);
  52. crmLoginContext.setNodeCode(MobileConsts.FUN_CODE_COVERPLAN);
  53. crmLoginContext.setPk_org(pk_org);
  54. crmLoginContext.setPk_user(userId);
  55. IMACoverPlanService service = NCLocatorFactory.getInstance().getCANCLocator().lookup(IMACoverPlanService.class);
  56. int pageSize = 0;
  57. if (!StringUtils.isEmpty(startline)) {
  58. pageSize = Integer.valueOf(count);
  59. }
  60. PaginationInfo pinfo = new PaginationInfo();
  61. pinfo.setPageSize(pageSize);
  62. SuperVO[] vos = null;
  63. if (StringUtils.isEmpty(startline)) {
  64. pinfo.setPageIndex(0);
  65. } else {
  66. pinfo.setPageIndex(Integer.valueOf(startline) / pageSize);
  67. }
  68. CrmQueryCondVO crmQueryCondVO = new CrmQueryCondVO();
  69. String sql = "";
  70. if (StringUtils.isNotEmpty(condition)) {
  71. sql = ActivityVO.VNAME + " like ‘%" + condition + "%‘";
  72. }
  73. crmQueryCondVO.setWherePart(sql);
  74. crmQueryCondVO.setCrmScope(true);
  75. crmQueryCondVO.setOrderPart(this.getOrderByPart());
  76. //crmQueryCondVO.setExtSql(AccountVO.ENABLESTATE + "=" + EnableStateEnum.ENABLESTATE_ENABLE);
  77. try {
  78. //vos = service.queryVOs(crmLoginContext, new ActivityVO(), pinfo, crmQueryCondVO);
  79. vos = this.getService().queryVOs(pinfo, new FugaiPlanVO(),sql, this.getOrderByPart());
  80. } catch (LfwBusinessException e) {
  81. return MobileCommon.exceptionReturn(e, e.getMessage());
  82. }
  83. List<Map> funInfo = new ArrayList<Map>();
  84. Map funMap = new HashMap();
  85. funInfo.add(funMap);
  86. funMap.put(MobileConsts.ORGID, pk_org);
  87. funMap.put(MobileConsts.BNSTYPE, "");
  88. funMap.put(MobileConsts.WINID, "coverplan_listwin");
  89. funMap.put(MobileConsts.FUNCODE, MobileConsts.FUN_CODE_COVERPLAN);
  90. List<Map<String, Object>> template = null;
  91. try {
  92. template = MobileTemplateManager.getTemplate(groupId, userId, "", "", "", funInfo);
  93. } catch (Exception e) {
  94. return MobileCommon.exceptionReturn(e, e.getMessage());
  95. }
  96. MobileReferListHandler mobileReferListHandler = new MobileReferListHandler(template, vos,
  97. "", FugaiPlanVO.VMEMO);
  98. try {
  99. return mobileReferListHandler.handle();
  100. } catch (Exception e) {
  101. return MobileCommon.exceptionReturn(e, e.getMessage());
  102. }
  103. }
  104. //省略了其他业务代码
  105. }
我们在这个方法里写上自己的逻辑,其他代码可以不用怎么改,大概根据别人写好的,改下就好,但是这个考验你的迁移能力,可能会遇到各种错,慢慢调,这里提醒一下关注vos = this.getService().queryVOs(pinfo, new FugaiPlanVO(),sql, this.getOrderByPart());。因为这个方法是得到你的相应的VO,为什么要得到VO,因为这个VO封装了页面所需要的参数与值,这相当于是一种协议,一种约定。它要什么,你就必须给什么。
这个
MobileReferListHandler mobileReferListHandler = new MobileReferListHandler(template, vos,
"", FugaiPlanVO.VMEMO);
最好也关注一下,至于它是干嘛的,自己可以跟进去看,我这里不做解释,大概就是找到模板,填充数据。
还有一些业务的改动,它显示这个参照的时候,如果我希望用户选择完毕后,做一个数据的回显,那么我们需要关注这个类
ActivityObjectViewData
  1. private List<Map> getHeadData(List<Map> headTplList) throws Exception {
  2. List<Map> headList = new ArrayList<Map>();
  3. Map headMap = new HashMap();
  4. headList.add(headMap);
  5. Map tabContentMap = new HashMap();
  6. headMap.put(TABCONTENT, tabContentMap);
  7. List<Map> groupList = new ArrayList<Map>();
  8. tabContentMap.put(GROUP, groupList);
  9. Map groupMap = new HashMap();
  10. groupList.add(groupMap);
  11. groupMap.put(TABCODE, "");
  12. groupMap.put(TABNAME, "");
  13. groupMap.put("relatedlist",
  14. ((Map) ((List) this.template.get(0).get(MobileConsts.HEAD_TEMPLATE_KEY)).get(0)).get("relatedlist"));
  15. Map billItemDataMap = new HashMap();
  16. groupMap.put(TABCONTENT, billItemDataMap);
  17. List<Map> dataList = new ArrayList<Map>();
  18. billItemDataMap.put(BILLITEM_DATA, dataList);
  19. for (Map attrMap : headTplList) {
  20. String type = attrMap.get("type").toString();
  21. String value = null;
  22. if (StringUtils.isNotEmpty(type)) {
  23. if (MobileConsts.REFERTYPE.equalsIgnoreCase(type) || MobileConsts.ADDRESS.equalsIgnoreCase(type)) {
  24. try {
  25. if ("referobj_name".equals(attrMap.get(MobileConsts.KEY).toString())) {
  26. value = this.getRealValue("referobj_name", parentVO);
  27. } else {
  28. value = MobileReferUtil.getReferItemValue(parentVO, attrMap, type,
  29. attrMap.get(MobileConsts.KEY).toString());
  30. }
  31. } catch (Exception e) {
  32. LfwLogger.error(e.getMessage());
  33. }
  34. }
  35. //日期类型去掉时分秒
  36. else if (MobileConsts.DATE.equalsIgnoreCase(type) && null != attrMap.get(MobileConsts.KEY)) {
  37. if (parentVO.getAttributeValue(attrMap.get(MobileConsts.KEY).toString()) != null)
  38. value = parentVO.getAttributeValue(attrMap.get(MobileConsts.KEY).toString()).toString()
  39. .split(" ")[0];
  40. } else if (MobileConsts.COMBO.equalsIgnoreCase(type) && null != attrMap.get(MobileConsts.KEY)) {
  41. List<Map> enumList = (List<Map>) attrMap.get("enumlist");
  42. if (enumList == null || enumList.size() == 0) {
  43. value = this.getRealValue(attrMap.get(MobileConsts.KEY).toString(), parentVO);
  44. } else {
  45. String key = "";
  46. if (parentVO.getAttributeValue(attrMap.get(MobileConsts.KEY).toString()) != null) {
  47. key = parentVO.getAttributeValue(attrMap.get(MobileConsts.KEY).toString()).toString();
  48. }
  49. if (StringUtils.isEmpty(key)) {
  50. value = "";
  51. } else {
  52. for (Map map : enumList) {
  53. if (map.get("realval").equals(key)) {
  54. value = map.get("diplayval").toString();
  55. }
  56. }
  57. }
  58. }
  59. // if (value == null) {
  60. // value = "";
  61. // }
  62. }else if (MobileConsts.MONEY.equalsIgnoreCase(type) && null != attrMap.get(MobileConsts.KEY)) {
  63. value = ActivityUtils.getOrgCurrtypeSign((ActivityVO) parentVO)
  64. + parentVO.getAttributeValue((String)attrMap.get(MobileConsts.KEY));
  65. }else {
  66. String attrId = attrMap.get(MobileConsts.KEY).toString();
  67. if("action_name".equals(attrId))
  68. value = getShowValue4ItemMap("action", parentVO);
  69. else if("refstage_name".equals(attrId))
  70. value = getShowValue4ItemMap("refstage", parentVO);
  71. else if("vdef11".equals(attrId)){
  72. // ICrmQueryOpt service = NCLocatorFactory.getInstance().getCANCLocator()
  73. // .lookup(ICrmQueryOpt.class);
  74. //
  75. // SuperVO fgvo = (SuperVO) service.queryVOs("select vmemo from fugaiplan where pk_plan= ‘"+value+"‘ ");
  76. // if (fgvo != null) {
  77. //TODO 显示覆盖计划的内容
  78. // value = (String) fgvo.getAttributeValue("vmemo");
  79. // }
  80. value = MobileCommon.getString(parentVO.getAttributeValue(attrId));
  81. BaseDAO baseDAO=new BaseDAO();
  82. List<Map> list=(List<Map>) baseDAO.executeQuery("select vmemo from cuma_fugaiplan where pk_plan= ‘"+value+"‘ ", new MapListProcessor());
  83. Map map=list.get(0);
  84. value = (String) map.get("vmemo");
  85. }
  86. else
  87. value = MobileCommon.getString(parentVO.getAttributeValue(attrId));
  88. }
  89. }
  90. attrMap.put(MobileConsts.DIGEST, "N");
  91. attrMap.put(MobileConsts.VALUE, value);
  92. attrMap.put(MobileConsts.PARAMLIST, getParamList(attrMap.get(MobileConsts.KEY).toString(), parentVO));
  93. dataList.add(attrMap);
  94. }
  95. addAttachment(dataList);
  96. return headList;
  97. }
这个方法就是塞数据的类了,我们注意到我写的那部分
  1. else if("vdef11".equals(attrId)){

  2. value = MobileCommon.getString(parentVO.getAttributeValue(attrId));
  3. BaseDAO baseDAO=new BaseDAO();
  4. List<Map> list=(List<Map>) baseDAO.executeQuery("select vmemo from cuma_fugaiplan where pk_plan= ‘"+value+"‘ ", new MapListProcessor());
  5. Map map=list.get(0);
  6. value = (String) map.get("vmemo");
  7. }

这里利用BaseDAO查询数据库,回显数据
这里,手机端参照写法大概就写完了,大家有需要的时候可以实践一下,可能一次不会成功,坚持就是胜利哦,加油!
最后说一句,分享代码,让生活更美好!






手机端参照写法

标签:

原文地址:http://www.cnblogs.com/lanzhiming/p/4925698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!