Browse Source

多表新增,更新

Sakana 1 week ago
parent
commit
8a5859d803

+ 17 - 0
edu-travel-remote/edu-travel-remote-warehouse/src/main/java/edu/travel/dto/ShopWarehouseDto.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import edu.travel.po.PagePO;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -60,4 +61,20 @@ public class ShopWarehouseDto extends PagePO {
      * 删除标记 0正常 1删除
      */
     private Integer deleteFlag;
+    /**
+     * 项目标识
+     */
+    private String project;
+    /**
+     *
+     * 创建时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+    /**
+     * 更新时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
 }

+ 80 - 0
edu-travel-remote/edu-travel-remote-warehouse/src/main/java/edu/travel/dto/ShopWarehouseSaveDto.java

@@ -0,0 +1,80 @@
+package edu.travel.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import edu.travel.po.PagePO;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+@Data
+public class ShopWarehouseSaveDto{
+    /**
+     * 库房表ID
+     */
+    private Long id;
+
+    /**
+     * 0是总仓
+     */
+    private Long parentId;
+
+    /**
+     * 库房名称
+     */
+    private String warehouseName;
+
+    /**
+     * 经度
+     */
+    private String longitude;
+
+    /**
+     * 维度
+     */
+    private String latitude;
+
+    /**
+     * 国家ID
+     */
+    private String countryServeId;
+
+    /**
+     * 库房详细地址
+     */
+    private String detailedAddress;
+
+    /**
+     * '启用禁用 0 启用 1禁用'
+     */
+    private Integer status;
+
+    /**
+     * 删除标记 0正常 1删除
+     */
+    private Integer deleteFlag;
+    /**
+     * 项目标识
+     */
+    private String project;
+    /**
+     * 创建人
+     */
+    private String createUserId;
+    /**
+     * 更新人
+     */
+    private String updateUserId;
+    /**
+     *
+     * 创建时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+    /**
+     * 更新时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
+    private List<ShopWarehouseStaffDto> staffList; // 员工角色信息
+}

+ 4 - 0
edu-travel-remote/edu-travel-remote-warehouse/src/main/java/edu/travel/dto/ShopWarehouseStaffDto.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import edu.travel.po.PagePO;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -47,6 +48,7 @@ public class ShopWarehouseStaffDto extends PagePO {
     /**
      * 创建时间
      */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
     /**
@@ -57,6 +59,7 @@ public class ShopWarehouseStaffDto extends PagePO {
     /**
      * 更新时间
      */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
     private Date updateTime;
 
     /**
@@ -68,4 +71,5 @@ public class ShopWarehouseStaffDto extends PagePO {
      * 删除标记 0正常 1删除
      */
     private Integer deleteFlag;
+
 }

+ 4 - 0
edu-travel-remote/edu-travel-remote-warehouse/src/main/java/edu/travel/vo/ShopWarehouseStaffVo.java

@@ -57,4 +57,8 @@ public class ShopWarehouseStaffVo extends BaseEntity {
      * 删除标记 0正常 1删除
      */
     private Integer deleteFlag;
+    /**
+     * 项目标识
+     */
+    private String project;
 }

+ 1 - 0
edu-travel-service/edu-travel-service-warehouse/src/main/java/edu/travel/warehouse/entity/ShopWarehouse.java

