条件查询List集合,由查询的结果,算出一行数据,添加到集合中!

版权声明:本文为博主原创文章,请尊重劳动成果以及产权,转载请注明出处:初生的萌芽,网址:文章链接! https://blog.csdn.net/baidu_34046383/article/details/52247655
BigDecimal  reshuijin_qichu =new BigDecimal("0");
BigDecimal reshuijin_qimo = new BigDecimal("0");
BigDecimal reshuichu_qichu = new BigDecimal("0");
BigDecimal reshuichu_qimo = new BigDecimal("0");
BigDecimal danjia = new BigDecimal("0");  //热水进单价
String address = "";
boolean reshui_flg = false;


for(int i=0;i<houseListTmp.size();i++){
HouseDataBean housedata=new HouseDataBean();
housedata.setAddress(houseListTmp.get(i).getAddress());

//当地址不同要计算热水使用量
if(!address.equals(houseListTmp.get(i).getAddress())) {
if(i > 0 && reshui_flg){
housedata.setAddress(address);    //金额小计
//计算上一个address对应的用水量
housedata.setQichu_val(reshuijin_qichu.subtract(reshuichu_qichu).toString());  //期初值
housedata.setQimo_val(reshuijin_qimo.subtract(reshuichu_qimo).toString());   //期末值


BigDecimal zongliang=new BigDecimal("0");
zongliang=reshuijin_qimo.subtract(reshuichu_qimo).subtract(reshuijin_qichu.subtract(reshuichu_qichu));
housedata.setZongliang(zongliang.toString());
housedata.setPrice(danjia.toString());   //单价
housedata.setJine(danjia.multiply(zongliang).toString());    //金额小计

housedata.setName("热水量");
housedata.setComid("");
housedata.setQichu_sj("");
housedata.setQimo_sj("");
houseList.add(housedata);

//default
reshuijin_qichu =new BigDecimal("0");
reshuijin_qimo = new BigDecimal("0");
reshuichu_qichu = new BigDecimal("0");
reshuichu_qimo = new BigDecimal("0");
danjia = new BigDecimal("0");
reshui_flg = false;
}
}
address=houseListTmp.get(i).getAddress();

if("1".equals(houseListTmp.get(i).getInout_flg())) {
//热水进期初期末值
if(houseListTmp.get(i).getQichu_val()!=null && houseListTmp.get(i).getQichu_val()!=""){
reshuijin_qichu =new BigDecimal(houseListTmp.get(i).getQichu_val());
}else{
reshuijin_qichu =new BigDecimal("0");
}
if(houseListTmp.get(i).getQimo_val()!=null && houseListTmp.get(i).getQimo_val()!=""){
reshuijin_qimo = new BigDecimal(houseListTmp.get(i).getQimo_val());
}else{
reshuijin_qimo = new BigDecimal("0");
}
if(houseListTmp.get(i).getPrice()!=null & houseListTmp.get(i).getPrice()!=""){
danjia = new BigDecimal(houseListTmp.get(i).getPrice());  //热水进单价
}else{
danjia = new BigDecimal("");  //热水进单价
}
reshui_flg = true;
}
if("2".equals(houseListTmp.get(i).getInout_flg())) {
//热水出期初期末值
if(houseListTmp.get(i).getQichu_val()!=null && houseListTmp.get(i).getQichu_val()!=""){
reshuichu_qichu =new BigDecimal(houseListTmp.get(i).getQichu_val());
}else{
reshuichu_qichu =new BigDecimal(houseListTmp.get(i).getQichu_val());
}
if(houseListTmp.get(i).getQimo_val()!=null && houseListTmp.get(i).getQimo_val()!=""){
reshuichu_qimo = new BigDecimal(houseListTmp.get(i).getQimo_val());
}else{
reshuichu_qimo = new BigDecimal("0");
}
reshui_flg = true;
}
//限制总用量的长度    33.41000000000015   33.41
String zl=houseListTmp.get(i).getZongliang();   //12.1200000000015
int dhindex=-1;
if(zl!=null && zl!=""){
dhindex=zl.indexOf(".");
if(dhindex!=-1){  
//String zlvalue=zl.substring(dhindex);   //.1200000000015
//if(zlvalue.length()>3){
houseListTmp.get(i).setZongliang(zl.substring(0, dhindex+3));
//}
}
}
//限制金额小计的长度  22.260000000015  22.26
String jexj=houseListTmp.get(i).getJine();
if(jexj!=null && jexj!=""){
dhindex=jexj.indexOf(".");
if(dhindex!=-1){
//String jexjvalue=jexj.substring(dhindex);
//if(jexjvalue.length()>3){
houseListTmp.get(i).setJine(jexj.substring(0,dhindex+3));
//}
}
}
//限制期末时间的长度
String qimo_sj=houseListTmp.get(i).getQimo_sj();
if(qimo_sj!=null && qimo_sj!=""){
if(qimo_sj.length()>19){
houseListTmp.get(i).setQimo_sj(qimo_sj.substring(0,19));
}
}
//限制期初时间的长度
String qichu_sj=houseListTmp.get(i).getQichu_sj();
if(qichu_sj!=null && qichu_sj!=""){
if(qichu_sj.length()>19){
houseListTmp.get(i).setQichu_sj(qichu_sj.substring(0,19));
}
}
houseList.add(houseListTmp.get(i));
//最后一行
if(i == houseListTmp.size()-1 && reshui_flg){
housedata=new HouseDataBean();
housedata.setAddress(address);    //金额小计
//计算上一个address对应的用水量
housedata.setQichu_val(reshuijin_qichu.subtract(reshuichu_qichu).toString());  //期初值
housedata.setQimo_val(reshuijin_qimo.subtract(reshuichu_qimo).toString());   //期末值


BigDecimal zongliang=new BigDecimal("0");
zongliang=reshuijin_qimo.subtract(reshuichu_qimo).subtract(reshuijin_qichu.subtract(reshuichu_qichu));
housedata.setZongliang(zongliang.toString());
housedata.setPrice(danjia.toString());   //单价
housedata.setJine(danjia.multiply(zongliang).toString());    //金额小计

housedata.setName("热水量");
housedata.setComid("");
housedata.setQichu_sj("");
housedata.setQimo_sj("");
houseList.add(housedata);
}
}
展开阅读全文

没有更多推荐了,返回首页