苍穹报表开发样例

 1: 猪场生产日报

package zb.pc.formplugin.pcsr.pigfarmdaily;

import kd.bos.algo.*;
import kd.bos.algo.input.CollectionInput;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.report.AbstractReportListDataPlugin;
import kd.bos.entity.report.FilterInfo;
import kd.bos.entity.report.ReportQueryParam;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.QueryServiceHelper;
import org.apache.commons.lang3.StringUtils;
import zb.common.constant.PigFieldConstant;
import zb.pc.common.constant.BaseConstant;
import zb.pc.common.constant.ImmediateLiveStockConstant;
import zb.pc.common.constant.ImportSeedRecordConstant;
import zb.pc.common.constant.pbdem.deadrecord.DeadRecordConstant;
import zb.pc.common.constant.pbsm.AbnPregRecordConstant;
import zb.pc.common.constant.pbsm.BirthConstant;
import zb.pc.common.constant.pbsm.MatingRecordConstant;
import zb.pc.common.enums.PigStateEnum;
import zb.pc.common.enums.PigTypeEnum;
import zb.pc.common.utils.DateUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Module:
 * @ClassName: PigfarmDaily
 * @Description: 繁殖报表--猪场生产日报
 * @Author xxx
 * @Date 2022/4/18
 * @Version 1.0
 */
public class PigfarmDailyListDataPlugin extends AbstractReportListDataPlugin {


    @Override
    public DataSet query(ReportQueryParam param, Object o) throws Throwable {
        // 创建一个空的DataSet
        Collection<Object[]> coll = new ArrayList<>();
        //将自定义的字段和类型对应插入
        ArrayList<String> names = PigfarmDailyListDataPlugin.FieldEnum.getNames();
        ArrayList<DataType> types = PigfarmDailyListDataPlugin.FieldEnum.getTypes();
        RowMeta rowMeta = RowMetaFactory.createRowMeta(names.toArray(new String[]{}), types.toArray(new DataType[]{}));
        CollectionInput inputs = new CollectionInput(rowMeta, coll);
        //Algo 创建dataSet
        DataSet resultDataSet = Algo.create(this.getClass().getName()).createDataSet(inputs);
        FilterInfo filterInfo = param.getFilter();
        DynamicObject farm = filterInfo.getDynamicObject("zb_pigfarmfilter");
        Date startDate = filterInfo.getDate("zb_stardate");
        Date endDate = filterInfo.getDate("zb_enddate");
        DynamicObjectCollection fields = QueryServiceHelper.query(PigFieldConstant.FORMBILLID, String.join(",", PigFieldConstant.ID), new QFilter[]{new QFilter(PigFieldConstant.ZB_PIGFARM, QCP.equals, farm.getPkValue())});
        List<Long> fieldId = fields.stream().map(info -> info.getLong(BaseConstant.ID)).collect(Collectors.toList());
        DynamicObjectCollection matingQuery = QueryServiceHelper.query(MatingRecordConstant.FORMBILLID,
                String.join(",", MatingRecordConstant.ENTRYENTITYID_ZB_PB_MATINGRECORD_ET + "." + MatingRecordConstant.MATINGRECORD_ET_ZB_ISHBFEMALE, MatingRecordConstant.ZB_PIGFIELD),
                new QFilter[]{new QFilter(MatingRecordConstant.ZB_PIGFARM, QCP.equals, farm.getPkValue()).and(MatingRecordConstant.ZB_BIZDATE, QCP.large_equals, startDate).and(MatingRecordConstant.ZB_BIZDATE, QCP.less_equals, endDate)});
        Map<Long, Map<Boolean, Long>> matings = matingQuery.stream().filter(Objects::nonNull).
                collect(Collectors.groupingBy(info -> info.getLong(MatingRecordConstant.ZB_PIGFIELD),
                        Collectors.groupingBy(item -> item.getBoolean(MatingRecordConstant.ENTRYENTITYID_ZB_PB_MATINGRECORD_ET + "." + MatingRecordConstant.MATINGRECORD_ET_ZB_ISHBFEMALE),
                                Collectors.counting())));

        DynamicObjectCollection abnQuery = QueryServiceHelper.query(AbnPregRecordConstant.FORMBILLID,
                String.join(",", AbnPregRecordConstant.ENTRYENTITYID_ZB_PB_ABNPREGRECORD_ET + "." + AbnPregRecordConstant.ABNPREGRECORD_ET_ABNREASON, AbnPregRecordConstant.PIGFIELD),
                new QFilter[]{new QFilter(AbnPregRecordConstant.PIGFARM, QCP.equals, farm.getPkValue()).and(AbnPregRecordConstant.BIZDATE, QCP.large_equals, startDate).and(AbnPregRecordConstant.BIZDATE, QCP.less_equals, endDate)});
        Map<Long, Map<Boolean, Long>> abns = abnQuery.stream().filter(Objects::nonNull).
                collect(Collectors.groupingBy(info -> info.getLong(AbnPregRecordConstant.PIGFIELD),
                        Collectors.groupingBy(item -> item.getBoolean(AbnPregRecordConstant.ENTRYENTITYID_ZB_PB_ABNPREGRECORD_ET + "." + AbnPregRecordConstant.ABNPREGRECORD_ET_ABNREASON),
                                Collectors.counting())));

        DynamicObjectCollection birthQuery = QueryServiceHelper.query(BirthConstant.FormBillId, String.join(",",
                        BirthConstant.Totallive, BirthConstant.Totaldith, BirthConstant.Totalmumy, BirthConstant.Totalderm, BirthConstant.EntryEntityId_zb_birth_detail, BirthConstant.Pigfield),
                new QFilter[]{new QFilter(BirthConstant.Pigfarm, QCP.equals, farm.getPkValue()).and(BirthConstant.Bizdate, QCP.large_equals, startDate).and(BirthConstant.Bizdate, QCP.less_equals, endDate)});
        Map<Long, List<DynamicObject>> births = birthQuery.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(info -> info.getLong(BirthConstant.Pigfield)));