@@ -74,6 +74,7 @@ public class ShopWarehouse {
     /**
      * 创建时间
      */
+
     @TableField(value = "create_time")
     private Date createTime;
 

+ 3 - 0
edu-travel-service/edu-travel-service-warehouse/src/main/java/edu/travel/warehouse/mapper/ShopWarehouseStaffMapper.java

@@ -2,6 +2,9 @@ package edu.travel.warehouse.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import edu.travel.warehouse.entity.ShopWarehouseStaff;
+import org.apache.ibatis.annotations.Update;
 
 public interface ShopWarehouseStaffMapper extends BaseMapper<ShopWarehouseStaff> {
+    @Update("UPDATE shop_warehouse_staff SET delete_flag = 1 WHERE warehouse_id = #{warehouseId}")
+    void deleteByWarehouseId(Long warehouseId);
 }

+ 5 - 0
edu-travel-service/edu-travel-service-warehouse/src/main/java/edu/travel/warehouse/service/ShopWarehouseService.java

@@ -3,6 +3,7 @@ package edu.travel.warehouse.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import edu.travel.dto.ShopWarehouseDto;
+import edu.travel.dto.ShopWarehouseSaveDto;
 import edu.travel.rpc.RPCBaseResponse;
 import edu.travel.vo.ShopWarehouseStaffVo;
 import edu.travel.vo.ShopWarehouseVo;
@@ -18,4 +19,8 @@ public interface ShopWarehouseService extends IService<ShopWarehouse> {
 
     //库房关联人员(角色)查询
     RPCBaseResponse<List<ShopWarehouseStaffVo>> getWarehouseTenantRole(String id);
+//连表新增
+    RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity);
+
+    RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity);
 }

+ 121 - 9
edu-travel-service/edu-travel-service-warehouse/src/main/java/edu/travel/warehouse/service/impl/ShopWarehouseServiceImpl.java

@@ -7,6 +7,8 @@ import edu.travel.adapter.service.country.CountryAdapter;
 import edu.travel.adapter.service.tenant.SysRoleAdapter;
 import edu.travel.adapter.service.tenant.TenantAdapter;
 import edu.travel.dto.ShopWarehouseDto;
+import edu.travel.dto.ShopWarehouseSaveDto;
+import edu.travel.dto.ShopWarehouseStaffDto;
 import edu.travel.remote.feign.mode.vo.tenant.EduTenantVo;
 import edu.travel.remote.feign.mode.vo.tenant.SysRoleVo;
 import edu.travel.rpc.RPCBaseResponse;
@@ -22,6 +24,7 @@ import edu.travel.warehouse.service.ShopWarehouseService;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -40,13 +43,6 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
     private ShopWarehouseStaffMapper shopWarehouseStaffMapper;
     /**
      * 树形结构查询(连表)
-     * @param dto
-     * @return
-     */
-    /**
-     * 树形结构查询(连表)
-     * @param dto
-     * @return
      */
     @Override
     public RPCBaseResponse<List<ShopWarehouseVo>> getWarehouseCountryForm(ShopWarehouseDto dto) {
@@ -82,6 +78,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         return new RPCBaseResponse<>(200, "SUCCESS", tree);
     }
 
+    /**
+     * 分页动态查询(连表)
+     */
     @Override
     public RPCBaseResponse<IPage<ShopWarehouseVo>> getWarehouseCountryPageForm(ShopWarehouseDto dto) {
         // 创建分页对象
@@ -93,7 +92,7 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
                 dto.getStatus(),
                 dto.getParentId(),
                 dto.getPageSize(),
-                (int) ((dto.getCurrentPage() - 1) * dto.getPageSize())
+                (dto.getCurrentPage() - 1) * dto.getPageSize()
         );
         int total = shopWarehouseMapper.countWarehouseWithCountry(dto.getWarehouseName(), dto.getStatus(), dto.getParentId());
 
@@ -134,6 +133,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
     }
 
