码迷,mamicode.com
首页 > 其他好文 > 详细

让你写的代码“说话”

时间:2016-01-22 13:54:36      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

方法很简单: 按功能点用空行隔开。下面的注释我不会加,写上只是说明我的观点。什么时候加注释:你对所在公司有好的期望,敷衍公司的规定。    

//方法的命名一定要用英文,别说英文不行,下个有道或什么的工具,如果是一个项目,建议开工前搞一个面向领域的词汇集,就算意
//义不是很明确也比汉语拼音的简写强百倍。
public String batch_pay() throws DbException
    {
//这两句话代码要对字符串数组处理,一个功能点
            String[] fybxdh =  this.getParameterValues("fybxdh");
            String[] ss = fybxdh[0].replaceAll("\‘|\\[|\\]", "").split(",");
   //这两点话表示产生当前日期的格式化字符串 ,刚开始我把这两句话放到第二个循环中,如果数据量巨大,不断地new ,
//影响程序性能 ,为了程序阅读方便,其实这两句应该移到第二个for之前。       
            SimpleDateFormat formatter = new SimpleDateFormat ("yyyy/MM/dd");
            String date_bxrq = formatter.format(new Date());
              //循环表示对上面的字符串数组进行迭代处理   
            for(int i = 0; i < ss.length; i++)
            {
                 String select_dqzt = "select t.dqzt  from SBXT_YWCL_B_FYBX_BXMXB t where   t.FYBXDH = ‘"+ ss[i] +"‘";
                 Result rs = sqlSession._sqlQuery(select_dqzt);
                 rs.next();
                 String dqzt = rs.getString("dqzt");
                   //对当前状态判断,如果有杂质,返回去重新去选。             
                 if(dqzt.equals("支付") )
                 {
                        return "您选择的报销单中有已支付状态的选项,请重新选择!";
                 }
            }

//程序到这里,已经没有杂质了,可以进行数据库操作。以下这个循环我现在怀疑会产生数据异常,是否在一个事务中呢?
            for(int i = 0; i < ss.length; i++)
            {
               
                String update_bx_sql = "UPDATE SBXT_YWCL_B_FYBX_BXMXB SET dqzt = ‘支付‘, bxrq = to_date(‘"+date_bxrq+"‘, ‘yyyy/mm/dd‘)  " +
                                       "WHERE fybxdh IN (" +
                                                 "SELECT T.fybxdh\n" +
                                                 "FROM (SELECT T.FYBXDH, T.KHYH\n" +
                                                       "FROM SBXT_YWCL_B_FYBX_BXMXB T, SBXT_XTGL_B_JBXX_CBRJBXXB T1\n" +
                                                       "WHERE T.BXXMBM = ‘003‘\n" +
                                                       "AND T.FYBXDH = ‘"+ ss[i] +"‘" +
                                                       "AND T1.CBRID = T.CBRID) T)";
               String update_zf_sql = "UPDATE SBXT_YWCL_B_FYBX_zfMXB SET dqzt=‘支付‘ WHERE fyzfdh IN (SELECT T.fybxdh\n" +
                                   "  FROM (SELECT T.FYBXDH, T.KHYH\n" +
                                   "                 FROM SBXT_YWCL_B_FYBX_BXMXB T, SBXT_XTGL_B_JBXX_CBRJBXXB T1\n" +
                                   "                 WHERE T.BXXMBM = ‘003‘\n" +
                                   "                 AND T.FYBXDH = ‘"+ ss[i] +"‘" + 
                                   "                 AND T1.CBRID = T.CBRID) T\n" +
                                   ")";
       
               int result = sqlSession._sqlUpdate(update_bx_sql);
               result = sqlSession._sqlUpdate(update_zf_sql);
           }
           //返回处理的结果
           if(ss.length > 0)
           {
               return "成功支付"+ss.length+"个报销单!";
           }else
           {
               return "没有要支付的报销单!";
           }
    }   

让你写的代码“说话”

标签:

原文地址:http://www.cnblogs.com/herosoft/p/5150723.html

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