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

import jxl.CellView;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import market.Com.pb.DoubleUtil;
import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.FundManagement.mapper.SlmFundFirstAccountMapper;
import market.Slm.FundManagement.mapper.SlmFundSettleBillMapper;
import market.Slm.FundManagement.mapper.SlmFundSettleWriteDownMapper;
import market.Slm.FundManagement.service.SlmFundSettleWriteDownService;
import market.Slm.FundManagement.vo.SlmFundFirstAccount;
import market.Slm.FundManagement.vo.SlmFundSettleBill;
import market.Slm.FundManagement.vo.SlmFundSettleWriteDown;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="SlmFundSettleWriteDownService")
public class SlmFundSettleWriteDownServiceImpl extends BaseServiceImpl<SlmFundSettleWriteDown,Object> implements SlmFundSettleWriteDownService {

	/**
	 * 冲减 - 查询
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		SlmFundSettleWriteDown down=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			String sWhere =" 1=1 ";
			if(startTime!=null&&!"".equals(startTime)){
				sWhere+=" and to_char(settle_write_down_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";
			}
			if(endTime!=null&&!"".equals(endTime)){
				sWhere+=" and to_char(settle_write_down_time, 'yyyy-mm-dd hh24:mi:ss') <= '"+endTime+"'";
			}
			// 写死只查询有效的冲减信息：20220330 treals
			sWhere+=" and VALID_FLAG = '1'";
			List<SlmFundSettleWriteDown> list=this.getMapper(SlmFundSettleWriteDownMapper.class).findWithCondition(down, sWhere, " valid_flag desc, create_time desc", 0, 0);
			rm.setState("200");
			rm.setData(list);
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 新增
	 * */
	public ResultModel doAddWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		SlmFundSettleWriteDown down=sum.getObject();
		try{
			String seq=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+PbMethod.RandomCreate(6);
			down.setSeq(seq);
			down.setCreate_man_no(userId);
			down.setCreate_man_name(userName);
			down.setCreate_time(new Date());
			down.setSettle_write_down_time(new Date());
			down.setValid_flag("1");
			down.setFlag("1"); 		//编辑
			//只能新增一条有效的冲减信息
			SlmFundSettleWriteDown check=new SlmFundSettleWriteDown();
			check.setSettle_bill_no(down.getSettle_bill_no());
			check.setValid_flag("1");
			int count=this.getMapper(SlmFundSettleWriteDownMapper.class).count(check);
			if(count>0){
				rm.setState("500");
				rm.setMsgInfo("该结算单已有一条冲减信息，无法继续新增");
				return rm;
			}

			//补收时，判断该客户的账户的可拨金额是否足够
			rm=doJudgeInOutFund(down);
			if("500".equals(rm.getState())) return rm;
			this.getMapper(SlmFundSettleWriteDownMapper.class).insert(down);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 编辑
	 * */
	public ResultModel doUpdateWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		SlmFundSettleWriteDown down=sum.getObject();
		try{
			if(down.getSeq()==null){
				rm.setState("500");
				rm.setMsgInfo("请传入参数seq");
				return rm;
			}
			SlmFundSettleWriteDown check=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
			if(check==null){
				rm.setState("500");
				rm.setMsgInfo("冲减数据丢失，请联系管理员");
				return rm;
			}
			if(!"1".equals(check.getFlag())){
				rm.setState("500");
				rm.setMsgInfo("只有编辑状态的数据才能修改");
				return rm;
			}
			rm=doJudgeInOutFund(down);
			if("500".equals(rm.getState())) return rm;
			down.setUpdate_man_no(userId);
			down.setUpdate_man_name(userName);
			down.setUpdate_time(new Date());
			this.getMapper(SlmFundSettleWriteDownMapper.class).update(down);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 删除
	 * */
	public ResultModel doDeleteWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SlmFundSettleWriteDown> list=sum.getObjectList();
		try{
			if(list==null){
				rm.setState("500");
				rm.setMsgInfo("请选中数据进行删除");
				return rm;
			}
			for(SlmFundSettleWriteDown down:list){
				SlmFundSettleWriteDown check=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
				if(check!=null&&!"1".equals(check.getFlag())){
					rm.setState("500");
					rm.setMsgInfo("只有编辑状态的数据才能删除");
					return rm;
				}
				down.setDelete_man_no(userId);
				down.setDelete_man_name(userName);
				down.setDelete_time(new Date());
				down.setValid_flag("0"); 	//无效
				this.getMapper(SlmFundSettleWriteDownMapper.class).update(down);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 提交
	 * */
	public ResultModel doSubmitWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SlmFundSettleWriteDown> list=sum.getObjectList();
		try{
			if(list==null){
				rm.setState("500");
				rm.setMsgInfo("请选中数据进行提交");
				return rm;
			}
			for(SlmFundSettleWriteDown down:list){
				SlmFundSettleWriteDown check=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
				if(check==null){
					rm.setState("500");
					rm.setMsgInfo("冲减数据丢失，请联系管理员");
					return rm;
				}
				if(!"1".equals(check.getFlag())){
					rm.setState("500");
					rm.setMsgInfo("只有编辑状态的数据才能提交");
					return rm;
				}
				down.setUpdate_man_no(userId);
				down.setUpdate_man_name(userName);
				down.setUpdate_time(new Date());
				down.setFlag("2"); 		//待确认
				this.getMapper(SlmFundSettleWriteDownMapper.class).update(down);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 撤回
	 * */
	public ResultModel doRollbackWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SlmFundSettleWriteDown> list=sum.getObjectList();
		try{
			if(list==null){
				rm.setState("500");
				rm.setMsgInfo("请选中数据进行提交");
				return rm;
			}
			for(SlmFundSettleWriteDown down:list){
				SlmFundSettleWriteDown check=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
				if(check==null){
					rm.setState("500");
					rm.setMsgInfo("冲减数据丢失，请联系管理员");
					return rm;
				}
				if(!"2".equals(check.getFlag())){
					rm.setState("500");
					rm.setMsgInfo("只有待确认状态的数据才能撤回");
					return rm;
				}
				down.setUpdate_man_no(userId);
				down.setUpdate_man_name(userName);
				down.setUpdate_time(new Date());
				down.setFlag("1"); 		//编辑
				this.getMapper(SlmFundSettleWriteDownMapper.class).update(down);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 审核确认
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doPassWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SlmFundSettleWriteDown> list=sum.getObjectList();
		try{
			if(list==null){
				rm.setState("500");
				rm.setMsgInfo("请选中数据进行提交");
				return rm;
			}
			for(SlmFundSettleWriteDown down:list){
				SlmFundSettleWriteDown check=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
				if(check==null){
					rm.setState("500");
					rm.setMsgInfo("冲减数据丢失，请联系管理员");
					return rm;
				}
				if(!"2".equals(check.getFlag())){
					rm.setState("500");
					rm.setMsgInfo("只有待确认状态的数据才能审核");
					return rm;
				}
				//补收时，判断该客户的账户的可拨金额是否足够
				//				rm=doJudgeInOutFund(check);
				//				if("500".equals(rm.getState())) return rm;
				//去客户账户扣款/加钱
				//				Double money=check.getSettle_write_down_fund();
				//				if("1".equals(check.getSettle_write_down_type())){
				//					money=-money;
				//				}
				//				SlmFundFirstAccount account=(SlmFundFirstAccount) rm.getData();
				//				account.setFinal_fund(DoubleUtil.sub(account.getFinal_fund(), money));	//可拨金额 - 冲减金额
				//				account.setUse_fund(DoubleUtil.sub(account.getUse_fund(), money));		//可用金额 - 冲减金额
				//				account.setBalance_fund(DoubleUtil.sub(account.getBalance_fund(), money));		//财务余额- 冲减金额
				//				account.setWrite_down_fund(DoubleUtil.sub(account.getWrite_down_fund(), money));		//冲减总额 - 冲减金额
				//				this.getMapper(SlmFundFirstAccountMapper.class).update(account);

				down.setUpdate_man_no(userId);
				down.setUpdate_man_name(userName);
				down.setUpdate_time(new Date());
				down.setCheck_man_no(userId);
				down.setCheck_man_name(userName);
				down.setCheck_time(new Date());
				down.setFlag("3"); 		//确认
				this.getMapper(SlmFundSettleWriteDownMapper.class).update(down);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减 - 反审
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doNotPassWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		List<SlmFundSettleWriteDown> list=sum.getObjectList();
		try{
			if(list==null){
				rm.setState("500");
				rm.setMsgInfo("请选中数据进行提交");
				return rm;
			}
			for(SlmFundSettleWriteDown down:list){
				SlmFundSettleWriteDown check=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
				if(check==null){
					rm.setState("500");
					rm.setMsgInfo("冲减数据丢失，请联系管理员");
					return rm;
				}
				if(!"3".equals(check.getFlag())){
					rm.setState("500");
					rm.setMsgInfo("只有确认状态的数据才能反审");
					return rm;
				}
				//判断账户可拨金额是否足够
				down.setUpdate_man_no(userId);
				down.setUpdate_man_name(userName);
				down.setUpdate_time(new Date());
				down.setCheck_man_no("");
				down.setCheck_man_name("");
				down.setFlag("2"); 		//待确认
				this.getMapper(SlmFundSettleWriteDownMapper.class).update(down);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减明细报表
	 * */
	public ResultModel doQueryReportWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		SlmFundSettleWriteDown down=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		String order=sum.getMemo1();		//顺序 0时间 1客户 2冲减类型 3金额 4结算单号
		try{
			if(down==null) down=new SlmFundSettleWriteDown();
			down.setValid_flag("1");
			String sWhere=" 1=1 ";
			String sOrder=" settle_write_down_time desc";
			if(startTime!=null&&!"".equals(startTime)){		
				startTime+=" 00:00:00";
				sWhere+=" and to_char(settle_write_down_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
				sWhere+=" and to_char(settle_write_down_time, 'yyyy-mm-dd hh24:mi:ss') <= '"+endTime+"'";
			}
			if(down.getSettle_bill_no()!=null&&!"".equals(down.getSettle_bill_no())){
				sWhere+=" and settle_bill_no like concat(CONCAT('%','"+down.getSettle_bill_no()+"'),'%')";
				down.setSettle_bill_no(null);
			}
			if("1".equals(order)) sOrder=" customer_no desc,settle_write_down_time desc";
			if("2".equals(order)) sOrder=" settle_write_down_type desc";
			if("3".equals(order)) sOrder=" settle_write_down_fund desc";
			if("4".equals(order)) sOrder=" settle_bill_no desc";
			List<SlmFundSettleWriteDown> down_list=this.getMapper(SlmFundSettleWriteDownMapper.class).findWithCondition(down, sWhere, sOrder, 0, 0);
			SimpleDateFormat sdf=new SimpleDateFormat("MM-dd");
			for(SlmFundSettleWriteDown downs:down_list){
				downs.setDown_time(sdf.format(downs.getSettle_write_down_time()));
				//				downs.setSettle_write_down_time(sdf.parse(sdf.format(downs.getSettle_write_down_time())));
			}

			rm.setState("200");
			rm.setData(down_list);
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 冲减明细报表
	 * */
	public ResultModel doExportReportWeb(CommonPage<SlmFundSettleWriteDown> sum){
		ResultModel rm=new ResultModel();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			// 1，创建一个webbook，对应一个Excel文件
			WritableWorkbook workbook;
			// 2,设置用户下载路径
			String path = this.getRequest().getServletContext().getRealPath("/")+ "excel" + File.separator; // 临时保存路径
			File dir = new File(path);
			if (!dir.exists()) {
				new File(path).mkdir();
			}
			String filename ="";
			if(startTime != null && !"".equals(startTime)&&endTime != null && !"".equals(endTime)){
				filename = startTime +"到"+ endTime + "资金冲减明细";
			}else{
				filename =  "资金冲减明细";
			}
			String file=filename+".xls";  //文件名
			//数据
			rm=doQueryReportWeb(sum);
			List<SlmFundSettleWriteDown> list=(List<SlmFundSettleWriteDown>) rm.getData();

			//3. 操作EXCEL文件
			workbook = Workbook.createWorkbook(new File(path+file));
			WritableSheet sheet = workbook.createSheet("资金冲减明细", 1);
			//行高
			sheet.getSettings().setDefaultRowHeight(300);
			//字体  参数可自行配置
			WritableFont font1 = new WritableFont(WritableFont.ARIAL,11,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE);  
			WritableCellFormat cellFormat1 = new WritableCellFormat(font1); 
			cellFormat1.setAlignment(Alignment.CENTRE);
			cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
			//
			jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#.##"); //设置数字格式
			jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); //设置表单格式
			wcfN.setAlignment(Alignment.CENTRE);
			wcfN.setVerticalAlignment(VerticalAlignment.CENTRE);
			CellView cellView = new CellView();  
			cellView.setAutosize(true); //设置自动大小

			//表头
			sheet.mergeCells(0, 0, 0, 1);
			sheet.addCell(new Label(0,0,"序号",cellFormat1));

			sheet.mergeCells(1, 0, 1, 1);
			sheet.addCell(new Label(1,0,"日期",cellFormat1));

			sheet.mergeCells(2, 0, 2, 1);
			sheet.addCell(new Label(2,0,"用户",cellFormat1));

			sheet.mergeCells(3, 0, 3, 1);
			sheet.addCell(new Label(3,0,"类型",cellFormat1));

			sheet.mergeCells(4, 0, 4, 1);
			sheet.addCell(new Label(4,0,"金额",cellFormat1));

			sheet.mergeCells(5, 0, 5, 1);
			sheet.addCell(new Label(5,0,"结算单号",cellFormat1));

			sheet.mergeCells(6, 0, 6, 1);
			sheet.addCell(new Label(6,0,"备注",cellFormat1));

			WritableFont font = new WritableFont(WritableFont.ARIAL,11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE);  
			WritableCellFormat cellFormat = new WritableCellFormat(font); 
			cellFormat.setAlignment(Alignment.CENTRE);
			cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
			//时间转字符串的格式
			SimpleDateFormat newsdf = new SimpleDateFormat("MM-dd");
			double total_money = 0;
			for(int i = 0; i < list.size(); i++) {
				//序号
				sheet.addCell(new Label(0,i+2,""+(i+1),cellFormat));
				//日期
				if(list.get(i).getSettle_write_down_time() != null ) {
					sheet.addCell(new Label(1,i+2,newsdf.format(list.get(i).getSettle_write_down_time()),cellFormat));
				}
				//用户
				sheet.setColumnView(i+2, cellView);//根据内容自动设置列宽  
				sheet.addCell(new Label(2,i+2,list.get(i).getCustomer_name(),cellFormat));
				//类型
				String type="冲减";
				if("2".equals(list.get(i).getSettle_write_down_type())) type="补收";
				sheet.addCell(new Label(3,i+2,type,cellFormat));
				//金额
				if(list.get(i).getSettle_write_down_fund() != null ) {
					double  money=DoubleUtil.round(list.get(i).getSettle_write_down_fund(),2);
					sheet.addCell(new Label(4,i+2,String.valueOf(money),wcfN));
					total_money=DoubleUtil.add(total_money,money);
				}
				//结算单号
				sheet.addCell(new Label(5,i+2,list.get(i).getSettle_bill_no(),cellFormat));
				//备注
				sheet.addCell(new Label(6,i+2,list.get(i). getMemo(),cellFormat));
			}

			sheet.addCell(new Label(0,list.size()+2,"合计",cellFormat));
			WritableCellFormat cellFormat2 = new WritableCellFormat(font); 
			cellFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
			DecimalFormat df=new DecimalFormat("0.00");
			sheet.addCell(new Label(4,list.size()+2,String.valueOf(df.format(total_money)),cellFormat2));//统计总回款金额
			sheet.getSettings().setVerticalFreeze(1);  		//首行冻结
			sheet.getSettings().setVerticalFreeze(2);
			//关闭
			workbook.write();
			workbook.close();

			rm.setData("/download?filename="+file);

			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	//补收时，判断该客户的账户的可拨金额是否足够
	private ResultModel doJudgeInOutFund(SlmFundSettleWriteDown down) {
		ResultModel rm=new ResultModel();
		rm.setState("200");
		try{
			if(down.getCustomer_no()==null){
				rm.setState("500");
				rm.setMsgInfo("请选择一个客户");
				return rm;
			}
			SlmFundFirstAccount account=new SlmFundFirstAccount();
			account.setCustomer_no(down.getCustomer_no());
			List<SlmFundFirstAccount> accountList=this.getMapper(SlmFundFirstAccountMapper.class).find(account,0,0);
			if(accountList.size()>0){
				account=accountList.get(0);
				if("1".equals(account.getLock_flag())){
					rm.setState("500");
					rm.setMsgInfo("该合同账户已结转，如须冲减请解锁");
				}
				//是1.冲减（从客户账户里扣款）则判断金额是否大于结算单金额
				if("1".equals(down.getSettle_write_down_type())){		
					SlmFundSettleBill bill=this.getMapper(SlmFundSettleBillMapper.class).findById(down.getSettle_bill_no());
					if(bill!=null){
						if(down.getSettle_write_down_fund()>bill.getBalance_amount()){
							rm.setState("500");
							rm.setMsgInfo("冲减金额["+down.getSettle_write_down_fund()+"]超出客户账户的可用金额["+account.getUse_fund()+"]，无法补收");
							return rm;
						}
					}
				}
				//是2.补收（从客户账户里扣款）则判断金额是否足够
				if(down.getSettle_write_down_fund()>account.getUse_fund()&&"2".equals(down.getSettle_write_down_type())){		//与可拨金额比对
					rm.setState("500");
					rm.setMsgInfo("冲减金额["+down.getSettle_write_down_fund()+"]超出客户账户的可用金额["+account.getUse_fund()+"]，无法补收");
					return rm;
				}
				rm.setData(account);
			}else{
				rm.setState("500");
				rm.setMsgInfo("未找到对应的客户账户");
				return rm;
			}
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

//	/**
//	 * 发送冲减信息给NC
//	 * */
//	@SuppressWarnings("unchecked")
//	public ResultModel sendSettleBillToNc(SlmFundSettleWriteDown down) throws Exception{
//		ResultModel rm=new ResultModel();
//		try{
//			down=this.getMapper(SlmFundSettleWriteDownMapper.class).findById(down.getSeq());
//			if(down==null){
//				rm.setState("500");
//				rm.setMsgInfo("未找到冲减信息");
//				return rm;
//			}
//			//组合参数
//			String param=PbMethod.toStringWeb(down);
////			param="["+param+"]";
//
//			//调用用友接口传参
//			MessystemToNC65ServiceLocator locator=new MessystemToNC65ServiceLocator();
//			OuterSystemRetVO result=new OuterSystemRetVO();
////			result=locator.getMessystemToNC65ServiceSOAP11port_http().distributeMd("be02","q02","ADD", param);
//			if(result!=null){
//				rm.setState("200");
//				rm.setMsgInfo(result.getErrorMsg());
//			}
//			rm.setState("200");
//		}catch(Exception e){
//			rm.setState("500");
//			rm.setMsgInfo(e.getMessage());
//		}
//		return rm;
//	}
}