/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-13
 * 描述            ：客户结算货款信息表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Slm.FundManagement.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.FundManagement.mapper.SlmFundSettleGoodMapper;
import market.Slm.FundManagement.service.SlmFundSettleGoodService;
import market.Slm.FundManagement.vo.SlmFundSettleGood;

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

@RemoteService(path="SlmFundSettleGoodService")
public class SlmFundSettleGoodServiceImpl extends BaseServiceImpl<SlmFundSettleGood,Object> implements SlmFundSettleGoodService {

	/**
	 * 结算单-货款-新增
	 * */
	public ResultModel doAdd(SlmFundSettleGood good){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			String id=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+PbMethod.RandomCreate(6);
			good.setFlag("1");
			good.setValid_flag("1");
			good.setSeq(id);		
			good.setCreate_man_no(userId);
			good.setCreate_man_name(userName);
			good.setCreate_time(new Date());
			this.getMapper(SlmFundSettleGoodMapper.class).insert(good);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 查询 line_no
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmFundSettleGood> sum) {
		ResultModel rm=new ResultModel();
		SlmFundSettleGood good=sum.getObject();
		try{
			List<SlmFundSettleGood> goodList=this.getMapper(SlmFundSettleGoodMapper.class).findWithCondition(good,null," create_time desc" ,0, 0);
			rm.setData(goodList);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	public ResultModel doDelete(String bill_no) {
		ResultModel rm=new ResultModel();
		try{
			SlmFundSettleGood good=new SlmFundSettleGood();
			good.setBill_no(bill_no);
			List<SlmFundSettleGood> goodList=this.getMapper(SlmFundSettleGoodMapper.class).find(good, 0, 0);
			for(SlmFundSettleGood goods:goodList){
				this.getMapper(SlmFundSettleGoodMapper.class).delete(goods.getSeq());
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}
}