| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.*; |
| | | import com.whyc.mapper.FileParamMapper; |
| | | import com.whyc.pojo.FileInfo; |
| | | import com.whyc.pojo.FileParam; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.MathUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Autowired(required = false) |
| | | private FileParamMapper mapper; |
| | | |
| | | @Autowired(required = false) |
| | | private BattGroupDataMapper dataMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private FileParamMapper paramMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private FileInfoMapper infoMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private TestParamMapper testParamMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private BattgroupInfoMapper groupInfoMapper; |
| | | |
| | | //解析xml文件(传参一个文件) |
| | | public Response getXmlValue(String filePath) { |
| | | File file=new File(filePath); |
| | |
| | | if (file.isFile()) { |
| | | FileInfo fileInfo = XmlFileOpreate.readXml(filePath); |
| | | fileInfo.setFileUrl(filePath); |
| | | fileInfo.setFileId("0"); |
| | | String fileName = filePath.substring(filePath.lastIndexOf("\\")+1); |
| | | fileInfo.setFileName(fileName); |
| | | fileInfo.setFileNameTmp(fileName+" tmp1.~xml"); |
| | |
| | | |
| | | //通过修改属性窗口值来修改文件值 |
| | | public Response updateXmlByFileParam(FileParam fileParam,String filePath) { |
| | | //修改文件对应的数据库数据 |
| | | //paramMapper.updateParamByFileUrl(fileParam,filePath); |
| | | updateParamByFileUrl(fileParam,filePath); |
| | | |
| | | Map<String,String> map=new HashMap<>(); |
| | | Class paramClass=fileParam.getClass(); |
| | | // 获取所有的属性数组 |
| | |
| | | if(map.size()>0){ |
| | | bl=XmlFileOpreate.writeXml(map,filePath); |
| | | } |
| | | |
| | | return new Response().setII(1,bl,map,"修改文件"); |
| | | } |
| | | //修改文件对应的数据库数据 |
| | | public void updateParamByFileUrl(FileParam fileParam,String filePath){ |
| | | //根据文件路径查出file_id |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("file_url",filePath); |
| | | List<FileInfo> list=infoMapper.selectList(wrapper); |
| | | if(list!=null&&list.size()>0){ |
| | | for (FileInfo info:list){ |
| | | //修改参数信息 |
| | | paramMapper.updateParam(fileParam,info.getFileId()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | //通过修改属性窗口值来修改文件值 |
| | | public Response updateXmlByParamMap(Map<String,String> map,String filePath) { |
| | | boolean bl=false; |
| | |
| | | return new Response().setII(1,list.size()>0,list,"返回所有的标称电压类型"); |
| | | } |
| | | //按照筛选条件查询数据库信息 |
| | | public Response getDataByCondition(Date testTime1, Date testTime2, int battVol) { |
| | | List<FileParam> list=mapper.getDataByCondition(testTime1,testTime2,battVol); |
| | | return new Response().setII(1,list.size()>0,list,"筛选数据库信息"); |
| | | public Response getDataByCondition(Date testTime1, Date testTime2, String battVol,int pageCurr,int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | | List<FileParam> list=mapper.getDataByCondition(testTime1,testTime2,Float.valueOf(battVol)); |
| | | QueryWrapper testParamWrapper=new QueryWrapper(); |
| | | testParamWrapper.eq("enabled",1); |
| | | TestParam testParam=testParamMapper.selectOne(testParamWrapper); |
| | | float std=0f; |
| | | if(list!=null&&list.size()>0){ |
| | | for (FileParam fparam:list) { |
| | | List<BattgroupInfo> binfInfoList=fparam.getBattInfoList(); |
| | | std=fparam.getBattRes(); |
| | | if(binfInfoList!=null&&binfInfoList.size()>0){ |
| | | for (BattgroupInfo binfo:binfInfoList) { |
| | | List<BattgroupData> binfDataList=binfo.getBattDataList(); |
| | | float minStd=9999999.0f; |
| | | List listBv=new ArrayList(); |
| | | List listBr=new ArrayList(); |
| | | List listBs=new ArrayList(); |
| | | List listCr=new ArrayList(); |
| | | if(binfDataList!=null&&binfDataList.size()>0) { |
| | | for (BattgroupData bData : binfDataList) { |
| | | listBv.add(Float.valueOf(bData.getBv())); |
| | | listBr.add(Float.valueOf(bData.getBr())); |
| | | listBs.add(Float.valueOf(bData.getBs())); |
| | | listCr.add(Float.valueOf(bData.getCr())); |
| | | if( Float.parseFloat(bData.getBr())<=minStd){ |
| | | minStd= Float.parseFloat(bData.getBr()); |
| | | } |
| | | } |
| | | binfo.setSdBasebv(MathUtil.getStandardDeviation(listBv)); |
| | | binfo.setSdBasebr(MathUtil.getStandardDeviation(listBr)); |
| | | binfo.setSdBasebs(MathUtil.getStandardDeviation(listBs)); |
| | | binfo.setSdBasecr(MathUtil.getStandardDeviation(listCr)); |
| | | binfo.setBrJudge(MathUtil.getJudge(minStd,std,testParam)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"筛选数据库信息"); |
| | | } |
| | | |
| | | |
| | | public FileParam getByFileId(String fileId) { |
| | | QueryWrapper<FileParam> query = Wrappers.query(); |
| | | query.eq("file_id",fileId).last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | //删除基站下数据 |
| | | public Response deleteDataById(int stationId, int fileId) { |
| | | //删除所有文件数据(指定机房id和文件id) |
| | | //dataMapper.deleteDataAndInfo(stationId,fileId); |
| | | deleteDataAndInfo(stationId,fileId); |
| | | //删除所有文件参数 |
| | | paramMapper.deleteParamByFileId(fileId); |
| | | //移除机房下挂在的文件 |
| | | infoMapper.deleteFileInStation(stationId,fileId); |
| | | return new Response().set(1,"删除成功!"); |
| | | } |
| | | //3根据(stationId,fileId)删除groupinfo和groupdata数据 |
| | | public void deleteDataAndInfo(int stationId,int fileId){ |
| | | //先查询出对应的电池组id然后删除 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("station_id",stationId); |
| | | wrapper.eq("file_id",fileId); |
| | | List<BattgroupInfo> list=groupInfoMapper.selectList(wrapper); |
| | | if(list!=null&&list.size()>0){ |
| | | for (BattgroupInfo ginfo:list) { |
| | | UpdateWrapper dataWrapper=new UpdateWrapper(); |
| | | dataWrapper.eq("battGroup_id",ginfo.getBattgroupId()); |
| | | dataMapper.delete(dataWrapper); |
| | | } |
| | | } |
| | | //再删除groupinfo |
| | | UpdateWrapper infoWrapper=new UpdateWrapper(); |
| | | infoWrapper.eq("station_id",stationId); |
| | | infoWrapper.eq("file_id",fileId); |
| | | groupInfoMapper.delete(infoWrapper); |
| | | } |
| | | //根据fileId获取参数信息 |
| | | public Response getParamByFileId(int fileId) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("file_id",fileId); |
| | | wrapper.last("limit 1"); |
| | | FileParam fileParam=mapper.selectOne(wrapper); |
| | | return new Response().setII(1,fileParam!=null,fileParam,"返回数据"); |
| | | } |
| | | } |