Commit dffc7dba authored by liudong1993's avatar liudong1993

资产二维码

parent 7569e318
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using QRCoder;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
namespace REBORN.Common.Plugin
{
/// <summary>
/// 二维码和条形码
/// </summary>
public static class QRCodeHelper
{
/// <summary>
/// 批量生成二维码图片
/// </summary>
public static bool Create_CodeImages(string path, int imgSize,string logoPath, string savePath, System.Drawing.Imaging.ImageFormat imageFormat)
{
try
{
//生成图片
Bitmap image = GetLogoQRCode(path, logoPath, imgSize);
//保存图片
SaveImg(savePath, image, imageFormat);
return true;
}
catch (Exception ex)
{
LogHelper.Write(ex, "Create_CodeImages");
return false;
}
}
/// <summary>
/// 保存图片
/// </summary>
/// <param name="strPath">保存路径</param>
/// <param name="imgData">图片</param>
/// <param name="image">图片格式</param>
public static void SaveImg(string strPath, Bitmap imgData, System.Drawing.Imaging.ImageFormat image)
{
string DirectoryPath = Path.GetDirectoryName(strPath);
//保存图片到目录
if (!Directory.Exists(DirectoryPath))
{
//当前目录不存在,则创建
Directory.CreateDirectory(DirectoryPath);
}
//文件名称
imgData.Save(strPath, image);
}
#region 普通二维码
/// <summary>
///
/// </summary>
/// <param name="url">存储内容</param>
/// <param name="pixel">像素大小</param>
/// <returns></returns>
public static Bitmap GetPTQRCode(string url, int pixel)
{
QRCodeGenerator generator = new QRCodeGenerator();
QRCodeData codeData = generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true);
QRCoder.QRCode qrcode = new QRCoder.QRCode(codeData);
Bitmap qrImage = qrcode.GetGraphic(pixel, Color.Black, Color.White, true);
return qrImage;
}
#endregion
#region logo的二维码
/// <summary>
///
/// </summary>
/// <param name="url">存储内容</param>
/// <param name="pixel">像素大小</param>
/// <returns></returns>
public static Bitmap GetLogoQRCode(string url, string logoPath, int pixel)
{
QRCodeGenerator generator = new QRCodeGenerator();
QRCodeData codeData = generator.CreateQrCode(url, QRCodeGenerator.ECCLevel.M, true);
QRCoder.QRCode qrcode = new QRCoder.QRCode(codeData);
Bitmap icon = new Bitmap(logoPath);
Bitmap qrImage = qrcode.GetGraphic(pixel, Color.Black, Color.White, icon, 15, 6, true);
#region 参数介绍
//GetGraphic方法参数介绍
//pixelsPerModule //生成二维码图片的像素大小 ,我这里设置的是5
//darkColor //暗色 一般设置为Color.Black 黑色
//lightColor //亮色 一般设置为Color.White 白色
//icon //二维码 水印图标 例如:Bitmap icon = new Bitmap(context.Server.MapPath("~/images/zs.png")); 默认为NULL ,加上这个二维码中间会显示一个图标
//iconSizePercent //水印图标的大小比例 ,可根据自己的喜好设置
//iconBorderWidth // 水印图标的边框
//drawQuietZones //静止区,位于二维码某一边的空白边界,用来阻止读者获取与正在浏览的二维码无关的信息 即是否绘画二维码的空白边框区域 默认为true
#endregion
return qrImage;
}
#endregion
}
}
......@@ -10,6 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NPOI" Version="2.4.1" />
<PackageReference Include="QRCoder" Version="1.3.6" />
<PackageReference Include="StackExchange.Redis" Version="2.0.601" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0" />
</ItemGroup>
......
......@@ -232,5 +232,10 @@ namespace Property.Model.Entity
/// 资产所属公司
/// </summary>
public int? BranchId { get; set; }
/// <summary>
/// 资产二维码
/// </summary>
public string QRCode { get; set; }
}
}
\ No newline at end of file
......@@ -274,6 +274,17 @@ namespace Property.Module.FixedAssets
return list;
}
/// <summary>
/// 获取资产二维码列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_Property_Info_Extend> GetPropertyQRCodeList(RB_Property_Info_Extend demodel)
{
var list = property_InfoRepository.GetPropertyQRCodeList(demodel);
return list;
}
/// <summary>
/// 获取资产履历分页列表
/// </summary>
......@@ -703,8 +714,29 @@ namespace Property.Module.FixedAssets
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("vt:193213/3213/4123?Id=" + PropertyId, 3, 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.PropertyNum),BMStr},
{ nameof(RB_Property_Info.QRCode),ImageAddress}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
......@@ -3031,6 +3063,76 @@ namespace Property.Module.FixedAssets
return flag;
}
/// <summary>
/// 设置app盘点状态
/// </summary>
/// <param name="propertyId"></param>
/// <param name="type"></param>
/// <param name="remark"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public ApiResult SetPropertyAPPCheckDetailStatus(int propertyId, int Type, string Remark, UserInfo userInfo)
{
var list = property_CheckDetailRepository.GetList(new RB_Property_CheckDetail_Extend() { RB_Group_Id = userInfo.RB_Group_id, PropertyId = propertyId, CheckStatus = PropertyCheckStatusEnum.NoInventory });
if (!list.Any()) {
return ApiResult.Failed("该资产不存在待盘点,请核实后再试");
}
var trans = property_CheckDetailRepository.DbTransaction;
try
{
foreach (var item in list) {
Dictionary<string, object> flies = new Dictionary<string, object>();
if (Type == 1)//盘点
{
flies.Add(nameof(RB_Property_CheckDetail.CheckEmpId), userInfo.EmployeeId);
flies.Add(nameof(RB_Property_CheckDetail.CheckDate), DateTime.Now);
flies.Add(nameof(RB_Property_CheckDetail.CheckStatus), PropertyCheckStatusEnum.HaveInventory);
flies.Add(nameof(RB_Property_CheckDetail.Remark), Remark);
}
if (Type == 2)//盘亏
{
flies.Add(nameof(RB_Property_CheckDetail.CheckEmpId), userInfo.EmployeeId);
flies.Add(nameof(RB_Property_CheckDetail.CheckDate), DateTime.Now);
flies.Add(nameof(RB_Property_CheckDetail.CheckStatus), PropertyCheckStatusEnum.InventoryLosses);
flies.Add(nameof(RB_Property_CheckDetail.Remark), Remark);
}
else if (Type == 3)//盘点并通过
{
flies.Add(nameof(RB_Property_CheckDetail.CheckEmpId), userInfo.EmployeeId);
flies.Add(nameof(RB_Property_CheckDetail.CheckDate), DateTime.Now);
flies.Add(nameof(RB_Property_CheckDetail.CheckStatus), PropertyCheckStatusEnum.HaveInventory);
flies.Add(nameof(RB_Property_CheckDetail.AuditEmpId), userInfo.EmployeeId);
flies.Add(nameof(RB_Property_CheckDetail.AuditDate), DateTime.Now);
flies.Add(nameof(RB_Property_CheckDetail.AuditStatus), 2);
flies.Add(nameof(RB_Property_CheckDetail.Remark), Remark);
}
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Property_CheckDetail.Id),
FiledValue=item.Id,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = property_CheckDetailRepository.Update(flies, wheres);
if (!flag)
{
property_CheckDetailRepository.DBSession.Rollback();
return ApiResult.Failed();
}
}
property_CheckDetailRepository.DBSession.Commit();
return ApiResult.Success();
}
catch (Exception ex)
{
LogHelper.Write(ex, "SetPropertyAPPCheckDetailStatus");
property_CheckDetailRepository.DBSession.Rollback();
return ApiResult.Failed();
}
}
/// <summary>
/// 验证盘点单状态
/// </summary>
......@@ -3047,6 +3149,24 @@ namespace Property.Module.FixedAssets
return true;
}
/// <summary>
/// 获取资产是否在盘点
/// </summary>
/// <param name="propertyId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public bool GetPropertyIsHaveCheck(int propertyId, UserInfo userInfo)
{
var list= property_CheckDetailRepository.GetList(new RB_Property_CheckDetail_Extend() { RB_Group_Id = userInfo.RB_Group_id, PropertyId = propertyId, CheckStatus = PropertyCheckStatusEnum.NoInventory });
if (list.Any())
{
return true;
}
else {
return false;
}
}
#endregion
......@@ -3492,6 +3612,7 @@ namespace Property.Module.FixedAssets
return Robj;
}
#endregion
#region 请购单
/// <summary>
/// 获取请购单分页列表
......
using Property.Model.Entity;
using Property.Model.Extend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -332,6 +333,88 @@ left join rb_property_log pl on pl.PropertyId=pi.Id
return GetPage<RB_Property_Info_Extend>(pageIndex, pageSize, out count, sql).ToList();
}
/// <summary>
/// 获取二维码列表
/// </summary>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Property_Info_Extend> GetPropertyQRCodeList(RB_Property_Info_Extend dmodel)
{
string where = " where 1=1 ";
where += string.Format(" AND pi.{0}={1}", nameof(RB_Property_Info_Extend.Status), 0);
where += $@" and pi.RB_Group_Id={dmodel.RB_Group_Id}";
if (!string.IsNullOrWhiteSpace(dmodel.Name.Trim()))
{
where += " and pi." + nameof(RB_Property_Info_Extend.Name) + " like '%" + dmodel.Name.Trim() + "%'";
}
if (!string.IsNullOrWhiteSpace(dmodel.PropertyNum.Trim()))
{
where += " and pi." + nameof(RB_Property_Info_Extend.PropertyNum) + " like '%" + dmodel.PropertyNum.Trim() + "%'";
}
if (dmodel.CategoryId > 0)
{
where += " and pi." + nameof(RB_Property_Info_Extend.CategoryId) + "=" + dmodel.CategoryId;
}
if (dmodel.UseStatus > 0)
{
where += " and pi." + nameof(RB_Property_Info_Extend.UseStatus) + "=" + (int)dmodel.UseStatus;
}
if (dmodel.PropertyStatus > 0)
{
where += " and pi." + nameof(RB_Property_Info_Extend.PropertyStatus) + "=" + (int)dmodel.PropertyStatus;
}
if (!string.IsNullOrWhiteSpace(dmodel.SerialNumber.Trim()))
{
where += " and pi." + nameof(RB_Property_Info_Extend.SerialNumber) + " = '" + dmodel.SerialNumber.Trim() + "'";
}
if (dmodel.EmployeeId > 0)
{
where += " and pi." + nameof(RB_Property_Info_Extend.EmployeeId) + "=" + dmodel.EmployeeId;
}
if (dmodel.SupplierId > 0)
{
where += " and pi." + nameof(RB_Property_Info_Extend.SupplierId) + "=" + dmodel.SupplierId;
}
if (dmodel.BranchId >= 0)
{
where += " and pi." + nameof(RB_Property_Info_Extend.BranchId) + "=" + dmodel.BranchId;
}
if (!string.IsNullOrEmpty(dmodel.StartTime))
{
where += " and pi." + nameof(RB_Property_Info_Extend.BuyDate) + ">='" + dmodel.StartTime + "'";
}
if (!string.IsNullOrEmpty(dmodel.EndTime))
{
where += " and pi." + nameof(RB_Property_Info_Extend.BuyDate) + "<='" + dmodel.EndTime + " 23:59:59'";
}
if (dmodel.IsSelectDepreciation == 1)
{
where += " and pi." + nameof(RB_Property_Info_Extend.PropertyStatus) + "!=" + (int)REBORN.Common.Enum.PropertyStatusEnum.Dispose;
}
if (dmodel.IsSelectSelfApplication == 1)
{
where += " and pi.PropertyStatus=" + (int)REBORN.Common.Enum.PropertyStatusEnum.Leisure;
}
if (dmodel.IsSelectMyProperty == 1)
{
if (!string.IsNullOrEmpty(dmodel.PropertyIdStr))
{
where += " and (pi.EmployeeId=" + dmodel.CreateBy + " or pi.Id in(" + dmodel.PropertyIdStr + "))";
}
else
{
where += " and pi.EmployeeId=" + dmodel.CreateBy;
}
}
if (dmodel.IsSelectUseProperty == 1)
{
where += " and pi.EmployeeId > 0 ";
}
string sql = $@" select pi.Id,pi.Name,pi.PropertyNum,pi.QRCode from RB_Property_Info pi
{where} order by pi.Id desc";
return Get<RB_Property_Info_Extend>(sql).ToList();
}
/// <summary>
/// 获取资产待归还分页数据
/// </summary>
......
......@@ -660,6 +660,7 @@ namespace Property.WebApi.Controllers.User
model.SupplierName,
model.BranchId,
model.UseMonths,
model.QRCode,
BranchName = CacheManager.User.BranchReidsCache.GetBranch(model.BranchId)?.BName ?? ""
});
}
......@@ -3914,6 +3915,72 @@ namespace Property.WebApi.Controllers.User
}
/// <summary>
/// 获取资产是否在盘点
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetPropertyIsHaveCheck()
{
var requestParm = GetRequestParm();
UserInfo userInfo = CacheManager.User.UserReidsCache.GetUserLoginInfo(requestParm.uid);
JObject parms = JObject.Parse(requestParm.msg.ToString());
int PropertyId = parms.GetInt("PropertyId", 0);
if (PropertyId <= 0) {
return ApiResult.Failed("请传递资产id");
}
bool flag = propertyModule.GetPropertyIsHaveCheck(PropertyId, userInfo);
return ApiResult.Success("", flag);
}
/// <summary>
/// 设置app盘点单明细状态
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetPropertyAPPCheckDetailStatus()
{
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 Type = parms.GetInt("Type", 0);
string Remark = parms.GetStringValue("Remark");
if (PropertyId <= 0)
{
return ApiResult.ParamIsNull("请传递参数id");
}
if (Type != 1 && Type != 2 && Type != 3)
{
return ApiResult.ParamIsNull("type参数有误");
}
return propertyModule.SetPropertyAPPCheckDetailStatus(PropertyId, Type, Remark, userInfo);
}
/// <summary>
/// 获取资产二维码列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetPropertyQRCodeList()
{
var requestParm = GetRequestParm();
UserInfo userInfo = CacheManager.User.UserReidsCache.GetUserLoginInfo(requestParm.uid);
RB_Property_Info_Extend demodel = JsonConvert.DeserializeObject<RB_Property_Info_Extend>(requestParm.msg.ToString());
demodel.RB_Group_Id = userInfo.RB_Group_id;
var list = propertyModule.GetPropertyQRCodeList(demodel);
return ApiResult.Success("", list.Select(x => new
{
x.Id,
x.Name,
x.PropertyNum,
x.QRCode
}));
}
#endregion
#region 统计报表
......
......@@ -93,6 +93,12 @@ namespace Property.WebApi
Path.Combine(Directory.GetCurrentDirectory(), "ExportFile")),
RequestPath = "/ExportFile"
});
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "upfile")),
RequestPath = "/upfile"
});
}
}
}
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