From e16302f9d475c7cc4dd18c5abf1a23cb5502e362 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期三, 28 五月 2025 14:57:56 +0800 Subject: [PATCH] 密码验证加- --- src/main/java/com/whyc/service/UserWorkService.java | 63 +++++++++++++++++++++++-------- 1 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/whyc/service/UserWorkService.java b/src/main/java/com/whyc/service/UserWorkService.java index 82e89b1..b953645 100644 --- a/src/main/java/com/whyc/service/UserWorkService.java +++ b/src/main/java/com/whyc/service/UserWorkService.java @@ -5,7 +5,9 @@ import com.whyc.dto.paramter.UserWorkAlarmParam; import com.whyc.mapper.UserWorkMapper; import com.whyc.mapper.WorkAlarmMapper; +import com.whyc.pojo.UserInf; import com.whyc.pojo.UserWork; +import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.system.ApplicationHome; import org.springframework.core.env.Environment; @@ -13,11 +15,14 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.io.*; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; @Service public class UserWorkService { @@ -27,6 +32,9 @@ private WorkAlarmMapper workAlarmMapper; @Autowired private Environment environment; + + @Autowired + private BattGroupStationUserService battGroupStationUserService; public Response addOrUpdate(UserWork userWork){ if (userWork.getId()==null || userWork.getId()==0){ @@ -61,11 +69,11 @@ public Response searchByCondition(UserWork userWork){ QueryWrapper<UserWork> queryWrapper = new QueryWrapper<>(); - queryWrapper.eq(userWork.getUserId()!=null||userWork.getUserId()!=0,"userId",userWork.getUserId()); - queryWrapper.eq(userWork.getManagerId()!=null||userWork.getManagerId()!=0,"managerId",userWork.getManagerId()); - queryWrapper.eq(userWork.getWorkId()!=null||userWork.getWorkId()!=0,"workId",userWork.getWorkId()); + queryWrapper.eq(userWork.getUserId() != null && userWork.getUserId() != 0, "userId", userWork.getUserId()); + queryWrapper.eq(userWork.getManagerId() != null && userWork.getManagerId() != 0, "managerId", userWork.getManagerId()); + queryWrapper.eq(userWork.getWorkId() != null && userWork.getWorkId() != 0, "workId", userWork.getWorkId()); List<UserWork> list = mapper.selectList(queryWrapper); - return new Response().set(1,list,"鏌ヨ鎴愬姛"); + return new Response().set(1, list, "鏌ヨ鎴愬姛"); } @@ -82,7 +90,7 @@ //鎵撳寘鐗� fileDirName = jarFile.toString(); } - String root=fileDirName+"/stationsrc/alarm/"+ param.getStationId() + "/" + param.getAfterOrBefore() + "/"; + String root=fileDirName+"/fg_photo/stationsrc/alarm/"+ param.getStationId() + "/" + param.getAfterOrBefore() + "/"; List<String> filePathList = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); boolean isSuccess = false; @@ -125,14 +133,14 @@ } catch (IOException e) { e.printStackTrace(); } finally { - if(in != null){ + if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } - if(out != null){ + if (out != null) { try { out.close(); } catch (IOException e) { @@ -141,31 +149,54 @@ } } } - public void createFilefolderIFNotExist(String filePath){ + + public void createFilefolderIFNotExist(String filePath) { File f = new File(filePath); - if(!f.exists()){ - if(!f.getParentFile().exists()){ + if (!f.exists()) { + if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } } } - public void deleteAlarmFile(){ + public Response deleteAlarmFile(String fileNames, int stationId, String afterOrBefore, HttpServletRequest request) { + //鏍¢獙浼犲叆鐨剆tationId鏄惁涓哄綋鍓嶇敤鎴风鐞嗙殑 + UserInf user = (UserInf) request.getSession().getAttribute("user"); + if(user == null){ + user = new UserInf(); + user.setUName("鏈櫥褰曠殑鐢ㄦ埛璐﹀彿"); + user.setUId(0L); + user.setURole(0); + } + List<UserInf> userList = battGroupStationUserService.getUserList(stationId); + List<Long> userIdList = userList.stream().map(UserInf::getUId).collect(Collectors.toList()); + if(!userIdList.contains(user.getUId())){ + return new Response().set(0, "鍒犻櫎澶辫触,褰撳墠鐢ㄦ埛鏃犳潈闄愬垹闄や紶鍙傜珯鐐圭殑鏂囦欢"); + } + + //杩囨护鐗规畩瀛楃,閬垮厤璺緞閬嶅巻鏀诲嚮 + fileNames = ActionUtil.filterFileName(fileNames); + afterOrBefore = ActionUtil.filterFileName(afterOrBefore); + String names[] = fileNames.split(","); String fileDirName = ""; int configType = Integer.parseInt(environment.getProperty("configFile.type")); ApplicationHome applicationHome = new ApplicationHome(getClass()); File jarFile = applicationHome.getDir(); //娴嬭瘯鐗� - if(configType==1){ + if (configType == 1) { fileDirName = jarFile.getParentFile().toString(); - }else{ + } else { //鎵撳寘鐗� fileDirName = jarFile.toString(); } -// String root=fileDirName+"/stationsrc/alarm"+ param.getStationId() + "/" + param.getAfterOrBefore() + "/"; - + String root = fileDirName + "/fg_photo/stationsrc/alarm/" + stationId + File.separator + afterOrBefore + File.separator; + for (String name : names) { + String targetFilePath = root + name; + File file = new File(targetFilePath); + file.delete(); + } + return new Response().set(1, "鍒犻櫎鎴愬姛"); } - } -- Gitblit v1.9.1