        DynamicObjectCollection deadQuery = QueryServiceHelper.query(DeadRecordConstant.FORMBILLID, String.join(",", DeadRecordConstant.ZB_PIGFIELD,
                DeadRecordConstant.ZB_PIGTYPE + ".number"), new QFilter[]{new QFilter(DeadRecordConstant.ZB_PIGFARM, QCP.equals, farm.getPkValue()).and(DeadRecordConstant.ZB_BIZDATE, QCP.large_equals, startDate).and(DeadRecordConstant.ZB_BIZDATE, QCP.less_equals, endDate)});
        Map<Long, Map<String, Long>> deads = deadQuery.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(info -> info.getLong(AbnPregRecordConstant.PIGFIELD),
                Collectors.groupingBy(item -> item.getString(DeadRecordConstant.ZB_PIGTYPE + ".number"),
                        Collectors.counting())));


        DynamicObjectCollection importQuery = QueryServiceHelper.query(ImportSeedRecordConstant.FORMBILLID,
                String.join(",", ImportSeedRecordConstant.ZB_PIGFIELD, ImportSeedRecordConstant.ZB_SOWNO, ImportSeedRecordConstant.ZB_PIGNO),
                new QFilter[]{new QFilter(ImportSeedRecordConstant.ZB_PIGFARM, QCP.equals, farm.getPkValue()).and(ImportSeedRecordConstant.ZB_BIZDATE, QCP.large_equals, startDate).and(ImportSeedRecordConstant.ZB_BIZDATE, QCP.less_equals, endDate)});
        Map<Long, List<DynamicObject>> imports = importQuery.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(info -> info.getLong(ImportSeedRecordConstant.ZB_PIGFIELD)));


        DynamicObjectCollection immeQuery = QueryServiceHelper.query(ImmediateLiveStockConstant.FORMBILLID, String.join(",",
                        ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGFIELD,
                        ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number",
                        ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number",
                        ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY),
                new QFilter[]{new QFilter(ImmediateLiveStockConstant.ZB_PIGFARM, QCP.in, farm.getPkValue()).and(ImmediateLiveStockConstant.ZB_BIZDATE, QCP.equals, DateUtil.getLastDate(endDate))});
        Map<Long, List<DynamicObject>> immes = immeQuery.stream().filter(Objects::nonNull).collect(Collectors.groupingBy(info -> info.getLong(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGFIELD)));

        for (Long field : fieldId) {
            Object[] row = new Object[names.size()];
            row[FieldEnum.PIGFIELD.no] = field;
            row[FieldEnum.PRODUCTION.no] = matings.get(field).get(false);
            row[FieldEnum.RESERVE.no] = matings.get(field).get(true);
            //异常原因  空怀:1  返情:2  流产:3
            row[FieldEnum.KH.no] = abns.get(field).get("1");
            row[FieldEnum.FQ.no] = abns.get(field).get("2");
            row[FieldEnum.LC.no] = abns.get(field).get("3");
            int details = births.get(field).stream().mapToInt(info -> info.getDynamicObjectCollection(BirthConstant.EntryEntityId_zb_birth_detail).size()).sum();
            row[FieldEnum.TOTALSON.no] = details;
            int lives = births.get(field).stream().mapToInt(info -> info.getInt(BirthConstant.Totallive)).sum();
            row[FieldEnum.TOTALLIVE.no] = lives;
            row[FieldEnum.TOTALDITH.no] = births.get(field).stream().mapToInt(info -> info.getInt(BirthConstant.Totaldith)).sum();
            row[FieldEnum.TOTALMUMY.no] = births.get(field).stream().mapToInt(info -> info.getInt(BirthConstant.Totalmumy)).sum();
            row[FieldEnum.TOTALDERM.no] = births.get(field).stream().mapToInt(info -> info.getInt(BirthConstant.Totalderm)).sum();
            row[FieldEnum.QUALIFIED.no] = details == 0 ? 0 : new BigDecimal(lives).divide(new BigDecimal(details), 3, RoundingMode.HALF_UP);
            row[FieldEnum.LACTATION.no] = deads.get(field).get(PigTypeEnum.PIGLETS.getValue());
            row[FieldEnum.CONSERVATION.no] = deads.get(field).get(PigTypeEnum.CONSERVATION.getValue());
            row[FieldEnum.FATTEN.no] = deads.get(field).get(PigTypeEnum.FATTENPIG.getValue());
            row[FieldEnum.PRODUCTINGSOW.no] = deads.get(field).get(PigTypeEnum.PRODUCTION_SOW.getValue());
            row[FieldEnum.RESERVESOW.no] = deads.get(field).get(PigTypeEnum.BACKUP_SOW.getValue());
            row[FieldEnum.PRODUCTIONBOAR.no] = deads.get(field).get(PigTypeEnum.PRODUCTION_BOAR.getValue());
            row[FieldEnum.RESERVEBOAR.no] = deads.get(field).get(PigTypeEnum.BACKUP_BOAR.getValue());

            row[FieldEnum.INTRODUCTION.no] = imports.get(field).stream().mapToInt(info -> info.getInt(ImportSeedRecordConstant.ZB_SOWNO) + info.getInt(ImportSeedRecordConstant.ZB_PIGNO)).sum();

            row[FieldEnum.LIVESTOCKCOUNT.no] = immes.get(field).stream().
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKLACTATION.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number"), PigTypeEnum.PIGLETS.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKCONSERVATION.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number"), PigTypeEnum.CONSERVATION.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKFATTEN.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number"), PigTypeEnum.FATTENPIG.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKPR.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number"), PigStateEnum.BR.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKKD.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number"), PigStateEnum.KHWP.getValue()) ||
                            StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number"), PigStateEnum.DNWP.getValue()) ||
                            StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number"), PigStateEnum.LCWP.getValue()) ||
                            StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number"), PigStateEnum.FQWP.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKHY.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGSTATE + ".number"), PigStateEnum.HY.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKPRO.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number"), PigTypeEnum.PRODUCTION_BOAR.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKPRORESERVESW.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number"), PigTypeEnum.BACKUP_SOW.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
            row[FieldEnum.LIVESTOCKPRORESERVEBO.no] = immes.get(field).stream().
                    filter(info -> StringUtils.equals(info.getString(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_PIGTYPE + ".number"), PigTypeEnum.BACKUP_BOAR.getValue())).
                    mapToInt(info -> info.getInt(ImmediateLiveStockConstant.ENTRYENTITYID_ZB_LIVESTOCK + "." + ImmediateLiveStockConstant.ZB_LIVESTOCK_ZB_QUANTITY)).sum();
        }

        return resultDataSet;
    }

    enum FieldEnum {
        PIGFIELD("zb_pigfield", DataType.LongType, 0),
        PRODUCTION("zb_production", DataType.IntegerType, 1),
        RESERVE("zb_reserve", DataType.IntegerType, 2),
        KH("zb_kh", DataType.IntegerType, 3),
        FQ("zb_fq", DataType.IntegerType, 4),
        LC("zb_lc", DataType.IntegerType, 5),
        TOTALSON("zb_totalson", DataType.IntegerType, 6),
        TOTALLIVE("zb_totallive", DataType.IntegerType, 7),
        TOTALDITH("zb_totaldith", DataType.IntegerType, 8),
        TOTALMUMY("zb_totalmumy", DataType.IntegerType, 9),
        TOTALDERM("zb_totalderm", DataType.IntegerType, 10),
        QUALIFIED("zb_qualified", DataType.IntegerType, 11),
        LACTATION("zb_lactation", DataType.IntegerType, 12),
        CONSERVATION("zb_conservation", DataType.IntegerType, 13),
        FATTEN("zb_fatten", DataType.IntegerType, 14),
        PRODUCTINGSOW("zb_productingsow", DataType.IntegerType, 15),
        RESERVESOW("zb_reservesow", DataType.IntegerType, 16),
        PRODUCTIONBOAR("zb_productionboar", DataType.IntegerType, 17),
        RESERVEBOAR("zb_reserveboar", DataType.IntegerType, 18),
        FAT("zb_fat", DataType.IntegerType, 19),
        FATCOUNT("zb_fatcount", DataType.IntegerType, 20),
        BREEDING("zb_breeding", DataType.IntegerType, 21),
        BREEDINGCOUNT("zb_breedingcount", DataType.IntegerType, 22),
        PIGLET("zb_piglet", DataType.IntegerType, 23),
        PIGLETCOUNT("zb_pigletcount", DataType.IntegerType, 24),
        RESERVES("zb_reserves", DataType.IntegerType, 25),
        RESERVESCOUNT("zb_reservescount", DataType.IntegerType, 26),
        PRODUCTIONS("zb_productions", DataType.IntegerType, 27),
        PRODUCTIONSCOUNT("zb_productionscount", DataType.IntegerType, 28),
        INTRODUCTION("zb_introduction", DataType.IntegerType, 29),
        PIGLETS("zb_piglets", DataType.IntegerType, 30),
        LIVESTOCKCOUNT("zb_livestockcount", DataType.IntegerType, 31),
        LIVESTOCKLACTATION("zb_livestocklactation", DataType.IntegerType, 32),
        LIVESTOCKCONSERVATION("zb_livestockconservation", DataType.IntegerType, 33),
        LIVESTOCKFATTEN("zb_livestockfatten", DataType.IntegerType, 34),
        LIVESTOCKPR("zb_livestockpr", DataType.IntegerType, 35),
        LIVESTOCKKD("zb_livestockkd", DataType.IntegerType, 36),
        LIVESTOCKHY("zb_livestockhy", DataType.IntegerType, 37),
        LIVESTOCKPRO("zb_livestockpro", DataType.IntegerType, 38),
        LIVESTOCKPRORESERVESW("zb_livestockproreservesw", DataType.IntegerType, 39),
        LIVESTOCKPRORESERVEBO("zb_livestockproreservebo", DataType.IntegerType, 40);

        private String name;
        private DataType type;
        private Integer no;

        FieldEnum(String name, DataType type, Integer no) {
            this.name = name;
            this.type = type;
            this.no = no;
        }

        private static ArrayList<String> getNames() {
            PigfarmDailyListDataPlugin.FieldEnum[] fieldEnums = values();
            ArrayList<String> list = new ArrayList();
            for (int i = 0; i < fieldEnums.length; i++) {
                list.add(fieldEnums[i].name);
            }
            return list;
        }

        private static ArrayList<DataType> getTypes() {
            PigfarmDailyListDataPlugin.FieldEnum[] fieldEnums = values();
            ArrayList<DataType> list = new ArrayList();
            for (int i = 0; i < fieldEnums.length; i++) {
                list.add(fieldEnums[i].type);
            }
            return list;
        }
    }
}