+    /**
+     * 提取国家数据
+     */
     private Map<String, BaseCountryServeVo> fetchCountryData(Set<String> countryServeIds) {
         Map<String, BaseCountryServeVo> countryMap = new HashMap<>();
         if (!countryServeIds.isEmpty()) {
@@ -147,6 +149,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         return countryMap;
     }
 
+    /**
+     * 提取仓库数据
+     */
     private Map<Long, List<ShopWarehouseStaffVo>> fetchWarehouseTenantRoles(Set<Long> ids) {
         Map<Long, List<ShopWarehouseStaffVo>> staffMap = new HashMap<>();
         if (!ids.isEmpty()) {
@@ -160,6 +165,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         return staffMap;
     }
 
+    /**
+     *生成map
+     */
     private ShopWarehouseVo mapToWarehouseVo(ShopWarehouse shopWarehouse,
                                              Map<String, BaseCountryServeVo> countryMap,
                                              Map<Long, List<ShopWarehouseStaffVo>> staffMap) {
@@ -171,6 +179,7 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         shopWarehouseVo.setLatitude(shopWarehouse.getLatitude());
         shopWarehouseVo.setDetailedAddress(shopWarehouse.getDetailedAddress());
         shopWarehouseVo.setStatus(shopWarehouse.getStatus());
+        shopWarehouseVo.setProject(shopWarehouse.getProject());
         shopWarehouseVo.setParentId(shopWarehouse.getParentId());
         shopWarehouseVo.setDeleteFlag(shopWarehouse.getDeleteFlag());
         shopWarehouseVo.setMap(new HashMap<>());
@@ -184,6 +193,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         return shopWarehouseVo;
     }
 
+    /**
+     * 构建树
+     */
     private void addToTree(List<ShopWarehouseVo> tree, ShopWarehouseVo warehouseVo, Map<Long, ShopWarehouseVo> warehouseVoMap) {
         if (warehouseVo.getParentId() == null || warehouseVo.getParentId() == 0) {
             tree.add(warehouseVo);
@@ -201,7 +213,6 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
 
     /**
      * 库房关联人员(角色)查询,通过库房id,查询用户以及角色
-     * @return
      */
     @Override
     public RPCBaseResponse<List<ShopWarehouseStaffVo>> getWarehouseTenantRole(String id) {
@@ -278,4 +289,105 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
         return new RPCBaseResponse<>(200, "SUCCESS", resultList);
     }
 
+    /**
+     * 连表新增
+     */
+    @Override
+    @Transactional // 确保此方法在事务中执行
+    public RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity) {
+        // 保存仓库信息
+        ShopWarehouse warehouse = new ShopWarehouse();
+        warehouse.setParentId(entity.getParentId());
+        warehouse.setWarehouseName(entity.getWarehouseName());
+        warehouse.setLongitude(entity.getLongitude());
+        warehouse.setLatitude(entity.getLatitude());
+        warehouse.setCountryServeId(entity.getCountryServeId());
+        warehouse.setCreateTime(entity.getCreateTime());
+        warehouse.setUpdateUserId(entity.getUpdateUserId());
+        warehouse.setUpdateTime(new Date());
+        warehouse.setCreateUserId(entity.getCreateUserId());
+        warehouse.setDetailedAddress(entity.getDetailedAddress());
+        warehouse.setProject(entity.getProject());
+        warehouse.setStatus(entity.getStatus());
+        warehouse.setDeleteFlag(entity.getDeleteFlag());
+
+        // 插入仓库信息
+        shopWarehouseMapper.insert(warehouse);
+
+        // 获取新插入的仓库ID
+        Long warehouseId = warehouse.getId();
+
+        // 保存员工角色信息
+        List<ShopWarehouseStaffDto> staffList = entity.getStaffList();
+        if (staffList != null && !staffList.isEmpty()) {
+            for (ShopWarehouseStaffDto staffDto : staffList) {
+                ShopWarehouseStaff staff = new ShopWarehouseStaff();
+                staff.setWarehouseId(warehouseId); // 设置外键为新保存仓库的ID
+                staff.setUserId(staffDto.getUserId());
+                staff.setRoleId(staffDto.getRoleId());
+                shopWarehouseStaffMapper.insert(staff); // 保存员工角色信息
+            }
+        }
+
+        // 将保存的仓库信息转换为返回对象
+        ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
+        warehouseVo.setId(warehouse.getId());
+        warehouseVo.setWarehouseName(warehouse.getWarehouseName());
+        // 添加更多的字段映射,根据需要
+
+        return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
+    }
+
+
+    /**
+     * 更新
+     */
+    @Override
+    @Transactional // 确保此方法在事务中执行
+    public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity) {
+        // 更新仓库信息
+        ShopWarehouse warehouse = new ShopWarehouse();
+        warehouse.setId(entity.getId()); // 要更新的ID
+        warehouse.setParentId(entity.getParentId());
+        warehouse.setWarehouseName(entity.getWarehouseName());
+        warehouse.setLongitude(entity.getLongitude());
+        warehouse.setLatitude(entity.getLatitude());
+        warehouse.setCountryServeId(entity.getCountryServeId());
+        warehouse.setDetailedAddress(entity.getDetailedAddress());
+        warehouse.setProject(entity.getProject());
+        warehouse.setCreateTime(entity.getCreateTime());
+        warehouse.setUpdateUserId(entity.getUpdateUserId());
+        warehouse.setUpdateTime(new Date());
+        warehouse.setCreateUserId(entity.getCreateUserId());
+        warehouse.setStatus(entity.getStatus());
+        warehouse.setDeleteFlag(entity.getDeleteFlag());
+
+        // 执行更新操作
+        shopWarehouseMapper.updateById(warehouse);
+
+        // 更新员工角色信息
+        List<ShopWarehouseStaffDto> staffList = entity.getStaffList();
+        if (staffList != null && !staffList.isEmpty()) {
+            // 可以先删除原有的员工记录
+            shopWarehouseStaffMapper.deleteByWarehouseId(entity.getId()); // 这需要您在 Mapper 中实现
+
+            // 插入新的员工角色信息
+            for (ShopWarehouseStaffDto staffDto : staffList) {
+                ShopWarehouseStaff staff = new ShopWarehouseStaff();
+                staff.setWarehouseId(entity.getId()); // 设置外键为更新的仓库ID
+                staff.setUserId(staffDto.getUserId());
+                staff.setRoleId(staffDto.getRoleId());
+                shopWarehouseStaffMapper.insert(staff); // 保存员工角色信息
+            }
+        }
+
+        // 将保存的仓库信息转换为返回对象
+        ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
+        warehouseVo.setId(warehouse.getId());
+        warehouseVo.setWarehouseName(warehouse.getWarehouseName());
+        // 添加更多的字段映射,根据需要
+
+        return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
+    }
+
 }

+ 16 - 0
edu-travel-service/edu-travel-service-warehouse/src/main/java/edu/travel/warehouse/web/ShopWarehouseController.java

@@ -2,6 +2,7 @@ package edu.travel.warehouse.web;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import edu.travel.dto.ShopWarehouseDto;
+import edu.travel.dto.ShopWarehouseSaveDto;
 import edu.travel.remote.ShopWarehouseRemoteController;
 import edu.travel.rpc.RPCBaseResponse;
 import edu.travel.vo.ShopWarehouseStaffVo;
@@ -51,6 +52,21 @@ public class ShopWarehouseController extends BaseController<ShopWarehouse> imple
     public RPCBaseResponse<List<ShopWarehouseStaffVo>> getWarehouseTenantRole(String id) {
         return shopWarehouseService.getWarehouseTenantRole(id);
     }
+    /**
+     * 库房连表新增
+     */
+    @PostMapping("/saveAllForm")
+    public RPCBaseResponse<ShopWarehouseVo> saveAllForm(@RequestBody ShopWarehouseSaveDto entity){
+        return shopWarehouseService.saveAllForm(entity);
+    }
+    /**
+     * 库房连表修改
+     */
+    @PostMapping("/updateWarehouse")
+    public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(@RequestBody ShopWarehouseSaveDto entity){
+        return shopWarehouseService.updateWarehouse(entity);
+    }
+
 
     /**
      * 查询库房详情