public List<CpmlFxbPz> findByYearAndMonth(Integer year,Integer month){
Criteria criteria = cpmlFxbPzDao.createCriteria();
criteria.add(Restrictions.eq("year", year));
criteria.add(Restrictions.eq("month", month));
List<CpmlFxbPz> list = cpmlFxbPzDao.findByCriteria(criteria);
return list;
}
public void saveOrUpdate(Tabledata tabledata) throws Exception {
Integer year = tabledata.getYear();
Integer month = tabledata.getMonth();
List<YycbPz> yycbPzList = tabledata.getYycbPzList();//营业成本
List<YysrPz> yysrPzList = tabledata.getYysrPzList();//营业收入
List<CpmlFxbPz> cpmlFxbPzList = tabledata.getCpmlFxbPzList();//毛利分析表,毛利=营业收入-营业成本
if(!cpmlFxbPzList.isEmpty()){
for (CpmlFxbPz cpmlFxbPz : cpmlFxbPzList) {
if(cpmlFxbPz.getIsUpload()==null||!cpmlFxbPz.getIsUpload()){
cpmlFxbPzDao.delete(cpmlFxbPz);
}
}
}
Map<String,Object> map = new HashMap<String,Object>();
for (YycbPz yycbPz : yycbPzList) { //选一张表为主,将字段存在map中
String cppz=yycbPz.getCppz();
Double yycb=yycbPz.getValue();
map.put(cppz, yycb);
}
for (YysrPz yysrPz : yysrPzList) { //再将map对象和list对象进行操作。
String cppz=yysrPz.getCppz();
Double yysr=yysrPz.getValue();
Double cpml=0.0;
Double yycb=0.0;
if(map.get(cppz)!=null){
yycb=(Double) map.get(cppz);
}
cpml=yysr-yycb;
map.put(cppz, cpml);
}
ArrayList<CpmlFxbPz> list = new ArrayList<CpmlFxbPz>();
for (String cppz : map.keySet()) {
Double cpml = (Double) map.get(cppz);
CpmlFxbPz cpmlfxbPz = new CpmlFxbPz();
cpmlfxbPz.setCpml(cpml);
cpmlfxbPz.setCppz(cppz);
cpmlfxbPz.setYear(year);
cpmlfxbPz.setMonth(month);
cpmlfxbPz.setVersion(100);
cpmlfxbPz.setIsUpload(false);
cpmlfxbPz.setCreateDate(new Date());
cpmlfxbPz.setTabledata(tabledata);
cpmlFxbPzDao.saveOrUpdate(cpmlfxbPz);
list.add(cpmlfxbPz);
}
tabledata.setCpmlFxbPzList(list);
}