xiejun
2023-08-02 8b34692ac1b7cf58a1e1ead92b930d9acb9f86f6
Source/UBCS/ubcs-codeApply/src/main/java/com/vci/ubcs/codeapply/AttarSearchPanel.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,163 @@
package com.vci.ubcs.codeapply;
import com.vci.base.ui.swing.VCISwingUtil;
import com.vci.base.ui.swing.components.VCIJButton;
import com.vci.base.ui.swing.components.VCIJLabel;
import com.vci.base.ui.swing.components.VCIJPanel;
import com.vci.base.ui.swing.components.VCIJTextField;
import com.vci.ubcs.code.vo.webserviceModel.coderule.CodeShowFieldConfigVO;
import com.vci.ubcs.codeapply.object.UIFormRefer;
import org.apache.commons.collections4.CollectionUtils;
import java.awt.*;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
public class attarSearchPanel extends VCIJPanel {
   private LinkedHashMap<String , VCIJTextField> attrInerNameValMap = new LinkedHashMap<String,VCIJTextField>();
   private UIFormRefer uiFormRefer;
   public attarSearchPanel(UIFormRefer uiFormRefer){
      this.uiFormRefer = uiFormRefer;
      init();
   }
   private void init(){
      initcomponam();
   }
   private void initcomponam(){
      this.setLayout(new GridBagLayout());
      setAttrSearch();
      this.setVisible(true);
   }
   /**
    *
    * <p>把基本属性信息初始化到组件上面。并保存属性到Map(属性内部名称--textField)中</p>
    *
    * @time 2013-3-17
    */
   private void setAttrSearch(){
      List<CodeShowFieldConfigVO> codeShowFieldConfigVOS=this.uiFormRefer.getCodeShowFieldConfigVOS();
      if(!CollectionUtils.isEmpty(codeShowFieldConfigVOS)){
         CodeShowFieldConfigVO[] objs=codeShowFieldConfigVOS.toArray(new CodeShowFieldConfigVO []{});
         GridBagConstraints cons = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.EAST , GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
         for(int i = 0 ;i<objs.length;i++){
            if(cons.gridx  == 1 ){
               cons.gridwidth = GridBagConstraints.REMAINDER;
               cons.anchor = GridBagConstraints.WEST;
            }else if(cons.gridx >1){
               cons.gridx = 0;
               cons.anchor = GridBagConstraints.EAST;
               cons.gridy++;
               cons.gridwidth = 1;
            }
            VCIJPanel oneSearch = new VCIJPanel();
            oneSearch.setLayout(new FlowLayout(FlowLayout.RIGHT));
            String attrName = objs[i].getTitle();
            VCIJLabel attarLabel = new VCIJLabel(attrName+":");
            VCIJTextField attrText = new VCIJTextField("");
            attrInerNameValMap.put(objs[i].getField(), attrText);
            attrText.setPreferredSize(new Dimension(300, 30));
            oneSearch.add(attarLabel);
            oneSearch.add(attrText);
            cons.gridx++;
            this.add(oneSearch,cons);
         }
      }
   }
   /**
    *
    * <p>返回各个属性经过拼接后的查询SQL语句</p>
    *
    * @time 2013-3-17
    * @return
    */
   public  String getAttrSearchFilterString(){
      String result = "";
      StringBuilder sql  = new StringBuilder();
      Set<String> keys = attrInerNameValMap.keySet();
      for (Iterator it = keys.iterator(); it.hasNext();) {
         String key = (String)it.next();
         VCIJTextField textField =    attrInerNameValMap.get(key);
         String message = textField.getText().replaceAll(" ", "").trim();
         if(message.equals("")) continue;
         String text = getTextQueryVal(message);
         sql.append(" "+key+" ");
         sql.append("  like ");
         sql.append("'"+text+"'");
         sql.append(" and");
      }
      if(sql.length() != 0){
         result =  sql.substring(0, sql.lastIndexOf("and"));
      }
      return result;
   }
   /**
    *
    * <p>根据文本框输入内容,构造查询条件。
    *    è¿‡è™‘结果: 1、当内容是 ä»¥*开头,如'*abc',则返回内容"%abc";
    *          2、当内容以*结束,如"abc*",则返回内容"abc%";
    *          3、当内容中间包含*,如"abc*def",则返回内容"abc%def";
    *          4、输入的内容如果是空,则返回"%"
    *          5、其他情况均返回内容本身
    * </p>
    * @time 2013-3-17
    * @param text
    * @return
    */
   private String getTextQueryVal(String text){
      if(text.equals("")){
         return "%";
      }
      StringBuilder result = new StringBuilder();
      // update by xchao 2013.05.21 begin
      // æ”¯æŒæ›´çµæ´»çš„æœç´¢
      // ä¸»æ€æƒ³æŽ§åˆ¶é€»è¾‘
      // 1、将输入的条件中的*替换为%,XXX*XXX-> XXX%XXX
      // 2、如果输入的条件不包含*,则在条件的前后都加上%,以完成全模糊,'%XXX%'
      // 3、前面不输入*、后面不输入*与之前一致
      //    å³ï¼šå‰é¢ä¸åŒ…含*,则表明查询的是‘以XXX开头’的数据,'XXX%'
      //       åŽé¢ä¸åŒ…含*,则表面查询的是‘以XXX结束’的数据,'%XXX'
      // 4、
      if(text.indexOf("*") >= 0){
//         result.append(text.replace("*", "%"));
         // ä¸‹å¥å¯ä»¥æ”¯æŒä¸­é—´*
         result.append("%").append(text.replace("*", "%")).append("%");
      } else {
         result.append("%").append(text).append("%");
      }
      // update by xchao 2013.05.21 end
//      int midel = text.lastIndexOf("*");
//      if(text.startsWith("*")){
//         result.append("%");
//         result.append(text.substring(1));
//      }else if(text.endsWith("*")){
//         result.append(text.substring(0, text.length()-1));
//         result.append("%");
//      }else if(midel > 0){
//         String before = text.substring(0, midel);
//         result.append(before);
//         result.append("%");
//         String after = text.substring(midel+1);
//         result.append(after);
//      }else{
//         result.append(text);
//      }
      return result.toString();
   }
   public void clear(){
      Set<String> keys = attrInerNameValMap.keySet();
      for (Iterator it = keys.iterator(); it.hasNext();) {
         String key = (String)it.next();
         VCIJTextField textField =    attrInerNameValMap.get(key);
         textField.setText("");
      }
   }
}