Search in sources :

Example 6 with MobileChargingPrice

use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.

the class MobileAppserviceChargingController method update.

// 返回修改页面
@RequestMapping(value = "/update/{id}")
public String update(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {
    ApplicationInfo applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByPrimaryKey", id);
    uiModel.addAttribute("applicationInfo", applicationInfo);
    List<MobileAppserviceCharging> appserviceChargings = new ArrayList<MobileAppserviceCharging>();
    appserviceChargings = appserviceChargingService.selectList(id);
    AppserviceChargingWrap appserviceChargingWrap = new AppserviceChargingWrap();
    List<AppserviceChargingList> appserviceChargingLists = new ArrayList<AppserviceChargingList>();
    for (int i = 0; i < appserviceChargings.size(); i++) {
        AppserviceChargingList appserviceChargingList = new AppserviceChargingList();
        List<MobileAppserviceName> appserviceNames = new ArrayList<MobileAppserviceName>();
        appserviceNames = appserviceNameService.selectListByAppserviceCharging(appserviceChargings.get(i));
        List<AppserviceNameList> appserviceNameLists = new ArrayList<AppserviceNameList>();
        for (int j = 0; j < appserviceNames.size(); j++) {
            List<MobileChargingPrice> chargingPrices = chargingPriceService.selectListByOneAppserviceName(appserviceNames.get(j));
            AppserviceNameList appserviceNameList = new AppserviceNameList();
            ChargingPriceList chargingPriceList = new ChargingPriceList();
            // 1
            chargingPriceList.setChargingPriceLists(chargingPrices);
            // 2
            appserviceNameList.setAppserviceName(appserviceNames.get(j));
            appserviceNameList.setChargingPriceList(chargingPriceList);
            appserviceNameLists.add(appserviceNameList);
        }
        appserviceChargingList.setAppserviceCharging(appserviceChargings.get(i));
        appserviceChargingList.setAppserviceNameLists(appserviceNameLists);
        appserviceChargingLists.add(appserviceChargingList);
    }
    appserviceChargingWrap.setAppserviceChargingLists(appserviceChargingLists);
    uiModel.addAttribute("acw", appserviceChargingWrap);
    // Map<Long, AppService> appServiceMap = sqlSession.selectMap(
    // "com.itrus.portal.db.AppServiceMapper.selectByExample", null,
    // "id");
    // uiModel.addAttribute("appServiceMap", appServiceMap);
    returnParam(request, uiModel);
    return "appservicecharging/update";
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) ArrayList(java.util.ArrayList) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) AppserviceChargingWrap(com.itrus.portal.mobile.entity.AppserviceChargingWrap) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with MobileChargingPrice

use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.

the class MobileAppserviceChargingController method createOrUpdate.

