package com.thhy.pm.modules.biz.technology.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.thhy.general.common.BasicResult; import com.thhy.general.config.SysUserInfo; import com.thhy.general.utils.UserInfoUtils; import com.thhy.pm.modules.biz.file.service.FileService; import com.thhy.pm.modules.biz.technology.entity.TchFile; import com.thhy.pm.modules.biz.technology.entity.TchFiles; import com.thhy.pm.modules.biz.technology.entity.TchFilesListVo; import com.thhy.pm.modules.biz.technology.mapper.TchFileMapper; import com.thhy.pm.modules.biz.technology.mapper.TchFilesMapper; import com.thhy.pm.modules.biz.technology.service.TchFileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.Serializable; import java.util.Date; import java.util.List; /** * 服务实现类 * @author zhang_xiao_bo * @since 2023-04-25 13:06:53 */ @Service public class TchFileServiceImpl implements TchFileService { @Autowired private TchFileMapper tchFileMapper; @Autowired private TchFilesMapper filesMapper; @Autowired private FileService fileService; public TchFile get(Serializable id){ return tchFileMapper.queryById(id); } public List findList(TchFile tchFile){ return tchFileMapper.findList(tchFile); } @Override public List fileList(TchFiles tchFiles) { List filesListVos = filesMapper.findList(tchFiles); filesListVos.forEach(tf->{ JSONObject json = new JSONObject(); json.put("fullpath",tf.getTchFile()); BasicResult basicResult = fileService.fileinfo(json.toJSONString()); if(basicResult.isSuccess()){ JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString()); for(Object obj : jsonArray){ JSONObject j = JSON.parseObject(obj.toString()); if(j.containsKey("name")&&"name".equals(j.getString("name"))){ tf.setTchFileName(j.getString("value")); } } } }); return filesListVos; } /** * 增加和修改 * @param tchFile */ @Transactional public void addTchFile(TchFile tchFile){ SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo(); List tchFilesList = tchFile.getTchFilesList(); if(tchFile.getTchFileId() == null){ //增加操作 tchFile.setCreateUser(userInfo.getUserId()); tchFileMapper.insert(tchFile); }else{ //修改操作 tchFile.setUpdateUser(userInfo.getUserId()); tchFile.setUpdateTime(new Date()); tchFileMapper.update(tchFile); filesMapper.deleteByTchId(tchFile.getTchFileId()); } for(TchFiles tchFiles : tchFilesList){ tchFiles.setTchId(tchFile.getTchFileId()); filesMapper.insert(tchFiles); } } /** * 修改 * @param tchFile */ public void update(TchFile tchFile){ tchFileMapper.update(tchFile); } /** * 删除 * @param tchFileId */ public void delete(Serializable tchFileId){ tchFileMapper.deletelogic(tchFileId); } }