whycxzp
2021-03-17 1fc5c5b72db71c8c36c7d64950e2795cc8a5b3ac
src/main/java/com/whyc/service/ApplicationService.java
@@ -1,5 +1,6 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -23,33 +24,21 @@
    @Resource
    private ApplicationConfigMapper configMapper;
    @Resource
    private ApplicationConfigPicMapper configPicMapper;
    @Resource
    private UserInfMapper userInfMapper;
    /*======应用管理,admin才有权限更改======*/
    public Response insert(ApplicationDTO app) {
        UserInf userInf = userInfMapper.selectById(app.getUserId());
        if(!userInf.getUName().equals("admin")){
            return new Response<>().setMsg(0,"创建应用需admin权限");
        }
        mapper.insertApp(app.getApplication());
    /*======应用管理======*/
    public Response insert(Application app) {
        mapper.insert(app);
        return new Response<>().set(1,app,"创建成功");
    }
    public Response getAll() {
        List<Application> applications = mapper.selectList(null);
    public Response getAll(Integer userId) {
        QueryWrapper<Application> wrapper = Wrappers.query();
        wrapper.eq("user_id",userId);
        List<Application> applications = mapper.selectList(wrapper);
        return new Response<>().set(1,applications);
    }
    public Response update(ApplicationDTO app) {
        UserInf userInf = userInfMapper.selectById(app.getUserId());
        if(!userInf.getUName().equals("admin")){
            return new Response<>().setMsg(0,"更新应用需admin权限");
        }
        int res = mapper.updateById(app.getApplication());
    public Response update(Application app) {
        int res = mapper.updateById(app);
        if(res==1){
            return new Response<>().setMsg(1,"更新成功");
        }else{
@@ -57,21 +46,13 @@
        }
    }
    public Response delete(ApplicationDTO app) {
        UserInf userInf = userInfMapper.selectById(app.getUserId());
        if(!userInf.getUName().equals("admin")){
            return new Response<>().setMsg(0,"创建应用需admin权限");
        }
    public Response delete(Integer appId) {
        //删除应用
        mapper.deleteById(app.getApplication().getId());
        mapper.deleteById(appId);
        //删除应用的模块配置
        UpdateWrapper<ApplicationConfig> updateWrapper = Wrappers.update();
        updateWrapper.eq("app_id",app.getApplication().getId());
        updateWrapper.eq("app_id",appId);
        configMapper.delete(updateWrapper);
        //删除应用的模块图片
        UpdateWrapper<ApplicationConfigPic> wrapper = Wrappers.update();
        wrapper.eq("app_id",app.getApplication().getId());
        configPicMapper.delete(wrapper);
        return new Response<>().setMsg(1,"删除成功");
    }
@@ -80,18 +61,17 @@
    @Transactional
    public Response saveConfig(ApplicationConfigDTO configDTO) {
        try {
            //保存应用的图片信息,appId+userId为联合主键
            ApplicationConfigPic configPic = new ApplicationConfigPic();
            configPic.setAppId(configDTO.getAppId());
            configPic.setUserId(configDTO.getUserId());
            configPic.setBgPic(configDTO.getBgPic());
            configPic.setHeadPic(configDTO.getHeadPic());
            //保存应用的图片信息
            Application app = new Application();
            app.setId(configDTO.getAppId());
            app.setBgPic(configDTO.getBgPic());
            app.setHeadPic(configDTO.getHeadPic());
            configPicMapper.insertOrUpdate(configPic);
            mapper.updateById(app);
            //首先删除原有配置,再保存配置
            UpdateWrapper<ApplicationConfig> wrapper = Wrappers.update();
            wrapper.eq("app_id",configDTO.getAppId()).eq("user_id",configDTO.getUserId());
            wrapper.eq("app_id",configDTO.getAppId());
            configMapper.delete(wrapper);
            configMapper.saveConfig(configDTO);
        }catch (Exception e){
@@ -101,8 +81,8 @@
    }
    /**查询应用和对应的配置模块*/
    public Response getAllConfig(int appId,int userId) {
        ApplicationConfigDTO applicationConfigDTO = configMapper.getAllConfig(appId,userId);
    public Response getAllConfig(Integer appId) {
        ApplicationConfigDTO applicationConfigDTO = configMapper.getAllConfig(appId);
        return new Response<>().set(1,applicationConfigDTO);
    }