You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
228 lines
6.8 KiB
228 lines
6.8 KiB
using learun.iapplication;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Dapper;
|
|
using learun.util;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace learun.application
|
|
{
|
|
/// <summary>
|
|
/// 版 本 EasyCode EC管理后台
|
|
/// Copyright (c) 2019-present EC管理有限公司
|
|
/// 创建人:tobin
|
|
/// 日 期:2019.09.24
|
|
/// 描 述:公司管理
|
|
/// </summary>
|
|
public class CompanyService : ServiceBase
|
|
{
|
|
#region 构造函数和属性
|
|
|
|
private readonly string fieldSql;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public CompanyService()
|
|
{
|
|
fieldSql = @"
|
|
t.F_CompanyId,
|
|
t.F_Category,
|
|
t.F_ParentId,
|
|
t.F_EnCode,
|
|
t.F_ShortName,
|
|
t.F_FullName,
|
|
t.F_Nature,
|
|
t.F_OuterPhone,
|
|
t.F_InnerPhone,
|
|
t.F_Fax,
|
|
t.F_Postalcode,
|
|
t.F_Email,
|
|
t.F_Manager,
|
|
t.F_ProvinceId,
|
|
t.F_CityId,
|
|
t.F_CountyId,
|
|
t.F_Address,
|
|
t.F_WebAddress,
|
|
t.F_FoundedTime,
|
|
t.F_BusinessScope,
|
|
t.F_SortCode,
|
|
t.F_DeleteMark,
|
|
t.F_EnabledMark,
|
|
t.F_Description,
|
|
t.F_CreateDate,
|
|
t.F_CreateUserId,
|
|
t.F_CreateUserName,
|
|
t.F_ModifyDate,
|
|
t.F_ModifyUserId,
|
|
t.F_ModifyUserName
|
|
";
|
|
}
|
|
|
|
#endregion 构造函数和属性
|
|
|
|
#region 获取数据
|
|
|
|
/// <summary>
|
|
/// 获取公司列表信息
|
|
/// </summary>
|
|
/// <param name="keyWord">查询关键词</param>
|
|
/// <returns></returns>
|
|
public Task<IEnumerable<CompanyEntity>> GetList(string keyWord)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(fieldSql);
|
|
strSql.Append(" FROM LR_Base_Company t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
|
|
|
|
if (!string.IsNullOrEmpty(keyWord))
|
|
{
|
|
keyWord = "%" + keyWord + "%";
|
|
strSql.Append("AND( F_FullName like @keyWord or F_EnCode like @keyWord or F_ShortName like @keyWord ) ");
|
|
}
|
|
|
|
strSql.Append(" ORDER BY t.F_ParentId,t.F_FullName ");
|
|
return this.BaseRepository().FindList<CompanyEntity>(strSql.ToString(), new { keyWord });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取子公司列表信息
|
|
/// </summary>
|
|
/// <param name="pId">父级Id</param>
|
|
/// <returns></returns>
|
|
public Task<IEnumerable<CompanyEntity>> GetListByPId(string pId)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(fieldSql);
|
|
strSql.Append(" FROM LR_Base_Company t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 AND t.F_ParentId = @pId ");
|
|
strSql.Append(" ORDER BY t.F_ParentId,t.F_FullName ");
|
|
return this.BaseRepository().FindList<CompanyEntity>(strSql.ToString(), new { pId });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取实体
|
|
/// </summary>
|
|
/// <param name="keyValue">主键</param>
|
|
/// <returns></returns>
|
|
public Task<CompanyEntity> GetEntity(string keyValue)
|
|
{
|
|
return this.BaseRepository().FindEntityByKey<CompanyEntity>(keyValue);
|
|
}
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="param">参数</param>
|
|
/// <returns></returns>
|
|
public Task<CompanyEntity> GetEntity(object param)
|
|
{
|
|
return BaseRepository().FindEntity<CompanyEntity>(param);
|
|
}
|
|
|
|
#endregion 获取数据
|
|
|
|
#region 2
|
|
|
|
/// <summary>
|
|
/// 获取公司列表信息
|
|
/// </summary>
|
|
/// <param name="queryParam">查询关键词</param>
|
|
/// <returns></returns>
|
|
public Task<IEnumerable<CompanyEntity>> GetList2(JObject queryParam)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
var dp = new DynamicParameters(new { });
|
|
|
|
//
|
|
dp.Add("CompanyId", queryParam["CompanyId"], DbType.String);
|
|
strSql.Append($"SELECT {fieldSql} FROM LR_Base_Company t WHERE FIND_IN_SET(F_CompanyId, getCompanyChild(@CompanyId)) AND t.F_EnabledMark = 1 AND t.F_DeleteMark = 0");
|
|
// 关键字
|
|
if (!queryParam["Keyword"].IsEmpty())
|
|
{
|
|
dp.Add("Keyword", $"%{queryParam["Keyword"]}%", DbType.String);
|
|
strSql.Append(" AND (F_FullName like @Keyword || F_Manager like @Keyword)");
|
|
}
|
|
// 操作时间
|
|
if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
|
|
{
|
|
dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
|
|
dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
|
|
strSql.Append(" AND (F_CreateDate >= @startTime AND F_CreateDate <= @endTime)");
|
|
}
|
|
strSql.Append(" ORDER BY t.F_ParentId, t.F_FullName ");
|
|
return this.BaseRepository().FindList<CompanyEntity>(strSql.ToString(), dp);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取子公司列表信息
|
|
/// </summary>
|
|
/// <param name="companyId">父级Id</param>
|
|
/// <returns></returns>
|
|
public Task<IEnumerable<CompanyEntity>> GetChildList(string companyId)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(fieldSql);
|
|
strSql.Append(" FROM LR_Base_Company t WHERE FIND_IN_SET(F_CompanyId, getCompanyChild(@CompanyId)) AND t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
|
|
strSql.Append(" ORDER BY t.F_ParentId, t.F_FullName ");
|
|
return this.BaseRepository().FindList<CompanyEntity>(strSql.ToString(), new { CompanyId = companyId });
|
|
}
|
|
|
|
#endregion 2
|
|
|
|
#region 提交数据
|
|
|
|
/// <summary>
|
|
/// 删除公司
|
|
/// </summary>
|
|
/// <param name="keyValue">主键</param>
|
|
public async Task Delete(string keyValue)
|
|
{
|
|
await this.BaseRepository().DeleteAny<CompanyEntity>(new { F_CompanyId = keyValue });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存公司表单(新增、修改)
|
|
/// </summary>
|
|
/// <param name="keyValue">主键值</param>
|
|
/// <param name="entity">公司实体</param>
|
|
/// <returns></returns>
|
|
public async Task SaveEntity(string keyValue, CompanyEntity entity)
|
|
{
|
|
var userId = GetUserId();
|
|
var userAccount = GetUserAccount();
|
|
if (entity == null)
|
|
return;
|
|
|
|
var temp = !string.IsNullOrEmpty(entity.F_CompanyId) ? await GetEntity(new { F_CompanyId = entity.F_CompanyId }) : null;
|
|
if (temp == null)
|
|
{
|
|
entity.F_CompanyId = Guid.NewGuid().ToString();
|
|
entity.F_DeleteMark = 0;
|
|
entity.F_EnabledMark = 1;
|
|
|
|
entity.F_CreateUserId = userId;
|
|
entity.F_CreateUserName = userAccount;
|
|
entity.F_CreateDate = DateTime.Now;
|
|
entity.F_ModifyUserId = userId;
|
|
entity.F_ModifyUserName = userAccount;
|
|
entity.F_ModifyDate = entity.F_CreateDate;
|
|
|
|
await this.BaseRepository().Insert(entity);
|
|
}
|
|
else
|
|
{
|
|
entity.F_ModifyUserId = userId;
|
|
entity.F_ModifyUserName = userAccount;
|
|
entity.F_ModifyDate = DateTime.Now;
|
|
|
|
await this.BaseRepository().Update(entity);
|
|
}
|
|
}
|
|
|
|
#endregion 提交数据
|
|
}
|
|
}
|