CwjyServiceImpl.java 4.33 KB
package com.bsth.service.oil.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsth.common.ResponseCode;
import com.bsth.entity.oil.Cwjy;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.repository.oil.CwjyRepository;
import com.bsth.repository.oil.YlxxbRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.oil.CwjyService;
import com.bsth.util.PageHelper;
import com.bsth.util.PageObject;

@Service
public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements CwjyService
{
	@Autowired
	CwjyRepository repository;
	@Autowired
	YlxxbRepository ylxxbRepository;
	
	@SuppressWarnings("unchecked")
	public PageObject<Ylxxb> Pagequery(Map<String, Object> map) {
		// TODO Auto-generated method stub
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		List<Ylxxb> yList=new ArrayList<Ylxxb>();
		String rq=map.get("rq").toString();
		String nbbm="";
		if(map.get("nbbm")!=null){
			nbbm=map.get("nbbm").toString();
		}
		List<Object[]> list=repository.obtainCwjycl(rq,nbbm);
		for (int i = 0; i < list.size(); i++) {
			Ylxxb y=new Ylxxb();
			y.setGsdm(list.get(i)[0]==null?"":list.get(i)[0].toString());
			y.setNbbm(list.get(i)[1]==null?"":list.get(i)[1].toString());
			y.setJsy(list.get(i)[2]==null?"":list.get(i)[2].toString());
			y.setJzl(list.get(i)[3]==null?0.0:Double.parseDouble(list.get(i)[3].toString()));
			y.setStationid(list.get(i)[4]==null?"":list.get(i)[4].toString());
			y.setNylx(list.get(i)[5]==null?0:Integer.parseInt(list.get(i)[5].toString()));
			y.setYj(list.get(i)[6]==null?0.0:Double.parseDouble(list.get(i)[6].toString()));
			y.setBz(list.get(i)[7]==null?"":list.get(i)[7].toString());
			y.setLdgh(list.get(i)[8]==null?"":list.get(i)[8].toString());
			try {
				y.setYyrq(sdf.parse(rq));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			yList.add(y);
		}
		PageHelper pageHelper = new PageHelper(yList.size(), map);
		pageHelper.getMap();
		PageObject<Ylxxb> pageObject=pageHelper.getPageObject();
		pageObject.setDataList(yList);
		return pageObject;
	}

	@Override
	public Ylxxb bynbbm(Map<String, Object> map) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String rq = map.get("rq").toString();
		String nbbm = "";
		if (map.get("nbbm") != null) {
			nbbm = map.get("nbbm").toString();
		}
		List<Object[]> list = repository.obtainCwjycl(rq, nbbm);
		Ylxxb y = new Ylxxb();
		if (list.size() > 0) {
			y.setGsdm(list.get(0)[0] == null ? "" : list.get(0)[0].toString());
			y.setNbbm(list.get(0)[1] == null ? "" : list.get(0)[1].toString());
			y.setJsy(list.get(0)[2] == null ? "" : list.get(0)[2].toString());
			y.setJzl(list.get(0)[3] == null ? 0.0 : Double.parseDouble(list.get(0)[3].toString()));
			y.setStationid(list.get(0)[4] == null ? "" : list.get(0)[4].toString());
			y.setNylx(list.get(0)[5] == null ? 0 : Integer.parseInt(list.get(0)[5].toString()));
			y.setYj(list.get(0)[6] == null ? 0.0 : Double.parseDouble(list.get(0)[6].toString()));
			y.setBz(list.get(0)[7] == null ? "" : list.get(0)[7].toString());
			y.setLdgh(list.get(0)[8] == null ? "" : list.get(0)[8].toString());
			try {
				y.setYyrq(sdf.parse(rq));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return y;
	}

	@Override
	public Map<String, Object> savejzl(Ylxxb t) {
		// TODO Auto-generated method stub
		Map<String, Object> map=new HashMap<String,Object>();
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String rq = sdf.format(t.getYyrq());
			String nbbm=t.getNbbm();
			List<Ylxxb> yList=ylxxbRepository.obtainYlxx2(rq,nbbm);
			if(yList.size()>0){
				t.setId(yList.get(0).getId());
				ylxxbRepository.save(t);
			}else{
				ylxxbRepository.save(t);
			}
			map.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			map.put("status", ResponseCode.ERROR);
			e.printStackTrace();
			// TODO: handle exception
		}
		return map;
	}

}