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

import market.Com.pb.DoubleUtil;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.CustomerInformation.mapper.SlmCustomerAccountMapper;
import market.Slm.CustomerInformation.vo.SlmCustomerAccount;
import market.Slm.FundManagement.mapper.SlmFundDiscountMapper;
import market.Slm.FundManagement.mapper.SlmFundInvoiceApplyDetailMapper;
import market.Slm.FundManagement.mapper.SlmFundInvoiceApplyMapper;
import market.Slm.FundManagement.mapper.SlmFundInvoiceManageMapper;
import market.Slm.FundManagement.mapper.SlmFundSettleBillMapper;
import market.Slm.FundManagement.mapper.SlmFundSettleWriteDownMapper;
import market.Slm.FundManagement.service.SlmFundInvoiceApplyService;
import market.Slm.FundManagement.vo.SlmFundDiscount;
import market.Slm.FundManagement.vo.SlmFundInvoiceApply;
import market.Slm.FundManagement.vo.SlmFundInvoiceApplyDetail;
import market.Slm.FundManagement.vo.SlmFundInvoiceManage;
import market.Slm.FundManagement.vo.SlmFundSettleBill;
import market.Slm.FundManagement.vo.SlmFundSettleBillInvoice;
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="SlmFundInvoiceApplyService")
public class SlmFundInvoiceApplyServiceImpl extends BaseServiceImpl<SlmFundInvoiceApply,Object> implements SlmFundInvoiceApplyService {

