Skip to content

Instantly share code, notes, and snippets.

@trydofor
Last active June 3, 2016 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trydofor/baf4381470d07e9f6e6f8e1a3529489d to your computer and use it in GitHub Desktop.
Save trydofor/baf4381470d07e9f6e6f8e1a3529489d to your computer and use it in GitHub Desktop.
笔试题:重构代码

以下代码具有浓烈的坏味道,根据自己的手感,保证以功能>性能>可读性,重构之。

更多练习,可参见

            List<BaggagePo> baggagePos = baggageDao.findByOrderMainId(orderMainPo.getId());
            int k = 0;
            int l = 0;
            List<String> orderNumNoUse = new ArrayList<>();
            List<String> orderNumUse = new ArrayList<>();
            if (orderMainPo.getIsLocal() == 1) {

            for (BaggagePo po : baggagePos) {
                if (po.getStatus() == OrderStatusEnum.USUS_PICK.code()) {
                    orderNumNoUse.add(k, po.getTrackNumUs());
                    k++;
                }
                if (po.getStatus() != OrderStatusEnum.USUS_PICK.code()) {
                    orderNumUse.add(l, po.getTrackNumUs());
                    l++;
                }

            }

            List<ImptFedexBillsPo> imptFedexBillsPos = fedexBillsDao.findByOrderMainId(orderMainPo.getId());
            if (DecimalUtil.add(new BigDecimal(imptFedexBillsPos.size()), new BigDecimal(k)).equals(new BigDecimal(baggagePos.size()))) {
                orderMainService.updateStatus(orderMainPo.getId(), OrderStatusEnum.USUS_PAY.code());
                for (BaggagePo po : baggagePos) {
                    BaggagePo baggagePo = baggageDao.findById(po.getId());
                    baggagePo.setModifyTime(new Date());
                    baggagePo.setStatus(OrderStatusEnum.USUS_PAY.code());
                    if (orderNumNoUse == null) {
                        int cnt = baggageDao.updateBaggage(baggagePo);
                        DaoUtil.assertUpdateOne(cnt, baggagePo);
                    }
                    for(String s : orderNumUse){
                        if (s.equals(baggagePo.getTrackNumUs())) {
                            int cnt = baggageDao.updateBaggage(baggagePo);
                            DaoUtil.assertUpdateOne(cnt, baggagePo);
                        }
                    }
                }
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment