feat: 新增移动端接口

This commit is contained in:
fit2cloud-chenyw 2021-12-03 18:23:28 +08:00
parent 7747d9ed55
commit 75cd6ec371
6 changed files with 167 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package io.dataease.base.mapper.ext;
import io.dataease.mobile.dto.HomeItemDTO;
import java.util.List;
import java.util.Map;
public interface HomeMapper {
List<HomeItemDTO> queryStore(Long userId);
List<HomeItemDTO> queryHistory();
List<HomeItemDTO> queryShare(Map<String, Object> param);
}

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.dataease.base.mapper.ext.HomeMapper">
<select id="queryStore" resultType="io.dataease.mobile.dto.HomeItemDTO">
select
s.panel_group_id as id,
g.name as title,
s.create_time as `time`
from panel_store s
inner join panel_group g
on s.panel_group_id = g.id
where s.user_id = #{userId}
order by s.create_time desc
</select>
<select id="queryShare" resultType="io.dataease.mobile.dto.HomeItemDTO">
select
distinct(s.panel_group_id) as id,
g.name as title,
s.create_time as `time`
from panel_share s
inner join panel_group g
on s.panel_group_id = g.id
where
( s.target_id = #{userId} and s.type = 0 ) or
( s.target_id = #{deptId} and s.type = 2 ) or
( s.target_id in
<foreach collection="roleIds" item="roleId" open='(' separator=',' close=')'>
#{roleId}
</foreach>
and s.type = 1 )
order by s.create_time desc
</select>
</mapper>

View File

@ -0,0 +1,26 @@
package io.dataease.mobile.api;
import io.dataease.mobile.dto.HomeItemDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Api(tags = "移动端:首页")
@RequestMapping("/mobile/home")
public interface HomeApi {
@ApiOperation("查询")
@ApiImplicitParam(value = "类型", name = "type", paramType = "path", allowableValues = "{@code 0(收藏), 1(历史), 2(分享)}")
@PostMapping("/query/{type}")
List<HomeItemDTO> query(@PathVariable Integer type);
@ApiOperation("详情")
@ApiImplicitParam(value = "ID", name = "id", paramType = "path")
@PostMapping("/detail/{id}")
Object detail(@PathVariable String id);
}

View File

@ -0,0 +1,18 @@
package io.dataease.mobile.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
@ApiModel("首页数据实体")
public class HomeItemDTO implements Serializable {
@ApiModelProperty("ID")
private String id;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("时间")
private Long time;
}

View File

@ -0,0 +1,25 @@
package io.dataease.mobile.server;
import io.dataease.mobile.api.HomeApi;
import io.dataease.mobile.dto.HomeItemDTO;
import io.dataease.mobile.service.HomeService;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class HomeServer implements HomeApi {
@Resource
private HomeService homeService;
@Override
public List<HomeItemDTO> query(Integer type) {
return homeService.query(type);
}
@Override
public Object detail(String id) {
return null;
}
}

View File

@ -0,0 +1,44 @@
package io.dataease.mobile.service;
import io.dataease.auth.api.dto.CurrentRoleDto;
import io.dataease.auth.api.dto.CurrentUserDto;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.mobile.dto.HomeItemDTO;
import io.dataease.base.mapper.ext.HomeMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class HomeService {
@Resource
private HomeMapper homeMapper;
public List<HomeItemDTO> query(Integer type) {
List<HomeItemDTO> result = new ArrayList<>();
CurrentUserDto user = AuthUtils.getUser();
switch (type){
case 0:
result = homeMapper.queryStore(user.getUserId());
break;
case 1:
result = homeMapper.queryHistory();
break;
case 2:
Map<String, Object> param = new HashMap<>();
Long deptId = user.getDeptId();
List<Long> roleIds = user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList());
param.put("userId", user.getUserId());
param.put("deptId", deptId);
param.put("roleIds", roleIds);
result = homeMapper.queryShare(param);
break;
}
return result;
}
}