	static double tax=13d;
	/**
	 * 票据查询
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmFundInvoiceApply> sum){
		ResultModel rm=new ResultModel();
		SlmFundInvoiceApply apply=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		String flag=sum.getMemo1(); 			//1红字开票申请 （负金额）
		try{
			List<SlmFundInvoiceApply> list=this.getMapper(SlmFundInvoiceApplyMapper.class).findbill(apply, startTime, endTime,flag);
			rm.setState("200");
			rm.setData(list);
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 开票新增
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		ResultModel rm=new ResultModel();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		SlmFundInvoiceApply invo=sum.getObject();
		List<SlmFundInvoiceApply> invoice_list=sum.getObjectList();
		boolean in=true;
		try{
			if(invoice_list==null||(invoice_list!=null&&invoice_list.size()==0)){
				invoice_list=new ArrayList<SlmFundInvoiceApply>();
				invoice_list.add(invo);
				in=false;
			}

			for(SlmFundInvoiceApply invoice:invoice_list){
				//修改结算单信息
				SlmFundSettleBill bill=this.getMapper(SlmFundSettleBillMapper.class).findById(invoice.getSettle_bill_no());
				if(bill==null){
					rm.setState("500");
					rm.setMsgInfo("结算单信息丢失，请联系管理员");
					return rm;
				}
				if(!"3".equals(bill.getFlag())){
					rm.setState("500");
					rm.setMsgInfo("状态为确认的结算单才能进行开票申请");
					return rm;
				}
				//查询客户账户信息
				List<SlmCustomerAccount> account_list=this.getMapper(SlmCustomerAccountMapper.class).findWithCondition(null, " customer_no='"+invoice.getCustomer_no()+"'", null, 0, 0);
				if(account_list.size()==0){
					rm.setState("500");
					rm.setMsgInfo("未查询到该客户的账户信息");
					return rm;
				}
				//新增票据信息
				String date=new SimpleDateFormat("yyyy-MMdd").format(new Date());
				String maxId=this.getMapper(SlmFundInvoiceApplyMapper.class).findMaxId(date);
				if(maxId==null){
					date+="-0001";
				}else{
					String seq=maxId.substring(10);
					long seql=Long.parseLong(seq)+1;
					seq=String.format("%04d", seql);
					date+="-"+seq;
				}
				invoice.setApply_no(date);
				invoice.setValid_flag("1"); 		//有效
				invoice.setApply_flag("1"); 		//编辑
				invoice.setCreate_man_no(userId);
				invoice.setCreate_man_name(userName);
				invoice.setCreate_time(new Date());
				//开票金额计算（有冲减信息）
				double down_money=0;
				List<SlmFundSettleWriteDown> downList=this.getMapper(SlmFundSettleWriteDownMapper.class).findWithCondition(null, " settle_bill_no='"+invoice.getSettle_bill_no()+"' and valid_flag='1' and flag in ('3','4','5')", null,0,0);		
				for(SlmFundSettleWriteDown downs:downList){
					if("1".equals(downs.getSettle_write_down_type())){ 		//冲减
						down_money=DoubleUtil.sub(down_money, downs.getSettle_write_down_fund());
					}else{
						down_money=DoubleUtil.add(down_money, downs.getSettle_write_down_fund());
					}
					if("3".equals(downs.getFlag())){
						downs.setFlag("4"); 		//使用
						this.getMapper(SlmFundSettleWriteDownMapper.class).update(downs);
					}
				}
				if(invoice.getInvoice_fund()==null){
					invoice.setInvoice_fund(DoubleUtil.add(invoice.getBalance_amount(),down_money));
				}else{
					invoice.setInvoice_fund(DoubleUtil.add(invoice.getInvoice_fund(),down_money));
				}
//				if(invoice.getTax_rate()==null)
				invoice.setTax_rate(tax);
				this.getMapper(SlmFundInvoiceApplyMapper.class).insert(invoice);
				//票据子表新增
				if(invoice.getDetailList()!=null){
					int i=1;
					for(SlmFundInvoiceApplyDetail detail:invoice.getDetailList()){
						if(in){
							//参数转换
							detail.setSpec(detail.getWidth()+"*"+detail.getThick());
							detail.setCarriage_price(detail.getTrade_price());
							detail.setBalance_good_price(detail.getContract_price());
							detail.setBalance_work_price(detail.getWork_price());
							detail.setBalance_amount(detail.getAmount());
						}

						detail.setApply_no(date);
						detail.setSeq(date+"-"+String.format("%04d", i));
						this.getMapper(SlmFundInvoiceApplyDetailMapper.class).insert(detail);
						i++;
					}
				}
				bill.setFlag("4"); 		//开票申请
				bill.setUpdate_man_no(userId);
				bill.setUpdate_man_name(userName);
				bill.setUpdate_time(new Date());
				this.getMapper(SlmFundSettleBillMapper.class).update(bill);
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			e.printStackTrace();
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 票据修改
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWeb(CommonPage<SlmFundInvoiceApply> 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);
		SlmFundInvoiceApply invoice=sum.getObject();
		try{
			if(invoice==null||invoice.getApply_no()==null){
				rm.setState("500");
				rm.setMsgInfo("请选择数据进行修改");
				return rm;
			}
			SlmFundInvoiceApply check=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(invoice.getApply_no());
			if(check==null||!"1".equals(check.getApply_flag())){
				rm.setState("500");
				rm.setMsgInfo("票据状态不为编辑无法修改");
				return rm;
			}
			invoice.setUpdate_man_no(userId);
			invoice.setUpdate_man_name(userName);
			invoice.setUpdate_time(new Date());
			this.getMapper(SlmFundInvoiceApplyMapper.class).update(invoice);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 票据删除
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		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<SlmFundInvoiceApply> invoice_list=sum.getObjectList();
		try{
			for(SlmFundInvoiceApply invoice:invoice_list){
				invoice=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(invoice.getApply_no());
				if(invoice==null){
					rm.setState("500");
					rm.setMsgInfo("数据不存在，请联系管理员处理");
					return rm;
				}
				if(!"1".equals(invoice.getApply_flag())){
					rm.setState("500");
					rm.setMsgInfo("只有编辑状态的数据才能删除");
					return rm;
				}
				if(invoice.getInvoice_fund()!=null&&invoice.getInvoice_fund()<0){
					SlmFundInvoiceManage manage=this.getMapper(SlmFundInvoiceManageMapper.class).findById(invoice.getInvoice_no());
					if(manage!=null){
						manage.setHave_red("0");
						this.getMapper(SlmFundInvoiceManageMapper.class).update(manage);
					}
				}
				invoice.setValid_flag("0"); 		//无效
				invoice.setDelete_man_no(userId);
				invoice.setDelete_man_name(userName);
				invoice.setDelete_time(new Date());
				this.getMapper(SlmFundInvoiceApplyMapper.class).update(invoice);
				//结算单的状态回到3
				if(invoice.getInvoice_fund()!=null&&invoice.getInvoice_fund()>0){
					SlmFundSettleBill bill=this.getMapper(SlmFundSettleBillMapper.class).findById(invoice.getSettle_bill_no());
					if(bill!=null){
						bill.setFlag("3");
						bill.setUpdate_man_no(userId);
						bill.setUpdate_man_name(userName);
						bill.setUpdate_time(new Date());
						this.getMapper(SlmFundSettleBillMapper.class).update(bill);
					}
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 提交
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSubmitWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		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<SlmFundInvoiceApply> billList=sum.getObjectList();
		try{
			for(SlmFundInvoiceApply bill:billList){
				bill=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(bill.getApply_no());
				if(bill!=null&&"1".equals(bill.getApply_flag())){
					bill.setUpdate_man_no(userId);
					bill.setUpdate_man_name(userName);
					bill.setUpdate_time(new Date());
					bill.setApply_flag("2");		//待确认
					this.getMapper(SlmFundInvoiceApplyMapper.class).update(bill);
				}else{
					rm.setState("500");
					rm.setMsgInfo("只有编辑状态的数据才能提交");
					return rm;
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 撤回
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doRollbackWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		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<SlmFundInvoiceApply> billList=sum.getObjectList();
		try{
			for(SlmFundInvoiceApply bill:billList){
				bill=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(bill.getApply_no());
				if(bill!=null&&"2".equals(bill.getApply_flag())){
					bill.setUpdate_man_no(userId);
					bill.setUpdate_man_name(userName);
					bill.setUpdate_time(new Date());
					bill.setApply_flag("1");   		//编辑
					this.getMapper(SlmFundInvoiceApplyMapper.class).update(bill);
				}else{
					rm.setState("500");
					rm.setMsgInfo("只有待确认状态的数据才能撤回");
					return rm;
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 审核通过
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doPassWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		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<SlmFundInvoiceApply> billList=sum.getObjectList();
		try{
			for(SlmFundInvoiceApply bill:billList){
				bill=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(bill.getApply_no());
				if(bill!=null&&"2".equals(bill.getApply_flag())){
					bill.setUpdate_man_no(userId);
					bill.setUpdate_man_name(userName);
					bill.setUpdate_time(new Date());
					bill.setApply_flag("3");   		//确认
					this.getMapper(SlmFundInvoiceApplyMapper.class).update(bill);

					//红字开票通过时，判断结算单状态，已结算则吐出
					if(bill.getInvoice_fund()!=null&&bill.getInvoice_fund()<0){
						SlmFundSettleBill settle_bill=this.getMapper(SlmFundSettleBillMapper.class).findById(bill.getSettle_bill_no());
						if(settle_bill!=null){
//							if("6".equals(settle_bill.getFlag())){		//已结算 ，吐出金额

//							}else
							if("5".equals(settle_bill.getFlag())||"4".equals(settle_bill.getFlag())){//未结算，改为确认3
								settle_bill.setFlag("3");
								this.getMapper(SlmFundSettleBillMapper.class).update(settle_bill);
							}
						}
					}
					//对应发票号 从财务系统获取
					try{
						SlmFundSettleBill param=new SlmFundSettleBill();
						param.setSettle_bill_no(bill.getSettle_bill_no());
						param.setMemo(bill.getApply_no());
						this.getBean(SlmFundSettleBillServiceImpl.class).sendSettleBillToNc(param);
					}catch(Exception e){
						rm.setState("500");
						rm.setMsgInfo("获取发票编号异常，需手动新增发票编号"+e.getMessage());
						return rm;
					}

				}else{
					rm.setState("500");
					rm.setMsgInfo("只有待确认状态的数据才能审核");
					return rm;
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 反审 确认改成待确认
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doNotPassWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		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<SlmFundInvoiceApply> billList=sum.getObjectList();
		try{
			for(SlmFundInvoiceApply bill:billList){
				bill=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(bill.getApply_no());
				if(bill!=null&&"3".equals(bill.getApply_flag())){
					bill.setUpdate_man_no(userId);
					bill.setUpdate_man_name(userName);
					bill.setUpdate_time(new Date());
					bill.setApply_flag("2");   		//待确认
					this.getMapper(SlmFundInvoiceApplyMapper.class).update(bill);

					SlmFundSettleBill settle_bill=this.getMapper(SlmFundSettleBillMapper.class).findById(bill.getSettle_bill_no());
					if(bill!=null){
						settle_bill.setInvoice_no("");
						this.getMapper(SlmFundSettleBillMapper.class).update(settle_bill);
					}
				}else{
					rm.setState("500");
					rm.setMsgInfo("只有待发送状态的数据才能反审");
					return rm;
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 打印次数+1
	 * */
	public ResultModel doPrintWeb(CommonPage<SlmFundInvoiceApply> sum) throws Exception{
		ResultModel rm=new ResultModel();
		SlmFundInvoiceApply apply=sum.getObject();
		List<SlmFundInvoiceApply> apply_list=sum.getObjectList();
		try{
			if(apply_list==null){
				apply_list=new ArrayList<SlmFundInvoiceApply>();
				apply_list.add(apply);
			}
			List<SlmFundSettleBillInvoice> list=new ArrayList<SlmFundSettleBillInvoice>();
			CommonPage<SlmFundSettleBill> param_sum=new CommonPage<SlmFundSettleBill>();
			SlmFundSettleBill bill=new SlmFundSettleBill();
			ResultModel re_rm=new ResultModel();
			List<SlmFundSettleWriteDown> down_list=new ArrayList<SlmFundSettleWriteDown>();
			List<SlmFundInvoiceApply> re_list=new ArrayList<SlmFundInvoiceApply>();
			for(SlmFundInvoiceApply applys:apply_list){
				applys=this.getMapper(SlmFundInvoiceApplyMapper.class).findById(applys.getApply_no());
				if(applys!=null){
					applys.setPrint_num(applys.getPrint_num()+1);
					this.getMapper(SlmFundInvoiceApplyMapper.class).update(applys);
					bill.setSettle_bill_no(applys.getSettle_bill_no());
					param_sum.setObject(bill);
					// 之前是调用：doQueryInvoiceWeb 方法：20230218刘侣
					re_rm=this.getBean(SlmFundSettleBillServiceImpl.class).doQueryInvoiceWebPrint(param_sum);
					list=(List<SlmFundSettleBillInvoice>) re_rm.getData();
					applys.setBill_list(list);
					if(list.size()>0)
						applys.setContract_no(list.get(0).getContract_no());
					//冲减信息
					down_list=this.getMapper(SlmFundSettleWriteDownMapper.class).findWithCondition(null, " settle_bill_no='"+applys.getSettle_bill_no()+"' and valid_flag='1'", " valid_flag desc, create_time desc", 0, 0);
					if(down_list.size()>0)
						applys.setDown(down_list.get(0));
					re_list.add(applys);
				}
			}
			rm.setData(re_list);
			rm.setState("200");
		}catch(Exception e){
						rm.setState("500");
						rm.setMsgInfo(e.getMessage());
						//--19-10-15添加异常回滚
						throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}

	/**
	 * 红字开票新增
	 * 选中已开票信息 新增
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeficitAddWeb(CommonPage<SlmFundInvoiceManage> sum) throws Exception{
		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<SlmFundInvoiceManage> invoice_list=sum.getObjectList();
		try{
			if(invoice_list==null){
				rm.setState("500");
				rm.setMsgInfo("请传入参数objectList");
				return rm;
			}

			for(SlmFundInvoiceManage manage:invoice_list){
				manage=this.getMapper(SlmFundInvoiceManageMapper.class).findById(manage.getInvoice_no());
				if(manage==null){
					continue;
				}
				manage.setHave_red("1");
				this.getMapper(SlmFundInvoiceManageMapper.class).update(manage);
				//删除贴息关联
				SlmFundDiscount dis=new SlmFundDiscount();
				dis.setInvoice_no(manage.getInvoice_no());
				List<SlmFundDiscount> dis_list=this.getMapper(SlmFundDiscountMapper.class).find(dis, 0, 0);
				for(SlmFundDiscount dises:dis_list){
					dises.setInvoice_no("");
					dises.setRelation_man_no("");
					dises.setRelation_man_name("");
					dises.setFlag("3");
					this.getMapper(SlmFundDiscountMapper.class).update(dises);
				}
				//新增票据信息
				SlmFundInvoiceApply invoice=new SlmFundInvoiceApply();
				String date=new SimpleDateFormat("yyyy-MMdd").format(new Date());
				String maxId=this.getMapper(SlmFundInvoiceApplyMapper.class).findMaxId(date);
				if(maxId==null){
					date+="-0001";
				}else{
					String seq=maxId.substring(10);
					long seql=Long.parseLong(seq)+1;
					seq=String.format("%04d", seql);
					date+="-"+seq;
				}
				invoice.setCustomer_no(manage.getCustomer_no());
				invoice.setCustomer_name(manage.getCustomer_name());
				invoice.setBalance_object_no(manage.getBalance_object_no());
				invoice.setBalance_object_name(manage.getBalance_object_name());
				invoice.setBalance_unit_no(manage.getBalance_unit_no());
				invoice.setBalance_unit_name(manage.getBalance_unit_name());
				invoice.setSettle_bill_no(manage.getSettle_bill_no());
				invoice.setBack(manage.getBack());
				invoice.setAddress(manage.getAddress());
				invoice.setTax_registra_number(manage.getTax_registra_number());
				invoice.setTelphone(manage.getTelphone());
				invoice.setInvoice_no(manage.getInvoice_no());
				invoice.setInvoice_code(manage.getInvoice_code());
				if(invoice.getInvoice_fund()==null)
					invoice.setInvoice_fund(-manage.getInvoice_fund());
				invoice.setInvoice_time(manage.getInvoice_time());
				if(invoice.getMemo()==null)
					invoice.setMemo(manage.getMemo());
				invoice.setApply_no(date);
				invoice.setValid_flag("1"); 		//有效
				invoice.setApply_flag("1"); 		//编辑
				invoice.setCreate_man_no(userId);
				invoice.setCreate_man_name(userName);
				invoice.setCreate_time(new Date());
//				if(invoice.getTax_rate()==null)
					invoice.setTax_rate(tax);
				this.getMapper(SlmFundInvoiceApplyMapper.class).insert(invoice);

				//票据子表新增
				if(invoice.getDetailList()!=null){
					int i=1;
					for(SlmFundInvoiceApplyDetail detail:invoice.getDetailList()){
						//参数转换
						detail.setSpec(detail.getWidth()+"*"+detail.getThick());
						detail.setCarriage_price(detail.getTrade_price());
						detail.setBalance_good_price(detail.getContract_price());
						detail.setBalance_work_price(detail.getWork_price());
						detail.setBalance_amount(detail.getAmount());
						detail.setApply_no(date);
						detail.setSeq(date+"-"+String.format("%04d", i));
						this.getMapper(SlmFundInvoiceApplyDetailMapper.class).insert(detail);
						i++;
					}
				}
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo(e.getMessage());
			e.printStackTrace();
			//--19-10-15添加异常回滚
			throw new Exception(rm.getMsgInfo());
		}
		return rm;
	}
}