Browse Source

小程序头像更换接口

liyuan 3 months ago
parent
commit
8af7d746c9

+ 12 - 0
blade-service-api/blade-sales-part-api/src/main/java/org/springblade/salesPart/entity/PjCorpsDesc.java

@@ -384,4 +384,16 @@ public class PjCorpsDesc implements Serializable {
 	@TableField(exist = false)
 	private String notPurchased;
 
+	/**
+	 * 用户头像
+	 */
+	@TableField(exist = false)
+	private String avatar;
+
+	/**
+	 * 用户id
+	 */
+	@TableField(exist = false)
+	private Long userId;
+
 }

+ 33 - 33
blade-service/blade-sales-part/src/main/java/org/springblade/salesPart/corps/service/impl/CorpsDescServiceImpl.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.AllArgsConstructor;
 import org.springblade.client.entity.CorpsDesc;
+import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.api.R;
@@ -717,41 +718,40 @@ public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, PjCorpsDe
 	 */
 	@Override
 	public R getDetails() {
+		BladeUser bladeUser = AuthUtil.getUser();
 		PjCorpsAttn corpsAttn = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0)
-			.eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId())
-			.eq(PjCorpsAttn::getUserId, AuthUtil.getUserId()));
-		if (ObjectUtils.isNotNull(corpsAttn)) {
-			PjCorpsDesc corpsDesc = baseMapper.getCorpId(corpsAttn.getPid());
-			if (ObjectUtils.isNotNull(corpsDesc)) {
-				PjCorpsAddr corpsAddr = corpsAddrService.getOne(new LambdaQueryWrapper<PjCorpsAddr>().eq(PjCorpsAddr::getIsDeleted, 0)
-					.eq(PjCorpsAddr::getTenantId, AuthUtil.getTenantId())
-					.eq(PjCorpsAddr::getPid, corpsDesc.getId())
-					.eq(PjCorpsAddr::getDefaultAddres, "1")
-					.orderByDesc(PjCorpsAddr::getCreateTime)
-					.last(" limit 1"));
-				if (ObjectUtils.isNotNull(corpsAddr)) {
-					corpsDesc.setAttn(corpsAttn.getCname());
-					corpsDesc.setTel(corpsAttn.getTel());
-					corpsDesc.setAddr(corpsAddr.getBelongtoarea());
-					corpsDesc.setDetails(corpsAddr.getDetailedAddress());
-				}
-				return R.data(corpsDesc);
-			} else {
-				CorpsDesc corpsDesc1 = new CorpsDesc();
-				R<User> res = userClient.userInfoById(AuthUtil.getUserId());
-				if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
-					corpsDesc1.setTel(res.getData().getPhone());
-				}
-				return R.data(corpsDesc1);
-			}
-		} else {
-			PjCorpsDesc corpsDesc1 = new PjCorpsDesc();
-			R<User> res = userClient.userInfoById(AuthUtil.getUserId());
-			if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
-				corpsDesc1.setTel(res.getData().getPhone());
-			}
-			return R.data(corpsDesc1);
+			.eq(PjCorpsAttn::getTenantId, bladeUser.getTenantId())
+			.eq(PjCorpsAttn::getUserId, bladeUser.getUserId()));
+
+		R<User> res = userClient.userInfoById(AuthUtil.getUserId());
+		User user = ObjectUtils.isNotNull(res.getData()) ? res.getData() : null;
+		if (ObjectUtils.isNull(corpsAttn)) {
+			PjCorpsDesc corpsDesc = new PjCorpsDesc();
+			corpsDesc.setTel(user != null ? user.getPhone() : "");
+			return R.data(corpsDesc);
+		}
+		PjCorpsDesc corpsDesc = baseMapper.getCorpId(corpsAttn.getPid());
+		if (ObjectUtils.isNull(corpsDesc)) {
+			corpsDesc = new PjCorpsDesc();
+			corpsDesc.setTel(user != null ? user.getPhone() : "");
+			return R.data(corpsDesc);
 		}
+		corpsDesc.setTel(user != null ? user.getPhone() : "");
+		corpsDesc.setAvatar(user != null ? user.getAvatar() : "");
+		corpsDesc.setUserId(user != null ? user.getId() : null);
+		PjCorpsAddr corpsAddr = corpsAddrService.getOne(new LambdaQueryWrapper<PjCorpsAddr>().eq(PjCorpsAddr::getIsDeleted, 0)
+			.eq(PjCorpsAddr::getTenantId, bladeUser.getTenantId())
+			.eq(PjCorpsAddr::getPid, corpsDesc.getId())
+			.eq(PjCorpsAddr::getDefaultAddres, "1")
+			.orderByDesc(PjCorpsAddr::getCreateTime)
+			.last(" limit 1"));
+		if (ObjectUtils.isNotNull(corpsAddr)) {
+			corpsDesc.setAttn(corpsAttn.getCname());
+			corpsDesc.setTel(corpsAttn.getTel());
+			corpsDesc.setAddr(corpsAddr.getBelongtoarea());
+			corpsDesc.setDetails(corpsAddr.getDetailedAddress());
+		}
+		return R.data(corpsDesc);
 	}
 
 	@Override

+ 13 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java

@@ -59,6 +59,7 @@ import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
@@ -556,4 +557,16 @@ public class UserController {
 		return R.data(userList);
 	}
 
+
+	@PostMapping("updateUserAvatar")
+	public R updateUserAvatar(@RequestBody User user) {
+		if (Objects.isNull(user.getId()) || !org.springframework.util.StringUtils.hasText(user.getAvatar())) {
+			return R.fail("缺少必要参数");
+		}
+		User updateUser = new User();
+		updateUser.setId(user.getId());
+		updateUser.setAvatar(user.getAvatar());
+		return R.status(userService.updateById(updateUser));
+	}
+
 }