/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-13
 * 描述            ：客户二级账户历史信息表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Slm.FundManagement.impl;
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.SlmFundSecondAccountHisMapper;
import market.Slm.FundManagement.service.SlmFundSecondAccountHisService;
import market.Slm.FundManagement.vo.SlmFundSecondAccount;
import market.Slm.FundManagement.vo.SlmFundSecondAccountHis;

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

@RemoteService(path="SlmFundSecondAccountHisService")
public class SlmFundSecondAccountHisServiceImpl extends BaseServiceImpl<SlmFundSecondAccountHis,Object> implements SlmFundSecondAccountHisService {
	
	/**
	 * 查询二级账户的结转信息
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmFundSecondAccountHis> sum){
		ResultModel rm=new ResultModel();
		SlmFundSecondAccountHis his=sum.getObject();
		try{
			List<SlmFundSecondAccountHis> list=this.getMapper(SlmFundSecondAccountHisMapper.class).findWithCondition(null, " second_account_no='"+his.getSecond_account_no()+"'", " carryover_time desc ", 0, 0);
			rm.setState("200");
			rm.setData(list);
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}
	
	//新增
	public ResultModel doAdd(SlmFundSecondAccount account,String carryover_seq){
		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 seq=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(13);
			SlmFundSecondAccountHis his=new SlmFundSecondAccountHis();
			his.setSecond_account_no(account.getSecond_account_no());
			his.setSeq(seq);
			his.setFirst_account_no(account.getFirst_account_no());
			his.setFirst_account_name(account.getFirst_account_name());
			his.setSecond_account_name(account.getSecond_account_name());
			his.setBalance_object_no(account.getBalance_object_no());
			his.setBalance_object_name(account.getBalance_object_name());
			his.setCustomer_no(account.getCustomer_no());
			his.setCustomer_name(account.getCustomer_name());
			his.setDiscount_fund(account.getDiscount_fund());
			his.setInit_fund(account.getInit_fund());
			his.setUse_fund(account.getUse_fund());
			his.setIn_fund(account.getIn_fund());
			his.setOut_fund(account.getOut_fund());
			his.setInit_fund_time(account.getInit_fund_time());
			his.setCarryover_seq(carryover_seq);
			his.setCarryover_flag("1"); 		//结转状态？
			his.setCarryover_man_no(userId);
			his.setCarryover_man_name(userName);
			his.setCarryover_time(new Date());
			this.getMapper(SlmFundSecondAccountHisMapper.class).insert(his);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}
}