Blame view

.svn/pristine/e7/e77fe2af56b6beb29cb76d7a3762909cca21e1ac.svn-base 5.39 KB
Quilan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
package com.phxl.modules.goods.service.medplan;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.phxl.common.utils.BaseException;
import com.phxl.common.utils.IdUtil;
import com.phxl.modules.goods.dao.medplan.MedPlanDao;
import com.phxl.modules.goods.dao.medplan.MedPlanDetailDao;
import com.phxl.modules.goods.entity.medplan.MedPlan;
import com.phxl.modules.goods.entity.medplan.MedPlanDetail;
import com.phxl.modules.goods.entity.medplan.MedPlanWithDetail;


@Service
public class MedPlanService{

	@Autowired
	private MedPlanDao planDao;
	
	@Autowired
	private MedPlanDetailDao planDetailDao;
	
	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());

	
	private void checkMedPlan(List<MedPlanWithDetail> plans) {
		if(plans == null || plans.size() == 0){
			logger.error("无相应补货计划单据信息");
			throw new BaseException("无相应补货计划单据信息");
		}
		for (MedPlanWithDetail medPlans : plans) {
			String medCode = medPlans.getTrmedPlan().getMedCode();
			String medName = medPlans.getTrmedPlan().getMedName();
			if (StringUtils.isEmpty(medCode) || StringUtils.isEmpty(medName)) {
				logger.error("补货计划医疗机构编码以及医疗机构名称不能为空");
				throw new BaseException("补货计划医疗机构编码以及医疗机构名称不能为空");
			}
			String supplierCode = medPlans.getTrmedPlan().getSupplierCode();
			String suppliername = medPlans.getTrmedPlan().getSuppliername();
			if (StringUtils.isEmpty(supplierCode) || StringUtils.isEmpty(suppliername)) {
				logger.error("补货计划平台供应商代码以及平台供应商名称不能为空");
				throw new BaseException("补货计划平台供应商代码以及平台供应商名称不能为空");
			}
			String billNo = medPlans.getTrmedPlan().getBillNo();
			if (StringUtils.isEmpty(billNo)) {
				logger.error("补货计划单据编号不能为空");
				throw new BaseException("补货计划单据编号不能为空");
			}
			String billType = medPlans.getTrmedPlan().getBillType();
			if (StringUtils.isEmpty(billType)) {
				logger.error("补货计划单据类型不能为空");
				throw new BaseException("补货计划单据类型不能为空");
			}
			List<MedPlanDetail> details = medPlans.getTrmedPlan().getTrmedplandetails();
			if(details == null || details.size() == 0){
				logger.error("补货计划单据编号:"+billNo+"订单明细不能为空");
				throw new BaseException("补货计划单据编号:"+billNo+"订单明细不能为空");
			}
			for (MedPlanDetail medPlanDetail : details) {
				String detailBillNo = medPlanDetail.getBillNo();
				if (StringUtils.isEmpty(detailBillNo)) {
					logger.error("补货计划单据编号:"+billNo+"订单明细单据编号不能为空");
					throw new BaseException("补货计划单据编号:"+billNo+"订单明细单据编号不能为空");
				}
				String goodsCode = medPlanDetail.getGoodsCode();
				String goodsName = medPlanDetail.getGoodsName();
				if (StringUtils.isEmpty(goodsCode) || StringUtils.isEmpty(goodsName)) {
					logger.error("补货计划单据编号:"+billNo+"订单明细商品编码以及商品名称不能为空");
					throw new BaseException("补货计划单据编号:"+billNo+"订单明细商品编码以及商品名称不能为空");
				}
				BigDecimal poQty = medPlanDetail.getPoQty();
				if (poQty == null) {
					logger.error("补货计划单据编号:"+billNo+"订单明细订货数不能为空");
					throw new BaseException("补货计划单据编号:"+billNo+"订单明细订货数不能为空");
				}
				BigDecimal taxpriceoQty = medPlanDetail.getTaxprice();
				if (taxpriceoQty == null) {
					logger.error("补货计划单据编号:"+billNo+"订单明细商品含税单价不能为空");
					throw new BaseException("补货计划单据编号:"+billNo+"订单明细商品含税单价不能为空");
				}
				BigDecimal taxsum = medPlanDetail.getTaxsum();
				if (taxsum == null) {
					logger.error("补货计划单据编号:"+billNo+"订单明细商品含税总金额不能为空");
					throw new BaseException("补货计划单据编号:"+billNo+"订单明细商品含税总金额不能为空");
				}
				String unit = medPlanDetail.getUnit();
				if (StringUtils.isEmpty(unit)) {
					logger.error("补货计划单据编号:"+billNo+"订单明细订货单位不能为空");
					throw new BaseException("补货计划单据编号:"+billNo+"订单明细订货单位不能为空");
				}
				
			}
		}
		
		
	}


	public boolean batchSave(List<MedPlanWithDetail> medPlans) {
		
		boolean result = true;
		try {
			checkMedPlan(medPlans);
		} catch (Exception e) {
			throw new BaseException(e.getMessage());
		}
		for (MedPlanWithDetail medPlanWithDetail : medPlans) {
			MedPlan medPlan = medPlanWithDetail.getTrmedPlan();
			List<MedPlanDetail> details = medPlan.getTrmedplandetails();
			String id = IdUtil.uuid();
			
			medPlanWithDetail.getTrmedPlan().setId(id);
			if(details != null && details.size() != 0){
				for (MedPlanDetail medPlanDetail : details) {
					medPlanDetail.setBillNo(medPlanWithDetail.getTrmedPlan().getBillNo());
					medPlanDetail.setId(id);
				}
				planDao.insert(medPlan);
				planDetailDao.batchInsert(details);
			}
		}
		return result;
	}
	
}