Commit 3d340cf5 authored by lining's avatar lining

feat: 首页接口

parent 471c1de3
...@@ -18,4 +18,8 @@ public class BizConstants { ...@@ -18,4 +18,8 @@ public class BizConstants {
public static final String CATEGORY_SUBCLASS_SERVICE_NAME = "%s-%s"; public static final String CATEGORY_SUBCLASS_SERVICE_NAME = "%s-%s";
} }
public static class CommonConstants {
public static final String RELEASE_STATUS = "releaseStatus";
}
} }
package com.onsiteservice.miniapp.controller.category;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.miniapp.controller.category.vo.HomeViewVO;
import com.onsiteservice.miniapp.service.category.HomeCommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* <P>服务大类模块</P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/7 08:51
*/
@Api(tags = "首页模块")
@RestController
@RequestMapping("/common/")
@Validated
public class HomeCommonController {
@Resource
private HomeCommonService homeCommonService;
@ApiOperation(value = "首页")
@GetMapping("home")
public Result<HomeViewVO> home() {
return homeCommonService.home();
}
}
package com.onsiteservice.miniapp.controller.category.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
@Data
@ApiModel("首页轮播图")
public class BannerVO {
@ApiModelProperty("主键")
private Long id;
@ApiModelProperty("说明")
private String description;
@ApiModelProperty("图片地址")
private String url;
@ApiModelProperty("跳转类型 0 不跳转 1 图片 ,其他业务")
private Integer type;
@ApiModelProperty("跳转内容 如果是图片存url如果是资讯存id")
private String target;
@ApiModelProperty("是否启用")
private Boolean enabled;
@Column(name = "show_order")
@ApiModelProperty("排序")
private Integer showOrder;
}
\ No newline at end of file
package com.onsiteservice.miniapp.controller.category.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("首页通知")
public class HomeNoticeVO {
@ApiModelProperty("主键")
private Long id;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("摘要")
private String content;
@ApiModelProperty("备注")
private String remark;
@ApiModelProperty("显示排序号 数字越大优先级越高")
private Integer showOrder;
}
\ No newline at end of file
package com.onsiteservice.miniapp.controller.category.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("首页轮播图")
public class HomeViewVO {
@ApiModelProperty("轮播图")
private List<BannerVO> bannerList;
@ApiModelProperty("公告")
private List<HomeNoticeVO> noticeList;
@ApiModelProperty("服务")
private List<ServiceCategoryVO> serviceList;
}
\ No newline at end of file
package com.onsiteservice.miniapp.service.category;
import com.onsiteservice.constant.constant.BizConstants;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
import com.onsiteservice.dao.mapper.banner.BannerMapper;
import com.onsiteservice.dao.mapper.home.HomeNoticeMapper;
import com.onsiteservice.entity.banner.Banner;
import com.onsiteservice.entity.home.HomeNotice;
import com.onsiteservice.miniapp.controller.category.vo.BannerVO;
import com.onsiteservice.miniapp.controller.category.vo.HomeNoticeVO;
import com.onsiteservice.miniapp.controller.category.vo.HomeViewVO;
import com.onsiteservice.miniapp.controller.category.vo.ServiceCategoryVO;
import com.onsiteservice.util.AttrCopyUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class HomeCommonService {
@Resource
private BannerMapper bannerMapper;
@Resource
private HomeNoticeMapper homeNoticeMapper;
@Resource
private ServiceCategoryService serviceCategoryService;
public Result<HomeViewVO> home() {
// 轮播图
List<Banner> bannerList = bannerMapper.selectAll();
List<BannerVO> bannerVOList = bannerList.parallelStream()
.map(e -> AttrCopyUtils.copy(e, new BannerVO())).collect(Collectors.toList());
// 公告
Condition c = new Condition(HomeNotice.class);
c.createCriteria().andEqualTo(BizConstants.CommonConstants.RELEASE_STATUS, 2);
List<HomeNotice> noticeList = homeNoticeMapper.selectByCondition(c);
List<HomeNoticeVO> homeNoticeVOList = noticeList.parallelStream()
.map(e -> AttrCopyUtils.copy(e, new HomeNoticeVO())).collect(Collectors.toList());
// 服务
Result<List<ServiceCategoryVO>> serviceResult = serviceCategoryService.list(null);
HomeViewVO homeViewVO = HomeViewVO.builder()
.bannerList(bannerVOList)
.noticeList(homeNoticeVOList)
.serviceList(serviceResult.getData())
.build();
return ResultGenerator.success(homeViewVO);
}
}
...@@ -17,7 +17,7 @@ project: ...@@ -17,7 +17,7 @@ project:
# 安全路径白名单 无需token # 安全路径白名单 无需token
ant-paths: "/error,**.html**,**.js,**.css,/favicon.ico,/webjars/**,/swagger**, ant-paths: "/error,**.html**,**.js,**.css,/favicon.ico,/webjars/**,/swagger**,
/swagger-resources/configuration/ui,/**/v2/api-docs,/doc.html,/v2/api-docs-ext,/druid/**\ /swagger-resources/configuration/ui,/**/v2/api-docs,/doc.html,/v2/api-docs-ext,/druid/**\
/,/websocket/**,/category/page,/subclass/page,/token/base,/dict" /,/websocket/**,/category/page,/subclass/page,/token/base,/dict,/common/*"
# 基础token可以访问的路径白名单 # 基础token可以访问的路径白名单
base-token-ant-paths: "/login" base-token-ant-paths: "/login"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment