瀏覽代碼

Merge branch 'master' of http://www.sysuimars.com:3000/kelei12399/foster

 Conflicts:
	admin/src/main/java/com/flyer/foster/service/IFosterRecordService.java
shuhao 6 月之前
父節點
當前提交
1870788cd6

+ 13 - 6
admin/src/main/java/com/flyer/foster/controller/app/AppFosterRecordController.java

@@ -1,15 +1,13 @@
 package com.flyer.foster.controller.app;
 
-import cn.dev33.satoken.annotation.SaIgnore;
-import cn.dev33.satoken.stp.StpUtil;
+import com.flyer.foster.dto.app.FosterRecordAddDTO;
 import com.flyer.foster.entity.FosterRecord;
-import com.flyer.foster.entity.Garden;
-import com.flyer.foster.pojo.StpAppUtil;
 import com.flyer.foster.service.IFosterRecordService;
 import com.flyer.util.R;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.validation.Valid;
 import java.util.List;
 
 /**
@@ -23,7 +21,7 @@ import java.util.List;
 public class AppFosterRecordController {
 
     @Autowired
-    IFosterRecordService service;
+    private IFosterRecordService iFosterRecordService;
 
     /**
      * 领养记录列表
@@ -33,11 +31,20 @@ public class AppFosterRecordController {
     public R list(@PathVariable Integer gardenId) {
 //        Integer appUserId = (Integer)StpAppUtil.getLoginId();
         Integer appUserId = 4;
-        List<FosterRecord> res = service.lambdaQuery().
+        List<FosterRecord> res = iFosterRecordService.lambdaQuery().
                 eq(FosterRecord::getAppUserId, appUserId)
                 .eq(FosterRecord::getGardenId, gardenId)
                 .list();
         return R.ok().result(res);
     }
 
+    /**
+     * 确认领养
+     *
+     * @return
+     */
+    @PostMapping("")
+    public R addFosterRecord(@Valid @RequestBody FosterRecordAddDTO addDTO) {
+        return R.ok().result(iFosterRecordService.addFosterRecord(addDTO));
+    }
 }

+ 1 - 4
admin/src/main/java/com/flyer/foster/controller/app/AppUserController.java

@@ -1,9 +1,6 @@
 package com.flyer.foster.controller.app;
 
-import cn.dev33.satoken.annotation.SaCheckLogin;
-import cn.dev33.satoken.annotation.SaIgnore;
-import com.flyer.foster.dto.AppUserQueryDTO;
-import com.flyer.foster.pojo.StpAppUtil;
+import com.flyer.foster.dto.app.AppUserQueryDTO;
 import com.flyer.foster.service.IAppUserService;
 import com.flyer.util.R;
 import org.springframework.beans.factory.annotation.Autowired;

+ 1 - 1
admin/src/main/java/com/flyer/foster/dto/AppUserQueryDTO.java → admin/src/main/java/com/flyer/foster/dto/app/AppUserQueryDTO.java

@@ -1,4 +1,4 @@
-package com.flyer.foster.dto;
+package com.flyer.foster.dto.app;
 
 import lombok.Data;
 

+ 1 - 1
admin/src/main/java/com/flyer/foster/dto/AppUserRespDTO.java → admin/src/main/java/com/flyer/foster/dto/app/AppUserRespDTO.java

@@ -1,4 +1,4 @@
-package com.flyer.foster.dto;
+package com.flyer.foster.dto.app;
 
 import lombok.Data;
 

+ 24 - 0
admin/src/main/java/com/flyer/foster/dto/app/FosterRecordAddDTO.java

@@ -0,0 +1,24 @@
+package com.flyer.foster.dto.app;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * FosterRecordAddDTO
+ *
+ * @author kelei
+ * @since 2024/5/13/13:50
+ */
+@Data
+public class FosterRecordAddDTO {
+    /**
+     * 用户id
+     */
+    @NotNull(message = "用户id不能为空")
+    private Integer appUserId;
+
+    @NotNull(message = "树id不能为空")
+    private Integer treeId;
+
+}

+ 2 - 2
admin/src/main/java/com/flyer/foster/service/IAppUserService.java

@@ -1,7 +1,7 @@
 package com.flyer.foster.service;
 
-import com.flyer.foster.dto.AppUserQueryDTO;
-import com.flyer.foster.dto.AppUserRespDTO;
+import com.flyer.foster.dto.app.AppUserQueryDTO;
+import com.flyer.foster.dto.app.AppUserRespDTO;
 import com.flyer.foster.entity.AppUser;
 import com.baomidou.mybatisplus.extension.service.IService;
 

+ 0 - 7
admin/src/main/java/com/flyer/foster/service/IFosterRecordService.java

@@ -3,8 +3,6 @@ package com.flyer.foster.service;
 import com.flyer.foster.entity.FosterRecord;
 import com.baomidou.mybatisplus.extension.service.IService;
 
