src/main/java/com/mzl/flower/mapper/supplier/SupplierSubMapper.java
@@ -6,6 +6,7 @@ import com.mzl.flower.dto.response.supplier.SupplierSubVO; import com.mzl.flower.entity.supplier.SupplierSub; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; import java.util.List; @@ -13,4 +14,11 @@ @Repository public interface SupplierSubMapper extends BaseMapper<SupplierSub> { List<SupplierSubVO> querySupplierSub(@Param("dto") QuerySupplierSubDTO dto, Page page); @Select("select * from t_supplier_sub_info where deleted = '0' and user_id = #{id}") SupplierSub getCurrentSupplier(String id); @Select("select * from t_supplier_sub_info where deleted = '0' and supplier_id = #{supplierId}") List<SupplierSub> getSubSupplier(String supplierId); } src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java
@@ -162,7 +162,7 @@ } public Page<SupplierDTO> querySupplier(QuerySupplierSubDTO dto, Page page) { public Page<SupplierSubVO> querySupplier(QuerySupplierSubDTO dto, Page page) { List<SupplierSubVO> list = supplierSubMapper.querySupplierSub(dto, page); page.setRecords(list); return page; @@ -219,4 +219,12 @@ supplierSubMapper.deleteById(id); } } public List<SupplierSub> getSubSupplier() { SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); if(ObjectUtils.isEmpty(supplierDTO)){ throw new ValidationException("供应商信息不存在"); } return supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId())); } } src/main/java/com/mzl/flower/web/login/SupplierLoginController.java
@@ -12,8 +12,10 @@ import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.request.UserLoginDTO; import com.mzl.flower.dto.response.supplier.SupplierDTO; import com.mzl.flower.entity.supplier.SupplierSub; import com.mzl.flower.entity.system.User; import com.mzl.flower.mapper.supplier.SupplierMapper; import com.mzl.flower.mapper.supplier.SupplierSubMapper; import com.mzl.flower.service.login.LoginService; import com.mzl.flower.service.system.UserService; import io.swagger.annotations.Api; @@ -65,6 +67,11 @@ @Autowired private SupplierMapper supplierMapper; @Autowired private SupplierSubMapper supplierSubMapper; public static final String SMS_CODE_KEY = "SMS-CODE-KEY"; public static final String TOKEN_KEY = "TOKEN-KEY"; @@ -87,9 +94,27 @@ if(user == null){ throw new ValidationException("用户不存在"); } SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId()); if (supplierDTO != null && supplierDTO.getIsEnabled() == false) { throw new ValidationException("用户已禁用,请联系管理员"); // 子账号校验:1.不存在->放行。 // 2.存在->校验是否已经禁用。 // 3.存在且未禁用->校验父级账号是否禁用。 // 4.父级禁用->提示 // 5.父级未禁用->保存子账号token并返回 SupplierSub supplierSub = supplierSubMapper.getCurrentSupplier(user.getId()); if (supplierSub != null) { if (supplierSub.getIsEnabled() == false) { throw new ValidationException("子账号已禁用,请联系父级账号"); }else{ //这里拿父级供应商ID查询用户ID再校验 SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(String.valueOf( supplierSub.getSupplierId())); if (supplierDTO != null && supplierDTO.getIsEnabled() == false) { throw new ValidationException("父级账号用户已禁用,请联系管理员"); } } }else { SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId()); if (supplierDTO != null && supplierDTO.getIsEnabled() == false) { throw new ValidationException("用户已禁用,请联系管理员"); } } String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId()); if (StringUtils.isNotBlank(tokenCache)) { @@ -134,9 +159,27 @@ if(user == null){ throw new ValidationException("用户不存在"); } SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId()); if (supplierDTO != null && supplierDTO.getIsEnabled() == false) { throw new ValidationException("用户已禁用,请联系管理员"); // 子账号校验:1.不存在->放行。 // 2.存在->校验是否已经禁用。 // 3.存在且未禁用->校验父级账号是否禁用。 // 4.父级禁用->提示 // 5.父级未禁用->保存子账号token并返回 SupplierSub supplierSub = supplierSubMapper.getCurrentSupplier(user.getId()); if (supplierSub != null) { if (supplierSub.getIsEnabled() == false) { throw new ValidationException("子账号已禁用,请联系父级账号"); } else { //这里拿父级供应商ID查询用户ID再校验 SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(String.valueOf(supplierSub.getSupplierId())); if (supplierDTO != null && supplierDTO.getIsEnabled() == false) { throw new ValidationException("父级账号用户已禁用,请联系管理员"); } } } else { SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(user.getId()); if (supplierDTO != null && supplierDTO.getIsEnabled() == false) { throw new ValidationException("用户已禁用,请联系管理员"); } } String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId()); if (StringUtils.isNotBlank(tokenCache)) { src/main/java/com/mzl/flower/web/supplier/SupplierSubController.java
@@ -5,6 +5,9 @@ import com.mzl.flower.base.R; import com.mzl.flower.base.ReturnDataDTO; import com.mzl.flower.dto.request.supplier.*; import com.mzl.flower.dto.response.payment.DeliveryOrderItemListDTO; import com.mzl.flower.dto.response.supplier.SupplierSubVO; import com.mzl.flower.entity.supplier.SupplierSub; import com.mzl.flower.service.supplier.SupplierSubService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotNull; import java.util.List; @RestController @RequestMapping("/api/supplierSub") @@ -39,7 +43,7 @@ @GetMapping("/page") @ApiOperation(value = "运营端-供应商子账号分页查询", notes = "运营端-供应商子账号分页查询") public ResponseEntity<ReturnDataDTO<Page<SupplierSubDTO>>> querySupplier(QuerySupplierSubDTO dto, Page page) { public ResponseEntity<ReturnDataDTO<Page<SupplierSubVO>>> querySupplier(QuerySupplierSubDTO dto, Page page) { return returnData(R.SUCCESS.getCode(), supplierSubService.querySupplier(dto, page)); } @@ -57,4 +61,10 @@ supplierSubService.delete(id); return returnData(R.SUCCESS.getCode(), null); } @GetMapping("/sub/all") @ApiOperation(value = "获取当前用户下子账号信息", notes = "获取当前用户下子账号信息") public ResponseEntity<ReturnDataDTO<List<SupplierSub>>> getSubSupplier() { return returnData(R.SUCCESS.getCode(), supplierSubService.getSubSupplier()); } }