v10,大屏优化,批量上传优化

This commit is contained in:
gaoben 2024-08-14 16:38:43 +08:00
parent e81d002324
commit be212e350c
17 changed files with 195 additions and 47 deletions

View File

@ -2,19 +2,21 @@ package net.shapelight.common.utils;
import com.github.junrar.Archive;
import com.github.junrar.rarfile.FileHeader;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.io.FileUtils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
@Slf4j
public class CompressZipUtils {
// @Autowired
// @Autowired
// private static List<String> copyFileNames = new ArrayList<>();
private static List<String> excelFiles = new ArrayList<>();
private static List<String> imageFiles = new ArrayList<>();
@ -84,29 +86,30 @@ public class CompressZipUtils {
解压到指定文件夹下然后拷贝到目标文件夹下覆盖
*/
@SuppressWarnings("rawtypes")
public static Map<String,List<String>> unZipFiles(File zipFile, String unZipDir) throws Exception {
public static Map<String, List<String>> unZipFiles(File zipFile, String unZipDir) throws Exception {
excelFiles.clear();
imageFiles.clear();
Map<String,List<String>> filesMap = new HashMap<>();
Map<String, List<String>> filesMap = new HashMap<>();
File pathFile = new File(unZipDir);
if(!pathFile.exists()){
if (!pathFile.exists()) {
pathFile.mkdirs();
}
ZipFile zip = new ZipFile(zipFile);
//List<String> fileNames = new ArrayList<>();
for(Enumeration entries = zip.getEntries();entries.hasMoreElements();){
ZipEntry entry = (ZipEntry)entries.nextElement();
for (Enumeration entries = zip.getEntries(); entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
entry.setUnixMode(644); // 解决linux乱码
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);
String outPath = (unZipDir+zipEntryName).replaceAll("\\*", "/");;
String outPath = (unZipDir + zipEntryName).replaceAll("\\*", "/");
;
//判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if(!file.exists()){
if (!file.exists()) {
file.mkdirs();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if(new File(outPath).isDirectory()){
if (new File(outPath).isDirectory()) {
continue;
}
//输出文件路径信息
@ -115,8 +118,8 @@ public class CompressZipUtils {
OutputStream out = new FileOutputStream(outPath);
byte[] buf1 = new byte[1024];
int len;
while((len=in.read(buf1))>0){
out.write(buf1,0,len);
while ((len = in.read(buf1)) > 0) {
out.write(buf1, 0, len);
}
in.close();
out.close();
@ -133,27 +136,46 @@ public class CompressZipUtils {
// System.out.println(string);
// }
filesMap.put("excel",excelFiles);
filesMap.put("image",imageFiles);
filesMap.put("excel", excelFiles);
filesMap.put("image", imageFiles);
return filesMap;
}
public static void listFiles(File srcDir){
public static void listFiles(File srcDir) {
// excelFiles.clear();
// imageFiles.clear();
File[] files = srcDir.listFiles(); //列出所有的子文件
for(File file :files)
{
if(file.isFile())//如果是文件则输出文件名字
for (File file : files) {
if (file.isFile())//如果是文件则输出文件名字
{
String fileName = file.getAbsolutePath();
//判断jpg图片
if (fileName.endsWith("jpg") || fileName.endsWith("jpeg") || fileName.endsWith("png")) {
//-----------------------------压缩图片------------------------------------------------
try {
// File picture = new File(orgFileStr);
BufferedImage sourceImg = ImageIO.read(new FileInputStream(file));
int w = sourceImg.getWidth();
int h = sourceImg.getHeight();
// long fileSize = picture.length();
// if(fileSize<200000l){
// continue;
// }
if (w > 1080 || h > 1080) {
Thumbnails.of(file)
.size(1080, 1080)
.toFile(file);
}
log.error("压缩图片。。。。。。。。。。。。。。。。。。。。。。。。。。。。");
} catch (Exception e) {
log.error(e.getMessage());
}
//-----------------------------------------------------------------------------
imageFiles.add(fileName);
}else if(fileName.endsWith("xls") || fileName.endsWith("xlsx")){
} else if (fileName.endsWith("xls") || fileName.endsWith("xlsx")) {
excelFiles.add(fileName);
}
}else if(file.isDirectory())//如果是文件夹则输出文件夹的名字并递归遍历该文件夹
} else if (file.isDirectory())//如果是文件夹则输出文件夹的名字并递归遍历该文件夹
{
listFiles(file);//递归遍历
}
@ -161,7 +183,6 @@ public class CompressZipUtils {
}
// public static File[] returnFiles(String strPath) {
// File dir = new File(strPath);
// File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
@ -203,7 +224,7 @@ public class CompressZipUtils {
// return copyFileNames;
// }
public static void main(String args[]){
public static void main(String args[]) {
// try{
// File srcDir = new File("D:/images/20190909095419/2019");
// List<String> names = copyJpgFiles(srcDir,"D:/images/20190909095419/2020");
@ -213,16 +234,16 @@ public class CompressZipUtils {
//
// }
try{
try {
File srcDir = new File("D:\\project\\cell\\temp\\730349916982870023\\ab028c688f294c74a91ed4290c381afa");
listFiles(srcDir);
for(String string: CompressZipUtils.getExcelFiles()){
for (String string : CompressZipUtils.getExcelFiles()) {
System.out.println(string);
}
for(String string: CompressZipUtils.getImageFiles()){
for (String string : CompressZipUtils.getImageFiles()) {
System.out.println(string);
}
}catch (Exception e){
} catch (Exception e) {
}

View File

@ -0,0 +1,32 @@
package net.shapelight.common.utils;
public class IDCardValidator {
public static boolean isValidChineseID(String id) {
if (id == null || (id.length() != 18)) {
return false;
}
char[] idArray = id.toCharArray();
int[] weight = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char[] checkCode = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
int sum = 0;
for (int i = 0; i < idArray.length - 1; i++) {
int num = Integer.parseInt(String.valueOf(idArray[i]));
if (num < 0 || num > 9) {
return false;
}
sum += num * weight[i];
}
sum = sum % 11;
char lastChar = idArray[17];
return lastChar == checkCode[sum];
}
public static void main(String[] args) {
String id = "610402196509200013";
boolean valid = isValidChineseID(id);
System.out.println("身份证号码 " + id + " 是否有效: " + valid);
}
}

View File

@ -11,6 +11,7 @@ import com.arcsoft.face.toolkit.ImageInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.minio.PutObjectOptions;
import lombok.Getter;
import net.shapelight.common.utils.IDCardValidator;
import net.shapelight.common.utils.R;
import net.shapelight.common.utils.UUIDUtil;
import net.shapelight.commons.engine.sdk.PicSDK;
@ -239,6 +240,12 @@ public class PersonExcelListener extends AnalysisEventListener<PersonModel> {
list.add(personModel);
return;
}
boolean idCardVilid = IDCardValidator.isValidChineseID(personModel.getIdCard());
if(!idCardVilid){
personModel.setMessage("身份证号码不合规");
list.add(personModel);
return;
}
String gender = personModel.getGender();
if(gender==null){
@ -250,6 +257,8 @@ public class PersonExcelListener extends AnalysisEventListener<PersonModel> {
char genderCode = personModel.getIdCard().charAt(16);
String g = (genderCode % 2 == 0) ? "" : "";
personModel.setGender(g);
}else{
personModel.setGender("");
}
}
// if (!gender.equals("") && !gender.equals("")) {

View File

@ -1545,6 +1545,7 @@ public class HttpApiController {
record.setScore(Float.parseFloat(scoreString));
record.setIdCard(idCard);
record.setName(name);
record.setLabelName("访客");
try {
//保存图片
@ -1608,6 +1609,7 @@ public class HttpApiController {
//人脸识别成功
TenPersonEntity tenPersonEntity = tenPersonService.getByIdWithDelete(Long.parseLong(faceRecognitionResDTO.getPersonId()));
String labelName = "";
//----------------------------------------以下业务-----------------------------------------------------
log.debug("人脸识别成功:"+sn);
// TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
@ -1615,7 +1617,7 @@ public class HttpApiController {
if(tenPersonEntity.getPersonType() == Constant.PERSON_TYPE_GUEST){
//访客直接判断有效期
if(now.getTime() >= tenPersonEntity.getLiveStart().getTime() && now.getTime() <= tenPersonEntity.getLiveEnd().getTime()){
labelName = "访客";
}else{
//不在时间段内
return R.error("不在有效期,禁止通行");
@ -1629,6 +1631,7 @@ public class HttpApiController {
TenLabelEntity personLabel = tenLabelService.getById(tenPersonEntity.getLabelId());
for(TenLabelEntity labelEntity: labelList){
if(labelEntity.getLabelId().intValue() == personLabel.getLabelId().intValue()){
labelName = labelEntity.getName();
hasLabel = true;
break;
}
@ -1684,6 +1687,7 @@ public class HttpApiController {
// record.setScore(faceRecognitionResDTO.getSimilar());
record.setIdCard(tenPersonEntity.getIdCard());
record.setName(tenPersonEntity.getName());
record.setLabelName(labelName);
try {
//保存图片
@ -1713,6 +1717,7 @@ public class HttpApiController {
if(icCard !=null && icCard.length()>0){
// TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn);
TenPersonEntity tenPersonEntity = tenPersonService.findByIcCardTop(icCard,deviceEntity.getTenantId()+"");
String labelName = "";
if(tenPersonEntity!=null){
//----------------------------------------以下业务-----------------------------------------------------
@ -1724,6 +1729,7 @@ public class HttpApiController {
for(TenLabelEntity labelEntity: labelList){
if(labelEntity.getLabelId().intValue() == personLabel.getLabelId().intValue()){
hasLabel = true;
labelName = labelEntity.getName();
break;
}
}
@ -1758,6 +1764,7 @@ public class HttpApiController {
record.setIdCard(tenPersonEntity.getIdCard());
record.setName(tenPersonEntity.getName());
record.setScore(1.0f);
record.setLabelName(labelName);
// tenRecordService.saveServer(record);
recordSaveSyncService.offerQueue(record);

View File

@ -12,9 +12,7 @@ import net.shapelight.modules.sys.entity.SysUserEntity;
import net.shapelight.modules.sys.service.SysUserRoleService;
import net.shapelight.modules.ten.entity.*;
import net.shapelight.modules.ten.service.*;
import net.shapelight.modules.vo.TenBuildVo;
import net.shapelight.modules.vo.TenPersonMonthCountVo;
import net.shapelight.modules.vo.TenRecordVo;
import net.shapelight.modules.vo.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -604,4 +602,25 @@ public class TenDataViewController extends AbstractController {
private String name;
private Integer value;
}
@GetMapping("/getTodayLabelRecordCount")
@ApiOperation(value = "当天人员类型通行统计",response = Map.class)
public R getTodayLabelRecordCount(@RequestParam Map<String, Object> params){
String tenantId = getUser().getTenantId()+"";
params.put("tenantId",tenantId+"");
List<TenTodayLabelCount> countData = tenRecordService.findTodayLabelCount(tenantId);
return R.ok().put("data", countData);
}
@GetMapping("/getDeptPersonCount")
@ApiOperation(value = "组织人员统计",response = Map.class)
public R getDeptPersonCount(@RequestParam Map<String, Object> params){
String tenantId = getUser().getTenantId()+"";
params.put("tenantId",tenantId+"");
List<TenDeptPersonCount> countData = tenPersonService.findDeptCount(tenantId);
return R.ok().put("data", countData);
}
}

View File

@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.shapelight.modules.ten.entity.TenLabelEntity;
import net.shapelight.modules.ten.entity.TenPersonEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.shapelight.modules.vo.TenPersonIdUpdateAllVo;
import net.shapelight.modules.vo.TenPersonIdUpdateVo;
import net.shapelight.modules.vo.TenPersonMonthCountVo;
import net.shapelight.modules.vo.TenPersonVo;
import net.shapelight.modules.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -131,4 +128,6 @@ public interface TenPersonDao {
List<String> getAllIdCard(@Param("tenantId")String tenantId);
List<TenDeptPersonCount> findDeptCount(@Param("tenantId")String tenantId);
}

View File

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.shapelight.modules.ten.entity.TenLabelEntity;
import net.shapelight.modules.ten.entity.TenRecordEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.shapelight.modules.vo.TenTodayLabelCount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -53,4 +54,6 @@ public interface TenRecordDao{
void deleteDaysIntervalRecords(@Param("days") String days, @Param("tenantId") String tenantId);
List<TenRecordEntity> findListAll(@Param("cellIds") List<Long> cellIds, @Param("params") Map params);
List<TenTodayLabelCount> findTodayLabelCount(@Param("tenantId") String tenantId);
}

View File

@ -188,4 +188,6 @@ cameraParam 否 string 相机参数
private String idCard;
private String name;
private String labelName;
}

View File

@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import net.shapelight.common.utils.PageUtils;
import net.shapelight.modules.excel.model.PersonModel;
import net.shapelight.modules.ten.entity.*;
import net.shapelight.modules.vo.TenPersonIdUpdateAllVo;
import net.shapelight.modules.vo.TenPersonIdUpdateVo;
import net.shapelight.modules.vo.TenPersonMonthCountVo;
import net.shapelight.modules.vo.TenPersonVo;
import net.shapelight.modules.vo.*;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -162,5 +159,7 @@ public interface TenPersonService {
List<String> getAllIdCard(String tenantId);
List<TenDeptPersonCount> findDeptCount(String tenantId);
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import net.shapelight.common.utils.PageUtils;
import net.shapelight.modules.ten.entity.TenRecordEntity;
import net.shapelight.modules.vo.TenTodayLabelCount;
import org.apache.ibatis.annotations.Param;
import java.io.Serializable;
@ -54,5 +55,7 @@ public interface TenRecordService {
List<TenRecordEntity> findListAll(Map<String, Object> params);
List<TenTodayLabelCount> findTodayLabelCount(String tenantId);
}

View File

@ -2570,4 +2570,9 @@ public class TenPersonServiceImpl implements TenPersonService {
public List<String> getAllIdCard(String tenantId) {
return tenPersonDao.getAllIdCard(tenantId);
}
@Override
public List<TenDeptPersonCount> findDeptCount(String tenantId) {
return tenPersonDao.findDeptCount(tenantId);
}
}

View File

@ -13,6 +13,7 @@ import net.shapelight.modules.ten.dao.TenLabelDao;
import net.shapelight.modules.ten.entity.*;
import net.shapelight.modules.ten.service.*;
import net.shapelight.modules.vo.TenRecordVo;
import net.shapelight.modules.vo.TenTodayLabelCount;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
@ -556,4 +557,9 @@ public class TenRecordServiceImpl implements TenRecordService {
}
return page;
}
@Override
public List<TenTodayLabelCount> findTodayLabelCount(String tenantId) {
return tenRecordDao.findTodayLabelCount(tenantId);
}
}

View File

@ -0,0 +1,9 @@
package net.shapelight.modules.vo;
import lombok.Data;
@Data
public class TenDeptPersonCount {
private String deptName;
private Integer count;
}

View File

@ -0,0 +1,9 @@
package net.shapelight.modules.vo;
import lombok.Data;
@Data
public class TenTodayLabelCount {
private String labelName;
private Integer labelCount;
}

View File

@ -61,9 +61,9 @@ global:
opt_dir: opt
db_bak:
db_filepath: db_bak
db_name: cell_db_0511
db_username: root
db_password: root
db_name: cell_db_v10_pv_xianyang2
db_username: user
db_password: user@server001
db_host: localhost
db_port: 3306
minio:
@ -109,8 +109,8 @@ config:
sdk-key: vWbvUyStZeartSaM6QoTzPYWFpSaj4uhfDmRifSzCd6
active-key: 82G1-11QA-713Y-8NB4
active-file:
detect-pool-size: 5
compare-pool-size: 5
detect-pool-size: 16
compare-pool-size: 16
rec-face-thd: 0.8
rec-id-thd: 0.5

View File

@ -1392,5 +1392,14 @@
and person_type != 5005 and tenant_id = #{tenantId}
</select>
<select id="findDeptCount" resultType="net.shapelight.modules.vo.TenDeptPersonCount">
select d.name as deptName,count(d.name) as count from ten_person t
left join ten_cell_dept d
on t.dept_id = d.dept_id
where t.tenant_id = #{tenantId}
and t.delete_flag = 0
group by d.name
</select>
</mapper>

View File

@ -37,6 +37,7 @@
<result property="idCard" column="id_card"/>
<result property="name" column="name"/>
<result property="labelName" column="name"/>
</resultMap>
@ -116,6 +117,9 @@
<if test="name != null">
name,
</if>
<if test="labelName != null">
label_name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="recordId != null">
@ -192,6 +196,9 @@
<if test="name != null">
#{name},
</if>
<if test="labelName != null">
#{labelName},
</if>
</trim>
</insert>
@ -247,7 +254,10 @@
id_card = #{idCard,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{idCard,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
</if>
<if test="labelName != null">
name = #{labelName,jdbcType=VARCHAR},
</if>
</set>
where record_id = #{recordId,jdbcType=BIGINT}
@ -701,4 +711,10 @@
where DATE_SUB(CURDATE(), INTERVAL #{days} DAY) > record_time
</delete>
<select id="findTodayLabelCount" resultType="net.shapelight.modules.vo.TenTodayLabelCount">
select label_name as labelName,count(label_name) as labelCount from ten_record_${tenantId}
where DATE(record_time) = CURRENT_DATE()
group by label_name
</select>
</mapper>