abp框架+mysql 数据库 执行批量新增和修改
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
//每5分钟扫描一次
if (_lastScanTime.AddMinutes(5) > DateTime.Now)
{
await Task.Delay(10000, stoppingToken);
}
_lastScanTime = DateTime.Now; using (var unitOfWork = _unitOfWorkManager.Begin())
{
List<Log> techLogcationLogList = new List<Log>();
SvTech techInfo = new SvTech();
List<SvTech> techList = new List<SvTech>();
Log techLogcationLog = new Log();
Stopwatch watch = new Stopwatch();
watch.Start();
var LoginData = LoginSystemAsync().Result;//获取登录数据
if (LoginData.success == true)
{
var GpsData = GetTechLocationAsync(LoginData.id, LoginData.mds).Result;//获取定位数据
if (GpsData.success == true)
{ foreach (var item in GpsData.data)
{
foreach (var element in item.records)
{
Newtonsoft.Json.Linq.JArray location = (Newtonsoft.Json.Linq.JArray)element;
object[]? locationArr = location.ToObject<object[]>();
techInfo = _technicianRepository.GetAll().Where(s => s.gps_imei == locationArr[11].ToString()).FirstOrDefault();
if (techInfo != null)
{
techInfo.current_location = locationArr[2].ToString() + "," + locationArr[3].ToString();
techInfo.location_update_time = DateTime.Now;
techList.Add(techInfo); techLogcationLog.technician_id = techInfo.Id;
techLogcationLog.location = locationArr[2].ToString() + "," + locationArr[3].ToString();
techLogcationLog.update_datetime = DateTime.Now;
techLogcationLogList.Add(techLogcationLog);
}
}
}
}
else
{
//获取定位失败
}
}
else
{
//登录失败
}
if(techList.Count>0)
{
try
{
_technicianLocationLogRepository.GetDbContext().BulkInsert(techLogcationLogList); //批量新增
_technicianRepository.GetDbContext().BulkUpdate(techList); //批量修改
watch.Stop();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
unitOfWork.Complete();
_lastScanTime = DateTime.Now; }
}
}
注意事项:需要在数据库链接字符串后面加上 AllowLoadLocalInfile=true
"ConnectionStrings": {
"Default": "server=127.0.0.1;port=3306;user id=root;password=123456;database=test;AllowLoadLocalInfile=true"
},
否则会报如下错误
//错误提示 To use MySqlBulkLoader.Local=true, set AllowLoadLocalInfile=true in the connection string. See https://fl.vu/mysql-load-data”
abp框架+mysql 数据库 执行批量新增和修改的更多相关文章
- 基于abp框架的数据库种子数据初始化
目录 基于abp框架的数据库种子数据初始化 1.背景 2.参照 3.解决方案 3.1 初始化数据 3.2 依赖注入方法容器里获取数据库上下文 3.3 封装创建初始化数据列表方法 3.4 数据库中没有的 ...
- MySQL数据库执行计划(简单版)
+++++++++++++++++++++++++++++++++++++++++++标题:MySQL数据库执行计划简单版时间:2019年2月25日内容:MySQL数据库执行计划简单版重点:MySQL ...
- mysql数据库忘记密码时如何修改(一)
方法/步骤 打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 打开cmd命令提示符,进入上一步mysql.exe所在的文件夹. 输入命令 mysqld --skip-grant ...
- ABP——切换MySQL数据库
我是一名.net新手,应公司要求开始学习.net,使用的是土耳其大牛写的框架ASP.NET Boilerplate 简称ABP,是基于DDD的现代ASP.NET开发框架,ABP提供了一个启动模板用于新 ...
- ABP 切换mysql 数据库报错mysqlexception: incorrect string value: ‘\xe7\xae\x80\xe4\xbd\x93…’ for column display name
刚折腾了ABP框架,为了跨平台,将SQL Server数据库换成了MySQL数据库,ABP框架上支持多语言,中间被字符集折腾的够呛,翻了N个博客,最后终于在StackOverFlow 上找到了最终的解 ...
- python3使用pymysql模块,连接mysql数据库,实现新增、查询和更新操作
1.环境数据准备: python3环境.pymysql模块 mysql数据库:本次代码中用到的数据库为本地的testdb数据库,user表(表字段比较简单,只有主键id,手机号mobile,密码pas ...
- Python连接MySQL数据库执行sql语句时的参数问题
由于工作需要,今天写了一个Python小脚本,其中需要连接MySQL数据库,在执行sql命令时需要传递参数,结果出问题了.在网上查了一下,发现有以下几种方式传递参数: 一.直接把sql查询语句完整写入 ...
- Python 连接Mysql数据库执行语句操作
学习Mysql模块的使用,模块命名的坑,解决SHA加密错误无法连接
- 通用mapper版+SpringBoot+MyBatis框架+mysql数据库的整合
转:https://blog.csdn.net/qq_35153200/article/details/79538440 开发环境: 开发工具:Intellij IDEA 2017.2.3 JDK : ...
- 【转】ABP使用Mysql数据库
原文地址:https://www.cnblogs.com/LonelyCode/p/6477065.html 1.先安装Mysql的包,EntityFramework和Web项目都需要安装 2.修改W ...
随机推荐
- studiostyl.es网站scheme文件无法下载
原因网站引用Google的服务 解决方法:查看网页源码.选择选取页面中的元素,选择download按钮,如下图所示 downloadExisting后面的数字代表主题的ID. 在网站中输入https: ...
- composer更新报错
在用composer安装Yii2的扩展插件时,报错: [UnexpectedValueException] Could not parse version constraint <=2.*: I ...
- 权昌TSC244条码打印机如何加载数据实现大批量打印呢?
我公司的TSC TTP-244条码打印机,只会改个名称打一张,怎么样改数据或者是加载数据实现大量打印的呢? 解答: TSC TTP-244条码打印机,是一款性能不错的桌面型条码打印机,最大打印 ...
- JS学习-Web Worker
Web Worker 在专用workers的情况下,DedicatedWorkerGlobalScope 对象代表了worker的上下文(专用workers是指标准worker仅在单一脚本中被使用:共 ...
- Python request模块 携带cookie
# _*_coding:utf-8 _*_ import time import requests import json import sys import random import string ...
- 【北邮人论坛帖子备份】【FAQ】给今年国企求职学弟学妹的一点建议
目录 主要内容 补充--[心得][校招]面向国企秋招的一些体会 补充--[心得]回馈论坛,某toca的小弟金融类央企秋招过程中的一点点 主要内容 时间:Fri Feb 19 23:00:33 2021 ...
- cam对象类型
//此函数的功能是打印当前坐标系试图的所有坐标系名称 static void geom_list_name(tag_t group_tag) { //ask_member_list int count ...
- nodejs中的kafkajs,消费顺序,不重复消费
参考:https://kafka.js.org/docs 确保同一个消息发送到同一个partition,一个topic,一个partition,一个consumer,内部单线程消费1.封装kafkaU ...
- 在Unity3D中开发的Rim Shader
Swordmaster Rim Shaders 特点 本资源包共包含两种Rim效果的Shader (1)Rim Bumped Specular. (2)Rim StandardPBR(Metallic ...
- 普通的patch 和使用git 打patch
参考博客: https://www.cnblogs.com/laoxiaobaiup/p/9455088.html https://blog.csdn.net/u012701023/article/d ...