/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-02-02
 * 描述            ：炼钢牌号适用钢级牌号表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.metallurgy.impl;
import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.metallurgy.mapper.ComBaseGradeRSteelMapper;
import market.Qms.metallurgy.service.ComBaseGradeRSteelService;
import market.Qms.metallurgy.vo.ComBaseGradeRSteel;

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

@RemoteService(path = "ComBaseGradeRSteelService")
public class ComBaseGradeRSteelServiceImpl extends BaseServiceImpl<ComBaseGradeRSteel,Object> implements ComBaseGradeRSteelService {

	/****
	 * 炼钢牌号——维护确认勾选
	 * @param cp
	 * 传入参数：钢种代码grade_code
	 * @return
	 */
	public ResultModel doQueryGradeRSteel(CommonPage<ComBaseGradeRSteel> cp){
		ResultModel rm=new ResultModel();
		ComBaseGradeRSteel cbGradeRSteel = cp.getObject();
		String condition = "1=1 and GRADE_CODE = '" + cbGradeRSteel.getGrade_code() + "'";
		try {
			rm.setData(this.getMapper(ComBaseGradeRSteelMapper.class).findWithCondition(null, condition, null, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("保存失败！");
			e.printStackTrace();
		}
		return rm;
	}
	
	/******
	 * 炼钢牌号——维护
	 * @param cp
	 * memo1:炼钢代码grade_code
	 * @return
	 */
	public ResultModel doSaveGradeRSteel(CommonPage<ComBaseGradeRSteel> cp){
		ResultModel rm=new ResultModel();
		List<ComBaseGradeRSteel> cSteels = cp.getObjectList();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String grade_code = cp.getMemo1();
		try {
			this.getMapper(ComBaseGradeRSteelMapper.class).doDelete(grade_code);
			if (cSteels != null) {
				for (ComBaseGradeRSteel comBaseGradeRSteel : cSteels) {
					if (comBaseGradeRSteel.getCreate_time() != null) {
						comBaseGradeRSteel.setUpdate_name(userName);
						comBaseGradeRSteel.setUpdate_time(new Date());
						comBaseGradeRSteel.setGrade_code(grade_code);
						this.getMapper(ComBaseGradeRSteelMapper.class).insert(comBaseGradeRSteel);
						rm.setState("200");
					}else {
						comBaseGradeRSteel.setCreate_name(userName);
						comBaseGradeRSteel.setCreate_time(new Date());
						comBaseGradeRSteel.setValidflag("1");
						comBaseGradeRSteel.setGrade_code(grade_code);
						this.getMapper(ComBaseGradeRSteelMapper.class).insert(comBaseGradeRSteel);
						rm.setState("200");
					}
				}
			}
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("保存失败！");
			e.printStackTrace();
		}
		return rm;
	}
	
	
	public boolean doSaveGradeRSteelxz(List<ComBaseGradeRSteel> Steels,String grade_code){
		boolean count=false;
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			this.getMapper(ComBaseGradeRSteelMapper.class).doDelete(grade_code);
			if (Steels != null) {
				for (ComBaseGradeRSteel comBaseGradeRSteel : Steels) {
					if (comBaseGradeRSteel.getCreate_time() != null) {
						comBaseGradeRSteel.setUpdate_name(userName);
						comBaseGradeRSteel.setUpdate_time(new Date());
						comBaseGradeRSteel.setGrade_code(grade_code);
						this.getMapper(ComBaseGradeRSteelMapper.class).insert(comBaseGradeRSteel);
						count=true;
					}else {
						comBaseGradeRSteel.setCreate_name(userName);
						comBaseGradeRSteel.setCreate_time(new Date());
						comBaseGradeRSteel.setValidflag("1");
						comBaseGradeRSteel.setGrade_code(grade_code);
						this.getMapper(ComBaseGradeRSteelMapper.class).insert(comBaseGradeRSteel);
						count=true;
					}
				}
			}
		} catch (Exception e) {
			count=false;
			e.printStackTrace();
		}
		return count;
	}
}
