Windchill 查询功能

一.使用SearchCondition

查询语句中用容器中的containerReference.key.id名称来代替数据库中的字段idA3containerReference

/**
     * 获取项目下所有的活动  StandardProjectReportService.java
     * @param project
     * @return
     */
    public static List<PlanActivity> getActivityByProject(Project2 project) throws Exception{
        List<PlanActivity> activityList = new ArrayList<PlanActivity>();
        QueryResult queryResult = null;
        if (project == null)
            return null;
        int[] index = { 0 };
        
        QuerySpec querySpec = new QuerySpec(PlanActivity.class);//SELECT A0.* FROM com.ptc.projectmanagement.plan.PlanActivity A0
        long projectId = PersistenceHelper.getObjectIdentifier(project).getId();
        WhereExpression whereExpression = new SearchCondition(
                PlanActivity.class, "containerReference.key.id",/* 数据库字段是 idA3containerReference */
                SearchCondition.EQUAL, projectId);//WHERE (A0.idA3containerReference = projectId
        
        querySpec.appendWhere(whereExpression, index);
        queryResult = PersistenceHelper.manager.find((StatementSpec) querySpec);
        PlanActivity projectActivity = null;
        while(queryResult.hasMoreElements()){
            projectActivity = (PlanActivity) queryResult.nextElement();
            activityList.add(projectActivity);
        }
     
        return activityList;
    }

表名PlanActivity的类名是 com.ptc.projectmanagement.plan.PlanActivity

在服务器中的Wndchill shell中输入如下命令:inforeport  com.ptc.projectmanagement.plan.PlanActivity

inforeport wt.projmgmt.admin.Project2

会在D:\ptc\Windchill_10.1\Windchill\temp 目录中自动生成文件admin.Project2.ou,打开即可

二.使用TableColumn

直接使用数据库中 字段

