/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.10.24
 * 描述               :        			快递公司信息
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/

package market.Slm.BaseInformation.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.BaseInformation.mapper.SlmBaseExpressMapper;
import market.Slm.BaseInformation.service.SlmBaseExpressService;
import market.Slm.BaseInformation.vo.SlmBaseExpress;

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="SlmBaseExpressService")
public class SlmBaseExpressServiceImpl extends BaseServiceImpl<SlmBaseExpress,Object> implements SlmBaseExpressService {
	/**
	 * 查询
	 * @return
	 */
	public ResultModel doQueryWeb(CommonPage<SlmBaseExpress> sum) {
		ResultModel rm=new ResultModel();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();
		try{
			PageModel<SlmBaseExpress> pm = new PageModel<SlmBaseExpress>(pageIndex,pageSize);
			SlmBaseExpress sb=sum.getObject();
			String sWhere="";
			if(sb!=null){
				if(sb.getExpress_name()!=null&&!"".equals(sb.getExpress_name())){
					sWhere=" express_name like '%"+sb.getExpress_name()+"%' ";
					sb.setExpress_name(null);
				}
				if(sb.getPrint_name()!=null&&!"".equals(sb.getPrint_name())){
					sWhere=sWhere==""?(" print_name like '%"+sb.getPrint_name()+"%' "):(" and print_name like '%"+sb.getPrint_name()+"%' ");
					sb.setPrint_name(null);
				}
			}
	
			pm.setRows(this.getMapper(SlmBaseExpressMapper.class).findWithCondition(sb, sWhere, " express_name ", (pageIndex-1)*pageSize, pageSize));
			pm.setTotal(this.getMapper(SlmBaseExpressMapper.class).countWithCondition(sb,sWhere));
	
			rm.setState("200");
			rm.setData(pm);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;

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

	/**
	 * 添加数据
	 * 
	 * @param bd
	 * @return
	 */
	public ResultModel doAddWeb(CommonPage<SlmBaseExpress> sum) {
		ResultModel rm=new ResultModel();
		try {
			SlmBaseExpress bd=sum.getObject();
			bd.setExpress_no(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3));

			String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			bd.setCreate_man_no(userId);
			bd.setCreate_man_name(userName);
			bd.setValid_flag("1");
			bd.setCreate_time(new Date());
			bd.setPy(PbMethod.getPYIndexStr(bd.getExpress_name(), true));
			this.getMapper(SlmBaseExpressMapper.class).insert(bd);
			rm.setState("200");
			
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，新增失败!");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 修改数据
	 * 
	 * @param bd
	 * @return
	 */
	public ResultModel doUpdateWeb(CommonPage<SlmBaseExpress> sum) {
		ResultModel rm=new ResultModel();
		SlmBaseExpress obd = sum.getObject();
		try {
			String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			obd.setPy(PbMethod.getPYIndexStr(obd.getExpress_name(), true));
			obd.setUpdate_man_no(userId);
			obd.setUpdate_man_name(userName);
			obd.setUpdate_time(new Date());
			this.getMapper(SlmBaseExpressMapper.class).update(obd);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("修改失败!");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 删除数据
	 * @param bd
	 * @return
	 */
	public ResultModel doDeleteWeb(CommonPage<SlmBaseExpress> sum) {
		ResultModel rm=new ResultModel();
		
		SlmBaseExpress obd = sum.getObject();
		try {
			obd.setExpress_no(obd.getExpress_no());
			obd.setValid_flag("0");
			this.getMapper(SlmBaseExpressMapper.class).update(obd);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("删除失败!");
			e.printStackTrace();
		}
		return rm;
	}
	
}
