Forráskód Böngészése

修改企业上传接口保存图片的路径

ZhangWenQiang 6 éve
szülő
commit
21b861a63c

+ 14 - 8
happy-boot-module-hppay/src/main/java/org/jeecg/modules/company/service/impl/CompanyAuthenticationServiceImpl.java

@@ -13,7 +13,10 @@ import org.jeecg.modules.hpposition.mapper.PositionMapper;
 import org.jeecg.modules.message.entity.Message;
 import org.jeecg.modules.message.mapper.MessageMapper;
 import org.jeecg.modules.message.service.IMessageService;
+import org.jeecg.modules.user.entity.User;
+import org.jeecg.modules.user.service.IUserService;
 import org.jeecg.modules.util.TokenUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -46,6 +49,8 @@ public class CompanyAuthenticationServiceImpl extends ServiceImpl<CompanyAuthent
     private MessageMapper messageMapper;
     @Resource
     private PositionMapper positionMapper;
+    @Resource
+    private IUserService userService;
 
     @Override
     public Page<CompanyAuthentication> queryPageList1(Page<CompanyAuthentication> page, CompanyAuthentication companyAuthentication) {
@@ -69,6 +74,7 @@ public class CompanyAuthenticationServiceImpl extends ServiceImpl<CompanyAuthent
         String userToken = request.getParameter("user_token");
         //验证用户合法性
         if (TokenUtil.validateToken(userId, userToken)) {
+            User user = userService.getById(userId);
             CompanyAuthentication companyAuthentication = new CompanyAuthentication();
             companyAuthentication.setUserId(Integer.parseInt(userId));
             List<CompanyAuthentication> list = companyAuthenticationMapper.getEnterpriseList(companyAuthentication);
@@ -85,14 +91,14 @@ public class CompanyAuthenticationServiceImpl extends ServiceImpl<CompanyAuthent
             companyAuthentication.setExpiryDate(sdf.parse(expiryDate));
             if (request instanceof MultipartHttpServletRequest) {
                 //营业执照上传调用
-                Result<JSONObject> result = webupload(request, "licenseFront", companyAuthentication, "/hpuser/resume");
+                Result<JSONObject> result = webupload(request, "licenseFront", user, "/hppay/company");
                 if (result.isSuccess()) {
                     companyAuthentication.setLicenseFront(result.getMessage());
                 } else {
                     System.out.println("wpload========" + result.getMessage());
                 }
 
-                Result<JSONObject> result1 = webupload(request, "otherLicense", companyAuthentication, "/hpuser/resume");
+                Result<JSONObject> result1 = webupload(request, "otherLicense", user, "/hppay/company");
                 if (result.isSuccess()) {
                     companyAuthentication.setOtherLicense(result1.getMessage());
                 } else {
@@ -105,11 +111,11 @@ public class CompanyAuthenticationServiceImpl extends ServiceImpl<CompanyAuthent
             companyAuthentication.setCreateTime(new Date());
             companyAuthentication.setUpdateTime(new Date());
             companyAuthentication.setDelFlag("0");
-            if(list.size()>0){
+            if (list.size() > 0) {
                 companyAuthentication.setId(list.get(0).getId());
                 updateById(companyAuthentication);
-                companyAuthentication=getById(companyAuthentication.getId());
-            }else {
+                companyAuthentication = getById(companyAuthentication.getId());
+            } else {
                 companyAuthenticationMapper.saveCompanyInfo(companyAuthentication);
             }
             returnMap.put("companyAuthentication", companyAuthentication);
@@ -125,13 +131,13 @@ public class CompanyAuthenticationServiceImpl extends ServiceImpl<CompanyAuthent
      *
      * @param request
      * @param param
-     * @param companyAuthentication
+     * @param user
      * @param uploadPath
      * @return
      * @throws IllegalStateException
      * @throws IOException
      */
-    public Result<JSONObject> webupload(HttpServletRequest request, String param, CompanyAuthentication companyAuthentication, String uploadPath) throws IllegalStateException, IOException {
+    public Result<JSONObject> webupload(HttpServletRequest request, String param, User user, String uploadPath) throws IllegalStateException, IOException {
         Result<JSONObject> result = new Result<JSONObject>();
         //创建一个通用的多部分解析器.
         CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
@@ -151,7 +157,7 @@ public class CompanyAuthenticationServiceImpl extends ServiceImpl<CompanyAuthent
                 Calendar cal = Calendar.getInstance();
                 int year = cal.get(Calendar.YEAR);
                 int month = cal.get(Calendar.MONTH) + 1;
-                String fileDir = USERFILES_BASE_URL + uploadPath + "/" + companyAuthentication.getId() + "/" + year + "/" + month + "/";
+                String fileDir = USERFILES_BASE_URL + uploadPath + "/" + user.getId() + "/" + year + "/" + month + "/";
                 // 判断文件是否为空
                 if (!file.isEmpty()) {
                     String filePath = ossUtil.uploadImg2OSS(file, fileDir);