2:繁殖用电明细
package zb.pc.formplugin.pcem.report.useeldetail;

import kd.bos.algo.*;
import kd.bos.algo.input.CollectionInput;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.ObjectUtils;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.report.AbstractReportColumn;
import kd.bos.entity.report.AbstractReportListDataPlugin;
import kd.bos.entity.report.FilterInfo;
import kd.bos.entity.report.ReportQueryParam;
import zb.common.enums.DBRouteEnum;

import java.util.*;

/**
 * @Description: 正邦报表-繁殖综合-繁殖用电明细
 * @Author xxx
 * @Date 2022/5/26
 */
public class UseElDetailReportListPlugin extends AbstractReportListDataPlugin {

    //报表的自定义字段,必须和表报中的标识名一一对应
    private static final String[] fieldNames = {"zb_area", "zb_monthlivestock", "zb_nowstock", "zb_ammeternum", "zb_electrovalence"
            ,"zb_quota", "zb_superquota", "zb_taotal", "zb_oneweek", "zb_towweek"
            ,"zb_threeweek", "zb_fourweek"};
    //报表列表上所有字段对应的数据类型,必须和FIELDS中的元素一一对应
    private static final DataType[] dataTypes = {DataType.StringType, DataType.DoubleType, DataType.DoubleType, DataType.IntegerType, DataType.DoubleType
            ,DataType.DoubleType, DataType.DoubleType, DataType.DoubleType, DataType.DoubleType, DataType.DoubleType
            ,DataType.DoubleType, DataType.DoubleType};


