| | |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | 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; |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | public Response andOrChangePicture(Integer id, MultipartFile file) throws IOException { |
| | | DeviceSpare spare = mapper.selectById(id); |
| | | //对存储路径进行定义 |
| | | Date now = new Date(); |
| | | String timeFormat = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM_DD_HH_MM_SS_UNION, now); |
| | | String dirMonth = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM, now); |
| | | String fileDirPath = CommonUtil.getRootFile() + "deviceSpare" + File.separator + dirMonth; |
| | | File fileDir = new File(fileDirPath); |
| | | //如果文件夹不存在则创建 |
| | | if (!fileDir.exists()) { |
| | | fileDir.mkdirs(); |
| | | } |
| | | String filePath = fileDirPath + File.separator + spare.getName()+"_"+spare.getModel()+"_"+spare.getVersion() + "_"+ timeFormat+".png"; |
| | | |
| | | // 保存图片到本地 |
| | | file.transferTo(new File(filePath)); |
| | | String split = "pis_file"+File.separator+"deviceSpare"; |
| | | String picUrl = File.separator + filePath.substring(filePath.indexOf(split)); |
| | | //更新图片 |
| | | UpdateWrapper<DeviceSpare> update = Wrappers.update(); |
| | | update.eq("id",id); |
| | | update.set("picture_url",picUrl); |
| | | mapper.update((DeviceSpare) CommonUtil.nullObject,update); |
| | | //记录变更 |
| | | deviceSpareLogService.add(id,2,"更换图片",now); |
| | | return new Response().setII(1,"新增或者替换图片完成"); |
| | | } |
| | | } |