/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.10.24
 * 描述               :        			客户运输线路信息
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
 ***********************************************************/
package market.Slm.CustomerInformation.impl;

import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.CustomerInformation.mapper.SlmCustomerTransLineMapper;
import market.Slm.CustomerInformation.service.SlmCustomerTransLineService;
import market.Slm.CustomerInformation.vo.SlmCustomerTransLine;

import org.springframework.transaction.annotation.Transactional;

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="SlmCustomerTransLineService")
public class SlmCustomerTransLineServiceImpl extends BaseServiceImpl<SlmCustomerTransLine,Object> implements SlmCustomerTransLineService {
	/**
	 * 查询
	 * @return
	 */
	public ResultModel doQueryWeb(CommonPage<SlmCustomerTransLine> sum) {
		ResultModel rm=new ResultModel();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();

		PageModel<SlmCustomerTransLine> pm = new PageModel<SlmCustomerTransLine>(pageIndex,pageSize);

		try {
			SlmCustomerTransLine sb=sum.getObject();
			pm.setRows(this.getMapper(SlmCustomerTransLineMapper.class).findWithCondition(sb, null, null, (pageIndex-1)*pageSize, pageSize));
			pm.setTotal(this.getMapper(SlmCustomerTransLineMapper.class).count(sb));
			rm.setState("200");
			rm.setData(pm);

		} catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 查看详情
	 * */
	public ResultModel doQueryDetailWeb(CommonPage<SlmCustomerTransLine> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setState("200");
			rm.setData(this.getMapper(SlmCustomerTransLineMapper.class).findById(sum.getObject().getLine_no()));
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 添加数据
	 * @throws Exception 
	 * 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doAddWeb(CommonPage<SlmCustomerTransLine> sum) throws Exception {
		ResultModel rm=new ResultModel();
		try {
			SlmCustomerTransLine bd=sum.getObject();

			String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			SlmCustomerTransLine sctl=new SlmCustomerTransLine();
			sctl.setSolutions_no(bd.getSolutions_no());
			int icount=this.getMapper(SlmCustomerTransLineMapper.class).count(sctl)+1;
			bd.setLine_no(bd.getSolutions_no()+String.format("%03d", icount));
			bd.setSeq(icount);
			bd.setCreate_man_no(userId);
			bd.setCreate_man_name(userName);
			bd.setValid_flag("1");
			bd.setCreate_time(new Date());
			this.getMapper(SlmCustomerTransLineMapper.class).insert(bd);
			rm.setState("200");

		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，新增失败!");
			e.printStackTrace();
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 修改数据
	 * @param br
	 * @return
	 * @throws Exception 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doUpdateWeb(CommonPage<SlmCustomerTransLine> sum) throws Exception {
		ResultModel rm=new ResultModel();
		SlmCustomerTransLine bd = sum.getObject();
		try {
			String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);

			bd.setUpdate_man_no(userId);
			bd.setUpdate_man_name(userName);
			bd.setUpdate_time(new Date());
			this.getMapper(SlmCustomerTransLineMapper.class).update(bd);

			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("修改失败!");
			e.printStackTrace();
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;			
	}

	/**
	 * 启用、停用数据
	 * @param bd
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateFlagWeb(CommonPage<SlmCustomerTransLine> sum) {
		ResultModel rm=new ResultModel();
		List<SlmCustomerTransLine> obd = sum.getObjectList();
		for(SlmCustomerTransLine sbr:obd){
			this.getMapper(SlmCustomerTransLineMapper.class).update(sbr);
		}
		rm.setState("200");
		return rm;
	}
}
