/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-07-04
 * 描述            ：资材备件库-库存信息表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Lms.Equipment.impl;

import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Equipment.mapper.YdmEquipmentDetailSecondMapper;
import market.Lms.Equipment.service.YdmEquipmentDetailSecondService;
import market.Lms.Equipment.vo.YdmEquipmentDetailSecond;

import org.apache.commons.lang.StringUtils;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;

@RemoteService(path = "YdmEquipmentDetailSecondService")
public class YdmEquipmentDetailSecondServiceImpl extends BaseServiceImpl<YdmEquipmentDetailSecond, Object> implements YdmEquipmentDetailSecondService {
		
	/**
	 * 查询机组二级库存记录
	 * @param cp
	 * @return
	 */
	public ResultModel doQueryYdmEquipmentDetailSecond(CommonPage<YdmEquipmentDetailSecond> cp){
		ResultModel rm=new ResultModel();
		YdmEquipmentDetailSecond yed = cp.getObject();
		try {
			String condition = " and t.quantity > 0";
			if (StringUtils.isNotEmpty(yed.getMachine_code())) {
				condition += " and machine_code = '"+yed.getMachine_code()+"'";
			}
			if (StringUtils.isNotEmpty(yed.getMat_code())) {
				condition += " and mat_code = '"+yed.getMat_code()+"'";
			}
			if (StringUtils.isNotEmpty(yed.getSpec())) {
				condition += " and spec = '"+yed.getSpec()+"'";
			}
			if (StringUtils.isNotEmpty(yed.getSupplier_name())) {
				condition += " and supplier_name = '"+yed.getSupplier_name()+"'";
			}
			String sql = "select t.object_no, t.machine_code,t.machine_name,t.mat_code,t.mat_name,t.srot_code,t.srot_name,t.spec,t.supplier_name,t.unit,"
					+ " t.price,sum(t.quantity) quantity,sum(quantity)*t.price amount from ydm_equipment_detail_second t "
					+ " where 1=1"+ condition
					+ " group by t.object_no, t.machine_code,t.machine_name,t.mat_code,t.mat_name,t.srot_code,t.srot_name,t.spec,t.price,t.supplier_name,t.unit";
			List<YdmEquipmentDetailSecond> yedList = this.getMapper(YdmEquipmentDetailSecondMapper.class).doQueryYdmEquipmentDetailSecond(sql);
			
			rm.setData(yedList);
			rm.setState("200");
			rm.setMsgInfo("查询成功");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("查询失败！"+ex.getMessage());
		}
		return rm;
	}

	
}
