bb351e3e3628db9a15d76312d57f681d5b8983ba.svn-base 3.86 KB
package com.phxl.modules.goods.service.spills;


import java.math.BigDecimal;
import java.util.Date;
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.util.JsonMapper;
import com.phxl.common.utils.BaseException;
import com.phxl.common.utils.IdUtil;
import com.phxl.modules.goods.dao.spills.HisSpillsDao;
import com.phxl.modules.goods.entity.spills.HisSpills;
import com.phxl.modules.goods.entity.spills.HisSpillsList;

@Service
public class HisSpillsService {

	@Autowired
	private HisSpillsDao hisSpillsDao;
	
	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	
	public boolean batchSave(List<HisSpillsList> spills) {
		boolean result = false;
		if (spills != null && spills.size() != 0) {
			for (HisSpillsList hisSpillsList : spills) {
				HisSpills hisSpills = hisSpillsList.getData();
				try {
					checkSpills(hisSpills);
				} catch (Exception e) {
					String json = JsonMapper.toJsonString(hisSpills);
					logger.error("同步医院盘点损溢单:" + json + "信息异常");
					throw new BaseException(e.getMessage());
				}
				hisSpills.setId(IdUtil.uuid());
				hisSpillsDao.insert(hisSpills);
			}
			
			result = true;
		}
		return result;
	}


	private void checkSpills(HisSpills hisSpills) {
		// 获取库存信息中供应商信息
		String medCode = hisSpills.getMedCode();
		String medName = hisSpills.getMedName();
		String supplierCode = hisSpills.getSupplierCode();
		String supplierName = hisSpills.getSupplierName();
		String stockbillno = hisSpills.getTackStockBillNo(); 
		if (StringUtils.isEmpty(medCode) || StringUtils.isEmpty(medName)) {
			logger.error("盘点损溢信息医疗机构编码以及名称不能为空");
			throw new BaseException("盘点损溢信息医疗机构编码以及名称不能为空");
		}
		if (StringUtils.isEmpty(supplierCode) || StringUtils.isEmpty(supplierName)) {
			logger.error("盘点损溢信息供应商编码以及名称不能为空");
			throw new BaseException("盘点损溢信息供应商编码以及名称不能为空");
		}
		if (StringUtils.isEmpty(stockbillno)) {
			logger.error("盘点单号不能为空");
			throw new BaseException("盘点单号不能为空");
		}
		Date tackStockDate = hisSpills.getTackStockDate();
		if (tackStockDate == null) {
			logger.error("盘点损溢信息报溢时间不能为空");
			throw new BaseException("盘点损溢信息报溢时间不能为空");
		}
		String operaterName = hisSpills.getOperaterName();
		if (StringUtils.isEmpty(operaterName)) {
			logger.error("盘点损溢信息审核人不能为空");
			throw new BaseException("盘点损溢信息审核人不能为空");
		}
		String goodsCode = hisSpills.getGoodsCode();
		if (StringUtils.isEmpty(goodsCode)) {
			logger.error("盘点损溢信息商品编码不能为空");
			throw new BaseException("盘点损溢信息商品编码不能为空");
		}
		String lot = hisSpills.getLot();
		if (StringUtils.isEmpty(lot)) {
			logger.error("盘点损溢信息批号不能为空");
			throw new BaseException("盘点损溢信息批号不能为空");
		}
		BigDecimal number = hisSpills.getNumber();
		if (number == null) {
			logger.error("盘点损溢信息库存数量不能为空");
			throw new BaseException("盘点损溢信息库存数量不能为空");
		}
		BigDecimal storckNum = hisSpills.getStorckNum();
		if (storckNum == null) {
			logger.error("盘点损溢信息盘点数量不能为空");
			throw new BaseException("盘点损溢信息盘点数量不能为空");
		}
		BigDecimal differenceNum = hisSpills.getDifferenceNum();
		if (differenceNum == null) {
			logger.error("盘点损溢信息损溢数量不能为空");
			throw new BaseException("盘点损溢信息损溢数量不能为空");
		}
	}
	
}