package com.hzya.frame.sys.productVersion.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.sys.product.dao.ISysProductMapper;
import com.hzya.frame.sys.product.entity.SysProduct;
import com.hzya.frame.sys.productVersion.dao.ISysProductVersionMapper;
import com.hzya.frame.sys.productVersion.entity.SysProductVersion;
import com.hzya.frame.sys.productVersion.service.ISysProductVersionService;
import com.hzya.frame.serviceUtil.ServiceUtil;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 产品版本表  service
 * @tableName:   sys_product_version
 * @entityName:  Sysproductversion
 * @author: 	 llg
 * @history:	 1.0
 */
@Service(value = "sysProductVersionService")
public class  SysProductVersionServiceImpl    extends ServiceUtil implements ISysProductVersionService {

	@Resource
	private ISysProductVersionMapper sysProductVersionMapper ;

	@Resource
	private ISysProductMapper sysProductMapper ;

	@Override
	public JsonResultEntity queryProductVersion(JSONObject jsonObject) {
		SysProductVersion sysProductVersion = getData("jsonStr",jsonObject,SysProductVersion.class);
		if(sysProductVersion.getProductId() == null || "".equals(sysProductVersion.getProductId()) ){
			SysProduct sysProduct = new SysProduct();
			sysProduct.setSts("Y");
			sysProduct.setCode(sysProductVersion.getCode());
			List<SysProduct> sysProductList	= sysProductMapper.entity_list_base(sysProduct);
			if(sysProductList == null && sysProductList.size() != 1){
				return BaseResult.getFailureMessageEntity("获取产品版本失败");
			}
			sysProductVersion.setProductId(sysProductList.get(0).getId());
		}
		sysProductVersion.setSts("Y");
		//查询产品参数
		List<SysProductVersion> sysProductVersionList = sysProductVersionMapper.entity_list_base(sysProductVersion);
		return BaseResult.getSuccessMessageEntity("获取产品版本成功", sysProductVersionList);
	}
}
