| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.whyc.mapper.DevUpdateStateMapper; |
| | | import com.whyc.pojo.DevUpdateState; |
| | | import com.whyc.pojo.Response; |
| | | import com.whyc.util.FileDirPath; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | |
| | | import static com.whyc.util.ActionUtil.createFilefolderIFNotExist; |
| | | |
| | | @Service |
| | | public class DevUpdateStateService { |
| | | @Autowired(required = false) |
| | | private DevUpdateStateMapper mapper; |
| | | //检测是否存在重新上传的人脸 |
| | | public boolean updateDfu(MultipartFile file,int devId){ |
| | | boolean bl=false; |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String root=fileDirName+ File.separator+"FDFiles"+File.separator+devId+File.separator+"update"; |
| | | String fileFileName = file.getOriginalFilename(); |
| | | String filePath = root + fileFileName; |
| | | createFilefolderIFNotExist(filePath); |
| | | try { |
| | | file.transferTo(new File(filePath)); |
| | | bl=true; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return bl; |
| | | |
| | | } |
| | | //远程升级 |
| | | public Response updateDfu(MultipartFile file, DevUpdateState dfu) { |
| | | if(file==null){ |
| | | return new Response().set(1,false,"文件失败,文件不存在"); |
| | | } |
| | | String fileFileName = file.getOriginalFilename(); |
| | | boolean bl=updateDfu(file,dfu.getDevId()); |
| | | if(bl){ |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("dfu_file",fileFileName); |
| | | wrapper.set("dfu_en",1); |
| | | wrapper.set("dfu_wr_stat",dfu.getDfuWrStat()); |
| | | wrapper.set("dfu_data_blocknum",dfu.getDfuDataBlocknum()); |
| | | wrapper.eq("dev_id",dfu.getDevId()); |
| | | mapper.update(null,wrapper); |
| | | return new Response().set(1,bl,"升级文件上传成功"); |
| | | }else { |
| | | return new Response().set(1,bl,"升级文件上传失败"); |
| | | } |
| | | |
| | | } |
| | | //远程升级停止 |
| | | public Response stopDfu(int devId) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("dfu_en",3); |
| | | wrapper.eq("dev_id",devId); |
| | | mapper.update(null,wrapper); |
| | | return new Response().set(1,true); |
| | | } |
| | | } |