| | |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.service.data.DirService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | |
| | | */ |
| | | @Service |
| | | public class BaseUploadService { |
| | | @Autowired |
| | | @Resource |
| | | protected DirService dirService; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | protected PathHelper pathHelper; |
| | | |
| | | @Resource |
| | | protected TokenService tokenService; |
| | | |
| | | public final Log log = LogFactory.getLog(getClass()); |
| | | |
| | |
| | | if (StringHelper.isEmpty(code)) { |
| | | DirEntity baseDir = findBaseDirByPath(dirs, filePath); |
| | | if (null != baseDir) { |
| | | createDirByPath(baseDir, mfe.getPath()); |
| | | createDirByPath(baseDir, mfe.getPath().replace("/", "\\")); |
| | | dirs = dirService.selectRecursiveById(dir.getId()); |
| | | code = findDirByPath(dirs, filePath, fileName); |
| | | } |
| | |
| | | * 根据路径创建目录 |
| | | */ |
| | | private void createDirByPath(DirEntity baseDir, String filePath) { |
| | | int start = filePath.toLowerCase().indexOf(baseDir.getFullName().toLowerCase() + "\\") + baseDir.getFullName().length() + 1; |
| | | int end = filePath.lastIndexOf("\\"); |
| | | if (end <= start) { |
| | | return; |
| | | } |
| | | if (0 == baseDir.getLevel()) { |
| | | baseDir.setLevel(2); |
| | | } |
| | | |
| | | HttpServletRequest req = WebHelper.getRequest(); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | |
| | | String[] strs = filePath.substring(start, end).split("\\\\"); |
| | | for (String str : strs) { |
| | | DirEntity entity = dirService.selectDirByName(str, baseDir.getId()); |
| | | if (null == entity) { |
| | | entity = new DirEntity(); |
| | | entity.setPid(baseDir.getId()); |
| | | entity.setName(str); |
| | | entity.setOrderNum(dirService.selectMaxOrderNum()); |
| | | entity.setLevel(baseDir.getLevel() + 1); |
| | | entity.setCreateUser(ue.getId()); |
| | | |
| | | dirService.insert(entity); |
| | | baseDir = dirService.selectDir(entity.getId()); |
| | | } else { |
| | | baseDir = entity; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |