| | |
| | | import com.whyc.constant.UserOperation; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.SoftDto; |
| | | import com.whyc.mapper.SoftcodeMapper; |
| | | import com.whyc.mapper.SoftwareMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.Softcode; |
| | | import com.whyc.pojo.Software; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.text.ParseException; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | |
| | | public class SoftwareService { |
| | | @Autowired(required = false) |
| | | private SoftwareMapper mapper; |
| | | |
| | | @Autowired(required = false) |
| | | private SoftcodeMapper codeMapper; |
| | | |
| | | @Autowired |
| | | private DocLogService logService; |
| | |
| | | |
| | | } |
| | | //查询软件列表的信息 |
| | | public Response getAllSoftware(String fileName,String applyMaterialCode,String applyModel,String owner, String boardNumber,int pageCurr, int pageSize) { |
| | | public Response getAllSoftware(Integer lockFlag, String fileName, String applyMaterialCode, String applyModel, String owner, String boardNumber |
| | | ,String version, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List list=mapper.getFileUrl(fileName,applyMaterialCode,applyModel,owner,boardNumber); |
| | | List<SoftDto> list=mapper.getFileUrl(lockFlag,fileName,applyMaterialCode,applyModel,owner,boardNumber,version); |
| | | //根据软件名称查询是否存在源码(0:否,1:存在) |
| | | for (SoftDto dto:list) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("file_name",dto.getFileName()); |
| | | wrapper.last("limit 1"); |
| | | Softcode code=codeMapper.selectOne(wrapper); |
| | | if(code!=null){ |
| | | dto.setCodeFlag(1); |
| | | dto.setCodeName(code.getCodeName()); |
| | | }else{ |
| | | dto.setCodeFlag(0); |
| | | dto.setCodeName(""); |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"软件信息返回"); |
| | | } |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | //记录日志 |
| | | DocUser docUser= ActionUtil.getUser(); |
| | | String operationDetail="具体软件名称为:"+software.getFileName(); |
| | | String opreationMsg="执行了软件下载操作"; |
| | | String terminalIp=req.getRemoteAddr(); |
| | | logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); |
| | | logService.recordOperationLogDownLoad(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), UserOperation.TYPE_DOWNLOAD_SOFWARE.getType(),new Date(),req.getRemoteAddr() |
| | | ,filename,fileDirName+File.separator+software.getFileUrl(),"",String.valueOf(id),software.getVersion()); |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | public Response upload(MultipartFile file1, MultipartFile file2, String fontUpdateTime, List<Software> softwareList) throws IOException { |
| | | String userName = ActionUtil.getUser().getName(); |
| | | String file1Name = file1.getOriginalFilename(); |
| | | String file2Name = file2.getOriginalFilename(); |
| | | Software software = softwareList.get(0); |
| | |
| | | } |
| | | Date date = new Date(); |
| | | String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date); |
| | | //文件重命名(暂不需要,严格遵守名称规则的情况下不会重名) |
| | | //file1Name = file1Name.substring(0,file1Name.lastIndexOf(".")) + "_" + dateUnion +file1Name.substring(file1Name.lastIndexOf(".")); |
| | | //file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf(".")); |
| | | //文件重命名(严格遵守名称规则的情况下不会重名) |
| | | file1Name = file1Name.substring(0,file1Name.lastIndexOf(".")) + "_" + dateUnion +file1Name.substring(file1Name.lastIndexOf(".")); |
| | | file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf(".")); |
| | | //存储路径 |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | String softwareDir = rootFile + "software" + File.separator + software.getOwner()+ File.separator + software.getFileName(); |
| | |
| | | software1.setFileUrl(softwareHttpUrl+File.separator+file1Name); |
| | | software1.setExcelUrl(softwareHttpUrl+File.separator+file2Name); |
| | | software1.setCreateTime(date); |
| | | software1.setUploadUser(userName); |
| | | //锁定-专供测试人员才能解锁 |
| | | software1.setLockFlag(-1); |
| | | } |
| | | /* 取消自动锁定原来版本,因为新版本需要进行测试才能使用 |
| | | //锁定原来的所有版本:根据版号和软件类型 |
| | | List<String> materialCodeList = softwareList.stream().map(Software::getApplyMaterialCode).collect(Collectors.toList()); |
| | | lockByBoardNumberAndTypeAndMaterialCode(software.getBoardNumber(),software.getType(),materialCodeList); |
| | | lockByBoardNumberAndTypeAndMaterialCode(software.getBoardNumber(),software.getType(),materialCodeList);*/ |
| | | //写入数据库 |
| | | insertBatch(softwareList); |
| | | return new Response().set(1,true,"上传完成"); |
| | |
| | | .set("local_reason","软件版本升级") |
| | | .eq("board_number",boardNumber) |
| | | .eq("type",type) |
| | | .ne("lock_flag",-1) |
| | | .in("apply_material_code",materialCodeList); |
| | | mapper.update(null,update); |
| | | } |
| | |
| | | UpdateWrapper<Software> update = Wrappers.update(); |
| | | update.eq("file_name",softwareDB.getFileName()); |
| | | mapper.delete(update); |
| | | String fontUpdateTime = softwareDB.getFontUpdateTime(); |
| | | softwareList.forEach(software2 -> { |
| | | software2.setFileUrl(softwareDB.getFileUrl()); |
| | | software2.setExcelUrl(softwareHttpUrl + File.separator + originalFilename); |
| | | software2.setCreateTime(new Date()); |
| | | software2.setLockFlag(-1); |
| | | software2.setFontUpdateTime(fontUpdateTime); |
| | | }); |
| | | mapper.insertBatchSomeColumn(softwareList); |
| | | |
| | | return new Response().set(1,true,"更新完成"); |
| | | } |
| | | } |
| | | //根据软件id修改软件锁定状态 |
| | | public Response updateSoftwareLock(String fileUrl,int lockFlag,String localReason) { |
| | | |
| | | /** |
| | | * 根据软件唯一值字段修改软件锁定状态,这里选取fileUrl |
| | | * |
| | | * @param fileUrl |
| | | * @param lockFlagNow |
| | | * @param lockFlag |
| | | * @param localReason |
| | | * @return |
| | | */ |
| | | public Response updateSoftwareLock(String fileUrl, int lockFlagNow, int lockFlag, String localReason) { |
| | | String userName = ActionUtil.getUser().getName(); |
| | | if(lockFlag ==0){ |
| | | //只有李桂华才能解锁 待测试锁定的软件 |
| | | QueryWrapper<Software> query = Wrappers.query(); |
| | | query.eq("file_url",fileUrl); |
| | | List<Software> softwareListInDB = mapper.selectList(query); |
| | | Software softwareInDB = softwareListInDB.get(0); |
| | | if(softwareInDB.getLockFlag() == -1){ |
| | | //if(!userName.equals("李桂华")){ |
| | | // return new Response().set(1,false,"无权限解锁 待测试的软件"); |
| | | //}else{ |
| | | //锁定原来的所有版本:根据版号和软件类型,排除待测试版本 |
| | | List<String> materialCodeList = softwareListInDB.stream().map(Software::getApplyMaterialCode).collect(Collectors.toList()); |
| | | lockByBoardNumberAndTypeAndMaterialCode(softwareInDB.getBoardNumber(),softwareInDB.getType(),materialCodeList); |
| | | |
| | | //} |
| | | } |
| | | } |
| | | UpdateWrapper uwrapper=new UpdateWrapper(); |
| | | uwrapper.set("lock_flag",lockFlag); |
| | | uwrapper.set("local_reason",localReason); |
| | | uwrapper.eq("file_url",fileUrl); |
| | | uwrapper.eq("lock_flag",lockFlagNow); |
| | | int flag=mapper.update(null,uwrapper); |
| | | return new Response().set(1,flag>0,"锁定/解锁成功"); |
| | | } |
| | | //根据软件名称实现软件删除 |
| | | public Response deleteSoftware(String fileName,String version) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("file_name",fileName); |
| | | wrapper.eq("version",version); |
| | | int flag=mapper.delete(wrapper); |
| | | return new Response().set(1,flag>0,"件id实现软件删除"); |
| | | } |
| | | |
| | | //查询日期三天内的所有上传软件 |
| | | public Response getFileNameByCreateTime(String createTime) { |
| | | //获取endtime的三天前的时间 |
| | | LocalDate createDay= LocalDate.parse(createTime); |
| | | LocalDateTime end = createDay.atTime(LocalTime.MAX); |
| | | Date endtime=Date.from(end.atZone(ZoneId.systemDefault()).toInstant()); |
| | | //获取createTime的三天前的时间 |
| | | LocalDate threeDaysAgo = createDay.minusDays(3); |
| | | LocalDateTime startOfDay = threeDaysAgo.atStartOfDay(); |
| | | Date starttime=Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.select("distinct file_name","type","version","based_version","owner","filing_date","create_time","owner"); |
| | | wrapper.ge("create_time",starttime); |
| | | wrapper.le("create_time",endtime); |
| | | wrapper.eq("owner",ActionUtil.getUser().getName()); |
| | | List<Software> list=mapper.selectList(wrapper); |
| | | //获取list中fileName的集合 |
| | | //List<String> nameList = list.stream().map(Software::getFileName).collect(Collectors.toList()); |
| | | return new Response().setII(1,list!=null,list,"查询日期三天内的所有上传软件"); |
| | | } |
| | | } |