using NCC.Common.Core.Manager;
using NCC.Common.Enum;
using NCC.Common.Extension;
using NCC.Common.Filter;
using NCC.Dependency;
using NCC.DynamicApiController;
using NCC.FriendlyException;
using NCC.Extend.Interfaces.LqYcsdJsj;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NCC.Extend.Entitys.lq_ycsd_jsj;
using NCC.Extend.Entitys.Dto.LqYcsdJsj;
using Yitter.IdGenerator;
using NCC.Common.Helper;
using NCC.JsonSerialization;
using NCC.Common.Model.NPOI;
using NCC.Common.Configuration;
using NCC.DataEncryption;
using NCC.ClayObject;
namespace NCC.Extend.LqYcsdJsj
{
///
/// 金三角设定服务
///
[ApiDescriptionSettings(Tag = "Extend",Name = "LqYcsdJsj", Order = 200)]
[Route("api/Extend/[controller]")]
public class LqYcsdJsjService : ILqYcsdJsjService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository _lqYcsdJsjRepository;
private readonly SqlSugarScope _db;
private readonly IUserManager _userManager;
///
/// 初始化一个类型的新实例
///
public LqYcsdJsjService(
ISqlSugarRepository lqYcsdJsjRepository,
IUserManager userManager)
{
_lqYcsdJsjRepository = lqYcsdJsjRepository;
_db = _lqYcsdJsjRepository.Context;
_userManager = userManager;
}
///
/// 获取金三角设定
///
/// 参数
///
[HttpGet("{id}")]
public async Task GetInfo(string id)
{
var entity = await _db.Queryable().FirstAsync(p => p.Id == id);
var output = entity.Adapt();
return output;
}
///
/// 获取金三角设定列表
///
/// 请求参数
///
[HttpGet("")]
public async Task GetList([FromQuery] LqYcsdJsjListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable()
.WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
.WhereIF(!string.IsNullOrEmpty(input.yf), p => p.Yf.Contains(input.yf))
.WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Contains(input.md))
.WhereIF(!string.IsNullOrEmpty(input.jsj), p => p.Jsj.Contains(input.jsj))
.WhereIF(!string.IsNullOrEmpty(input.gw), p => p.Gw.Contains(input.gw))
.WhereIF(!string.IsNullOrEmpty(input.jks), p => p.Jks.Contains(input.jks))
.WhereIF(!string.IsNullOrEmpty(input.cjl), p => p.Cjl.Equals(input.cjl))
.WhereIF(!string.IsNullOrEmpty(input.cjyj), p => p.Cjyj.Equals(input.cjyj))
.WhereIF(!string.IsNullOrEmpty(input.cjtd), p => p.Cjtd.Equals(input.cjtd))
.WhereIF(!string.IsNullOrEmpty(input.syyj), p => p.Syyj.Equals(input.syyj))
.WhereIF(!string.IsNullOrEmpty(input.cqts), p => p.Cqts.Equals(input.cqts))
.WhereIF(!string.IsNullOrEmpty(input.xtyj), p => p.Xtyj.Equals(input.xtyj))
.WhereIF(!string.IsNullOrEmpty(input.zyj), p => p.Zyj.Equals(input.zyj))
.WhereIF(!string.IsNullOrEmpty(input.jcyj), p => p.Jcyj.Equals(input.jcyj))
.WhereIF(!string.IsNullOrEmpty(input.hzyj), p => p.Hzyj.Equals(input.hzyj))
.WhereIF(!string.IsNullOrEmpty(input.jlyj), p => p.Jlyj.Equals(input.jlyj))
.WhereIF(!string.IsNullOrEmpty(input.xms), p => p.Xms.Equals(input.xms))
.WhereIF(!string.IsNullOrEmpty(input.sg), p => p.Sg.Equals(input.sg))
.WhereIF(!string.IsNullOrEmpty(input.sfsyzd), p => p.Sfsyzd.Contains(input.sfsyzd))
.WhereIF(!string.IsNullOrEmpty(input.fsmzkq), p => p.Fsmzkq.Contains(input.fsmzkq))
.WhereIF(!string.IsNullOrEmpty(input.zdzzrs), p => p.Zdzzrs.Equals(input.zdzzrs))
.WhereIF(!string.IsNullOrEmpty(input.kqhbsyzd), p => p.Kqhbsyzd.Equals(input.kqhbsyzd))
.WhereIF(!string.IsNullOrEmpty(input.zdtc), p => p.Zdtc.Equals(input.zdtc))
.WhereIF(!string.IsNullOrEmpty(input.ayrtc), p => p.Ayrtc.Equals(input.ayrtc))
.WhereIF(!string.IsNullOrEmpty(input.zztcd), p => p.Zztcd.Equals(input.zztcd))
.WhereIF(!string.IsNullOrEmpty(input.jcyjtc), p => p.Jcyjtc.Equals(input.jcyjtc))
.WhereIF(!string.IsNullOrEmpty(input.hzyjtc), p => p.Hzyjtc.Equals(input.hzyjtc))
.WhereIF(!string.IsNullOrEmpty(input.tchj), p => p.Tchj.Equals(input.tchj))
.WhereIF(!string.IsNullOrEmpty(input.grzb), p => p.Grzb.Equals(input.grzb))
.WhereIF(!string.IsNullOrEmpty(input.zyhj), p => p.Zyhj.Equals(input.zyhj))
.WhereIF(!string.IsNullOrEmpty(input.gwtc), p => p.Gwtc.Equals(input.gwtc))
.Select(it=> new LqYcsdJsjListOutput
{
id = it.Id,
yf=it.Yf,
md=it.Md,
jsj=it.Jsj,
gw=it.Gw,
jks=it.Jks,
cjl=it.Cjl,
cjyj=it.Cjyj,
cjtd=it.Cjtd,
syyj=it.Syyj,
cqts=it.Cqts,
xtyj=it.Xtyj,
zyj=it.Zyj,
jcyj=it.Jcyj,
hzyj=it.Hzyj,
jlyj=it.Jlyj,
xms=it.Xms,
sg=it.Sg,
sfsyzd=it.Sfsyzd,
fsmzkq=it.Fsmzkq,
zdzzrs=it.Zdzzrs,
kqhbsyzd=it.Kqhbsyzd,
zdtc=it.Zdtc,
ayrtc=it.Ayrtc,
zztcd=it.Zztcd,
jcyjtc=it.Jcyjtc,
hzyjtc=it.Hzyjtc,
tchj=it.Tchj,
grzb=it.Grzb,
zyhj=it.Zyhj,
gwtc=it.Gwtc,
}).MergeTable().OrderBy(sidx+" "+input.sort).ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult.SqlSugarPageResult(data);
}
///
/// 新建金三角设定
///
/// 参数
///
[HttpPost("")]
public async Task Create([FromBody] LqYcsdJsjCrInput input)
{
var userInfo = await _userManager.GetUserInfo();
var entity = input.Adapt();
entity.Id = YitIdHelper.NextId().ToString();
var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1000);
}
///
/// 获取金三角设定无分页列表
///
/// 请求参数
///
[NonAction]
public async Task GetNoPagingList([FromQuery] LqYcsdJsjListQueryInput input)
{
var sidx = input.sidx == null ? "id" : input.sidx;
var data = await _db.Queryable()
.WhereIF(!string.IsNullOrEmpty(input.id), p => p.Id.Contains(input.id))
.WhereIF(!string.IsNullOrEmpty(input.yf), p => p.Yf.Contains(input.yf))
.WhereIF(!string.IsNullOrEmpty(input.md), p => p.Md.Contains(input.md))
.WhereIF(!string.IsNullOrEmpty(input.jsj), p => p.Jsj.Contains(input.jsj))
.WhereIF(!string.IsNullOrEmpty(input.gw), p => p.Gw.Contains(input.gw))
.WhereIF(!string.IsNullOrEmpty(input.jks), p => p.Jks.Contains(input.jks))
.WhereIF(!string.IsNullOrEmpty(input.cjl), p => p.Cjl.Equals(input.cjl))
.WhereIF(!string.IsNullOrEmpty(input.cjyj), p => p.Cjyj.Equals(input.cjyj))
.WhereIF(!string.IsNullOrEmpty(input.cjtd), p => p.Cjtd.Equals(input.cjtd))
.WhereIF(!string.IsNullOrEmpty(input.syyj), p => p.Syyj.Equals(input.syyj))
.WhereIF(!string.IsNullOrEmpty(input.cqts), p => p.Cqts.Equals(input.cqts))
.WhereIF(!string.IsNullOrEmpty(input.xtyj), p => p.Xtyj.Equals(input.xtyj))
.WhereIF(!string.IsNullOrEmpty(input.zyj), p => p.Zyj.Equals(input.zyj))
.WhereIF(!string.IsNullOrEmpty(input.jcyj), p => p.Jcyj.Equals(input.jcyj))
.WhereIF(!string.IsNullOrEmpty(input.hzyj), p => p.Hzyj.Equals(input.hzyj))
.WhereIF(!string.IsNullOrEmpty(input.jlyj), p => p.Jlyj.Equals(input.jlyj))
.WhereIF(!string.IsNullOrEmpty(input.xms), p => p.Xms.Equals(input.xms))
.WhereIF(!string.IsNullOrEmpty(input.sg), p => p.Sg.Equals(input.sg))
.WhereIF(!string.IsNullOrEmpty(input.sfsyzd), p => p.Sfsyzd.Contains(input.sfsyzd))
.WhereIF(!string.IsNullOrEmpty(input.fsmzkq), p => p.Fsmzkq.Contains(input.fsmzkq))
.WhereIF(!string.IsNullOrEmpty(input.zdzzrs), p => p.Zdzzrs.Equals(input.zdzzrs))
.WhereIF(!string.IsNullOrEmpty(input.kqhbsyzd), p => p.Kqhbsyzd.Equals(input.kqhbsyzd))
.WhereIF(!string.IsNullOrEmpty(input.zdtc), p => p.Zdtc.Equals(input.zdtc))
.WhereIF(!string.IsNullOrEmpty(input.ayrtc), p => p.Ayrtc.Equals(input.ayrtc))
.WhereIF(!string.IsNullOrEmpty(input.zztcd), p => p.Zztcd.Equals(input.zztcd))
.WhereIF(!string.IsNullOrEmpty(input.jcyjtc), p => p.Jcyjtc.Equals(input.jcyjtc))
.WhereIF(!string.IsNullOrEmpty(input.hzyjtc), p => p.Hzyjtc.Equals(input.hzyjtc))
.WhereIF(!string.IsNullOrEmpty(input.tchj), p => p.Tchj.Equals(input.tchj))
.WhereIF(!string.IsNullOrEmpty(input.grzb), p => p.Grzb.Equals(input.grzb))
.WhereIF(!string.IsNullOrEmpty(input.zyhj), p => p.Zyhj.Equals(input.zyhj))
.WhereIF(!string.IsNullOrEmpty(input.gwtc), p => p.Gwtc.Equals(input.gwtc))
.Select(it=> new LqYcsdJsjListOutput
{
id = it.Id,
yf=it.Yf,
md=it.Md,
jsj=it.Jsj,
gw=it.Gw,
jks=it.Jks,
cjl=it.Cjl,
cjyj=it.Cjyj,
cjtd=it.Cjtd,
syyj=it.Syyj,
cqts=it.Cqts,
xtyj=it.Xtyj,
zyj=it.Zyj,
jcyj=it.Jcyj,
hzyj=it.Hzyj,
jlyj=it.Jlyj,
xms=it.Xms,
sg=it.Sg,
sfsyzd=it.Sfsyzd,
fsmzkq=it.Fsmzkq,
zdzzrs=it.Zdzzrs,
kqhbsyzd=it.Kqhbsyzd,
zdtc=it.Zdtc,
ayrtc=it.Ayrtc,
zztcd=it.Zztcd,
jcyjtc=it.Jcyjtc,
hzyjtc=it.Hzyjtc,
tchj=it.Tchj,
grzb=it.Grzb,
zyhj=it.Zyhj,
gwtc=it.Gwtc,
}).MergeTable().OrderBy(sidx+" "+input.sort).ToListAsync();
return data;
}
///
/// 导出金三角设定
///
/// 请求参数
///
[HttpGet("Actions/Export")]
public async Task Export([FromQuery] LqYcsdJsjListQueryInput input)
{
var userInfo = await _userManager.GetUserInfo();
var exportData = new List();
if (input.dataType == 0)
{
var data = Clay.Object(await this.GetList(input));
exportData = data.Solidify>().list;
}
else
{
exportData = await this.GetNoPagingList(input);
}
List paramList = "[{\"value\":\"主键\",\"field\":\"id\"},{\"value\":\"月份\",\"field\":\"yf\"},{\"value\":\"门店\",\"field\":\"md\"},{\"value\":\"金三角\",\"field\":\"jsj\"},{\"value\":\"岗位\",\"field\":\"gw\"},{\"value\":\"健康师\",\"field\":\"jks\"},{\"value\":\"成交率\",\"field\":\"cjl\"},{\"value\":\"成交业绩\",\"field\":\"cjyj\"},{\"value\":\"成交提点\",\"field\":\"cjtd\"},{\"value\":\"剩余业绩\",\"field\":\"syyj\"},{\"value\":\"出勤天数\",\"field\":\"cqts\"},{\"value\":\"系统业绩\",\"field\":\"xtyj\"},{\"value\":\"总业绩\",\"field\":\"zyj\"},{\"value\":\"基础业绩\",\"field\":\"jcyj\"},{\"value\":\"合作业绩\",\"field\":\"hzyj\"},{\"value\":\"奖励业绩\",\"field\":\"jlyj\"},{\"value\":\"项目数\",\"field\":\"xms\"},{\"value\":\"手工\",\"field\":\"sg\"},{\"value\":\"是否属于战队\",\"field\":\"sfsyzd\"},{\"value\":\"是否满足考勤\",\"field\":\"fsmzkq\"},{\"value\":\"战队最终人数\",\"field\":\"zdzzrs\"},{\"value\":\"视为单人\",\"field\":\"kqhbsyzd\"},{\"value\":\"战队提成\",\"field\":\"zdtc\"},{\"value\":\"按1人提成\",\"field\":\"ayrtc\"},{\"value\":\"最终提成点\",\"field\":\"zztcd\"},{\"value\":\"基础业绩提成\",\"field\":\"jcyjtc\"},{\"value\":\"合作业绩提成\",\"field\":\"hzyjtc\"},{\"value\":\"提成合计\",\"field\":\"tchj\"},{\"value\":\"个人占比\",\"field\":\"grzb\"},{\"value\":\"组员合计\",\"field\":\"zyhj\"},{\"value\":\"顾问提成\",\"field\":\"gwtc\"},]".ToList();
ExcelConfig excelconfig = new ExcelConfig();
excelconfig.FileName = "金三角设定.xls";
excelconfig.HeadFont = "微软雅黑";
excelconfig.HeadPoint = 10;
excelconfig.IsAllSizeColumn = true;
excelconfig.ColumnModel = new List();
List selectKeyList = input.selectKey.Split(',').ToList();
foreach (var item in selectKeyList)
{
var isExist = paramList.Find(p => p.field == item);
if (isExist != null)
{
excelconfig.ColumnModel.Add(new ExcelColumnModel() { Column = isExist.field, ExcelColumn = isExist.value });
}
}
var addPath = FileVariable.TemporaryFilePath + excelconfig.FileName;
ExcelExportHelper.Export(exportData, excelconfig, addPath);
var fileName = _userManager.UserId + "|" + addPath + "|xls";
var output = new
{
name = excelconfig.FileName,
url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "NCC")
};
return output;
}
///
/// 批量删除金三角设定
///
/// 主键数组
///
[HttpPost("batchRemove")]
public async Task BatchRemove([FromBody] List ids)
{
var entitys = await _db.Queryable().In(it => it.Id, ids).ToListAsync();
if (entitys.Count > 0)
{
try
{
//开启事务
_db.BeginTran();
//批量删除金三角设定
await _db.Deleteable().In(d => d.Id,ids).ExecuteCommandAsync();
//关闭事务
_db.CommitTran();
}
catch (Exception)
{
//回滚事务
_db.RollbackTran();
throw NCCException.Oh(ErrorCode.COM1002);
}
}
}
///
/// 更新金三角设定
///
/// 主键
/// 参数
///
[HttpPut("{id}")]
public async Task Update(string id, [FromBody] LqYcsdJsjUpInput input)
{
var entity = input.Adapt();
var isOk = await _db.Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1001);
}
///
/// 删除金三角设定
///
///
[HttpDelete("{id}")]
public async Task Delete(string id)
{
var entity = await _db.Queryable().FirstAsync(p => p.Id == id);
_ = entity ?? throw NCCException.Oh(ErrorCode.COM1005);
var isOk = await _db.Deleteable().Where(d => d.Id == id).ExecuteCommandAsync();
if (!(isOk > 0)) throw NCCException.Oh(ErrorCode.COM1002);
}
}
}