// 新建和修改处理
@RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public synchronized Map<String, Object> createOrUpdate(@RequestParam("appserviceChargingStr") String appserviceChargingStr) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
    // 事物的传播行为,使用同一个事物
    dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(dtd);
    try {
        AppserviceChargingWrap acw = jsonTool.readValue(appserviceChargingStr, AppserviceChargingWrap.class);
        List<AppserviceChargingList> appserviceChargingLists = acw.getAppserviceChargingLists();
        for (int i = 0; i < appserviceChargingLists.size(); i++) {
            // 取出单个的服务名称主表对象和服务名封装list
            MobileAppserviceCharging appCharging = appserviceChargingLists.get(i).getAppserviceCharging();
            // if (null == appCharging.getChargingType()) {
            // cc.setChargingType(ComNames.CHARGING_TYPE_SMRZ_1);
            // }
            List<AppserviceNameList> appserviceNameLists = appserviceChargingLists.get(i).getAppserviceNameLists();
            Map<String, Object> mapAC = new HashMap<String, Object>();
            mapAC = appserviceChargingService.saveOrUpdateAppserviceCharging(appCharging);
            boolean retCodeAC = false;
            retCodeAC = (boolean) mapAC.get("flag");
            // 新增或修改MobileAppserviceCharging成功
            if (retCodeAC) {
                appCharging = (MobileAppserviceCharging) mapAC.get("appserviceCharging");
                MobileAppserviceCharging oldAC = (MobileAppserviceCharging) mapAC.get("oldAppserviceCharging");
                // 将MobileAppserviceCharging的id值赋值给serviceNameList中新增的服务
                appserviceNameLists = appserviceNameService.insertIdIntoAppserviceName(appCharging, appserviceNameLists);
                // 2.新增或修改ServiceName
                for (int j = 0; j < appserviceNameLists.size(); j++) {
                    MobileAppserviceName appserviceName = appserviceNameLists.get(j).getAppserviceName();
                    ChargingPriceList chargingPriceList = appserviceNameLists.get(j).getChargingPriceList();
                    boolean retCodeSN = false;
                    Map<String, Object> mapAppserviceName = new HashMap<String, Object>();
                    mapAppserviceName = appserviceNameService.saveOrUpdateServiceName(appserviceName, appCharging, oldAC);
                    retCodeSN = (boolean) mapAppserviceName.get("flag");
                    // 新增或修改ServiceName成功
                    if (retCodeSN) {
                        appserviceName = (MobileAppserviceName) mapAppserviceName.get("appserviceName");
                        MobileAppserviceName oldAppserviceName = (MobileAppserviceName) mapAppserviceName.get("oldAppserviceName");
                        List<MobileAppserviceName> oldAppserviceNames = (List<MobileAppserviceName>) mapAppserviceName.get("appserviceNames");
                        // 将serviceNameId,CertificationCharging的id值赋值给chargingPriceList中计费以及价格区间
                        chargingPriceList = chargingPriceService.insertIdIntoChargingPrice(appserviceName, chargingPriceList);
                        List<MobileChargingPrice> chargingPrices = chargingPriceList.getChargingPriceLists();
                        // 3.charprice新增或修改
                        for (int k = 0; k < chargingPrices.size(); k++) {
                            Map<String, Object> mapChargingPrice = new HashMap<String, Object>();
                            mapChargingPrice = chargingPriceService.saveOrUpdateChargingPrice(appCharging, appserviceName, chargingPrices.get(k), oldAC, oldAppserviceName, oldAppserviceNames);
                            boolean retCodeChargingPrice = false;
                            retCodeChargingPrice = (boolean) mapChargingPrice.get("flag");
                            // 新增或修改ChargingPrice失败
                            if (!retCodeChargingPrice) {
                                transactionManager.rollback(status);
                                retMap = mapChargingPrice;
                                return retMap;
                            }
                        }
                    } else {
                        // TODO 新增或修改ServiceName错误,返回异常信息
                        transactionManager.rollback(status);
                        retMap = mapAppserviceName;
                        return retMap;
                    }
                }
            } else {
                // TODO 新增或修改CertificationCharging错误,返回异常信息
                transactionManager.rollback(status);
                retMap = mapAC;
                return retMap;
            }
        }
        LogUtil.adminlog(sqlSession, "新增计费规则", "新增了计费规则");
        transactionManager.commit(status);
        retMap.put("flag", true);
        // 修改应用对应的服务:将应用和服务关联起来
        // Set<Long> set = appserviceChargingService.getAllAppId();
        // if (null != set && set.size() >0) {
        // for (Long long1 : set) {
        // Set<Long> AppserviceIDs = appserviceChargingService.getAppserviceIDsByAppId(long1);
        // applicationInfoService.addServiceByAppInfo(long1,AppserviceIDs);
        // }
        // }
        // 通知其他机器,加载缓存
        CertificationChargingHandler cch = new CertificationChargingHandler();
        QueueThread.buildCertificationTask(cch);
        // cacheCustomer.initChargeRule();
        return retMap;
    } catch (JsonParseException e) {
        transactionManager.rollback(status);
        e.printStackTrace();
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (JsonMappingException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    } catch (IOException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    } catch (Exception e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) TransactionStatus(org.springframework.transaction.TransactionStatus) JsonParseException(org.codehaus.jackson.JsonParseException) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) List(java.util.List) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) ArrayList(java.util.ArrayList) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) ServiceNameList(com.itrus.portal.entity.ServiceNameList) MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) IOException(java.io.IOException) AppserviceChargingWrap(com.itrus.portal.mobile.entity.AppserviceChargingWrap) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) CertificationChargingHandler(com.itrus.portal.service.CertificationChargingHandler) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with MobileChargingPrice

use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.

the class MobileAppserviceNameService method initAppServiceNameMap.

/**
 * 初始化当前时间内有效的serviceName
 * @return
 */
public ConcurrentHashMap<Long, MobileAppserviceName> initAppServiceNameMap() {
    ConcurrentHashMap<Long, MobileAppserviceName> serviceNameMap = new ConcurrentHashMap<>();
    ConcurrentHashMap<String, List<MobileChargingPrice>> chargeRuleMap = new ConcurrentHashMap<String, List<MobileChargingPrice>>();
    MobileAppserviceChargingExample cce = new MobileAppserviceChargingExample();
    MobileAppserviceChargingExample.Criteria criteria = cce.or();
    Date nowDate = new Date();
    criteria.andEndTimeGreaterThan(nowDate);
    cce.setOrderByClause("start_time asc");
    // 将入以下条件之后,只会加载当前时间处于计费起始终止时间内的计费规则,起始时间比当前时间还晚的就不加载
    // 加载一个小时以后也有效的计费规则,避免定时任务的空白期出现无可用计费的规则的情况
    Date laterDate = appserviceChargingService.getHourLaterDate(nowDate);
    criteria.andStartTimeLessThanOrEqualTo(laterDate);
    List<MobileAppserviceCharging> certificationChargings = new ArrayList<MobileAppserviceCharging>();
    certificationChargings = sqlSession.selectList("com.itrus.portal.db.MobileAppserviceChargingMapper.selectByExample", cce);
    if (null == certificationChargings) {
        return serviceNameMap;
    }
    for (int i = 0; i < certificationChargings.size(); i++) {
        List<MobileAppserviceName> serviceNames = selectListByCertificationChargingId(certificationChargings.get(i).getId());
        if (null != serviceNames && !serviceNames.isEmpty()) {
            for (MobileAppserviceName serviceName : serviceNames) {
                serviceNameMap.put(serviceName.getId(), serviceName);
            }
        }
    }
    return serviceNameMap;
}
Also used : MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ArrayList(java.util.ArrayList) MobileAppserviceChargingExample(com.itrus.portal.db.MobileAppserviceChargingExample) Date(java.util.Date) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 9 with MobileChargingPrice

