using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Common;
using PTMedicalInsurance.Helper;
using PTMedicalInsurance.Variables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/**
*
*
* 310100 职工基本医疗保险统筹基金 501000 一至六级残疾军人医疗补助基金
* 310200 职工基本医疗保险个人账户基金 370100 企业补充医疗保险基金
* 320100 公务员医疗补助基金 390100 城乡居民基本医疗保险基金
* 330100 职工大额医疗费用补助基金 610100 医疗救助基金
* 340100 离休人员医疗保障基金 999999 其他基金
* 391100 城乡居民大病医疗保险资
*/
namespace PTMedicalInsurance.Business
{
class LocalPayFundSplitService
{
///
/// 根据返回的金额进行拆分基金分类
///
/// 结算返回值
///
public JArray Split(JObject joSettle)
{
JArray joRtn = new JArray();
try
{
Dictionary medTypeDict = new Dictionary()
{
{ "A","310100"}, //职工
{ "B","390100"} //居民
};
Dictionary> fundDict = new Dictionary>()
{
["hifp_pay"] = new Dictionary() {
{ "310100", "职工基本医疗保险统筹基金" },
{ "390100","城乡居民基本医疗保险基金"} },
["acct_pay"] = CreateKeyPair("310200", "职工基本医疗保险个人账户基金"),
["hifob_pay"] = CreateKeyPair("330100", "职工大额医疗费用补助基金"),
["hifes_pay"] = CreateKeyPair("370100", "企业补充医疗保险基金"),
["hifmi_pay"] = CreateKeyPair("391100", "城乡居民大病医疗保险资"),
["maf_pay"] = CreateKeyPair("610100", "医疗救助基金"),
["cvlserv_pay"] = CreateKeyPair("320100", "公务员医疗补助基金"),
};
string inscopeAmt = joSettle["inscp_scp_amt"].Text();
string medType = Global.pat.medType ?? "A"; //默认职工
string medFundCode = medTypeDict.ToList().FirstOrDefault(s => s.Key == medType).Value;
foreach (var k in fundDict.Keys)
{
if (!string.IsNullOrEmpty(joSettle[k].Text()))
{
dynamic fund = new JObject();
fund.fund_payamt = decimal.Parse(joSettle[k].Text());
if (fund.fund_payamt <= 0.0D) continue;
fund.inscp_scp_amt = inscopeAmt;
if (fundDict[k].Count > 1)
{
fund.fund_pay_type = medFundCode;
fund.fund_pay_type_name = fundDict[k].ToList().FirstOrDefault(s => s.Key == medFundCode).Value;
}
else
{
fund.fund_pay_type = fundDict[k].First().Key;
fund.fund_pay_type_name = fundDict[k].First().Value;
}
joRtn.Add(fund);
}
}
}
catch (Exception e)
{
Global.writeLog("基金分类转换错误:"+e.Message);
}
return joRtn;
}
private Dictionary CreateKeyPair(string key, string value)
{
return new Dictionary() { { key, value } };
}
}
}