| | |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.FileUtils; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | |
| | | * @since 2022-01-12 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class SupervisionServiceImpl extends ServiceImpl<SupervisionMapper, Supervision> implements SupervisionService { |
| | | |
| | | @Autowired |
| | |
| | | @Override |
| | | public Map<String, Object> add(MultipartFile[] files, Supervision supervision) { |
| | | //获取jar包所在目录 |
| | | ApplicationHome h = new ApplicationHome(getClass()); |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 |
| | | String path = h.getSource().getParentFile().toString() + "/static/img/"; |
| | | String path = applicationHome.getSource().getParentFile().toString() + "/static/img"; |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | |
| | | @Override |
| | | public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) { |
| | | |
| | | String path = this.getClass().getClassLoader() |
| | | .getResource("").getFile() + "static/img/"; |
| | | //获取jar包所在目录 |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 |
| | | String path = applicationHome.getSource().getParentFile().toString() + "/static/img"; |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | |
| | |
| | | supervisionMapper.updateById(supervision); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteSupervision(Integer supervisionId) { |
| | | QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("id", "images").eq("id", supervisionId); |
| | | Supervision supervision = supervisionMapper.selectOne(queryWrapper); |
| | | String[] images = supervision.getImages().split(","); |
| | | |
| | | //逻辑删除 |
| | | supervision.setIsDelete(Constants.DELETE); |
| | | supervision.setImages(null); |
| | | supervisionMapper.updateById(supervision); |
| | | |
| | | |
| | | //删除服务器中的督办单中图片 |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | String path = applicationHome.getSource().getParentFile().toString() + "/static/img"; |
| | | for (String image : images) { |
| | | String realPath = path + File.separator + image; |
| | | File file = new File(realPath); |
| | | if (file.exists() && file.isFile()) { |
| | | file.delete(); |
| | | } |
| | | } |
| | | } |
| | | } |