public static List<Project2> queryProjects(HashMap<String, String> queryParams)
    throws Exception {
        String department = queryParams.get("department"); //0
        String user = queryParams.get("user"); //1
        System.out.println("user=====ddd==========>" + user);
        String pjName = queryParams.get("pjName"); //2项目名称
        String projComp = queryParams.get("projComp"); //3 项目进度查询
        String create_date = queryParams.get("create_date");//4
        String end_date = queryParams.get("end_date"); //5
        List<Project2> list = new ArrayList<Project2>();
        QueryResult queryResult = null;
        QuerySpec querySpec = null;
        try {
            querySpec = new QuerySpec();
            int projectClassIndex = querySpec.appendClassList(Project2.class,true);//wt.projmgmt.admin.Project2  A0
            int userClassIndex = querySpec.appendClassList(WTUser.class, true);//wt.org.WTUser A1
            int epplanClassIndex = querySpec.appendClassList(Plan.class, true);//com.ptc.projectmanagement.plan.Plan A2
            //System.out.println(">>>>querySpec22222----------"+querySpec);
            //SELECT A0.*,A1.*,A2.* FROM wt.projmgmt.admin.Project2 A0  ,wt.org.WTUser A1  ,com.ptc.projectmanagement.plan.Plan A2
            querySpec.setAdvancedQueryEnabled(true);
            String[] aliases = new String[3];
            aliases[0] = querySpec.getFromClause().getAliasAt(projectClassIndex);//A0
            aliases[1] = querySpec.getFromClause().getAliasAt(epplanClassIndex);//A2
            aliases[2] = querySpec.getFromClause().getAliasAt(userClassIndex);//A1
            
            TableColumn projectIdColumn = new TableColumn(aliases[0], "idA2A2");//A0.idA2A2
            TableColumn projectNameColumn = new TableColumn(aliases[0], "namecontainerInfo");//A0.namecontainerInfo 
            TableColumn projectUserIDColumn = new TableColumn(aliases[0],"idA3B2containerInfo"); //A0.idA3B2containerInfo
            TableColumn projectStateColumn = new TableColumn(aliases[0],"statecontainerTeamManagedInf");//A0.statecontainerTeamManagedInf
            TableColumn foreignKeyColumn = new TableColumn(aliases[1], "idA3containerReference");//A2.idA3containerReference
            TableColumn userIDColumn = new TableColumn(aliases[2], "idA2A2");//A1.idA2A2
            TableColumn percentCompleteColumn = new TableColumn(aliases[1],"percentWorkComplete"); // 项目完成进度
            TableColumn actualStartTimeColumn = new TableColumn(aliases[1],"startDate"); // 实际开始时间    //epplan表
            TableColumn finishDateColumn = new TableColumn(aliases[1],"finishDate"); // 实际完成时间
            
            CompositeWhereExpression andExpression = new CompositeWhereExpression(LogicalOperator.AND);//where
            andExpression.append(new SearchCondition(projectIdColumn, "=",foreignKeyColumn));//A0.idA2A2 = A2.idA3containerReference
            andExpression.append(new SearchCondition(projectUserIDColumn, "=",userIDColumn));//A0.idA3B2containerInfo = A1.idA2A2
            andExpression.append(new SearchCondition(projectStateColumn, SearchCondition.NOT_EQUAL,ConstantExpression.newExpression("SUSPENDED")));//A0.statecontainerTeamManagedInf <> N‘SUSPENDED‘
            // WHERE ((A0.idA2A2 = A2.idA3containerReference) AND (A0.idA3B2containerInfo = A1.idA2A2) AND (A0.statecontainerTeamManagedInf <> N‘SUSPENDED‘)
            //AND (A0.namecontainerInfo LIKE N‘D1409 %‘))
            
            //项目名称模糊查询
            if(pjName!= null && !pjName.equals("")){
                andExpression.append(new SearchCondition(projectNameColumn,
                        SearchCondition.LIKE, ConstantExpression.newExpression(pjName+"%")));//A0.namecontainerInfo LIKE N‘D1409 %‘
            }
            // 项目进度查询
            if (projComp != null && !projComp.equals("")) {
                andExpression.append(new SearchCondition(percentCompleteColumn,
                        ">=", ConstantExpression.newExpression(Integer.parseInt(projComp))));
            }                                                    
            DateFormat dateFormat = new SimpleDateFormat(DATE_STYLE,SessionHelper.getLocale());
//            String formatText = WTMessage.getLocalizedMessage();
//            SimpleDateFormat exportTableTimeFormat = new SimpleDateFormat(formatText, SessionHelper.getLocale());
            dateFormat.setTimeZone(TimeZoneHelper.getLocalTimeZone());
            
            Date date = null;
            Date date2 = null;
            try {
                if(create_date!=null && !create_date.equalsIgnoreCase("")){
                    date =  dateFormat.parse(create_date);    //date为项目开始时间转化成了Date格式
                }
                if(end_date!=null && !end_date.equalsIgnoreCase("")){
                    date2 = dateFormat.parse(end_date);            //date2为项目结束时间
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            
            if (date != null) {
                andExpression.append(new SearchCondition(actualStartTimeColumn,
                        SearchCondition.GREATER_THAN_OR_EQUAL,ConstantExpression.newExpression(date)));//>=
            }
            if (date2 != null) {
                andExpression.append(new SearchCondition(finishDateColumn,
                        SearchCondition.LESS_THAN_OR_EQUAL, ConstantExpression.newExpression(date2)));//<=
            }
            querySpec.appendWhere(andExpression, null);
            
            queryResult = PersistenceHelper.manager.find((StatementSpec) querySpec);
            System.out.println(">>>>querySpec5555----------"+querySpec);
            while (queryResult.hasMoreElements()) {
                Object obj= queryResult.nextElement();
                Project2 project2 = (Project2) ((Object[])obj)[0];
                WTPrincipal principal=project2.getOwner();
                WTPrincipalReference wf = WTPrincipalReference.newWTPrincipalReference(principal);
                String ownerName = wf.getFullName();
                //按人员过滤,通过条件:1.人员为project owner,
                ////HM=============================================HM==============
                //System.out.println("Pro=============>" + ProjectUtil.findJoinUserByProject2(project2, user.trim()));
                if(ProjectUtil.findJoinUserByProject2(project2, user.trim())== true|| ownerName.equals(user.trim())){
                    list.add(project2);
                }
            }
        } catch (QueryException e) {
            e.printStackTrace();
        }
        return list;
    }

时间: 2024-07-29 20:21:56

Windchill 查询功能的相关文章

python实现whois查询功能的方法源码

恐怕很多朋友跟我一样,使用python语言居然能实现whois服务器查询功能.下面我把代码和说明搬来给大家看看,有谁需要可以参考下.本来想直接从whois服务器查询的,但是发现要写socket 用43端口链接服务器,但是有些服务器的地址不清楚,而且查询命令貌似有改变所以不想折腾了,就想着直接用chinaz的页面实现一下算了.如下代码是在 win7下操作的,安装python3.2测试通过. Python3.2实现whois查询功能的方法源码: # -*- coding:utf-8 -*- impo

[Architecture Pattern] Repository实作查询功能

[Architecture Pattern] Repository实作查询功能 范例下载 范例程序代码:点此下载 问题情景 在系统的BLL与DAL之间,加入Repository Pattern的设计,能够切割BLL与DAL之间的相依性,并且提供系统抽换DAL的能力.但在软件开发的过程中,套用Repository Pattern最容易遇到的问题就是,如何在Repository中实作「查询」这个功能.像是在下列这个查询订单的页面,系统必须要依照用户输入的查询条件,来从DAL中查询出所有符合条件内容的

利用PHP访问数据库——实现分页功能与多条件查询功能

1.实现分页功能 <body><table width="100%" border="1">  <thead>    <tr>      <th>代号</th>      <th>名称</th>      <th>价格</th>    </tr>  </thead>  <tbody>      <?php 

组合查询功能实现

前言 这是我的第二篇文章,这是我之前做的ERP项目的时候设计实现的.在这个ERP系统中,功能比较多,表设计的时候建立了很多业务表.对于一些业务表需要执行很多查询,客户要求针对不同的字段进行查询,基于我们之前的设计,针对不同的查询条件设计不同的DAL方法,通过不同的方法签名来实现客户的对于不同条件查询的要求.但是这种解决方案会让程序员很被动,久而久之整个DAL层会显得很臃肿. 面对这样的困境,考虑是否可以实现用一个通用的DAL方法来代替所有的不同筛选条件查询方法,因为这些查询方法内部的逻辑是一样的

微信公众平台开发(35)(天气预报、股票查询、手机归属查询、在线听音乐、翻译、成绩查询功能)代码分享

微信公众平台开发应用(天气预报.股票查询.手机归属查询.在线听音乐.翻译.成绩查询功能) 原文: http://www.cnblogs.com/imaker/p/5491433.html 1.xml(信息返回用扩展语言XML来传递值) $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post data if (!empty($postStr)){ $postObj = simplexml_load_string($postStr

JqueryMobile为Listview动态添加、删除查询功能

JqueryMobile的版本不同,引用JS的API也不同,因此为Listview动态添加.删除查询功能的代码也不同. 假设Listview控件内容如下: <ul data-role="listview" id="listview"  data-inset="true"> <li><a href="#">Acura</a></li> <li><a h

分页和多条件查询功能

/** * 辅助拼接HQL语句的工具类 * @author G-Xia * */ public class QueryHelper { private String fromClause; // From子句 private String whereClause = ""; // Where子句 private String orderByClause = ""; // OrderBy子句 private List<Object> parameters

easyuI企业管理系统-实战六 查询功能

今天你学习了吗?本篇讲述查询功能 class="easyui-searchbox" //easyui自带的查询类 <input class="easyui-searchbox" style="" data-options="prompt:'请输入分类名...',menu:'#mm',searcher:doSearch" plain="true" style="width:300px"

RPM软件包管理的查询功能 转

RPM软件包管理的查询功能: 命令格式 rpm {-q|--query} [select-options] [query-options] RPM的查询功能是极为强大,是极为重要的功能之一:举几个常用的例子,更为详细的具体的,请参考#man rpm 1.对系统中已安装软件的查询: 1)查询系统已安装的软件: 语法:rpm -q 软件名 举例: [[email protected] beinan]# rpm -q gaim gaim-1.3.0-1.fc4 -q就是 --query ,中文意思是“