javaGroup

 

public List<IpnorsDetailKkbhSM> getSisakuAndKkbhInfos(IpnorsDetailRegistSearchSM ipnorsDetailRegistSearchSM){

 

        AsdUser user = SecurityUtils.getLoggedInUser();

 

        // 3次店で販売店情報を取得する

        CmsSryHanbaiTenCustomParameter cmsSryHanbaiTenCustomParameter = new CmsSryHanbaiTenCustomParameter();

        // チャネルコード

        cmsSryHanbaiTenCustomParameter.setHanbaiTenChannelCd(ipnorsDetailRegistSearchSM.getHanbaiTenChannelCd());

        // 社員コード

        cmsSryHanbaiTenCustomParameter.setShainCd(user.getShainCd());

        // 3次店コード

        cmsSryHanbaiTenCustomParameter.setHanbaiTenSry3JitenInCd(ipnorsDetailRegistSearchSM.getSanjiTenCd());

        // 1次店コード

        cmsSryHanbaiTenCustomParameter.setHanbaiTenSry1JitenInCd(ipnorsDetailRegistSearchSM.getIchijiTenCd());

        List<CmsSryHanbaiTenDM> cmsSryHanbaiTenDMList = cmsSryHanbaiTenCustomDAO.getHanbaitenBySanjitenInfo(cmsSryHanbaiTenCustomParameter);

        Map<String, CmsSryHanbaiTenDM> hanbaitenMap = new HashMap<String, CmsSryHanbaiTenDM>();

        for (CmsSryHanbaiTenDM dm : cmsSryHanbaiTenDMList) {

            hanbaitenMap.put(dm.getHanbaiTenCd(), dm);

        }

        Map<String, CmsSryHanbaiTenDM> hanbaitenMapSorted = new TreeMap<String, CmsSryHanbaiTenDM>(hanbaitenMap);

        Iterator<String> hanbaitenCds = hanbaitenMapSorted.keySet().iterator();

        List<String> hanbaitenCdList = new ArrayList<String>();

        while (hanbaitenCds.hasNext()) {

            hanbaitenCdList.add(hanbaitenCds.next());

        }

 

        // 引数値を生成する

        CtrKkbhDMParameter ctrKkbhDMParameter = new CtrKkbhDMParameter();

        ctrKkbhDMParameter.setHeadNhkShoNo(ipnorsDetailRegistSearchSM.getNhkShoNo());

        ctrKkbhDMParameter.setMhkShoNo(ipnorsDetailRegistSearchSM.getMhkShoNo());

        ctrKkbhDMParameter.setCoCd(user.getCoCd());

 

        List<IpnorsDetailKkbhSM> result = new ArrayList<IpnorsDetailKkbhSM>();

 

        // 月次販売計画書番号で施策情報を検索する

        List<CtrKkbhDM> ctrKkbhList = ctrKkbhCustomDAO.selectSskInfoByMthKeikakuNo(ctrKkbhDMParameter);

 

        if (ctrKkbhList != null) {

            // 施策で、グループ化する。

            Map<String, List<CtrKkbhDM>> shisakuGroup = new HashMap<String, List<CtrKkbhDM>>();

            for (CtrKkbhDM ctrKkbhDM : ctrKkbhList) {

                List<CtrKkbhDM> sisakuList = new ArrayList<CtrKkbhDM>();

                sisakuList.add(ctrKkbhDM);

                sisakuList = shisakuGroup.put(ctrKkbhDM.getTgtShisakuId(), sisakuList);

                if (sisakuList != null) {

                    sisakuList.add(ctrKkbhDM);

                    shisakuGroup.put(ctrKkbhDM.getTgtShisakuId(), sisakuList);

                }

            }

 

            // 施策で、ソートする。

            Map<String, List<CtrKkbhDM>> shisakuGroupSortedByShisakuCd = new TreeMap<String, List<CtrKkbhDM>>(shisakuGroup);

            Iterator<String> shisakuCdList = shisakuGroupSortedByShisakuCd.keySet().iterator();

 

            while (shisakuCdList.hasNext()) {

                IpnorsDetailKkbhSM sm = new IpnorsDetailKkbhSM();

 

                // 各販売店の情報

                for (int i = 0; i < hanbaitenCdList.size(); i++) {

                    sm.getHonsyaKakubaihiAList().add(new IpnorsDetailKkbhSM.Kakubaihi());

                    sm.getShisyaKakubaihiAList().add(new IpnorsDetailKkbhSM.Kakubaihi());

                    // 拡売費番号

                    sm.getKkbhNoList().add(null);

                    // 月次販売計画明細番号

                    sm.getHanbaiKkuMsiNoList().add(null);

                    // 商流販売店販売店コート

                    sm.getTskInCdList().add(null);

                    // 営業経費更新日時

                    sm.getEigKeihKsnDateList().add(null);

                }

 

                String shisakuCd = shisakuCdList.next();

                List<CtrKkbhDM> list = shisakuGroupSortedByShisakuCd.get(shisakuCd);

 

                Map<String, List<CtrKkbhDM>> syohinGroup = new HashMap<String, List<CtrKkbhDM>>();

 

                // 商品で、グループ化する。

                for (int i = 0; i < list.size(); i++) {

                    CtrKkbhDM ctrKkbhDM = list.get(i);

                    List<CtrKkbhDM> tempList = new ArrayList<CtrKkbhDM>();

                    tempList.add(ctrKkbhDM);

                    tempList = syohinGroup.put(ctrKkbhDM.getSmryShohinCd(), tempList);

                    if (tempList != null) {

                        tempList.add(ctrKkbhDM);

                        syohinGroup.put(ctrKkbhDM.getSmryShohinCd(), tempList);

                    }

                }

 

                Map<String, List<CtrKkbhDM>> syohinGroupSortedBySmryShohinCd = new TreeMap<String, List<CtrKkbhDM>>(syohinGroup);

                Iterator<String> smryShohinCdList = syohinGroupSortedBySmryShohinCd.keySet().iterator();

 

                int smryShohinCdCount = syohinGroupSortedBySmryShohinCd.size();

                // 各商品の情報

                for (int m = 0; m < smryShohinCdCount; m++) {

                    sm.getKakubaihiInHanbaitenList().add(new ArrayList<IpnorsDetailKkbhSM.Kakubaihi>());

                }

                int indexOfSyohin = -1;

                while (smryShohinCdList.hasNext()) {

                    indexOfSyohin++;

                    // 各販売店の拡売費

                    List<IpnorsDetailKkbhSM.Kakubaihi> kakubaihiList = new ArrayList<IpnorsDetailKkbhSM.Kakubaihi>();

                    for (int i = 0; i < hanbaitenCdList.size(); i++) {

                        IpnorsDetailKkbhSM.Kakubaihi kakubaihi = new IpnorsDetailKkbhSM.Kakubaihi();

                        kakubaihiList.add(kakubaihi);

                    }

                    String smryShohinCd = smryShohinCdList.next();

                    List<CtrKkbhDM> tempList = syohinGroupSortedBySmryShohinCd.get(smryShohinCd);

 

                    Collections.sort(tempList, new Comparator<CtrKkbhDM>() {

                        @Override

                        public int compare(CtrKkbhDM o1, CtrKkbhDM o2) {

                            if (o2.getTskInCd() == null) {

                                return 0;

                            } else if (o1.getTskInCd() == null) {

                                return -1;

                            }

                            return o1.getTskInCd().compareTo(o2.getTskInCd());

                        }

                    });

 

                    for (CtrKkbhDM ctrKkbhDM : tempList) {

                        this.replace(ctrKkbhDM,

                                sm.getHanbaiKkuMsiNoList(),

                                sm.getEigKeihKsnDateList(),

                                sm.getKkbhNoList(),

                                sm.getHonsyaKakubaihiAList(),

                                sm.getShisyaKakubaihiAList(),

                                kakubaihiList,

                                hanbaitenCdList);

 

                        this.setFirstOfSortedSyohinInfo(sm.getDisplayKategori(),

                                sm.getDisplayBurando(),

                                sm.getDisplaySmallBurando(),

                                sm.getDisplayGoods(),

                                ctrKkbhDM);

                    }

 

                    // 各販売店の拡売費を格納する。

                    sm.getKakubaihiInHanbaitenList().set(indexOfSyohin, kakubaihiList);

                }

 

                if (!list.isEmpty()) {

                    // 施策ID

                    sm.setShisakuId(list.get(0).getTgtShisakuId());

                    // 施策名称

                    sm.setShisakuMeisho(list.get(0).getShisakuMeisho());

                }

 

                result.add(sm);

            }

        }

 

        // 月次販売計画書番号で拡売費情報を検索する

        ctrKkbhList = ctrKkbhCustomDAO.selectKkbhInfoByMthKeikakuNo(ctrKkbhDMParameter);

        if (ctrKkbhList != null) {

            // 拡売費用途コードで、グループ化する。

            Map<String, List<CtrKkbhDM>> kakubaihiYotoCdGroup = new HashMap<String, List<CtrKkbhDM>>();

            for (CtrKkbhDM ctrKkbhDM : ctrKkbhList) {

                List<CtrKkbhDM> kakubaihiYotoCdList = new ArrayList<CtrKkbhDM>();

                kakubaihiYotoCdList.add(ctrKkbhDM);

                kakubaihiYotoCdList = kakubaihiYotoCdGroup.put(ctrKkbhDM.getKkbhYotoCd(), kakubaihiYotoCdList);

                if (kakubaihiYotoCdList != null) {

                    kakubaihiYotoCdList.add(ctrKkbhDM);

                    kakubaihiYotoCdGroup.put(ctrKkbhDM.getKkbhYotoCd(), kakubaihiYotoCdList);

                }

            }

 

            // 拡売費用途コードで、ソートする。

            Map<String, List<CtrKkbhDM>> kakubaihiYotoCdGroupSortedByShisakuCd = new TreeMap<String, List<CtrKkbhDM>>(kakubaihiYotoCdGroup);

            Iterator<String> kakubaihiYotoCdList = kakubaihiYotoCdGroupSortedByShisakuCd.keySet().iterator();

 

            while (kakubaihiYotoCdList.hasNext()) {

                IpnorsDetailKkbhSM sm = new IpnorsDetailKkbhSM();

 

                // 各販売店の情報

                for (int i = 0; i < hanbaitenCdList.size(); i++) {

                    sm.getHonsyaKakubaihiAList().add(new IpnorsDetailKkbhSM.Kakubaihi());

                    sm.getShisyaKakubaihiAList().add(new IpnorsDetailKkbhSM.Kakubaihi());

                    // 拡売費番号

                    sm.getKkbhNoList().add(null);

                    // 月次販売計画明細番号

                    sm.getHanbaiKkuMsiNoList().add(null);

                    // 商流販売店販売店コート

                    sm.getTskInCdList().add(null);

                    // 営業経費更新日時

                    sm.getEigKeihKsnDateList().add(null);

                }

 

                String kakubaihiYotoCd = kakubaihiYotoCdList.next();

                List<CtrKkbhDM> list = kakubaihiYotoCdGroupSortedByShisakuCd.get(kakubaihiYotoCd);

 

                Map<String, List<CtrKkbhDM>> syohinGroup = new HashMap<String, List<CtrKkbhDM>>();

 

                // 商品で、グループ化する。

                for (int i = 0; i < list.size(); i++) {

                    CtrKkbhDM ctrKkbhDM = list.get(i);

                    List<CtrKkbhDM> tempList = new ArrayList<CtrKkbhDM>();

                    tempList.add(ctrKkbhDM);

                    tempList = syohinGroup.put(ctrKkbhDM.getSmryShohinCd(), tempList);

                    if (tempList != null) {

                        tempList.add(ctrKkbhDM);

                        syohinGroup.put(ctrKkbhDM.getSmryShohinCd(), tempList);

                    }

                }

 

                Map<String, List<CtrKkbhDM>> syohinGroupSortedBySmryShohinCd = new TreeMap<String, List<CtrKkbhDM>>(syohinGroup);

                Iterator<String> smryShohinCdList = syohinGroupSortedBySmryShohinCd.keySet().iterator();

 

                int smryShohinCdCount = syohinGroupSortedBySmryShohinCd.size();

                // 各商品の情報

                for (int m = 0; m < smryShohinCdCount; m++) {

                    sm.getKakubaihiInHanbaitenList().add(new ArrayList<IpnorsDetailKkbhSM.Kakubaihi>());

                }

                int indexOfSyohin = -1;

                while (smryShohinCdList.hasNext()) {

                    indexOfSyohin++;

                    // 各販売店の拡売費

                    List<IpnorsDetailKkbhSM.Kakubaihi> kakubaihiList = new ArrayList<IpnorsDetailKkbhSM.Kakubaihi>();

                    for (int i = 0; i < hanbaitenCdList.size(); i++) {

                        IpnorsDetailKkbhSM.Kakubaihi kakubaihi = new IpnorsDetailKkbhSM.Kakubaihi();

                        kakubaihiList.add(kakubaihi);

                    }

                    String smryShohinCd = smryShohinCdList.next();

                    List<CtrKkbhDM> tempList = syohinGroupSortedBySmryShohinCd.get(smryShohinCd);

 

                    Collections.sort(tempList, new Comparator<CtrKkbhDM>() {

                        @Override

                        public int compare(CtrKkbhDM o1, CtrKkbhDM o2) {

                            if (o2.getTskInCd() == null) {

                                return 0;

                            } else if (o1.getTskInCd() == null) {

                                return -1;

                            }

                            return o1.getTskInCd().compareTo(o2.getTskInCd());

                        }

                    });

 

                    for (CtrKkbhDM ctrKkbhDM : tempList) {

                        this.replace(ctrKkbhDM,

                                sm.getHanbaiKkuMsiNoList(),

                                sm.getEigKeihKsnDateList(),

                                sm.getKkbhNoList(),

                                sm.getHonsyaKakubaihiAList(),

                                sm.getShisyaKakubaihiAList(),

                                kakubaihiList,

                                hanbaitenCdList);

 

                        this.setFirstOfSortedSyohinInfo(sm.getDisplayKategori(),

                                sm.getDisplayBurando(),

                                sm.getDisplaySmallBurando(),

                                sm.getDisplayGoods(),

                                ctrKkbhDM);

                    }

 

                    // 各販売店の拡売費を格納する。

                    sm.getKakubaihiInHanbaitenList().set(indexOfSyohin, kakubaihiList);

                }

 

                if (!list.isEmpty()) {

                    // 拡売費用途コード

                    sm.setKakubaihiYotoCd(list.get(0).getKkbhYotoCd());

                }

 

                result.add(sm);

            }

        }

 

        return result;

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值