package com.whyc.service;
|
|
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.ApplicationDTO;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.*;
|
import com.whyc.pojo.*;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Service
|
public class ApplicationService {
|
|
@Resource
|
private ApplicationMapper mapper;
|
|
@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());
|
return new Response<>().set(1,app,"创建成功");
|
}
|
|
public Response getAll() {
|
List<Application> applications = mapper.selectList(null);
|
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());
|
if(res==1){
|
return new Response<>().setMsg(1,"更新成功");
|
}else{
|
return new Response<>().setMsg(0,"更新失败");
|
}
|
}
|
|
public Response delete(ApplicationDTO app) {
|
UserInf userInf = userInfMapper.selectById(app.getUserId());
|
if(!userInf.getUName().equals("admin")){
|
return new Response<>().setMsg(0,"创建应用需admin权限");
|
}
|
//删除应用
|
mapper.deleteById(app.getApplication().getId());
|
//删除应用的模块配置
|
UpdateWrapper<ApplicationConfig> updateWrapper = Wrappers.update();
|
updateWrapper.eq("app_id",app.getApplication().getId());
|
configMapper.delete(updateWrapper);
|
//删除应用的模块图片
|
UpdateWrapper<ApplicationConfigPic> wrapper = Wrappers.update();
|
wrapper.eq("app_id",app.getApplication().getId());
|
configPicMapper.delete(wrapper);
|
|
return new Response<>().setMsg(1,"删除成功");
|
}
|
|
/*======应用配置======*/
|
@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());
|
|
configPicMapper.insertOrUpdate(configPic);
|
|
//首先删除原有配置,再保存配置
|
UpdateWrapper<ApplicationConfig> wrapper = Wrappers.update();
|
wrapper.eq("app_id",configDTO.getAppId()).eq("user_id",configDTO.getUserId());
|
configMapper.delete(wrapper);
|
configMapper.saveConfig(configDTO);
|
}catch (Exception e){
|
return new Response<>().setMsg(0,"保存失败");
|
}
|
return new Response<>().setMsg(1,"保存成功");
|
}
|
|
/**查询应用和对应的配置模块*/
|
public Response getAllConfig(int appId,int userId) {
|
ApplicationConfigDTO applicationConfigDTO = configMapper.getAllConfig(appId,userId);
|
return new Response<>().set(1,applicationConfigDTO);
|
}
|
|
}
|