-import java.util.List;
-
 /**
  * <p>
  * 领养记录 服务类
@@ -15,9 +13,4 @@ import java.util.List;
  */
 public interface IFosterRecordService extends IService<FosterRecord> {
 
-    /**
-     * 验证果树是否已经被领养 返回没被领养的数组
-     */
-//    List<Integer> checkFoster
-
 }

+ 20 - 5
admin/src/main/java/com/flyer/foster/service/impl/AppUserServiceImpl.java

@@ -1,24 +1,26 @@
 package com.flyer.foster.service.impl;
 
+import cn.dev33.satoken.session.SaSession;
+import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
+import com.flyer.exception.BusinessException;
 import com.flyer.foster.consts.LoginDevice;
 import com.flyer.foster.consts.WechatConst;
-import com.flyer.foster.dto.AppUserQueryDTO;
-import com.flyer.foster.dto.AppUserRespDTO;
+import com.flyer.foster.dto.app.AppUserQueryDTO;
+import com.flyer.foster.dto.app.AppUserRespDTO;
 import com.flyer.foster.entity.AppUser;
+import com.flyer.foster.entity.Garden;
 import com.flyer.foster.mapper.IAppUserMapper;
 import com.flyer.foster.pojo.Code2SessionResp;
 import com.flyer.foster.pojo.StpAppUtil;
 import com.flyer.foster.service.IAppUserService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.flyer.foster.service.IGardenService;
 import com.flyer.foster.util.WeChatApiUtil;
-import org.etsi.uri.x01903.v13.ResponderIDType;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.expression.spel.ast.OpInc;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
-import java.util.Map;
 
 /**
  * <p>
@@ -45,11 +47,19 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
     @Autowired
     private IAppUserService iAppUserService;
 
+    @Autowired
+    private IGardenService iGardenService;
+
     @Override
     public AppUserRespDTO login(AppUserQueryDTO dto) {
         // 查找用户信息
         Code2SessionResp code2Session = weChatApiUtil.getCode2Session(dto.getCode(), WechatConst.APP_ID, WechatConst.APP_SECRET);
         String openid = code2Session.getOpenid();
+        // 根据gardenId获取租户id
+        Garden garden = iGardenService.getById(dto.getGardenId());
+        if (garden == null) {
+            throw new BusinessException("无效的gardenId");
+        }
         // 查找用户信息,存在更新,不存在新增
         AppUser appUser = iAppUserService.lambdaQuery().eq(AppUser::getOpenId, openid).one();
         if (appUser == null) {
@@ -59,6 +69,7 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
             appUser.setOpenId(code2Session.getOpenid());
             appUser.setName(DEFAUT_NAME);
             appUser.setIcon(DEFAULT_ICON);
+            appUser.setTenantId(garden.getTenantId());
             appUser.setCreatedBy("kelei");
             appUser.setCreatedTime(LocalDateTime.now());
             appUser.setUpdatedBy("kelei");
@@ -67,6 +78,10 @@ public class AppUserServiceImpl extends ServiceImpl<IAppUserMapper, AppUser> imp
             this.save(appUser);
         }
         StpAppUtil.login(appUser.getId(), LoginDevice.APP);
+        SaSession tokenSession = StpAppUtil.getTokenSession();
+        // 设置tenantId
+        tokenSession.set("tenantId", appUser.getTenantId());
+
         AppUserRespDTO respDTO = new AppUserRespDTO();
         BeanUtil.copyProperties(appUser, respDTO);
         respDTO.setToken(StpAppUtil.getTokenValue());

+ 13 - 0
admin/src/main/java/com/flyer/foster/service/impl/FosterRecordServiceImpl.java

@@ -1,10 +1,14 @@
 package com.flyer.foster.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
+import com.flyer.foster.dto.app.FosterRecordAddDTO;
 import com.flyer.foster.entity.FosterRecord;
 import com.flyer.foster.mapper.IFosterRecordMapper;
+import com.flyer.foster.pojo.StpAppUtil;
 import com.flyer.foster.service.IFosterRecordService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -17,4 +21,13 @@ import org.springframework.stereotype.Service;
 @Service
 public class FosterRecordServiceImpl extends ServiceImpl<IFosterRecordMapper, FosterRecord> implements IFosterRecordService {
 
+    @Transactional
+    @Override
+    public boolean addFosterRecord(FosterRecordAddDTO addDTO) {
+        int tenantId = StpAppUtil.getTokenSession().getInt("tenantId");
+        FosterRecord fosterRecord = new FosterRecord();
+        BeanUtil.copyProperties(addDTO, fosterRecord);
+        fosterRecord.setTenantId(tenantId);
+        return this.save(fosterRecord);
+    }
 }

+ 4 - 1
admin/src/main/resources/mysql/ddl/init-table.sql

@@ -292,4 +292,7 @@ alter table tb_whisper
     add column end_time   varchar(10) comment '结束时间' after start_time;
 
 alter table tb_app_user
-    add column garden_id int default 0 comment '最新进入果园id' after id;
+    add column garden_id int default 0 comment '最新进入果园id' after id;
+
+alter table tb_foster_record
+    add column garden_id int default 0 comment '果园id' after app_user_id;