whycxzp
2021-10-08 0296f70f903fc22393e216ad124a4819dd09e6bd
更新默认应用布局接口
3个文件已修改
107 ■■■■ 已修改文件
src/main/java/com/whyc/controller/ApplicationController.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ApplicationConfig.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ApplicationService.java 92 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ApplicationController.java
@@ -37,6 +37,10 @@
        return service.getAll(userId);
    }
    /**
     * 如果更新的为默认布局,则复制默认布局为当前用户布局
     * 前端需要传递userId 前端 TODO
     */
    @PutMapping
    @ApiOperation(value = "应用-更新名称")
    public Response update(@RequestBody Application app){
@@ -55,6 +59,9 @@
        return service.updateActive(app);
    }
    /**
     * 针对每个用户的<默认应用布局>这一功能,查询时,如果没有激活的应用,则展示 默认应用布局
     */
    @GetMapping("active")
    @ApiOperation(value = "应用-查询当前激活")
    public Response getActive(@RequestParam Integer userId){
@@ -62,6 +69,11 @@
    }
    /*======应用配置======*/
    /**
     * 前端需要做限制,不允许appId=0的应用进行修改,需要先重命名应用 前端 TODO
     * @param configDTO
     * @return
     */
    @PostMapping("config")
    @ApiOperation(value = "配置-保存当前应用的配置")
    public Response saveConfig(@RequestBody ApplicationConfigDTO configDTO){
src/main/java/com/whyc/pojo/ApplicationConfig.java
@@ -1,5 +1,6 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import org.apache.ibatis.type.Alias;
@@ -12,6 +13,8 @@
@TableName( schema = "`db_app_sys`",value = "`tb_application_config`")
public class ApplicationConfig {
    @TableId
    private Integer num;
    private Integer id;
    /**应用id*/
    private Integer appId;
src/main/java/com/whyc/service/ApplicationService.java
@@ -14,6 +14,7 @@
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ApplicationService {
@@ -38,29 +39,65 @@
    public Response getAll(Integer userId) {
        QueryWrapper<Application> wrapper = Wrappers.query();
        wrapper.eq("user_id",userId);
        /**wrapper.eq("user_id",userId);*/
        //新增默认应用,在查询的时候,添加上默认应用
        wrapper.in("user_id",userId,0);
        List<Application> applications = mapper.selectList(wrapper);
        //如果没有设置为激活的,则将默认应用设置为手动设置为激活,供展示
        boolean noMatchElement = applications.stream().noneMatch(application -> application.getActiveStatus() == 1);
        if(noMatchElement){
            for(Application temp:applications){
                if(temp.getId()==0){
                    temp.setActiveStatus(1);
                    break;
                }
            }
        }
        return new Response<>().set(1,applications);
    }
    @Transactional
    public Response update(Application app) {
        int res = mapper.updateById(app);
        if(res==1){
            return new Response<>().setMsg(1,"更新成功");
        int res = 0;
        if(app.getId()!=0) {
            res = mapper.updateById(app);
        }else{
            return new Response<>().setMsg(0,"更新失败");
            //更新的为默认应用-布局
            //复制默认布局为当前用户布局
            app.setId(null);
            app.setActiveStatus(0);
            int res1 = mapper.insert(app);
            //查询默认布局
            ApplicationConfigDTO allConfig = configMapper.getAllConfig(0);
            List<ApplicationConfig> applicationConfigList = allConfig.getChildren();
            for (ApplicationConfig config:applicationConfigList){
                config.setAppId(app.getId());
            }
            int res2 = configMapper.insertBatchSomeColumn(applicationConfigList);
            if(res1==1 && res2==applicationConfigList.size()){
                res = 1;
            }
        }
        if (res == 1) {
            return new Response<>().setMsg(1, "更新成功");
        } else {
            return new Response<>().setMsg(0, "更新失败");
        }
    }
    public Response delete(Integer appId) {
        //删除应用
        mapper.deleteById(appId);
        //删除应用的模块配置
        UpdateWrapper<ApplicationConfig> updateWrapper = Wrappers.update();
        updateWrapper.eq("app_id",appId);
        configMapper.delete(updateWrapper);
        if(appId!=0) {
            //删除应用
            mapper.deleteById(appId);
            //删除应用的模块配置
            UpdateWrapper<ApplicationConfig> updateWrapper = Wrappers.update();
            updateWrapper.eq("app_id", appId);
            configMapper.delete(updateWrapper);
            return new Response<>().setMsg(1,"删除成功");
        }else{
            return new Response<>().setMsg(0,"无法删除默认大屏展示");
        }
        return new Response<>().setMsg(1,"删除成功");
    }
    public Response updateActive(Application app) {
@@ -68,8 +105,13 @@
        wrapper.set("active_status",0).eq("user_id",app.getUserId()).eq("active_status",1).last("limit 1");
        mapper.update(null,wrapper);
        app.setActiveStatus(1);
        mapper.updateById(app);
        if(app.getId()!=0) {
            app.setActiveStatus(1);
            mapper.updateById(app);
        }else{
            //如果是激活 默认布局,无需操作
        }
        return new Response().setMsg(1,"激活成功");
    }
@@ -78,6 +120,12 @@
        QueryWrapper<Application> wrapper = Wrappers.query();
        wrapper.select("id","name").eq("user_id",userId).eq("active_status",1);
        Application application = mapper.selectOne(wrapper);
        //如果没有激活的应用,则展示 默认应用布局
        if(application==null){
            QueryWrapper<Application> wrapper2 = Wrappers.query();
            wrapper2.select("id","name").eq("id",0);
            application = mapper.selectOne(wrapper2);
        }
        return new Response().set(1,application);
    }
@@ -93,15 +141,19 @@
            mapper.updateById(app);
            //首先删除原有配置,再保存配置
            UpdateWrapper<ApplicationConfig> wrapper = Wrappers.update();
            wrapper.eq("app_id",configDTO.getAppId());
            configMapper.delete(wrapper);
            configMapper.saveConfig(configDTO);
            if (configDTO.getAppId() != 0){
                //首先删除原有配置,再保存配置
                UpdateWrapper<ApplicationConfig> wrapper = Wrappers.update();
                wrapper.eq("app_id", configDTO.getAppId());
                configMapper.delete(wrapper);
                configMapper.saveConfig(configDTO);
                return new Response<>().setMsg(1,"保存成功");
            }else{
                return new Response<>().setMsg(0,"修改默认大屏展示布局前,需先重命名应用名称");
            }
        }catch (Exception e){
            return new Response<>().setMsg(0,"保存失败");
        }
        return new Response<>().setMsg(1,"保存成功");
    }
    /**查询应用和对应的配置模块*/