250 lines
9.7 KiB
C#
250 lines
9.7 KiB
C#
using YLErp.Model.Enum;
|
|
using YLErp.Modules.ClientModule;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
public class clientdutyController : BaseController
|
|
{
|
|
public ActionResult clientdutyEditPopInner(int rid, bool isOnlyView = false)
|
|
{
|
|
var models = clientDB.clientduty.Where(s => s.ClientId == rid).OrderBy(x => x.id).ToList();
|
|
var contantType = clientDB.contactype.ToList();
|
|
|
|
foreach (var model in models)
|
|
{
|
|
GetContactType(model, contantType);
|
|
}
|
|
|
|
ViewBag.IsOnlyView = isOnlyView;
|
|
|
|
return View(models);
|
|
}
|
|
|
|
public void GetContactType(ClientDuty model, List<contactype> contantTypeList)
|
|
{
|
|
if (contantTypeList.Count > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(model.ContactTypeId))
|
|
{
|
|
var typeList = new List<string>();
|
|
var ids = model.ContactTypeId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var id in ids)
|
|
{
|
|
var type = contantTypeList.FirstOrDefault(s => s.id == int.Parse(id)).ContactType;
|
|
typeList.Add(type);
|
|
}
|
|
model.ContactType = string.Join(",", typeList);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult clientdutyQuery(ClientDutyReq req)
|
|
{
|
|
var sList = new ClientDutyService(CurUser).SearchList(req);
|
|
return Json(sList);
|
|
}
|
|
|
|
public ActionResult clientdutyEdit(string enid, int? rid)
|
|
{
|
|
ClientDuty r = null;
|
|
var isAdd = string.IsNullOrEmpty(enid) || enid == "0";
|
|
Client client;
|
|
|
|
if (isAdd)
|
|
{
|
|
if (rid != null)
|
|
{
|
|
client = clientDB.client.Find(rid);
|
|
if (client == null)
|
|
{
|
|
throw new ServiceException("请先保存用户基本信息");
|
|
}
|
|
if (client != null)
|
|
{
|
|
ViewBag.IsProduct = client.ClientType == "产品";
|
|
}
|
|
r = new ClientDuty() { ClientId = client?.id };
|
|
}
|
|
return View(r);
|
|
}
|
|
|
|
var intid = DecryptInt(enid);
|
|
r = clientDB.clientduty.Find(intid);
|
|
client = clientDB.client.Find(r.ClientId);
|
|
if (client != null)
|
|
{
|
|
ViewBag.IsProduct = client.ClientType == "产品";
|
|
}
|
|
|
|
return View(r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult clientdutyEditJson(ClientDuty req, bool isDirectSubApp = false)
|
|
{
|
|
req.id = string.IsNullOrEmpty(req.EncryptId) ? 0 : DecryptInt(req.EncryptId);
|
|
var r = new ClientDutyService(CurUser).SaveClientDuty(req, Request.Form.Keys.Cast<string>().ToHashSet(StringComparer.OrdinalIgnoreCase), isDirectSubApp);
|
|
var typeids = DataConvert.ConvertCommaValuesToInt32Array(r.ContactTypeId);
|
|
var types = clientDB.contactype.Where(n => typeids.Contains(n.id)).Select(n => n.ContactType).ToArray();
|
|
r.ContactType = string.Join(",", types);
|
|
return JsonSuccess("更新成功", r);
|
|
}
|
|
|
|
[HttpPost]
|
|
public JsonResult Deleteclientduty(string intid, bool isDirectSubApp = false)
|
|
{
|
|
var id = int.Parse(intid);
|
|
|
|
var r = clientDB.clientduty.FirstOrDefault(s => s.id == id);
|
|
if (r == null)
|
|
{
|
|
return JsonError("删除失败,找不到机构客户职责联系人信息表");
|
|
}
|
|
else
|
|
{
|
|
clientDB.clientduty.Remove(r);
|
|
clientDB.SaveChanges();
|
|
clientDB.ClientAuditLog.Add(new ClientAuditLog
|
|
{
|
|
ClientId = r.ClientId ?? 0,
|
|
OptType = "删除人员信息",
|
|
Changes = string.Empty,
|
|
DataType = "00",
|
|
OptId = UserId,
|
|
OptName = UserName,
|
|
OptDate = DateTime.Now
|
|
});
|
|
}
|
|
|
|
clientDB.SaveChanges();
|
|
return JsonSuccess("删除成功", r);
|
|
}
|
|
|
|
#region 获取下拉菜单enum列表信息
|
|
|
|
public static List<SelectListItem> GetAllIdCardType()
|
|
{
|
|
var AllIdCardType = new List<SelectListItem>(){
|
|
new SelectListItem()
|
|
{
|
|
Text = IdCardTypeEnum.身份证.ToString(),
|
|
Value = ((int)IdCardTypeEnum.身份证).ToString()
|
|
},
|
|
new SelectListItem()
|
|
{
|
|
Text = IdCardTypeEnum.军官证.ToString(),
|
|
Value = ((int)IdCardTypeEnum.军官证).ToString()
|
|
},
|
|
new SelectListItem()
|
|
{
|
|
Text = IdCardTypeEnum.港澳通行证.ToString(),
|
|
Value = ((int)IdCardTypeEnum.港澳通行证).ToString()
|
|
},
|
|
new SelectListItem()
|
|
{
|
|
Text = IdCardTypeEnum.护照.ToString(),
|
|
Value = ((int)IdCardTypeEnum.护照).ToString()
|
|
},
|
|
new SelectListItem(){
|
|
Text=IdCardTypeEnum.台胞证.ToString(),
|
|
Value=((int)IdCardTypeEnum.台胞证).ToString()
|
|
},
|
|
new SelectListItem()
|
|
{
|
|
Text = IdCardTypeEnum.其他.ToString(),
|
|
Value = ((int)IdCardTypeEnum.其他).ToString()
|
|
}
|
|
};
|
|
return AllIdCardType;
|
|
}
|
|
|
|
public static string GetIdCardTypeName(int? idCardType)
|
|
{
|
|
return idCardType == null ? "" : Enum.Parse(typeof(IdCardTypeEnum), idCardType.Value.ToString()).ToString();
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 人员信息详情
|
|
/// </summary>
|
|
public JsonResult AjaxGetDutyDetail(string enid)
|
|
{
|
|
var intid = DecryptInt(enid);
|
|
var dbModel = intid > 0 ? clientDB.clientduty.AsNoTracking().FirstOrDefault(n => n.id == intid) : null;
|
|
if (dbModel == null)
|
|
{
|
|
return JsonError("没有找到人员信息");
|
|
}
|
|
return JsonSuccessData(dbModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据客户ID获取人员信息列表
|
|
/// </summary>
|
|
public JsonResult AjaxGetDutyList(int clientId, bool isApproval = false)
|
|
{
|
|
// var list = clientDB.clientduty.AsNoTracking().Where(n => n.ClientId == clientId).ToArray();
|
|
var list = clientId == 0 ? new ClientDuty[0] : clientDB.clientduty.Where(b => b.ClientId == clientId && b.ApprovalOrder != (int)ApprovalOrderEnum.审批作废).ToArray();
|
|
|
|
if (isApproval)
|
|
{
|
|
var notdutys = list.Where(x => x.SourceId > 0).Select(x => x.SourceId ?? 0).ToList();
|
|
notdutys.AddRange(list.Where(x => x.ApprovalOrder == (int?)ApprovalOrderEnum.删除).Select(x => x.id).ToList());
|
|
list = list.Where(x => !notdutys.Contains(x.id)).ToArray();
|
|
}
|
|
else
|
|
{
|
|
list = list.Where(x => x.ApprovalOrder < 1).ToArray();
|
|
}
|
|
|
|
var dic = clientDB.contactype.ToDictionary(n => n.id, m => m.ContactType);
|
|
if (list.Any())
|
|
{
|
|
foreach (var bc in list)
|
|
{
|
|
var types = (bc.ContactTypeId ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(n => int.TryParse(n, out var id) && dic.TryGetValue(id, out var type) ? type : string.Empty)
|
|
.Where(n => !string.IsNullOrWhiteSpace(n)).ToArray();
|
|
bc.ContactType = string.Join(",", types);
|
|
}
|
|
}
|
|
return JsonSuccessData(list);
|
|
}
|
|
/// <summary>
|
|
/// 根据客户ID获取董事会人员信息列表
|
|
/// </summary>
|
|
public JsonResult AjaxGetDirectorDutyList(int clientId)
|
|
{
|
|
// var list = clientDB.clientduty.AsNoTracking().Where(n => n.ClientId == clientId).ToArray();
|
|
var list = clientDB.clientduty.Where(b => b.ApprovalOrder < 1 && b.ClientId == clientId).ToArray();
|
|
var dic = clientDB.contactype.ToDictionary(n => n.id, m => m.ContactType);
|
|
if (list.Any())
|
|
{
|
|
foreach (var bc in list)
|
|
{
|
|
var types = (bc.ContactTypeId ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(n => int.TryParse(n, out var id) && dic.TryGetValue(id, out var type) ? type : string.Empty)
|
|
.Where(n => !string.IsNullOrWhiteSpace(n)).ToArray();
|
|
bc.ContactType = string.Join(",", types);
|
|
}
|
|
//只筛选 控股股东,董事会成员,普通股东
|
|
var listDirector = dic.Where(l => l.Value == "控股股东" || l.Value == "董事会成员" || l.Value == "普通股东").Select(n => n.Key.ToString());
|
|
list = list.Where(l => l.ContactTypeId.Split(',').ToList().Intersect(listDirector).Any()).ToArray();
|
|
}
|
|
return JsonSuccessData(list);
|
|
}
|
|
|
|
public JsonResult AjaxRemoveClientDuty(string enid, bool isDirectSubApp = false)
|
|
{
|
|
var intid = DecryptInt(enid);
|
|
|
|
var r = new ClientDutyService(CurUser).RemoveClientDuty(intid, isDirectSubApp);
|
|
|
|
return JsonSuccess("删除成功", r);
|
|
}
|
|
}
|
|
}
|