    /**
     * 报表查询方法
     * @param reportQueryParam
     * @param o
     * @return
     * @throws Throwable
     */
    @Override
    public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {
        DataSet resultDataSet = null;
        Collection<Object[]> coll = new ArrayList<>();
        RowMeta  rowMeta= RowMetaFactory.createRowMeta(fieldNames, dataTypes);

        FilterInfo filter = reportQueryParam.getFilter();
        DynamicObject pigFarm = filter.getDynamicObject("zb_pigfarmfilter");
        Date month = filter.getDate("zb_datemonth");
        Date startDate = null;
        Date endDate = null;

        if(ObjectUtils.isEmpty(month)){
            coll = null;
        }else{
            StringBuffer sql = new StringBuffer();
            sql.append("/*dialect*/ \n");
            sql.append("SELECT temp.fk_zb_pigfarmid \n");
            sql.append("       ,temp.fk_zb_listareaid \n");
            sql.append("       ,temp.qty qty \n");
            sql.append("       ,nvl(d.fk_zb_electprice, 0) electprice \n");
            sql.append("\t\t\t ,e.fname areaname \n");
            sql.append(" \n");
            sql.append("FROM ( \n");
            sql.append("  SELECT DISTINCT a.fk_zb_pigfarmid,c.fk_zb_listareaid,COUNT(c.fk_zb_listareaid) qty \n");
            sql.append("  FROM yzpc.tk_zb_pc_hydropowerrecord a \n");
            sql.append("  INNER JOIN yzpc.tk_zb_pc_electricentry b ON a.fid=b.fid \n");
            sql.append("  INNER JOIN yzpc.tk_zb_pc_electtable c ON b.fk_zb_electric=c.fid \n");
            sql.append("\tAND c.fstatus='C' AND c.fenable=1 \n");
            sql.append("\tWHERE a.fbillstatus='C' \n");
            sql.append("\tAND a.fk_zb_pigfarmid='560583063785050245' \n");
            sql.append("  GROUP BY a.fk_zb_pigfarmid,c.fk_zb_listareaid \n");
            sql.append(") temp \n");
            sql.append("LEFT JOIN yzpc.tk_zb_pc_pigfarm d ON d.fid=temp.fk_zb_pigfarmid \n");
            sql.append("LEFT JOIN yzpc.tk_zb_pc_areaarchives_l e ON e.fid=temp.fk_zb_listareaid AND e.flocaleid='zh_CN' \n");

            Collection<Object[]> sqlData = DB.query(DBRoute.of(DBRouteEnum.PC.getValue()), sql.toString(), rs -> {
                Collection<Object[]> tempColl = new ArrayList<>();
                while (rs.next()) {
                    Object[] rowData = new Object[fieldNames.length];
                    rowData[0]=rs.getString("areaname"); //区域
                    rowData[3]=rs.getString("qty"); //电表个数
                    rowData[4]=rs.getString("electprice"); //电价
                    tempColl.add(rowData);
                }
                return tempColl;
            });
            coll = sqlData;
        }


        CollectionInput input = new CollectionInput(rowMeta, coll);
        resultDataSet= Algo.create(this.getClass().getName()).createDataSet(input);
        return resultDataSet;
    }

    /**
     * 改变列信息
     * @param columns
     * @return
     * @throws Throwable
     */
    @Override
    public List<AbstractReportColumn> getColumns(List<AbstractReportColumn> columns) throws Throwable {
        return super.getColumns(columns);
    }

    /**
     * 设置进度,用于异步查询时界面显示进度
     * @param percent
     */
    @Override
    public void setProgress(int percent) {
        super.setProgress(percent);
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值