345476fdb7c9dccadccd44593d77575c6964b20f.svn-base 2.34 KB
package com.phxl.modules.goods.service.hisCtMedicineMaterial;

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 org.springframework.transaction.annotation.Transactional;

import com.phxl.common.utils.BaseException;
import com.phxl.common.utils.IdUtil;
import com.phxl.modules.goods.dao.hisCtMedicineMaterial.HisCtMedicineMaterialDao;
import com.phxl.modules.goods.entity.hisCtMedicineMaterial.HisCtMedicineMaterial;


@Service
public class HisCtMedicineMaterialService{

    @Autowired
    private HisCtMedicineMaterialDao hisCtMedicineMaterialDao;
    
    /**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());

	
	/**
	 * 同步药品目录信息
	 */
	@Transactional
	public String saveMedicine(HisCtMedicineMaterial materials) {
		try {
			checkMaterial(materials);
			if(hisCtMedicineMaterialDao.get(materials)!=null){
				hisCtMedicineMaterialDao.update(materials);
			}else{
				materials.setId(IdUtil.uuid());
				hisCtMedicineMaterialDao.insert(materials);
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new BaseException(e.getMessage()); 
		}
		return "1";
	}


	private void checkMaterial(HisCtMedicineMaterial materials) {
		String medCode = materials.getMedCode();
		String medName = materials.getMedName();
		if (StringUtils.isEmpty(medCode) || StringUtils.isEmpty(medName)) {
			logger.error("前置机:药品目录医疗机构编码以及医疗机构名称不能为空");
			throw new BaseException("前置机:药品目录医疗机构编码以及医疗机构名称不能为空");
		}
		String goodsCode = materials.getGoodsCode();
		String goodsName = materials.getGoodsName();
		if (StringUtils.isEmpty(goodsCode) || StringUtils.isEmpty(goodsName)) {
			logger.error("前置机:药品目录商品编码以及商品名称不能为空");
			throw new BaseException("前置机:药品目录商品编码以及商品名称不能为空");
		}
		String goodsSpec = materials.getGoodsSpec();
		if (StringUtils.isEmpty(goodsSpec)) {
			logger.error("前置机:药品目录商品规格不能为空");
			throw new BaseException("前置机:药品目录商品规格不能为空");
		}
	}


	public String createRequest() {

		return null;
		
	}

	
}