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

bugfix: add exception result

caiaa 1 éve
szülő
commit
d8ddac3296

+ 9 - 11
src/main/java/com/dragon/tj/portal/controller/AppController.java

@@ -12,7 +12,6 @@ import com.dragon.tj.portal.service.AppService;
 import com.dragon.tj.portal.service.InstallInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -38,7 +37,7 @@ public class AppController {
     @PostMapping("list")
     public R appList(@RequestBody PageParam<AppInfo> appInfoPage) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        return R.ok(appService.installApp(appInfoPage,loginUser));
+        return R.ok(appService.installApp(appInfoPage, loginUser));
     }
 
     /*
@@ -48,7 +47,7 @@ public class AppController {
     @GetMapping("install/{appId}")
     public R install(@PathVariable("appId") Integer appId) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        return R.ok(appService.install(appId,loginUser.getIdCard()));
+        return R.ok(appService.install(appId, loginUser.getIdCard()));
     }
 
     /*
@@ -58,7 +57,7 @@ public class AppController {
     @GetMapping("uninstall/{appId}")
     public R uninstall(@PathVariable("appId") Integer appId) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        return R.ok(appService.uninstall(appId,loginUser.getIdCard()));
+        return R.ok(appService.uninstall(appId, loginUser.getIdCard()));
     }
 
     /***************************************/
