| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class ApplicationService { |
| | |
| | | |
| | | 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) { |
| | |
| | | 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,"激活成功"); |
| | | } |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | |
| | | 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,"保存成功"); |
| | | } |
| | | |
| | | /**查询应用和对应的配置模块*/ |