use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.

the class MobileChargingPriceService method checkSave.

/**
 * 新增约束检测,通过则返true,不通过则false
 *
 * @param serviceName
 * @param chargingPrice
 * @return
 */
private Map<String, Object> checkSave(MobileAppserviceName appserviceName, MobileChargingPrice chargingPrice) {
    List<MobileChargingPrice> chargingPrices = selectChargingPriceList(appserviceName);
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    if (null != chargingPrices && chargingPrices.size() != 0) {
        // 找到规则点
        MobileChargingPrice checkChargingPrice = null;
        for (int i = 0; i < chargingPrices.size(); i++) {
            // 先根据新插入的记录的最大值是不是最大的,如果是,这个就插入点;如果不是,则证明要插入的是中间位置,中间位置的最大值要==某个最小值
            if (chargingPrices.get(i).getMaximumNumber() <= chargingPrice.getMinimumNumber()) {
                // 判断了最大值比记录中的都大了之后,应该判断最小值跟记录中的某条记录的最大值相等.形成阶梯关系
                if (chargingPrices.get(i).getMaximumNumber().equals(chargingPrice.getMinimumNumber())) {
                    checkChargingPrice = chargingPrices.get(i);
                    retMap.put("flag", true);
                    return retMap;
                }
            } else if (chargingPrices.get(i).getMinimumNumber().equals(chargingPrice.getMaximumNumber())) {
                checkChargingPrice = chargingPrices.get(i);
                retMap.put("flag", true);
                return retMap;
            } else {
                retMap.put("retMsg", "新增的计费以及价格区间不符合规则,请检查后再提交");
            }
        }
        retMap.put("retMsg", "新增的计费以及价格区间不连贯,请注意最大值和最小值之间的链接关系,请检查后再提交");
        return retMap;
    } else {
        // 如果是第一次增加一个记录,那么它的最小值是0
        retMap.put("flag", true);
    }
    return retMap;
}
Also used : HashMap(java.util.HashMap) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice)

Example 10 with MobileChargingPrice

use of com.itrus.portal.db.MobileChargingPrice in project portal by ixinportal.

the class MobileChargingPriceService method selectListByOneAppserviceName.

/**
 * 根据serviceName,获取对应的计费以及价格区间
 *
 * @param serviceNames
 * @return
 */
public List<MobileChargingPrice> selectListByOneAppserviceName(MobileAppserviceName appserviceName) {
    List<MobileChargingPrice> list = new ArrayList<MobileChargingPrice>();
    MobileChargingPriceExample chargingPriceExample = new MobileChargingPriceExample();
    MobileChargingPriceExample.Criteria criteria = chargingPriceExample.or();
    criteria.andAppserviceNameEqualTo(appserviceName.getId());
    chargingPriceExample.setOrderByClause("minimum_number asc");
    list = sqlSession.selectList("com.itrus.portal.db.MobileChargingPriceMapper.selectByExample", chargingPriceExample);
    return list;
}
Also used : MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ArrayList(java.util.ArrayList) MobileChargingPriceExample(com.itrus.portal.db.MobileChargingPriceExample)

Aggregations

MobileChargingPrice (com.itrus.portal.db.MobileChargingPrice)13 ArrayList (java.util.ArrayList)10 MobileAppserviceCharging (com.itrus.portal.db.MobileAppserviceCharging)7 MobileAppserviceName (com.itrus.portal.db.MobileAppserviceName)6 Date (java.util.Date)6 HashMap (java.util.HashMap)5 List (java.util.List)5 AppserviceNameList (com.itrus.portal.mobile.entity.AppserviceNameList)4 MobileChargingPriceExample (com.itrus.portal.db.MobileChargingPriceExample)3 AppserviceChargingList (com.itrus.portal.mobile.entity.AppserviceChargingList)3 AppserviceChargingWrap (com.itrus.portal.mobile.entity.AppserviceChargingWrap)3 ChargingPriceList (com.itrus.portal.mobile.entity.ChargingPriceList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)2 MobileAppserviceChargingExample (com.itrus.portal.db.MobileAppserviceChargingExample)2 CertificationChargingHandler (com.itrus.portal.service.CertificationChargingHandler)2 Map (java.util.Map)2 AppService (com.itrus.portal.db.AppService)1 Charging (com.itrus.portal.db.Charging)1