| | |
| | | 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.ApplicationConfigMapper; |
| | | import com.whyc.mapper.ApplicationMapper; |
| | | import com.whyc.pojo.Application; |
| | | import com.whyc.pojo.ApplicationConfig; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.*; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Resource |
| | | private ApplicationConfigMapper configMapper; |
| | | |
| | | public Response insert(Application app) { |
| | | mapper.insertApp(app); |
| | | @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,"创建成功"); |
| | | } |
| | | |
| | |
| | | return new Response<>().set(1,applications); |
| | | } |
| | | |
| | | public Response update(Application app) { |
| | | int res = mapper.updateById(app); |
| | | 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{ |
| | |
| | | } |
| | | } |
| | | |
| | | public Response delete(Application app) { |
| | | 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.getId()); |
| | | mapper.deleteById(app.getApplication().getId()); |
| | | //删除应用的模块配置 |
| | | UpdateWrapper<ApplicationConfig> updateWrapper = Wrappers.update(); |
| | | updateWrapper.eq("app_id",app.getId()); |
| | | 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 { |
| | | //保存应用的图片信息 |
| | | Application app = new Application(); |
| | | app.setId(configDTO.getAppId()); |
| | | app.setBgPic(configDTO.getBgPic()); |
| | | app.setHeadPic(configDTO.getHeadPic()); |
| | | mapper.updateById(app); |
| | | //保存应用的图片信息,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()); |
| | | wrapper.eq("app_id",configDTO.getAppId()).eq("user_id",configDTO.getUserId()); |
| | | configMapper.delete(wrapper); |
| | | configMapper.saveConfig(configDTO); |
| | | }catch (Exception e){ |
| | |
| | | } |
| | | |
| | | /**查询应用和对应的配置模块*/ |
| | | public Response getAllConfig(int appId) { |
| | | ApplicationConfigDTO applicationConfigDTO = configMapper.getAllConfig(appId); |
| | | public Response getAllConfig(int appId,int userId) { |
| | | ApplicationConfigDTO applicationConfigDTO = configMapper.getAllConfig(appId,userId); |
| | | return new Response<>().set(1,applicationConfigDTO); |
| | | } |
| | | |