/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-02-26
 * 描述            ：产能井设置表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.com.service.impl;
import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.com.mapper.ComBaseWellMapper;
import market.Qms.com.service.ComBaseWellService;
import market.Qms.com.vo.ComBaseWell;

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

@RemoteService(path="ComBaseWellService")
public class ComBaseWellServiceImpl extends BaseServiceImpl<ComBaseWell,Object> implements ComBaseWellService {
	public ResultModel doQueryWeb(CommonPage<ComBaseWell> sum) {
		ResultModel rm=new ResultModel();
		try{
			ComBaseWell well=sum.getObject();
			PageModel<ComBaseWell> pm = new PageModel<ComBaseWell>(sum.getPageIndex(),sum.getPageSize());
			pm.setRows(this.getMapper(ComBaseWellMapper.class).find(well, sum.getSkipResults(), sum.getPageSize()));
			pm.setTotal(this.getMapper(ComBaseWellMapper.class).count(well));
			rm.setState("200");
			rm.setMsgInfo("查询成功！");
			rm.setData(pm);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	/**
	 * 添加数据
	 * 
	 * @param bd
	 * @return
	 */
	public ResultModel doAddWeb(CommonPage<ComBaseWell> sum) {
		ResultModel rm=new ResultModel();
		ComBaseWell object = sum.getObject();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			ComBaseWell cbw =sum.getObject()==null?(new ComBaseWell()):sum.getObject();
			cbw.setWell_code(this.getMapper(ComBaseWellMapper.class).GetMaxCode());
			cbw.setCreate_name(userName);
			cbw.setCreate_time(new Date());
			this.getMapper(ComBaseWellMapper.class).insert(cbw);
			rm.setState("200");
			rm.setMsgInfo("新增成功！");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，新增失败!");
			e.printStackTrace();
		}
		return rm;
	}
	public ResultModel doupdate(CommonPage<ComBaseWell> sum) {
		ResultModel rm=new ResultModel();
		ComBaseWell object = sum.getObject();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			ComBaseWell cbw =sum.getObject()==null?(new ComBaseWell()):sum.getObject();
			cbw.setUpdate_name(userName);
			cbw.setUpdate_time(new Date());
			this.getMapper(ComBaseWellMapper.class).update(cbw);
			rm.setState("200");
			rm.setMsgInfo("修改成功！");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，新增失败!");
			e.printStackTrace();
		}
		return rm;
	}
	/**
	 * 作废数据
	 * 
	 * @param bd
	 * @return
	 */
	public ResultModel doInvaild(CommonPage<ComBaseWell> oci) {
		ResultModel rm=new ResultModel();
		ComBaseWell bd = oci.getObject();
		List<ComBaseWell> objectList = oci.getObjectList();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date date = new Date();
		try {
//			ComBaseWell object = oci.getObject();
			for(ComBaseWell object:objectList){
			ComBaseWell c = new ComBaseWell();
			c.setWell_code(object.getWell_code());
			List<ComBaseWell> list = this.getMapper(ComBaseWellMapper.class).find(c, 0, 0);
			if(!list.isEmpty()){
				if(list.get(0).getValidflag().equals("0")){
					rm.setMsgInfo("该信息已经作废！");
					rm.setState("500");
					return rm;
				}
			}
			object.setDelete_name(userName);
			object.setDelete_time(date);
			object.setValidflag("0");
			this.getMapper(ComBaseWellMapper.class).update(object);
			}
				rm.setState("200");	
			rm.setMsgInfo("作废成功！");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("修改失败!");
			e.printStackTrace();
		}
		return rm;
	}	
	
	/**
	 * 动作恢复
	 * @param bd
	 * @return
	 */
	public ResultModel doRecover(CommonPage<ComBaseWell> oci) {
		ResultModel rm=new ResultModel();
		ComBaseWell bd = oci.getObject();
		List<ComBaseWell> objectList = oci.getObjectList();
		try {
//			ComBaseWell object = oci.getObject();
			for(ComBaseWell object:objectList){
			ComBaseWell c = new ComBaseWell();
			c.setWell_code(object.getWell_code());
			List<ComBaseWell> list = this.getMapper(ComBaseWellMapper.class).find(c, 0, 0);
			if(!list.isEmpty()){
				if(list.get(0).getValidflag().equals("1")){
					rm.setMsgInfo("该信息已经恢复！");
					rm.setState("500");
					return rm;
				}
			}
			this.getMapper(ComBaseWellMapper.class).doRecovery(object.getWell_code());
			}
				rm.setState("200");	
			rm.setMsgInfo("恢复成功！");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("修改失败!");
			e.printStackTrace();
		}
		return rm;
}
}
