From 86f2f7e0023bfc56b2c20f2c594dc6a935a41a9d Mon Sep 17 00:00:00 2001 From: luodangjia <luodangjia> Date: 星期一, 25 十一月 2024 11:41:27 +0800 Subject: [PATCH] 11.25 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsCategoryController.java | 19 + ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/weChat/WeChatUtil.java | 396 +++++++++++----------- ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/OrderFallbackFactory.java | 39 ++ ruoyi-service/ruoyi-account/pom.xml | 4 ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java | 1 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/TAppUserService.java | 44 ++ ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java | 4 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/filter/AuthFilter.java | 2 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java | 84 ++++ ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/OrderClient.java | 24 + ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUserApplet.java | 57 +++ ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/BannerController.java | 44 ++ ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/dto/IndexConfigSetDto.java | 23 + ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java | 5 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Technician.java | 7 /dev/null | 75 ---- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/SystemConfigController.java | 37 + ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsEvaluate.java | 6 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java | 2 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java | 150 ++++++++ ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java | 33 + 21 files changed, 756 insertions(+), 300 deletions(-) diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsEvaluate.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsEvaluate.java index b4c2140..745cad0 100644 --- a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsEvaluate.java +++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/GoodsEvaluate.java @@ -10,6 +10,7 @@ import lombok.EqualsAndHashCode; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDateTime; /** @@ -39,10 +40,13 @@ @ApiModelProperty(value = "用户id") @TableField("app_user_id") private Long appUserId; + @ApiModelProperty(value = "订单id") + @TableField("order_id") + private Long orderId; @ApiModelProperty(value = "评分") @TableField("grade") - private Integer grade; + private BigDecimal grade; @ApiModelProperty(value = "评价内容") @TableField("comment") diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Technician.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Technician.java index 3483578..73960e5 100644 --- a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Technician.java +++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/domain/Technician.java @@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDateTime; /** @@ -69,6 +70,12 @@ @ApiModelProperty(value = "添加时间") @TableField("create_time") private LocalDateTime createTime; + @ApiModelProperty("服务次数") + @TableField(exist = false) + private Integer serveCount; + @ApiModelProperty("平均分") + @TableField(exist = false) + private BigDecimal grade; } diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/dto/IndexConfigSetDto.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/dto/IndexConfigSetDto.java new file mode 100644 index 0000000..00a8f45 --- /dev/null +++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/dto/IndexConfigSetDto.java @@ -0,0 +1,23 @@ +package com.ruoyi.other.api.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class IndexConfigSetDto { + @ApiModelProperty("公司理念") + private String companyWant; + @ApiModelProperty("宣传图片1") + private String pic1; + @ApiModelProperty("跳转类型1 - 1无2外部链接3商品详情4秒杀商品详情5领卷中心") + private Integer direct1; + @ApiModelProperty("宣传图片2") + private String pic2; + @ApiModelProperty("跳转类型2 - 1无2外部链接3商品详情4秒杀商品详情5领卷中心") + private String direct2; + @ApiModelProperty("公司简介") + private String companyInfo; + + + +} diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/OrderFallbackFactory.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/OrderFallbackFactory.java new file mode 100644 index 0000000..762b040 --- /dev/null +++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/OrderFallbackFactory.java @@ -0,0 +1,39 @@ +package com.ruoyi.other.api.factory; + +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.dto.ExchangeBackDto; +import com.ruoyi.common.core.dto.ExchangeDto; + +import com.ruoyi.other.api.feignClient.OrderClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 充电订单服务降级处理 + * + * @author ruoyi + */ +@Component +public class OrderFallbackFactory implements FallbackFactory<OrderClient> +{ + private static final Logger log = LoggerFactory.getLogger(OrderFallbackFactory.class); + + + @Override + public OrderClient create(Throwable cause) { + log.error("商品订单调用失败:{}", cause.getMessage()); + return new OrderClient() { + + + @Override + public R getOrderIdsByTechId(Integer id) { + return R.fail("根据技师id查订单ids失败:" + cause.getMessage()); + } + + }; + } +} diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/OrderClient.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/OrderClient.java new file mode 100644 index 0000000..75929d3 --- /dev/null +++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/OrderClient.java @@ -0,0 +1,24 @@ +package com.ruoyi.other.api.feignClient; + +import com.ruoyi.common.core.constant.ServiceNameConstants; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.dto.ExchangeBackDto; +import com.ruoyi.common.core.dto.ExchangeDto; + +import com.ruoyi.other.api.factory.OrderFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 后台订单服务 + * @author ruoyi + */ +@FeignClient(contextId = "OrderClient", value = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = OrderFallbackFactory.class) +public interface OrderClient { + @PostMapping(value = "/management/give/vip") + public R<List<Long>> getOrderIdsByTechId(@RequestParam("id") Integer id); + + +} diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java new file mode 100644 index 0000000..6ee36aa --- /dev/null +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java @@ -0,0 +1,150 @@ +package com.ruoyi.system.api.model; + + +import java.io.Serializable; +import java.util.Set; + +/** + * 用户信息 + * + * @author ruoyi + */ +public class LoginUser implements Serializable +{ + private static final long serialVersionUID = 1L; + + /** + * 用户唯一标识 + */ + private String token; + + /** + * 用户名id + */ + private Long userid; + + /** + * 用户名 + */ + private String username; + + /** + * 登录时间 + */ + private Long loginTime; + + /** + * 过期时间 + */ + private Long expireTime; + + /** + * 登录IP地址 + */ + private String ipaddr; + + /** + * 权限列表 + */ + private Set<String> permissions; + + /** + * 角色列表 + */ + private Set<String> roles; + + /** + * 用户信息 + */ + private SysUser sysUser; + + public String getToken() + { + return token; + } + + public void setToken(String token) + { + this.token = token; + } + + public Long getUserid() + { + return userid; + } + + public void setUserid(Long userid) + { + this.userid = userid; + } + + public String getUsername() + { + return username; + } + + public void setUsername(String username) + { + this.username = username; + } + + public Long getLoginTime() + { + return loginTime; + } + + public void setLoginTime(Long loginTime) + { + this.loginTime = loginTime; + } + + public Long getExpireTime() + { + return expireTime; + } + + public void setExpireTime(Long expireTime) + { + this.expireTime = expireTime; + } + + public String getIpaddr() + { + return ipaddr; + } + + public void setIpaddr(String ipaddr) + { + this.ipaddr = ipaddr; + } + + public Set<String> getPermissions() + { + return permissions; + } + + public void setPermissions(Set<String> permissions) + { + this.permissions = permissions; + } + + public Set<String> getRoles() + { + return roles; + } + + public void setRoles(Set<String> roles) + { + this.roles = roles; + } + + public SysUser getSysUser() + { + return sysUser; + } + + public void setSysUser(SysUser sysUser) + { + this.sysUser = sysUser; + } +} diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUserApplet.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUserApplet.java new file mode 100644 index 0000000..be73042 --- /dev/null +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUserApplet.java @@ -0,0 +1,57 @@ +package com.ruoyi.system.api.model; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 用户信息 小程序登录使用 + * + * @author 无关风月 + */ +@Data +public class LoginUserApplet implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户唯一标识 + */ + private String token; + /** + * 用户姓名 + */ + private String name; + + /** + * 用户名id + */ + private Long userId; + private String userIdStr; + + /** + * 用户手机号 + */ + private String phone; + /** + * 登录时间 + */ + private Long loginTime; + + /** + * 过期时间 + */ + private Long expireTime; + + /** + * 登录IP地址 + */ + private String ipaddr; + /** + * 头像 + */ + private String avatar; + /** + * 地址 + */ + private String address; +} diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java index c443059..53ed3c5 100644 --- a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java +++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java @@ -14,7 +14,6 @@ import com.ruoyi.common.core.utils.ip.IpUtils; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.system.api.RemoteUserService; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.model.LoginUser; diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java index a3220ef..2d674db 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java @@ -4,6 +4,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.system.api.model.SysOperLog; import org.apache.commons.lang3.ArrayUtils; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; @@ -27,7 +29,7 @@ import com.ruoyi.common.log.filter.PropertyPreExcludeFilter; import com.ruoyi.common.log.service.AsyncLogService; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.system.api.domain.SysOperLog; + /** * 操作日志记录处理 diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java index e44b648..3b712b3 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java @@ -1,11 +1,10 @@ package com.ruoyi.common.log.service; -import org.springframework.beans.factory.annotation.Autowired; +import com.ruoyi.system.api.model.SysOperLog; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import com.ruoyi.common.core.constant.SecurityConstants; -import com.ruoyi.system.api.RemoteLogService; -import com.ruoyi.system.api.domain.SysOperLog; + import javax.annotation.Resource; diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java index d748b39..d62ea0c 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java @@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletRequest; import com.ruoyi.common.core.exception.user.UserAppletException; +import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUserApplet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -18,7 +19,6 @@ import com.ruoyi.common.core.utils.uuid.IdUtils; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.system.api.model.LoginUser; /** * token验证处理 diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/DictUtils.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/DictUtils.java deleted file mode 100644 index 8282fdc..0000000 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/DictUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.ruoyi.common.security.utils; - -import java.util.Collection; -import java.util.List; -import com.alibaba.fastjson2.JSONArray; -import com.ruoyi.common.core.constant.CacheConstants; -import com.ruoyi.common.core.utils.SpringUtils; -import com.ruoyi.common.core.utils.StringUtils; -import com.ruoyi.common.redis.service.RedisService; -import com.ruoyi.system.api.domain.SysDictData; - -/** - * 字典工具类 - * - * @author ruoyi - */ -public class DictUtils -{ - /** - * 设置字典缓存 - * - * @param key 参数键 - * @param dictDatas 字典数据列表 - */ - public static void setDictCache(String key, List<SysDictData> dictDatas) - { - SpringUtils.getBean(RedisService.class).setCacheObject(getCacheKey(key), dictDatas); - } - - /** - * 获取字典缓存 - * - * @param key 参数键 - * @return dictDatas 字典数据列表 - */ - public static List<SysDictData> getDictCache(String key) - { - JSONArray arrayCache = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key)); - if (StringUtils.isNotNull(arrayCache)) - { - return arrayCache.toList(SysDictData.class); - } - return null; - } - - /** - * 删除指定字典缓存 - * - * @param key 字典键 - */ - public static void removeDictCache(String key) - { - SpringUtils.getBean(RedisService.class).deleteObject(getCacheKey(key)); - } - - /** - * 清空字典缓存 - */ - public static void clearDictCache() - { - Collection<String> keys = SpringUtils.getBean(RedisService.class).keys(CacheConstants.SYS_DICT_KEY + "*"); - SpringUtils.getBean(RedisService.class).deleteObject(keys); - } - - /** - * 设置cache key - * - * @param configKey 参数键 - * @return 缓存键key - */ - public static String getCacheKey(String configKey) - { - return CacheConstants.SYS_DICT_KEY + configKey; - } -} diff --git a/ruoyi-service/ruoyi-account/pom.xml b/ruoyi-service/ruoyi-account/pom.xml index 4c62224..7e756da 100644 --- a/ruoyi-service/ruoyi-account/pom.xml +++ b/ruoyi-service/ruoyi-account/pom.xml @@ -117,6 +117,10 @@ <version>2.6</version> <scope>compile</scope> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> </dependencies> <build> diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java index de53754..563464b 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java @@ -1,8 +1,20 @@ package com.ruoyi.account.controller; +import com.ruoyi.account.api.model.AppUser; +import com.ruoyi.account.service.AppUserService; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.security.service.TokenService; +import org.junit.Test; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +import javax.annotation.Resource; +import java.util.List; /** * <p> @@ -15,6 +27,27 @@ @RestController @RequestMapping("/app-user") public class AppUserController { + @Resource + private TokenService tokenService; + @Resource + private AppUserService appUserService; + @PostMapping("/index") + @ApiOperation(value = "个人中心首页", tags = {"小程序-个人中心首页"}) + @Test + public void index(){ + System.err.println("=-===="); +// Long userId = tokenService.getLoginUserApplet().getUserId(); + } + public void test(Long userId,Integer count){ + List<AppUser> list = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, userId).list(); + count = count + list.size(); + for (AppUser appUser : list) { + test(appUser.getId(),count); + } + + + } + } diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/filter/AuthFilter.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/filter/AuthFilter.java index 4ec9510..16c080e 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/filter/AuthFilter.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/filter/AuthFilter.java @@ -2,11 +2,9 @@ import com.alibaba.fastjson.JSON; import com.ruoyi.account.api.model.AppUser; -import com.ruoyi.account.service.IAppUserService; import com.ruoyi.common.core.constant.TokenConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; -import com.ruoyi.system.api.domain.SysUser; import org.apache.logging.log4j.core.config.Order; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/TAppUserService.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/TAppUserService.java new file mode 100644 index 0000000..2482d4a --- /dev/null +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/TAppUserService.java @@ -0,0 +1,44 @@ +package com.ruoyi.account.service; + +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.Map; + +/** + * <p> + * 服务类 + * </p> + * + * @author luodangjia + * @since 2024-08-06 + */ +public interface TAppUserService extends IService<TAppUser> { + + /** + * 微信小程序登录用户封装 + * @param appletUserDecodeData + * @return + */ + Map<String, Object> wxLogin(AppletUserDecodeData appletUserDecodeData,Long inviteUserId); + + /** + * 支付宝小程序登录用户封装 + * @param response + * @return + */ +// Map<String, Object> aliLogin(AlipaySystemOauthTokenResponse response, AlipayUserInfoShareResponse userInfo); + Map<String, Object> aliLogin(AlipaySystemOauthTokenResponse response,String phone,Long inviteUserId); + + /** + * 封装用户信息和token + * @param appUser + * @return + */ + Map<String, Object> getUserInfo(TAppUser appUser); + + /** + * 账号判断 + * @param status + */ + public void throwInfo(Integer status); +} diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/weChat/WeChatUtil.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/weChat/WeChatUtil.java index 7322624..7cf2c31 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/weChat/WeChatUtil.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/util/weChat/WeChatUtil.java @@ -1,203 +1,203 @@ -package com.ruoyi.account.util.weChat; - -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import java.util.HashMap; -import java.util.Map; - -/** - * 微信工具类 - */ -@Slf4j -@Component -public class WeChatUtil { - - @Value("${wx.appletsAppid}") - private String wxAppletsAppid; - - @Value("${wx.appletsAppSecret}") - private String wxAppletsAppSecret; - - @Value("{wx.officialAccountAppSecret}") - private String officialAccountAppSecret; - - @Value("${wx.appid}") - private String webAppId; - - @Value("${wx.appSecret}") - private String webAppSecret; - - - /** - * 小程序使用jscode获取openid - * @param jscode - * @return - */ - public Map<String, Object> code2Session(String jscode) throws Exception{ - String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret - + "&js_code=" + jscode + "&grant_type=authorization_code"; - HttpRequest get = HttpUtil.createGet(url); - HttpResponse response = get.execute(); - int status = response.getStatus(); - if(200 != status){ - throw new RuntimeException(response.body()); - } - JSONObject jsonObject = JSON.parseObject(response.body()); - int errcode = jsonObject.getIntValue("errcode"); - Map<String, Object> map = new HashMap<>(); - map.put("errcode", errcode); - if(errcode == 0){//成功 - map.put("openid", jsonObject.getString("openid")); - map.put("sessionKey", jsonObject.getString("session_key")); - map.put("unionid", jsonObject.getString("unionid")); - return map; - } - if(errcode == -1){//系统繁忙,此时请开发者稍候再试 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - if(errcode == 40029){//code 无效 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - if(errcode == 45011){//频率限制,每个用户每分钟100次 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - return null; - } - - - /** - * 获取微信小程序token - * @return - */ - public String getWxAppletsAccessToken() throws Exception{ - String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret; - HttpRequest get = HttpUtil.createGet(url); - HttpResponse response = get.execute(); - if(response.getStatus() != 200){ - return ""; - } - JSONObject jsonObject = JSON.parseObject(response.body()); - return jsonObject.getString("access_token"); - } - - - /** - * 网站应用登录 - * @param code - * @return - */ - public Map<String, String> webAccessToken(String code) throws Exception{ - String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + webAppId + "&secret=" + webAppSecret + "&code=" + code + "&grant_type=authorization_code"; - HttpRequest get = HttpUtil.createGet(url); - HttpResponse response = get.execute(); - if(response.getStatus() != 200){ - return null; - } - JSONObject jsonObject = JSON.parseObject(response.body()); - int errcode = jsonObject.getIntValue("errcode"); - Map<String, String> map = new HashMap<>(); - if(errcode == 0){//成功 - map.put("access_token", jsonObject.getString("access_token")); - map.put("openid", jsonObject.getString("openid")); - map.put("refresh_token", jsonObject.getString("refresh_token")); - map.put("unionid", jsonObject.getString("unionid")); - return map; - } - if(errcode == -1){//系统繁忙,此时请开发者稍候再试 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - if(errcode == 40029){//code 无效 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - if(errcode == 45011){//频率限制,每个用户每分钟100次 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - return map; - } - - - /** - * 获取微信个人信息 - * @param access_token - * @param openid - * @return - */ - public Map<String, Object> getUserInfo(String access_token, String openid) throws Exception{ - String url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid; - HttpRequest get = HttpUtil.createGet(url); - HttpResponse response = get.execute(); - if(response.getStatus() != 200){ - return null; - } - JSONObject jsonObject = JSON.parseObject(response.body()); - int errcode = jsonObject.getIntValue("errcode"); - Map<String, Object> map = new HashMap<>(); - if(errcode == 0){//成功 - map.put("nickname", jsonObject.getString("nickname")); - map.put("openid", jsonObject.getString("openid")); - map.put("sex", jsonObject.getString("sex")); - map.put("headimgurl", jsonObject.getString("headimgurl")); - return map; - } - if(errcode == -1){//系统繁忙,此时请开发者稍候再试 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - if(errcode == 40029){//code 无效 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - if(errcode == 45011){//频率限制,每个用户每分钟100次 - map.put("msg", jsonObject.getString("errmsg")); - return map; - } - return map; - } - - - - +//package com.ruoyi.account.util.weChat; +// +//import cn.hutool.http.HttpRequest; +//import cn.hutool.http.HttpResponse; +//import cn.hutool.http.HttpUtil; +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONObject; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.stereotype.Component; +//import java.util.HashMap; +//import java.util.Map; +// +///** +// * 微信工具类 +// */ +//@Slf4j +//@Component +//public class WeChatUtil { +// +// @Value("${wx.appletsAppid}") +// private String wxAppletsAppid; +// +// @Value("${wx.appletsAppSecret}") +// private String wxAppletsAppSecret; +// +// @Value("{wx.officialAccountAppSecret}") +// private String officialAccountAppSecret; +// +// @Value("${wx.appid}") +// private String webAppId; +// +// @Value("${wx.appSecret}") +// private String webAppSecret; +// +// // /** -// * 获取小程序二维码 -// * @param page 跳转页 例如 pages/index/index -// * @param scene 参数 a=1&b=2 +// * 小程序使用jscode获取openid +// * @param jscode +// * @return // */ -// public InputStream getwxacodeunlimit(String page, String scene){ -// try { -// String token = getWxAppletsAccessToken(); -// if(StringUtils.isEmpty(token)){ -// System.err.println("获取接口调用凭证失败"); -// } -// String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + token; -// Map<String, Object> param = new HashMap<>(); -// param.put("scene", scene); -// param.put("page", page); -// HttpHeaders httpHeaders = new HttpHeaders(); -// MediaType type=MediaType.parseMediaType("application/json;charset=UTF-8"); -// httpHeaders.setContentType(type); -// HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(param, httpHeaders); -// ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, new Object[0]); -// String body1 = exchange.getBody(); -//// System.err.println(body1); -// ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); -// byte[] body = entity.getBody(); -//// System.err.println(Base64.encodeBase64String(body)); -// return new ByteArrayInputStream(body); -// }catch (Exception e){ -// e.printStackTrace(); +// public Map<String, Object> code2Session(String jscode) throws Exception{ +// String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret +// + "&js_code=" + jscode + "&grant_type=authorization_code"; +// HttpRequest get = HttpUtil.createGet(url); +// HttpResponse response = get.execute(); +// int status = response.getStatus(); +// if(200 != status){ +// throw new RuntimeException(response.body()); +// } +// JSONObject jsonObject = JSON.parseObject(response.body()); +// int errcode = jsonObject.getIntValue("errcode"); +// Map<String, Object> map = new HashMap<>(); +// map.put("errcode", errcode); +// if(errcode == 0){//成功 +// map.put("openid", jsonObject.getString("openid")); +// map.put("sessionKey", jsonObject.getString("session_key")); +// map.put("unionid", jsonObject.getString("unionid")); +// return map; +// } +// if(errcode == -1){//系统繁忙,此时请开发者稍候再试 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// if(errcode == 40029){//code 无效 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// if(errcode == 45011){//频率限制,每个用户每分钟100次 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; // } // return null; // } -} +// +// +// /** +// * 获取微信小程序token +// * @return +// */ +// public String getWxAppletsAccessToken() throws Exception{ +// String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret; +// HttpRequest get = HttpUtil.createGet(url); +// HttpResponse response = get.execute(); +// if(response.getStatus() != 200){ +// return ""; +// } +// JSONObject jsonObject = JSON.parseObject(response.body()); +// return jsonObject.getString("access_token"); +// } +// +// +// /** +// * 网站应用登录 +// * @param code +// * @return +// */ +// public Map<String, String> webAccessToken(String code) throws Exception{ +// String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + webAppId + "&secret=" + webAppSecret + "&code=" + code + "&grant_type=authorization_code"; +// HttpRequest get = HttpUtil.createGet(url); +// HttpResponse response = get.execute(); +// if(response.getStatus() != 200){ +// return null; +// } +// JSONObject jsonObject = JSON.parseObject(response.body()); +// int errcode = jsonObject.getIntValue("errcode"); +// Map<String, String> map = new HashMap<>(); +// if(errcode == 0){//成功 +// map.put("access_token", jsonObject.getString("access_token")); +// map.put("openid", jsonObject.getString("openid")); +// map.put("refresh_token", jsonObject.getString("refresh_token")); +// map.put("unionid", jsonObject.getString("unionid")); +// return map; +// } +// if(errcode == -1){//系统繁忙,此时请开发者稍候再试 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// if(errcode == 40029){//code 无效 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// if(errcode == 45011){//频率限制,每个用户每分钟100次 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// return map; +// } +// +// +// /** +// * 获取微信个人信息 +// * @param access_token +// * @param openid +// * @return +// */ +// public Map<String, Object> getUserInfo(String access_token, String openid) throws Exception{ +// String url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid; +// HttpRequest get = HttpUtil.createGet(url); +// HttpResponse response = get.execute(); +// if(response.getStatus() != 200){ +// return null; +// } +// JSONObject jsonObject = JSON.parseObject(response.body()); +// int errcode = jsonObject.getIntValue("errcode"); +// Map<String, Object> map = new HashMap<>(); +// if(errcode == 0){//成功 +// map.put("nickname", jsonObject.getString("nickname")); +// map.put("openid", jsonObject.getString("openid")); +// map.put("sex", jsonObject.getString("sex")); +// map.put("headimgurl", jsonObject.getString("headimgurl")); +// return map; +// } +// if(errcode == -1){//系统繁忙,此时请开发者稍候再试 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// if(errcode == 40029){//code 无效 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// if(errcode == 45011){//频率限制,每个用户每分钟100次 +// map.put("msg", jsonObject.getString("errmsg")); +// return map; +// } +// return map; +// } +// +// +// +// +//// /** +//// * 获取小程序二维码 +//// * @param page 跳转页 例如 pages/index/index +//// * @param scene 参数 a=1&b=2 +//// */ +//// public InputStream getwxacodeunlimit(String page, String scene){ +//// try { +//// String token = getWxAppletsAccessToken(); +//// if(StringUtils.isEmpty(token)){ +//// System.err.println("获取接口调用凭证失败"); +//// } +//// String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + token; +//// Map<String, Object> param = new HashMap<>(); +//// param.put("scene", scene); +//// param.put("page", page); +//// HttpHeaders httpHeaders = new HttpHeaders(); +//// MediaType type=MediaType.parseMediaType("application/json;charset=UTF-8"); +//// httpHeaders.setContentType(type); +//// HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(param, httpHeaders); +//// ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, new Object[0]); +//// String body1 = exchange.getBody(); +////// System.err.println(body1); +//// ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); +//// byte[] body = entity.getBody(); +////// System.err.println(Base64.encodeBase64String(body)); +//// return new ByteArrayInputStream(body); +//// }catch (Exception e){ +//// e.printStackTrace(); +//// } +//// return null; +//// } +//} diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/BannerController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/BannerController.java index 750a415..4f31a82 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/BannerController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/BannerController.java @@ -1,6 +1,7 @@ package com.ruoyi.other.controller; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.other.api.domain.Banner; @@ -8,10 +9,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.ibatis.annotations.Param; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @@ -30,8 +28,8 @@ public class BannerController { @Resource private BannerService bannerService; - @GetMapping("/list") - @ApiOperation(value = "列表", tags = {"小程序-banner"}) + @PostMapping("/index/list") + @ApiOperation(value = "banner列表", tags = {"小程序-首页"}) public R<List<Banner>> list(String name, Integer jumpType, Integer position){ List<Banner> list = bannerService.lambdaQuery().like(StringUtils.isNotEmpty(name), Banner::getName, name) .eq(Banner::getJumpType, jumpType) @@ -39,6 +37,40 @@ .list(); return R.ok(list); } + @PostMapping("/add") + @ApiOperation(value = "添加", tags = {"后台-广告管理-banner管理"}) + public R add(@RequestBody Banner banner){ + bannerService.save(banner); + return R.ok(); + } + @PostMapping("/delete") + @ApiOperation(value = "删除", tags = {"后台-广告管理-banner管理"}) + public R delete(@RequestParam Integer id){ + bannerService.removeById(id); + return R.ok(); + } + @PostMapping("/edit") + @ApiOperation(value = "修改", tags = {"后台-广告管理-banner管理"}) + public R edit(@RequestBody Banner banner){ + bannerService.updateById(banner); + return R.ok(); + } + @PostMapping("/detail") + @ApiOperation(value = "详情", tags = {"后台-广告管理-banner管理"}) + public R detail(@RequestParam Integer id){ + Banner byId = bannerService.getById(id); + return R.ok(byId); + } + @PostMapping("/page/list") + @ApiOperation(value = "列表", tags = {"后台-广告管理--banner"}) + public R<Page<Banner>> pagelist(String name, Integer jumpType, Integer position,Integer pageNum,Integer pageSize){ + Page<Banner> page = bannerService.lambdaQuery().like(StringUtils.isNotEmpty(name), Banner::getName, name) + .eq(Banner::getJumpType, jumpType) + .eq(Banner::getPosition, position) + .page(Page.of(pageNum, pageSize)); + return R.ok(page); + } + } diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsCategoryController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsCategoryController.java index 481f4d6..7b59d65 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsCategoryController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsCategoryController.java @@ -1,10 +1,16 @@ package com.ruoyi.other.controller; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.other.api.domain.GoodsCategory; +import com.ruoyi.other.service.GoodsCategoryService; +import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; /** * <p> @@ -17,7 +23,18 @@ @RestController @RequestMapping("/goods-category") public class GoodsCategoryController { + @Resource + private GoodsCategoryService goodsCategoryService; - + @PostMapping("/index/list") + @ApiOperation(value = "商品分类", tags = {"小程序-首页"}) + public R<List<GoodsCategory>> list(){ + List<GoodsCategory> list = goodsCategoryService.lambdaQuery() + .orderByDesc(GoodsCategory::getCreateTime) + .last("limit 8") + .list() + ; + return R.ok(list); + } } diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/SystemConfigController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/SystemConfigController.java index 5971bd0..e9de37f 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/SystemConfigController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/SystemConfigController.java @@ -1,16 +1,17 @@ package com.ruoyi.other.controller; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.domain.R; import com.ruoyi.other.api.domain.SystemConfig; +import com.ruoyi.other.api.dto.IndexConfigSetDto; import com.ruoyi.other.service.SystemConfigService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; import io.swagger.annotations.ApiOperation; import javax.annotation.Resource; +import java.util.List; /** * <p> @@ -25,11 +26,29 @@ public class SystemConfigController { @Resource private SystemConfigService systemConfigService; - @GetMapping("/byType") - @ApiOperation(value = "1=启动页管理,2=首页配置,3=订单包邮设置", tags = {"小程序-启动页面","小程序-首页","订单包邮配置"}) - public R<SystemConfig> byType(Integer type){ - SystemConfig one = systemConfigService.lambdaQuery().eq(SystemConfig::getType, type).last("limit 1").one(); - return R.ok(one); + @PostMapping("/index/add") + @ApiOperation(value = "添加", tags = {"后台-广告管理-首页配置"}) + public R add(@RequestBody IndexConfigSetDto indexConfigSetDto){ + //先删除type=2的数据 + List<SystemConfig> list = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 2).list(); + systemConfigService.removeBatchByIds(list); + SystemConfig systemConfig = new SystemConfig(); + systemConfig.setType(2); + systemConfig.setContent(JSON.toJSONString(indexConfigSetDto)); + systemConfigService.save(systemConfig); + return R.ok(); + } + @PostMapping("/index/detail") + @ApiOperation(value = "宣传图片-公司简介", tags = {"后台-广告管理-首页配置","小程序-首页"}) + public R<IndexConfigSetDto> detail(){ + SystemConfig one = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 2).one(); + if (one==null){ + return R.ok(); + } + IndexConfigSetDto indexConfigSetDto = JSONObject.parseObject(one.getContent(), IndexConfigSetDto.class); + return R.ok(indexConfigSetDto); + } + } diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java index 9a0c750..8a9f299 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java @@ -1,9 +1,23 @@ package com.ruoyi.other.controller; -import org.springframework.web.bind.annotation.RequestMapping; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.security.service.TokenService; +import com.ruoyi.other.api.domain.GoodsEvaluate; +import com.ruoyi.other.api.domain.Technician; +import com.ruoyi.other.api.domain.TechnicianSubscribe; +import com.ruoyi.other.api.feignClient.OrderClient; +import com.ruoyi.other.service.GoodsEvaluateService; +import com.ruoyi.other.service.TechnicianService; +import com.ruoyi.other.service.TechnicianSubscribeService; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.List; /** * <p> @@ -16,6 +30,72 @@ @RestController @RequestMapping("/technician") public class TechnicianController { + @Resource + private TechnicianService technicianService; + @Resource + private GoodsEvaluateService goodsEvaluateService; + @Resource + private OrderClient orderClient; + @Resource + private TechnicianSubscribeService technicianSubscribeService; + @Resource + private TokenService tokenService; + @PostMapping("/shop/list") + @ApiOperation(value = "获取门店的技师列表", tags = {"小程序-门店详情-技师预约"}) + public R<Page<Technician>> shoplist(@RequestParam Integer shopId,@RequestParam Integer pageNum,@RequestParam Integer pageSize){ + //查出技师列表 + Page<Technician> page = technicianService.lambdaQuery().eq(Technician::getShopId, shopId).eq(Technician::getStatus, 2).page(Page.of(pageNum, pageSize)); + for (Technician technician : page.getRecords()) { + //查出技师订单 + R<List<Long>> orderIdsByTechId = orderClient.getOrderIdsByTechId(technician.getId()); + if (orderIdsByTechId.getData().isEmpty()){ + technician.setGrade(new BigDecimal(0)); + technician.setServeCount(0); + continue; + } + //查出技师评价 + List<GoodsEvaluate> list = goodsEvaluateService.lambdaQuery().in(GoodsEvaluate::getOrderId, orderIdsByTechId.getData()).list(); + + //算出平均分并保留一位小数 + BigDecimal avg = list.stream().map(GoodsEvaluate::getGrade).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(list.size()), 1, BigDecimal.ROUND_HALF_UP); + technician.setGrade(avg); + technician.setServeCount(orderIdsByTechId.getData().size()); + + } + return R.ok(page); + } + + @PostMapping("/shop/detail") + @ApiOperation(value = "获取门店的技师详情", tags = {"小程序-门店详情-技师预约"}) + public R<Technician> shopdetail(@RequestParam Integer techId){ + //查出技师列表 + Technician technician = technicianService.getById(techId); + + //查出技师订单 + R<List<Long>> orderIdsByTechId = orderClient.getOrderIdsByTechId(technician.getId()); + if (orderIdsByTechId.getData().isEmpty()){ + technician.setGrade(new BigDecimal(0)); + technician.setServeCount(0); + return R.ok(technician); + } + //查出技师评价 + List<GoodsEvaluate> list = goodsEvaluateService.lambdaQuery().in(GoodsEvaluate::getOrderId, orderIdsByTechId.getData()).list(); + + //算出平均分并保留一位小数 + BigDecimal avg = list.stream().map(GoodsEvaluate::getGrade).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(list.size()), 1, BigDecimal.ROUND_HALF_UP); + technician.setGrade(avg); + technician.setServeCount(orderIdsByTechId.getData().size()); + return R.ok(technician); + } + @PostMapping("/shop/tech") + @ApiOperation(value = "预约操作", tags = {"小程序-门店详情-技师预约"}) + public R<Technician> shoptech(@RequestBody TechnicianSubscribe subscribe){ + Long userId = tokenService.getLoginUserApplet().getUserId(); + subscribe.setAppUserId(userId); + technicianSubscribeService.save(subscribe); + return R.ok(); + } + } -- Gitblit v1.7.1