Search in sources :

Example 1 with CertificationCharging

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

the class CertificationChargingController method createOrUpdate.

// 新建和修改处理
@RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public synchronized Map<String, Object> createOrUpdate(@RequestParam("certificationChargingStr") String certificationChargingStr) {
    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 {
        CertificationChargingWrap ccw = jsonTool.readValue(certificationChargingStr, CertificationChargingWrap.class);
        List<CertificationChargingList> certificationChargingLists = ccw.getCertificationChargingLists();
        // 1.新增或修改CertificationCharging
        for (int i = 0; i < certificationChargingLists.size(); i++) {
            // 取出单个的服务名称主表对象和服务名封装list
            CertificationCharging cc = certificationChargingLists.get(i).getCertificationCharging();
            if (null == cc.getChargingType()) {
                cc.setChargingType(ComNames.CHARGING_TYPE_SMRZ_1);
            }
            List<ServiceNameList> serviceNameLists = certificationChargingLists.get(i).getServiceNameLists();
            Map<String, Object> mapCC = new HashMap<String, Object>();
            mapCC = certificationChargingService.saveOrUpdateCertificationCharging(cc);
            boolean retCodeCC = false;
            retCodeCC = (boolean) mapCC.get("flag");
            // 新增或修改CertificationCharging成功
            if (retCodeCC) {
                cc = (CertificationCharging) mapCC.get("certificationCharging");
                CertificationCharging oldCC = (CertificationCharging) mapCC.get("oldCertificationCharging");
                // 将CertificationCharging的id值赋值给serviceNameList中新增的服务
                serviceNameLists = serviceNameService.insertIdIntoServiceName(cc, serviceNameLists);
                // 2.新增或修改ServiceName
                for (int j = 0; j < serviceNameLists.size(); j++) {
                    ServiceName serviceName = serviceNameLists.get(j).getServiceName();
                    ChargingPriceList chargingPriceList = serviceNameLists.get(j).getChargingPriceList();
                    boolean retCodeSN = false;
                    Map<String, Object> mapServiceName = new HashMap<String, Object>();
                    mapServiceName = serviceNameService.saveOrUpdateServiceName(serviceName, cc, oldCC);
                    retCodeSN = (boolean) mapServiceName.get("flag");
                    // 新增或修改ServiceName成功
                    if (retCodeSN) {
                        serviceName = (ServiceName) mapServiceName.get("serviceName");
                        ServiceName oldServiceName = (ServiceName) mapServiceName.get("oldServiceName");
                        List<ServiceName> oldServiceNames = (List<ServiceName>) mapServiceName.get("serviceNames");
                        // 将serviceNameId,CertificationCharging的id值赋值给chargingPriceList中计费以及价格区间
                        chargingPriceList = chargingPriceService.insertIdIntoChargingPrice(serviceName, chargingPriceList);
                        List<ChargingPrice> chargingPrices = chargingPriceList.getChargingPriceLists();
                        // 3.charprice新增或修改
                        for (int k = 0; k < chargingPrices.size(); k++) {
                            Map<String, Object> mapChargingPrice = new HashMap<String, Object>();
                            mapChargingPrice = chargingPriceService.saveOrUpdateChargingPrice(cc, serviceName, chargingPrices.get(k), oldCC, oldServiceName, oldServiceNames);
                            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 = mapServiceName;
                        return retMap;
                    }
                }
            } else {
                // TODO 新增或修改CertificationCharging错误,返回异常信息
                transactionManager.rollback(status);
                retMap = mapCC;
                return retMap;
            }
        }
        LogUtil.adminlog(sqlSession, "新增计费规则", "新增了计费规则");
        transactionManager.commit(status);
        retMap.put("flag", true);
        // 修改应用对应的服务:将应用和服务关联起来
        Set<Long> set = certificationChargingService.getAllAppId();
        if (null != set && set.size() > 0) {
            for (Long long1 : set) {
                Set<Long> AppserviceIDs = certificationChargingService.getAppserviceIDsByAppId(long1);
                applicationInfoService.addServiceByAppInfo(long1, AppserviceIDs);
            }
        }
        // 通知其他机器,加载缓存
        CertificationChargingHandler cch = new CertificationChargingHandler();
        QueueThread.buildCertificationTask(cch);
        cacheCustomer.initChargeRule();
        return retMap;
    } catch (JsonParseException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (JsonMappingException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (IOException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (Exception e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) ChargingPriceList(com.itrus.portal.entity.ChargingPriceList) TransactionStatus(org.springframework.transaction.TransactionStatus) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) ArrayList(java.util.ArrayList) ServiceNameList(com.itrus.portal.entity.ServiceNameList) ChargingPriceList(com.itrus.portal.entity.ChargingPriceList) List(java.util.List) ServiceNameList(com.itrus.portal.entity.ServiceNameList) CertificationCharging(com.itrus.portal.db.CertificationCharging) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) CertificationChargingWrap(com.itrus.portal.entity.CertificationChargingWrap) ServiceName(com.itrus.portal.db.ServiceName) ChargingPrice(com.itrus.portal.db.ChargingPrice) CertificationChargingHandler(com.itrus.portal.service.CertificationChargingHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CertificationCharging

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

the class CertificationChargingController method show.

// 根据应用id,查询应用下的所有计费规则信息
@RequestMapping(value = "/show/{id}")
public String show(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {
    ApplicationInfo applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByPrimaryKey", id);
    uiModel.addAttribute("applicationInfo", applicationInfo);
    // 系统配置的实名认证服务集合
    List<AppService> appServices = new ArrayList<AppService>();
    AppServiceExample appServiceExample = new AppServiceExample();
    AppServiceExample.Criteria criteria = appServiceExample.or();
    criteria.andTypeEqualTo(ComNames.SERVICE_TYPE_CERTIFICATION);
    appServices = sqlSession.selectList("com.itrus.portal.db.AppServiceMapper.selectByExample", appServiceExample);
    uiModel.addAttribute("appServices", appServices);
    List<CertificationCharging> certificationChargings = new ArrayList<CertificationCharging>();
    certificationChargings = certificationChargingService.selectList(id, ComNames.CHARGING_TYPE_SMRZ_1);
    CertificationChargingWrap certificationChargingWrap = new CertificationChargingWrap();
    List<CertificationChargingList> certificationChargingLists = new ArrayList<CertificationChargingList>();
    for (int i = 0; i < certificationChargings.size(); i++) {
        CertificationChargingList certificationChargingList = new CertificationChargingList();
        List<ServiceName> serviceNames = new ArrayList<ServiceName>();
        serviceNames = serviceNameService.selectListByCertificationCharging(certificationChargings.get(i));
        List<ServiceNameList> serviceNameLists = new ArrayList<ServiceNameList>();
        for (int j = 0; j < serviceNames.size(); j++) {
            List<ChargingPrice> chargingPrices = chargingPriceService.selectListByOneServiceName(serviceNames.get(j));
            ServiceNameList serviceNameList = new ServiceNameList();
            ChargingPriceList chargingPriceList = new ChargingPriceList();
            // 1
            chargingPriceList.setChargingPriceLists(chargingPrices);
            // 2
            serviceNameList.setServiceName(serviceNames.get(j));
            serviceNameList.setChargingPriceList(chargingPriceList);
            serviceNameLists.add(serviceNameList);
        }
        certificationChargingList.setCertificationCharging(certificationChargings.get(i));
        certificationChargingList.setServiceNameLists(serviceNameLists);
        certificationChargingLists.add(certificationChargingList);
    }
    certificationChargingWrap.setCertificationChargingLists(certificationChargingLists);
    uiModel.addAttribute("ccw", certificationChargingWrap);
    Map<Long, AppService> appServiceMap = sqlSession.selectMap("com.itrus.portal.db.AppServiceMapper.selectByExample", null, "id");
    uiModel.addAttribute("appServiceMap", appServiceMap);
    // 返回页面上的表单数据
    returnParam(request, uiModel);
    return "certificationcharging/show";
}
Also used : ServiceNameList(com.itrus.portal.entity.ServiceNameList) AppService(com.itrus.portal.db.AppService) CertificationCharging(com.itrus.portal.db.CertificationCharging) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) ArrayList(java.util.ArrayList) ChargingPriceList(com.itrus.portal.entity.ChargingPriceList) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) AppServiceExample(com.itrus.portal.db.AppServiceExample) CertificationChargingWrap(com.itrus.portal.entity.CertificationChargingWrap) ServiceName(com.itrus.portal.db.ServiceName) ChargingPrice(com.itrus.portal.db.ChargingPrice) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CertificationCharging

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

the class ChargingPriceControllerTest method test2.

@Test
public void test2() throws ClassNotFoundException, IllegalAccessException, InterruptedException {
    ChargingPrice cp = new ChargingPrice();
    ChargingPrice cp2 = new ChargingPrice();
    cp.setMaximumNumber(Integer.valueOf(100));
    cp.setMinimumNumber(Integer.valueOf(0));
    cp2.setMaximumNumber(Integer.valueOf(100));
    cp2.setMinimumNumber(Integer.valueOf(0));
    CertificationCharging cc1 = new CertificationCharging();
    CertificationCharging cc2 = new CertificationCharging();
    Date date = new Date();
    cc1.setStartTime(date);
    // cc1.setIsValidity(true);
    Thread.sleep(1000);
    Date date2 = new Date();
    cc2.setStartTime(date2);
    // cc2.setIsValidity(false);
    List<Map<String, Object>> list = CompareTwoObjectUtils.compareTwoClass(cp, cp2);
    System.out.println(list.toString());
    List<Map<String, Object>> list2 = CompareTwoObjectUtils.compareTwoClass(cc1, cc2);
    System.out.println(list2.toString());
}
Also used : CertificationCharging(com.itrus.portal.db.CertificationCharging) ChargingPrice(com.itrus.portal.db.ChargingPrice) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Date(java.util.Date) Test(org.junit.Test)

Example 4 with CertificationCharging

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

the class ChargingPriceControllerTest method testUpdate.

@Test
public void testUpdate() {
    String str = "";
    ChargingPrice cp = new ChargingPrice();
    ChargingPrice cp2 = new ChargingPrice();
    cp.setMaximumNumber(Integer.valueOf(100));
    cp.setMinimumNumber(Integer.valueOf(0));
    cp.setCreateTime(new Date());
    cp.setUnitPrice(Double.valueOf(0.6));
    cp.setId(Long.valueOf(1));
    cp2.setCreateTime(new Date());
    cp2.setUnitPrice(Double.valueOf(0.5));
    cp2.setMaximumNumber(Integer.valueOf(1000));
    cp2.setMinimumNumber(Integer.valueOf(100));
    ChargingPriceList chargingPriceList = new ChargingPriceList();
    ChargingPriceList chargingPriceList2 = new ChargingPriceList();
    List<ChargingPrice> chargingPrices = new ArrayList<>();
    chargingPriceList.setChargingPriceLists(chargingPrices);
    chargingPriceList.getChargingPriceLists().add(cp);
    chargingPriceList2.setChargingPriceLists(chargingPrices);
    chargingPriceList2.getChargingPriceLists().add(cp2);
    ServiceNameList serviceNameList = new ServiceNameList();
    ServiceNameList serviceNameList2 = new ServiceNameList();
    ServiceName serviceName = new ServiceName();
    ServiceName serviceName2 = new ServiceName();
    serviceName.setCreateTime(new Date());
    serviceName.setCertificationCharging(null);
    serviceName.setCertificationServiceId(Long.valueOf(1));
    serviceName.setServieType(Long.valueOf(1));
    serviceName.setTotalNumber(Integer.valueOf(0));
    serviceName2.setCreateTime(new Date());
    serviceName2.setCertificationCharging(null);
    serviceName2.setCertificationServiceId(Long.valueOf(1));
    serviceName2.setServieType(Long.valueOf(1));
    serviceName2.setTotalNumber(Integer.valueOf(0));
    List<ServiceName> serviceNames = new ArrayList<>();
    serviceNames.add(serviceName);
    serviceNames.add(serviceName2);
    serviceNameList.setChargingPriceList(chargingPriceList);
    serviceNameList.setServiceName(serviceName);
    serviceNameList2.setChargingPriceList(chargingPriceList2);
    serviceNameList2.setServiceName(serviceName2);
    List<ServiceNameList> list = new ArrayList<ServiceNameList>();
    list.add(serviceNameList);
    list.add(serviceNameList2);
    /**
     * 		// 参数检查,参数不能为null,且结束时间大于起始时间
     *		boolean check = (null != certificationCharging
     *				&& null != certificationCharging.getApp()
     *				&& null != certificationCharging.getAccountingStrategy()
     *				&& null != certificationCharging.getUserGe() && (1 == certificationCharging
     *				.getEndTime().compareTo(certificationCharging.getStartTime())));
     */
    CertificationCharging certificationCharging = new CertificationCharging();
    certificationCharging.setApp(Long.valueOf(1));
    certificationCharging.setAccountingStrategy(Double.valueOf(1));
    certificationCharging.setUserGe(Long.valueOf(2));
    certificationCharging.setStartTime(new Date(2016, 5, 3));
    certificationCharging.setEndTime(new Date(2017, 3, 2));
    // certificationCharging.setIsValidity(true);
    certificationCharging.setCreateTime(new Date());
    CertificationChargingList certificationChargingList = new CertificationChargingList();
    CertificationChargingList certificationChargingList2 = new CertificationChargingList();
    certificationChargingList.setCertificationCharging(certificationCharging);
    certificationChargingList.setServiceNameLists(list);
    certificationChargingList2.setCertificationCharging(certificationCharging);
    certificationChargingList2.setServiceNameLists(list);
    List<CertificationChargingList> cList = new ArrayList<CertificationChargingList>();
    cList.add(certificationChargingList);
    cList.add(certificationChargingList2);
    CertificationChargingWrap certificationChargingWrap = new CertificationChargingWrap();
    certificationChargingWrap.setCertificationChargingLists(cList);
    ObjectMapper json = new ObjectMapper();
    try {
        str = json.writeValueAsString(certificationChargingWrap);
    // CertificationChargingWrap certificationChargingWrap2 = json.readValue(str, CertificationChargingWrap.class);
    // List<CertificationChargingList> chargingPriceLists = certificationChargingWrap2.getCertificationChargingLists();
    // CertificationChargingList certificationChargingList3 = chargingPriceLists.get(0);
    // System.out.println(certificationChargingWrap2.toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        // CertificationChargingController certificationChargingController = new CertificationChargingController();
        Map<String, Object> retmap = certificationChargingController.createOrUpdate(str);
        System.out.println(retmap.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServiceNameList(com.itrus.portal.entity.ServiceNameList) CertificationCharging(com.itrus.portal.db.CertificationCharging) ChargingPriceList(com.itrus.portal.entity.ChargingPriceList) ArrayList(java.util.ArrayList) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) IOException(java.io.IOException) Date(java.util.Date) IOException(java.io.IOException) CertificationChargingWrap(com.itrus.portal.entity.CertificationChargingWrap) ServiceName(com.itrus.portal.db.ServiceName) ChargingPrice(com.itrus.portal.db.ChargingPrice) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with CertificationCharging

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

the class ServiceNameServiceImpl method checkValidCertificationCharging.

/**
 * 如果该CertificationCharging下所有的ServiceName都已经无效了.那么就不校验改CertificationCharging
 * 校验该CertificationCharging
 * @param ccList
 * @return
 */
private List<CertificationCharging> checkValidCertificationCharging(List<CertificationCharging> ccList) {
    if (null == ccList || ccList.size() == 0) {
        return ccList;
    }
    Iterator<CertificationCharging> iterator = ccList.iterator();
    while (iterator.hasNext()) {
        CertificationCharging certificationCharging = iterator.next();
        ServiceNameExample serviceNameExample = new ServiceNameExample();
        ServiceNameExample.Criteria criteria = serviceNameExample.or();
        criteria.andCertificationChargingEqualTo(certificationCharging.getId());
        criteria.andIsValidityEqualTo(true);
        List<ServiceName> serviceNames = selectListByExample(serviceNameExample);
        if (null == serviceNames || serviceNames.size() == 0) {
            iterator.remove();
        }
    }
    return ccList;
}
Also used : CertificationCharging(com.itrus.portal.db.CertificationCharging) ServiceName(com.itrus.portal.db.ServiceName) ServiceNameExample(com.itrus.portal.db.ServiceNameExample)

Aggregations

CertificationCharging (com.itrus.portal.db.CertificationCharging)43 ArrayList (java.util.ArrayList)34 ServiceName (com.itrus.portal.db.ServiceName)25 Date (java.util.Date)23 ChargingPrice (com.itrus.portal.db.ChargingPrice)21 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)19 CertificationChargingExample (com.itrus.portal.db.CertificationChargingExample)16 List (java.util.List)15 HashMap (java.util.HashMap)13 ServiceNameList (com.itrus.portal.entity.ServiceNameList)9 CertificationChargingList (com.itrus.portal.entity.CertificationChargingList)6 CertificationChargingWrap (com.itrus.portal.entity.CertificationChargingWrap)6 ChargingPriceList (com.itrus.portal.entity.ChargingPriceList)6 IOException (java.io.IOException)4 Map (java.util.Map)4 Test (org.junit.Test)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 AppService (com.itrus.portal.db.AppService)3 ApplicationInfo (com.itrus.portal.db.ApplicationInfo)3 Charging (com.itrus.portal.db.Charging)3