@@ -101,7 +100,7 @@ public class AppController {
     @SysLog(value = "批量更新收藏", module = ModuleEnum.APP_UPDATE)
     @PostMapping("batchUpdate")
     public R batchUpdate(@RequestBody List<InstallInfo> list) {
-        installInfoService.batchUpdate(list,0);
+        installInfoService.batchUpdate(list, 0);
         return R.ok();
     }
 
@@ -125,8 +124,8 @@ public class AppController {
     @SysLog(value = "批量添加应用", module = ModuleEnum.APP_ADD)
     @PostMapping("batchAdd")
     public R batchAdd(MultipartFile file) {
-
-        return R.ok(appService.batchAdd(file));
+        boolean result = appService.batchAdd(file);
+        return result ? R.ok() : R.failed();
     }
 
 
@@ -144,7 +143,7 @@ public class AppController {
      *    4. 热门应用统计 定时、实时?
      * */
     // @Scheduled(fixedDelay = 1000 * 60 * 60)
-    public void appStatHandler(){
+    public void appStatHandler() {
 
         appService.updateAppStat();
     }
@@ -155,9 +154,8 @@ public class AppController {
     /**********************/
 
     /*
-    * 上传图片
-    * */
-
+     * 上传图片
+     * */
 
 
 }

+ 8 - 9
src/main/java/com/dragon/tj/portal/controller/BusinessController.java

@@ -12,7 +12,6 @@ import com.dragon.tj.portal.service.BusinessService;
 import com.dragon.tj.portal.service.InstallInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -38,7 +37,7 @@ public class BusinessController {
     @PostMapping("list")
     public R appList(@RequestBody PageParam<BusinessInfo> businessPage) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        return R.ok(businessService.installApp(businessPage,loginUser));
+        return R.ok(businessService.installApp(businessPage, loginUser));
     }
 
     /*
@@ -51,7 +50,7 @@ public class BusinessController {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         int install = businessService.install(appId, businessId, loginUser.getIdCard());
 
-        if (install == 0){
+        if (install == 0) {
 
             return R.failed("安装失败!!!");
         }
@@ -66,7 +65,7 @@ public class BusinessController {
     public R uninstall(@PathVariable("appId") Integer appId,
                        @PathVariable("businessId") Integer businessId) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        return R.ok(businessService.uninstall(appId,businessId,loginUser.getIdCard()));
+        return R.ok(businessService.uninstall(appId, businessId, loginUser.getIdCard()));
     }
 
     /***************************************/
@@ -87,7 +86,7 @@ public class BusinessController {
     public R addApp(@RequestBody BusinessInfo businessInfo) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         int b = businessService.add(businessInfo, loginUser);
-        if (b == 0){
+        if (b == 0) {
             return R.failed("添加失败!!!");
         }
 
@@ -98,8 +97,8 @@ public class BusinessController {
     @SysLog(value = "批量添加业务", module = ModuleEnum.BUSINESS_ADD)
     @PostMapping("batchAdd")
     public R batchAdd(MultipartFile file) {
-
-        return R.ok(businessService.batchAdd(file));
+        boolean result = businessService.batchAdd(file);
+        return result ? R.ok() : R.failed();
     }
 
 
@@ -124,7 +123,7 @@ public class BusinessController {
     @SysLog(value = "批量更新收藏业务", module = ModuleEnum.BUSINESS_UPDATE)
     @PostMapping("batchUpdate")
     public R batchUpdate(@RequestBody List<InstallInfo> list) {
-        installInfoService.batchUpdate(list,1);
+        installInfoService.batchUpdate(list, 1);
         return R.ok();
     }
 
@@ -159,7 +158,7 @@ public class BusinessController {
      *    4. 热门应用统计 定时、实时?
      * */
     // @Scheduled(fixedDelay = 1000 * 60 * 60)
-    public void appStatHandler(){
+    public void appStatHandler() {
 
         businessService.updateAppStat();
     }

+ 28 - 21
src/main/java/com/dragon/tj/portal/service/impl/AppServiceImpl.java

@@ -10,19 +10,26 @@ import com.dc.eventpoi.ExcelHelper;
 import com.dragon.tj.portal.auth.model.LoginUser;
 import com.dragon.tj.portal.auth.util.SecurityUtils;
 import com.dragon.tj.portal.common.base.R;
-import com.dragon.tj.portal.entity.*;
+import com.dragon.tj.portal.entity.AppInfo;
+import com.dragon.tj.portal.entity.InstallInfo;
+import com.dragon.tj.portal.entity.PageParam;
+import com.dragon.tj.portal.entity.SysDictItem;
 import com.dragon.tj.portal.mapper.app.AppInfoMapper;
 import com.dragon.tj.portal.mapper.app.InstallInfoMapper;
 import com.dragon.tj.portal.service.AppService;
 import com.dragon.tj.portal.service.FileManageService;
 import com.dragon.tj.portal.service.SysDictItemService;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
@@ -30,7 +37,7 @@ import java.util.Map;
 
 @Service
 public class AppServiceImpl implements AppService {
-
+    private static final Logger LOGGER = LoggerFactory.getLogger(AppServiceImpl.class);
 
     @Autowired
     private AppInfoMapper appInfoMapper;
@@ -46,7 +53,7 @@ public class AppServiceImpl implements AppService {
 
     private static List<SysDictItem> appTypeDict;
 
-    public List<SysDictItem> getAppTypeDict(){
+    public List<SysDictItem> getAppTypeDict() {
         if (appTypeDict == null || appTypeDict.size() == 0) {
             appTypeDict = sysDictItemService.list(Wrappers.<SysDictItem>query().lambda().eq(SysDictItem::getType, "app_type").orderByAsc(SysDictItem::getSort));
         }
@@ -107,8 +114,8 @@ public class AppServiceImpl implements AppService {
         //应用事权单位名称
         queryWrapper.like(StringUtils.isNotEmpty(appInfo.getDeptName()), AppInfo::getDeptName, appInfo.getDeptName());
         //应用类型
-        queryWrapper.eq(appInfo.getAppType() != null,AppInfo::getAppType, appInfo.getAppType());
-        queryWrapper.eq(appInfo.getDelFlag() != null,AppInfo::getDelFlag, appInfo.getDelFlag());
+        queryWrapper.eq(appInfo.getAppType() != null, AppInfo::getAppType, appInfo.getAppType());
+        queryWrapper.eq(appInfo.getDelFlag() != null, AppInfo::getDelFlag, appInfo.getDelFlag());
 
         rowPage.addOrder(OrderItem.desc(appInfoPage.getOrder()));
 
@@ -169,31 +176,31 @@ public class AppServiceImpl implements AppService {
 
         map.put("delFlag", params.getDelFlag());
         Integer appType = params.getAppType();
-        if (appType != null){
+        if (appType != null) {
             List<SysDictItem> appTypeList = getAppTypeDict();
-            SysDictItem  specialToolDict = appTypeList.stream().filter(item -> "专项工具".equals(item.getLabel())).findFirst().get();
+            SysDictItem specialToolDict = appTypeList.stream().filter(item -> "专项工具".equals(item.getLabel())).findFirst().get();
             map.put("std", specialToolDict.getId());//专项工具
 
-            if (specialToolDict.getId().compareTo(appType) == 0){
+            if (specialToolDict.getId().compareTo(appType) == 0) {
                 map.put("isSt", 1);//专项工具查询
             }
         }
 
         map.put("idcard", loginUser.getIdCard());
 
-        return appInfoMapper.getInstalledApp(iPage,map);
+        return appInfoMapper.getInstalledApp(iPage, map);
 
     }
 
     /*
-    *  应用统计
-    * */
+     *  应用统计
+     * */
     @Override
     public void updateAppStat() {
         //获取app安装次数
-        List<Map<String,Long>> apps = installInfoMapper.getAppInstallCount();
+        List<Map<String, Long>> apps = installInfoMapper.getAppInstallCount();
         //更新star
-        apps.forEach(app ->{
+        apps.forEach(app -> {
             AppInfo appInfo = new AppInfo();
             appInfo.setId(app.get("appId"));
             appInfo.setStar(app.get("count"));
@@ -205,7 +212,7 @@ public class AppServiceImpl implements AppService {
     @Override
     public int clickIncr(Long id) {
         QueryWrapper<AppInfo> wrapper = new QueryWrapper<>();
-        wrapper.eq("id",id);
+        wrapper.eq("id", id);
         AppInfo appInfo = appInfoMapper.selectOne(wrapper);
         appInfo.setId(id);
         appInfo.setHits(appInfo.getHits() + 1);
@@ -228,7 +235,7 @@ public class AppServiceImpl implements AppService {
             List<AppInfo> appInfos = ExcelHelper.parseExcelToObject(
                     new BufferedInputStream(tempFis),
                     inputStream,
-                    AppInfo.class,true);
+                    AppInfo.class, true);
 
             appInfos.forEach(appInfo -> {
                 AppInfo appInfo1 = parseAppInfo(appInfo);
@@ -236,9 +243,10 @@ public class AppServiceImpl implements AppService {
             });
 
         } catch (Exception e) {
-            e.printStackTrace();
+            LOGGER.error("上传出错", e);
+            return false;
         } finally {
-            if (inputStream != null){
+            if (inputStream != null) {
                 try {
                     inputStream.close();
                 } catch (IOException e) {
@@ -246,7 +254,6 @@ public class AppServiceImpl implements AppService {
                 }
             }
         }
-
         return true;
     }
 
@@ -261,11 +268,11 @@ public class AppServiceImpl implements AppService {
         appInfo.setAppType(sysDictItem.getId());
 
         //在用标识转换
-        appInfo.setActiveFlag("在用".equals(appInfo.getActiveName()) ? 1:0);
+        appInfo.setActiveFlag("在用".equals(appInfo.getActiveName()) ? 1 : 0);
 
         //图标处理
         byte[] iconImageByte = appInfo.getImage();
-        if (iconImageByte.length > 0){
+        if (iconImageByte.length > 0) {
 
             appInfo.setIcon(fileManageService.upload(
                     iconImageByte,

+ 5 - 2
src/main/java/com/dragon/tj/portal/service/impl/BusinessServiceImpl.java

@@ -16,6 +16,8 @@ import com.dragon.tj.portal.mapper.app.AppInfoMapper;
 import com.dragon.tj.portal.mapper.app.InstallInfoMapper;
 import com.dragon.tj.portal.service.*;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
@@ -29,7 +31,7 @@ import java.util.Map;
 
 @Service
 public class BusinessServiceImpl implements BusinessService {
-
+    private static final Logger LOGGER = LoggerFactory.getLogger(BusinessServiceImpl.class);
 
     @Autowired
     private BusinessMapper businessMapper;
@@ -259,7 +261,8 @@ public class BusinessServiceImpl implements BusinessService {
             });
 
         } catch (Exception e) {
-            e.printStackTrace();
+            LOGGER.error("上传出错", e);
+            return false;
         } finally {
             if (inputStream != null){
                 try {