Browse Source

等级评定下载

licailing 4 years ago
parent
commit
db0395e73f

+ 26 - 9
src/main/java/com/izouma/wenlvju/service/RateService.java

@@ -30,6 +30,8 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.multipdf.PDFMergerUtility;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
@@ -46,16 +48,25 @@ import java.util.stream.Collectors;
 
 @Service
 @Slf4j
-@AllArgsConstructor
+//@AllArgsConstructor
 public class RateService {
 
-    private final RateRepo                rateRepo;
-    private final CollaborateRepo         collaborateRepo;
-    private final GradingOrganizationRepo gradingOrganizationRepo;
-    private final RateAuditRepo           rateAuditRepo;
-    private final UserRepo                userRepo;
-    private final NjwlSmsService          njwlSmsService;
-    private final OrganizationRepo        organizationRepo;
+    @Autowired
+    private RateRepo                rateRepo;
+    @Autowired
+    private CollaborateRepo         collaborateRepo;
+    @Autowired
+    private GradingOrganizationRepo gradingOrganizationRepo;
+    @Autowired
+    private RateAuditRepo           rateAuditRepo;
+    @Autowired
+    private UserRepo                userRepo;
+    @Autowired
+    private NjwlSmsService          njwlSmsService;
+    @Autowired
+    private OrganizationRepo        organizationRepo;
+    @Value("${storage.local_path}")
+    private String                  localPath;
 
     public Page<Rate> all(PageQuery pageQuery) {
         return rateRepo.findAll(JpaUtils.toSpecification(pageQuery, Rate.class), JpaUtils.toPageRequest(pageQuery));
@@ -524,7 +535,10 @@ public class RateService {
         response.addHeader("Content-Disposition", "attachment;filename=" + "result.pdf");
 
         String pdfUrl = rate.getPdfUrl();
-        File file = new File(pdfUrl);
+
+        int start = pdfUrl.indexOf("/pdf");
+        String end = pdfUrl.substring(start + 1);
+        File file = new File(localPath + end);
 
         // 以流的形式下载文件。
         InputStream fis = new BufferedInputStream(new FileInputStream(file));
@@ -532,6 +546,9 @@ public class RateService {
 
         fis.read(buffer);
         fis.close();
+
+        //删除文件
+        FileUtils.delFiles(file);
         return buffer;
 
 //        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());

+ 25 - 0
src/main/java/com/izouma/wenlvju/service/UserService.java

@@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.izouma.wenlvju.config.Constants;
 import com.izouma.wenlvju.domain.*;
 import com.izouma.wenlvju.domain.performance.Participant;
@@ -365,4 +366,28 @@ public class UserService {
         map.put("token", token);
         return map;
     }
+
+    public String byPhone(String account) {
+        User user = userRepo.findByUsernameAndDelFalse(account);
+        if (ObjectUtil.isNotNull(user)) {
+            return account;
+        }
+        User byPhone = userRepo.findByPhoneAndDelFalse(account);
+        if (ObjectUtil.isNotNull(byPhone)) {
+            return byPhone.getUsername();
+        }
+        return null;
+    }
+
+    public void forgetPassword(String name, String phone, String password) {
+        User user = userRepo.findByPhoneAndDelFalse(phone);
+        if (ObjectUtil.isNull(user)) {
+            throw new BusinessException("此手机号并未注册!");
+        }
+        if (StrUtil.isEmpty(name) || !user.getWork().contains(name.trim())) {
+            throw new BusinessException("企业名称不正确");
+        }
+        user.setPassword(new BCryptPasswordEncoder().encode(password));
+        userRepo.save(user);
+    }
 }

+ 8 - 1
src/main/java/com/izouma/wenlvju/web/AuthenticationController.java

@@ -19,6 +19,7 @@ import org.springframework.security.core.Authentication;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Map;
@@ -35,7 +36,8 @@ public class AuthenticationController {
 
     @PostMapping("/login")
     public String loginByUserPwd(String username, String password, Integer expiration) {
-        Authentication authentication = authenticate(username, password);
+        String account = userService.byPhone(username);
+        Authentication authentication = authenticate(account, password);
         JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
         return jwtTokenUtil.generateToken(jwtUser);
 
@@ -106,4 +108,9 @@ public class AuthenticationController {
             throw new AuthenticationException("用户名或密码错误", e);
         }
     }
+
+    @PostMapping("/forgetPW")
+    public void forgetPassword(@RequestParam String name, @RequestParam String phone, @RequestParam String password) {
+        userService.forgetPassword(name, phone, password);
+    }
 }

+ 7 - 0
src/test/java/com/izouma/wenlvju/repo/RepoTest.java

@@ -213,4 +213,11 @@ public class RepoTest extends ApplicationTests {
         int sum2 = Math.round(75 * 80 / 100);
         System.out.println(sum1 + sum2);
     }
+
+    @Test
+    public void test7(){
+        String url = "http://yskj.njlyw.cn:8081/files/pdf/material12409.pdf";
+        int start = url.indexOf("/pdf");
+        System.out.println(url.substring(start));
+    }
 }