whycxzp
2021-03-13 dbd5cf4f85c99c7c2189905d4972e42d0b2cbbe1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
import com.whyc.dto.ApplicationConfigDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.ApplicationConfigMapper;
import com.whyc.mapper.ApplicationMapper;
import com.whyc.pojo.Application;
import com.whyc.pojo.ApplicationConfig;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class ApplicationService {
 
    @Resource
    private ApplicationMapper mapper;
 
    @Resource
    private ApplicationConfigMapper configMapper;
 
    public Response insert(Application app) {
        mapper.insertApp(app);
        return new Response<>().set(1,app,"创建成功");
    }
 
    public Response getAll() {
        List<Application> applications = mapper.selectList(null);
        return new Response<>().set(1,applications);
    }
 
    public Response update(Application app) {
        int res = mapper.updateById(app);
        if(res==1){
            return new Response<>().setMsg(1,"更新成功");
        }else{
            return new Response<>().setMsg(0,"更新失败");
        }
    }
 
    public Response delete(Application app) {
        //删除应用
        mapper.deleteById(app.getId());
        //删除应用的模块配置
        UpdateWrapper<ApplicationConfig> updateWrapper = Wrappers.update();
        updateWrapper.eq("app_id",app.getId());
        configMapper.delete(updateWrapper);
        return new Response<>().setMsg(1,"删除成功");
    }
 
    /*======应用配置======*/
 
    public Response saveConfig(ApplicationConfigDTO configDTO) {
        try {
            //保存应用的图片信息
            Application app = new Application();
            app.setId(configDTO.getAppId());
            app.setBgPic(configDTO.getBgPic());
            app.setHeadPic(configDTO.getHeadPic());
            mapper.updateById(app);
 
            //保存应用的配置
            configMapper.saveConfig(configDTO);
        }catch (Exception e){
            return new Response<>().setMsg(0,"保存失败");
        }
        return new Response<>().setCode(1);
    }
 
    /**查询应用和对应的配置模块*/
    public Response getAllConfig(int appId) {
        ApplicationConfigDTO applicationConfigDTO = configMapper.getAllConfig(appId);
        return new Response<>().set(1,applicationConfigDTO);
    }
 
}