package com.whyc.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.whyc.dto.Response; import com.whyc.mapper.PwrdevAlarmParamStandMapper; import com.whyc.pojo.db_pwrdev_alarm.PwrdevAlarmParamStand; import com.whyc.util.ActionUtil; import com.whyc.util.DateUtil; import com.whyc.util.FileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.Date; import java.util.List; @Service public class PwrdevAlarmParamStandService { @Autowired(required = false) private PwrdevAlarmParamStandMapper mapper; //查询标准参数 public Response getPwrStandParam(Integer powerType) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("power_type",powerType); queryWrapper.orderByAsc("num"); List list=mapper.selectList(queryWrapper); return new Response().setII(1,list!=null,list,"查询标准参数"); } //查询规范文件 public Response getStandFile(Integer powerType, String fileName) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.select("file_name","stand_file_path"); queryWrapper.eq("power_type",powerType); queryWrapper.like("file_name",fileName); List list=mapper.selectList(queryWrapper); return new Response().setII(1,list!=null,list,"查询规范文件"); } //设置标准参数 public Response setPwrStandParam(PwrdevAlarmParamStand stand) { UpdateWrapper wrapper=new UpdateWrapper(); if(stand.getAlarmLimith()!=null){ wrapper.set("alarm_limith",stand.getAlarmLimith()); } if(stand.getAlarmLimitl()!=null){ wrapper.set("alarm_limitl",stand.getAlarmLimitl()); } if(stand.getAlarmLimithUpeper()!=null){ wrapper.set("alarm_limith_upeper",stand.getAlarmLimithUpeper()); } if(stand.getAlarmLimitlLower()!=null){ wrapper.set("alarm_limitl_lower",stand.getAlarmLimitlLower()); } if(stand.getBasisVal()!=null){ wrapper.set("basis_val",stand.getBasisVal()); } wrapper.eq("num",stand.getNum()); int flag=mapper.update((PwrdevAlarmParamStand) ActionUtil.objeNull,wrapper); return new Response().set(1,flag>0,flag>0?"设置成功":"设置失败"); } //上传规范文件 public Response uploadStandFile(MultipartFile multipartFile, String num) throws IOException { Date now = new Date(); String originalFilename = multipartFile.getOriginalFilename(); String[] fileNameSplit = originalFilename.split("\\."); String dateFormat = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(now); String newFileName = fileNameSplit[0]+"_"+dateFormat+"."+fileNameSplit[1]; String fileUrlTemp = FileUtil.saveFile(multipartFile,"/stand/"+newFileName); UpdateWrapper wrapper=new UpdateWrapper(); wrapper.set("stand_file_path",fileUrlTemp); wrapper.set("file_name",newFileName); wrapper.eq("num",num); int flag=mapper.update((PwrdevAlarmParamStand) ActionUtil.objeNull,wrapper); return new Response().set(1,flag>0,flag>0?"上传成功":"上传失败"); } //添加标准参数 public Response addPwrStandParam(PwrdevAlarmParamStand stand) { int flag=mapper.insert(stand); return new Response().set(1,flag>0,flag>0?"添加成功":"添加失败"); } }