|
@@ -1,5 +1,7 @@
|
|
|
package edu.travel.warehouse.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -23,6 +25,8 @@ import edu.travel.warehouse.mapper.ShopWarehouseStaffMapper;
|
|
|
import edu.travel.warehouse.service.ShopWarehouseService;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -290,88 +294,142 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 连表新增
|
|
|
+ * 新增连表
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
*/
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional
|
|
|
public RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity) {
|
|
|
-
|
|
|
+
|
|
|
ShopWarehouse warehouse = new ShopWarehouse();
|
|
|
- copyWarehouseProperties(entity, warehouse);
|
|
|
-
|
|
|
-
|
|
|
- shopWarehouseMapper.insert(warehouse);
|
|
|
|
|
|
-
|
|
|
- saveStaffRoles(entity.getStaffList(), warehouse.getId());
|
|
|
+
|
|
|
+ Long currentUserId = getCurrentUserId();
|
|
|
|
|
|
-
|
|
|
- return buildWarehouseResponse(warehouse);
|
|
|
- }
|
|
|
+
|
|
|
+ copyWarehouseProperties(entity, warehouse);
|
|
|
+ warehouse.setCreateUserId(String.valueOf(currentUserId));
|
|
|
|
|
|
-
|
|
|
- private void copyWarehouseProperties(ShopWarehouseSaveDto source, ShopWarehouse target) {
|
|
|
- target.setParentId(source.getParentId());
|
|
|
- target.setWarehouseName(source.getWarehouseName());
|
|
|
- target.setLongitude(source.getLongitude());
|
|
|
- target.setLatitude(source.getLatitude());
|
|
|
- target.setCountryServeId(source.getCountryServeId());
|
|
|
- target.setDetailedAddress(source.getDetailedAddress());
|
|
|
- target.setStatus(source.getStatus());
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
+ shopWarehouseMapper.insert(warehouse);
|
|
|
|
|
|
-
|
|
|
- private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId) {
|
|
|
- if (staffList != null && !staffList.isEmpty()) {
|
|
|
- for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
- ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
- staff.setWarehouseId(warehouseId);
|
|
|
- staff.setUserId(staffDto.getUserId());
|
|
|
- staff.setRoleId(staffDto.getRoleId());
|
|
|
- shopWarehouseStaffMapper.insert(staff);
|
|
|
- }
|
|
|
+
|
|
|
+ if (entity.getStaffList() != null && !entity.getStaffList().isEmpty()) {
|
|
|
+ saveStaffRoles(entity.getStaffList(), warehouse.getId(), currentUserId);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- private RPCBaseResponse<ShopWarehouseVo> buildWarehouseResponse(ShopWarehouse warehouse) {
|
|
|
+
|
|
|
ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
warehouseVo.setId(warehouse.getId());
|
|
|
warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
+ warehouseVo.setProject(warehouse.getProject());
|
|
|
+ warehouseVo.setCreateTime(warehouse.getCreateTime());
|
|
|
+ warehouseVo.setCreateUserId(warehouse.getCreateUserId());
|
|
|
+ warehouseVo.setUpdateTime(warehouse.getUpdateTime());
|
|
|
+ warehouseVo.setUpdateUserId(warehouse.getUpdateUserId());
|
|
|
+ warehouseVo.setDeleteFlag(warehouse.getDeleteFlag());
|
|
|
+ warehouseVo.setParentId(warehouse.getParentId());
|
|
|
+ warehouseVo.setLongitude(warehouse.getLongitude());
|
|
|
+ warehouseVo.setLatitude(warehouse.getLatitude());
|
|
|
+ warehouseVo.setCountryServeId(warehouse.getCountryServeId());
|
|
|
+ warehouseVo.setDetailedAddress(warehouse.getDetailedAddress());
|
|
|
+ warehouseVo.setStatus(warehouse.getStatus());
|
|
|
|
|
|
+
|
|
|
+
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * 更新
|
|
|
- */
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional
|
|
|
public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity) {
|
|
|
-
|
|
|
- ShopWarehouse warehouse = new ShopWarehouse();
|
|
|
- warehouse.setId(entity.getId());
|
|
|
- copyWarehouseProperties(entity, warehouse);
|
|
|
- shopWarehouseMapper.updateById(warehouse);
|
|
|
+
|
|
|
+ ShopWarehouse existingWarehouse = shopWarehouseMapper.selectById(entity.getId());
|
|
|
+
|
|
|
+
|
|
|
+ if (existingWarehouse == null) {
|
|
|
+ return new RPCBaseResponse<>(404, "NULL", null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ copyWarehouseProperties(entity, existingWarehouse);
|
|
|
+
|
|
|
+
|
|
|
+ Long currentUserId = getCurrentUserId();
|
|
|
+ existingWarehouse.setUpdateUserId(String.valueOf(currentUserId));
|
|
|
+
|
|
|
+
|
|
|
+ shopWarehouseMapper.updateById(existingWarehouse);
|
|
|
|
|
|
|
|
|
- updateStaffRoles(entity.getStaffList(), entity.getId());
|
|
|
+ if (entity.getStaffList() != null) {
|
|
|
+
|
|
|
+ shopWarehouseStaffMapper.deleteByWarehouseId(existingWarehouse.getId());
|
|
|
+
|
|
|
+ saveStaffRoles(entity.getStaffList(), existingWarehouse.getId(), currentUserId);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- return buildWarehouseResponse(warehouse);
|
|
|
- }
|
|
|
+
|
|
|
+ ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
+ warehouseVo.setId(existingWarehouse.getId());
|
|
|
+ warehouseVo.setWarehouseName(existingWarehouse.getWarehouseName());
|
|
|
+ warehouseVo.setProject(existingWarehouse.getProject());
|
|
|
+ warehouseVo.setCreateTime(existingWarehouse.getCreateTime());
|
|
|
+ warehouseVo.setCreateUserId(existingWarehouse.getCreateUserId());
|
|
|
+ warehouseVo.setUpdateTime(existingWarehouse.getUpdateTime());
|
|
|
+ warehouseVo.setUpdateUserId(existingWarehouse.getUpdateUserId());
|
|
|
+ warehouseVo.setDeleteFlag(existingWarehouse.getDeleteFlag());
|
|
|
+ warehouseVo.setParentId(existingWarehouse.getParentId());
|
|
|
+ warehouseVo.setLongitude(existingWarehouse.getLongitude());
|
|
|
+ warehouseVo.setLatitude(existingWarehouse.getLatitude());
|
|
|
+ warehouseVo.setCountryServeId(existingWarehouse.getCountryServeId());
|
|
|
+ warehouseVo.setDetailedAddress(existingWarehouse.getDetailedAddress());
|
|
|
+ warehouseVo.setStatus(existingWarehouse.getStatus());
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- private void updateStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId) {
|
|
|
-
|
|
|
- shopWarehouseStaffMapper.deleteByWarehouseId(warehouseId);
|
|
|
+
|
|
|
+ return new RPCBaseResponse<>(200, "更新成功", warehouseVo);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- saveStaffRoles(staffList, warehouseId);
|
|
|
+
|
|
|
+ private void copyWarehouseProperties(ShopWarehouseSaveDto source, ShopWarehouse target) {
|
|
|
+ target.setParentId(source.getParentId());
|
|
|
+ target.setWarehouseName(source.getWarehouseName());
|
|
|
+ target.setLongitude(source.getLongitude());
|
|
|
+ target.setLatitude(source.getLatitude());
|
|
|
+ target.setCountryServeId(source.getCountryServeId());
|
|
|
+ target.setDetailedAddress(source.getDetailedAddress());
|
|
|
+ target.setStatus(source.getStatus());
|
|
|
+ if (source.getProject() != null) {
|
|
|
+ target.setProject(source.getProject());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private Long getCurrentUserId() {
|
|
|
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
+ Object principal = authentication.getPrincipal();
|
|
|
+ Long userId = null;
|
|
|
+
|
|
|
+ if (!(principal instanceof String && "anonymousUser".equals(principal))) {
|
|
|
+ String jsonString = JSON.toJSONString(principal);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonString);
|
|
|
+ userId = jsonObject.getLong("id");
|
|
|
+ }
|
|
|
|
|
|
+ return userId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId, Long currentUserId) {
|
|
|
+ for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
+ ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
+ staff.setWarehouseId(warehouseId);
|
|
|
+ staff.setUserId(staffDto.getUserId());
|
|
|
+ staff.setRoleId(staffDto.getRoleId());
|
|
|
+ staff.setCreateUserId(String.valueOf(currentUserId));
|
|
|
+ shopWarehouseStaffMapper.insert(staff);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|