Commit 3491c9ee authored by liudong1993's avatar liudong1993

复制资产

parent e27671a9
......@@ -4781,5 +4781,139 @@ namespace Property.Module.FixedAssets
return ApiResult.Success();
}
#endregion
#region 教育相关
/// <summary>
/// 获取用户领用资产的数量
/// </summary>
/// <param name="userIdList"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public object GetEduEmployeeReceiveNumList(List<int> userIdList, UserInfo userInfo)
{
string UserIds = string.Join(",", userIdList.Distinct());
var list = property_InfoRepository.GetEduEmployeeReceiveNumList(UserIds, userInfo.RB_Group_id);
return list.Select(x => new
{
x.EmployeeId,
x.PropertyNumber
});
}
/// <summary>
/// 复制资产
/// </summary>
/// <param name="propertyId"></param>
/// <param name="number"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public bool SetPropertyCopy(int propertyId, int number, UserInfo userInfo)
{
var demodel = property_InfoRepository.GetEntity(propertyId);
if (demodel == null) { return false; }
#region 初始化数据
demodel.Id = 0;
demodel.Status = 0;
demodel.UseStatus = PropertyUseStateEnum.Normal;
demodel.PropertyStatus = PropertyStatusEnum.Leisure;
demodel.EmployeeId = 0;
demodel.GetTime = null;
demodel.BackTime = null;
demodel.ProcurementId = 0;
demodel.QRCode = "";
demodel.CreateBy = userInfo.EmployeeId;
demodel.CreateDate = DateTime.Now;
demodel.UpdateBy = userInfo.EmployeeId;
demodel.UpdateDate = DateTime.Now;
#endregion
var trans = property_InfoRepository.DbTransaction;
try
{
for (int i = 0; i < number; i++)
{
int PropertyId = property_InfoRepository.Insert(demodel, trans);
bool flag = PropertyId > 0;
if (flag)
{
//编码自动生成
string BMStr = PropertyId.ToString();
if (BMStr.Length < 5)
{
switch (BMStr.Length)
{
case 1:
BMStr = "0000" + BMStr; break;
case 2:
BMStr = "000" + BMStr; break;
case 3:
BMStr = "00" + BMStr; break;
case 4:
BMStr = "0" + BMStr; break;
}
}
#region 生成二维码
string QRPath = DateTime.Now.Ticks.ToString() + ".png";
string basepath = AppContext.BaseDirectory;
string path_server = basepath + "\\upfile\\code\\" + QRPath;
string ImageAddress = "/upfile/code/" + QRPath;
string logoPath = basepath + "\\ExportFile\\Branch\\Logo.png";
try
{
QRCodeHelper.Create_CodeImages("PropertyCheck|Id=" + PropertyId, 5, logoPath, path_server, System.Drawing.Imaging.ImageFormat.Png);
}
catch (Exception ex)
{
LogHelper.Write(ex, "QRCodeHelper.Create_CodeImages");
ImageAddress = "";
}
#endregion
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Property_Info.PropertyNum),BMStr},
{ nameof(RB_Property_Info.QRCode),ImageAddress}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Property_Info.Id),
FiledValue=PropertyId,
OperatorEnum=OperatorEnum.Equal
}
};
property_InfoRepository.Update(files, wheres, trans);
string Content = "新增资产(复制资产)";
if (demodel.EmployeeId > 0)
{
Content += ";设置使用人:" + CacheManager.User.UserReidsCache.GetEmployee(demodel.EmployeeId)?.EmName ?? "";
}
//写入日志
property_LogRepository.Insert(new RB_Property_Log()
{
PropertyId = PropertyId,
Status = 0,
Content = Content,
TypeName = "入库",
RB_Branch_Id = userInfo.RB_Branch_id,
RB_Group_Id = userInfo.RB_Group_id,
CreateBy = userInfo.EmployeeId,
CreateDate = DateTime.Now
}, trans);
}
}
property_InfoRepository.DBSession.Commit();
return true;
}
catch (Exception ex)
{
property_InfoRepository.DBSession.Rollback();
LogHelper.Write(ex, "SetPropertyCopy");
return false;
}
}
#endregion
}
}
......@@ -773,5 +773,17 @@ GROUP BY pi.CategoryId,DATE_FORMAT(pu.Time,'%Y-%m') ";
return Get<RB_Property_Info_Extend>(sql).ToList();
}
}
/// <summary>
/// 获取用户领用/借用资产的数量
/// </summary>
/// <param name="userIds"></param>
/// <param name="rB_Group_id"></param>
/// <returns></returns>
public List<RB_Property_Info_Extend> GetEduEmployeeReceiveNumList(string userIds, int rB_Group_id)
{
string sql = $@"SELECT EmployeeId,COUNT(0) AS PropertyNumber from rb_property_info WHERE `Status`=0 and RB_Group_Id ={rB_Group_id} and PropertyStatus in(2,3) and EmployeeId in({userIds}) GROUP BY EmployeeId";
return Get<RB_Property_Info_Extend>(sql).ToList();
}
}
}
......@@ -5510,5 +5510,58 @@ namespace Property.WebApi.Controllers.User
return propertyModule.SetPropertyProcurementStockIn(demodel, userInfo);
}
#endregion
#region 教育相关
/// <summary>
/// 获取用户领用资产的数量
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetEduEmployeeReceiveNumList() {
var requestParm = GetRequestParm();
UserInfo userInfo = CacheManager.User.UserReidsCache.GetUserLoginInfo(requestParm.uid);
JObject parms = JObject.Parse(requestParm.msg.ToString());
string UserIds = parms.GetStringValue("UserIds");
if (string.IsNullOrEmpty(UserIds)) {
return ApiResult.ParamIsNull("请传递用户id");
}
List<int> UserIdList = JsonConvert.DeserializeObject<List<int>>("[" + UserIds + "]");
var list = propertyModule.GetEduEmployeeReceiveNumList(UserIdList, userInfo);
return ApiResult.Success("", list);
}
/// <summary>
/// 复制资产
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetPropertyCopy() {
var requestParm = GetRequestParm();
UserInfo userInfo = CacheManager.User.UserReidsCache.GetUserLoginInfo(requestParm.uid);
JObject parms = JObject.Parse(requestParm.msg.ToString());
int PropertyId = parms.GetInt("PropertyId", 0);
int Number = parms.GetInt("Number", 1);//复制几份
if (PropertyId <= 0)
{
return ApiResult.ParamIsNull("请传递资产id");
}
if (Number <= 0)
{
return ApiResult.ParamIsNull("请传递份数");
}
bool flag = propertyModule.SetPropertyCopy(PropertyId, Number, userInfo);
if (flag)
{
return ApiResult.Success();
}
else {
return ApiResult.Failed();
}
}
#endregion
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment