pricingmgmtserviceimpl.java

来自「当时就海底世界没客服热线mkxmykm,xkxtml, xrtlujlnszlt」· Java 代码 · 共 119 行

JAVA
119
字号
package com.tarena.oss.pricing.service;

import java.util.Collection;

import com.tarena.oss.pricing.dao.PricingMgmtDAO;
import com.tarena.oss.pricing.pojo.Pricing;
import com.tarena.oss.pricing.pojo.PricingConditionDTO;
import com.tarena.oss.util.QueryResult;

public class PricingMgmtServiceImpl implements PricingMgmtService {
	private PricingMgmtDAO dao;
	
	public void setDao(PricingMgmtDAO dao) {
		this.dao = dao;
	}

	public void addPricing(Pricing p) {
		dao.insertPricing(p);
	}

	public Collection<Pricing> findAll() {
		return dao.queryAll();
	}

	public Collection<Pricing> findAllByCondition(PricingConditionDTO dto) {
		StringBuffer sb = new StringBuffer();
		String name = dto.getName();
		double lowerBase = dto.getLowerBaseFee();
		double upperBase = dto.getUpperBaseFee();
		double lowerRate = dto.getLowerRateFee();
		double upperRate = dto.getUpperRateFee();
		if (name!=null && !name.trim().equals("")){
			sb.append(" and p.name like '%").append(name).append("%' ");
		}
		
		if (lowerBase != 0.0 && upperBase != 0.0){
			sb.append(" and p.baseFee between ").append(lowerBase).
				append(" and ").append(upperBase);
		}else if (lowerBase != 0.0){
			sb.append(" and p.baseFee >= ").append(lowerBase);
		}else if (upperBase != 0.0){
			sb.append(" and p.baseFee <= ").append(upperBase);
		}
		
		
		if (lowerRate != 0.0 && upperRate != 0.0){
			sb.append(" and p.rateFee between ").append(lowerRate).
				append(" and ").append(upperRate);
		}else if (lowerRate != 0.0){
			sb.append(" and p.rateFee >= ").append(lowerRate);
		}else if (upperRate != 0.0){
			sb.append(" and p.rateFee <= ").append(upperRate);
		}
		System.out.println("condition: " + sb.toString());
		
		return dao.queryAll(sb.toString());
	}

	public Pricing findPricingById(Integer id) {
		return dao.queryPricingById(id);
	}

	public void modifyPricing(Pricing p) {
		dao.updatePricing(p);
	}

	public void removePricing(Integer id) {
		Pricing p = dao.queryPricingById(id);
		if (!dao.isUsed(id))
			dao.deletePricing(p);
	}

	public QueryResult<Pricing> findAll(int currentPage, int rowCnt) {
		QueryResult<Pricing> qr = new QueryResult<Pricing>();
		qr.setData(dao.queryAll(currentPage, rowCnt));
		qr.setCounts(dao.queryRowCounts());
		
		return qr;
	}

	public QueryResult<Pricing> findAllByCondition(PricingConditionDTO dto, int currentPage, int rowCnt) {
		StringBuffer sb = new StringBuffer();
		String name = dto.getName();
		double lowerBase = dto.getLowerBaseFee();
		double upperBase = dto.getUpperBaseFee();
		double lowerRate = dto.getLowerRateFee();
		double upperRate = dto.getUpperRateFee();
		if (name!=null && !name.trim().equals("")){
			sb.append(" and p.name like '%").append(name).append("%' ");
		}
		
		if (lowerBase != 0.0 && upperBase != 0.0){
			sb.append(" and p.baseFee between ").append(lowerBase).
				append(" and ").append(upperBase);
		}else if (lowerBase != 0.0){
			sb.append(" and p.baseFee >= ").append(lowerBase);
		}else if (upperBase != 0.0){
			sb.append(" and p.baseFee <= ").append(upperBase);
		}
		
		
		if (lowerRate != 0.0 && upperRate != 0.0){
			sb.append(" and p.rateFee between ").append(lowerRate).
				append(" and ").append(upperRate);
		}else if (lowerRate != 0.0){
			sb.append(" and p.rateFee >= ").append(lowerRate);
		}else if (upperRate != 0.0){
			sb.append(" and p.rateFee <= ").append(upperRate);
		}
		System.out.println("condition: " + sb.toString());
		
		QueryResult<Pricing> qr =new QueryResult<Pricing>();
		qr.setData(dao.queryAll(currentPage, rowCnt));
		qr.setCounts(dao.queryRowCounts());
		return qr;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?