diff --git a/gather-app/src/main/java/com/ruoyi/business/controller/BusinessTripApprovalController.java b/gather-app/src/main/java/com/ruoyi/business/controller/BusinessTripApprovalController.java index 6e292a1..ba764d3 100644 --- a/gather-app/src/main/java/com/ruoyi/business/controller/BusinessTripApprovalController.java +++ b/gather-app/src/main/java/com/ruoyi/business/controller/BusinessTripApprovalController.java @@ -2,16 +2,17 @@ package com.ruoyi.business.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AddTreeSelect; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.TreeSelect; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.database.domain.BaseAddressInfo; import com.ruoyi.database.domain.BusinessTripApproval; -import com.ruoyi.database.domain.PoliceLeaveApproval; +import com.ruoyi.database.service.BaseAddressInfoService; import com.ruoyi.database.service.BusinessTripApprovalService; import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.system.service.ISysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -21,9 +22,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; /** * @Description BusinessTripApprovalController @@ -40,7 +40,7 @@ public class BusinessTripApprovalController extends BaseController { private final BusinessTripApprovalService businessTripApprovalService; private final ISysUserService sysUserService; private final ISysDeptService sysDeptService; - private final ISysDictDataService dictDataService; + private final BaseAddressInfoService baseAddressInfoService; @RequestMapping("/list") @@ -51,29 +51,29 @@ public class BusinessTripApprovalController extends BaseController { queryWrapper.orderByDesc("create_time"); List list = businessTripApprovalService.list(queryWrapper); long size = businessTripApprovalService.count(queryWrapper); - return getDataTableEnhance(list,size); + return getDataTableEnhance(list, size); } @PostMapping("add") @ApiOperation("新增出差申请") - public AjaxResult add(BusinessTripApproval dto){ + public AjaxResult add(BusinessTripApproval dto) { SysUser user = getLoginUser().getUser(); - if (dto.getHasOffcialCar() != null && dto.getHasOffcialCar() == 1){ - if (dto.getCarModel() == null){ + if (dto.getHasOffcialCar() != null && dto.getHasOffcialCar() == 1) { + if (dto.getCarModel() == null) { throw new RuntimeException("请选择使用车型"); } - if (dto.getUseCarType() == null){ + if (dto.getUseCarType() == null) { throw new RuntimeException("请选择用车方式"); } - if (dto.getSeats() == null){ + if (dto.getSeats() == null) { throw new RuntimeException("请输入座位数"); } } - if (dto.getStartDate() == null || dto.getEndDate() == null){ + if (dto.getStartDate() == null || dto.getEndDate() == null) { throw new RuntimeException("请选择出差时间范围"); } - if (dto.getDestinationId() == null){ + if (dto.getDestinationId() == null) { throw new RuntimeException("请选择出差目的地"); } dto.setUserName(user.getNickName()); @@ -139,9 +139,34 @@ public class BusinessTripApprovalController extends BaseController { } + @GetMapping("/addressList") + @ApiOperation("查询地址信息列表") + public AjaxResult addressList() { + List allAddresses = baseAddressInfoService.list(); + Map> addressMap = allAddresses.stream() + .collect(Collectors.groupingBy(BaseAddressInfo::getTopId)); + List tree = buildTree(addressMap, 0L); + return AjaxResult.success(tree); + } + private List buildTree( + Map> addressMap, + Long parentId + ) { + List children = addressMap.get(parentId); + if (children == null) return Collections.emptyList(); - + return children.stream() + .map(info -> { + AddTreeSelect node = new AddTreeSelect(); + node.setId(info.getId()); + node.setLabel(info.getAddName()); + node.setValue(info.getId().toString()); + node.setChildren(buildTree(addressMap, info.getId())); + return node; + }) + .collect(Collectors.toList()); + } } diff --git a/gather-app/src/main/java/com/ruoyi/database/domain/BaseAddressInfo.java b/gather-app/src/main/java/com/ruoyi/database/domain/BaseAddressInfo.java new file mode 100644 index 0000000..8777478 --- /dev/null +++ b/gather-app/src/main/java/com/ruoyi/database/domain/BaseAddressInfo.java @@ -0,0 +1,40 @@ +package com.ruoyi.database.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntityMini; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; +@Data +@EqualsAndHashCode(callSuper = false) +@TableName(value = "base_address_info") +@ApiModel(value = "BaseAddressInfo", description = "地址信息表") +public class BaseAddressInfo extends BaseEntityMini { + + + + @ApiModelProperty("主键") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + + @ApiModelProperty("地址编码") + private String addCode; + + + @ApiModelProperty("地址名称") + private String addName; + + + @ApiModelProperty("上级id") + private Long topId; + + +} diff --git a/gather-app/src/main/java/com/ruoyi/database/mapper/BaseAddressInfoMapper.java b/gather-app/src/main/java/com/ruoyi/database/mapper/BaseAddressInfoMapper.java new file mode 100644 index 0000000..91f8622 --- /dev/null +++ b/gather-app/src/main/java/com/ruoyi/database/mapper/BaseAddressInfoMapper.java @@ -0,0 +1,9 @@ +package com.ruoyi.database.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.database.domain.BaseAddressInfo; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface BaseAddressInfoMapper extends BaseMapper { +} diff --git a/gather-app/src/main/java/com/ruoyi/database/service/BaseAddressInfoService.java b/gather-app/src/main/java/com/ruoyi/database/service/BaseAddressInfoService.java new file mode 100644 index 0000000..bd2d279 --- /dev/null +++ b/gather-app/src/main/java/com/ruoyi/database/service/BaseAddressInfoService.java @@ -0,0 +1,7 @@ +package com.ruoyi.database.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.database.domain.BaseAddressInfo; + +public interface BaseAddressInfoService extends IService { +} diff --git a/gather-app/src/main/java/com/ruoyi/database/service/impl/BaseAddressInfoServiceImpl.java b/gather-app/src/main/java/com/ruoyi/database/service/impl/BaseAddressInfoServiceImpl.java new file mode 100644 index 0000000..f33efa6 --- /dev/null +++ b/gather-app/src/main/java/com/ruoyi/database/service/impl/BaseAddressInfoServiceImpl.java @@ -0,0 +1,11 @@ +package com.ruoyi.database.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.database.domain.BaseAddressInfo; +import com.ruoyi.database.mapper.BaseAddressInfoMapper; +import com.ruoyi.database.service.BaseAddressInfoService; +import org.springframework.stereotype.Service; + +@Service +public class BaseAddressInfoServiceImpl extends ServiceImpl implements BaseAddressInfoService { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AddTreeSelect.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AddTreeSelect.java new file mode 100644 index 0000000..19cb544 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AddTreeSelect.java @@ -0,0 +1,86 @@ +package com.ruoyi.common.core.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysMenu; + +import java.io.Serializable; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Treeselect树结构实体类 + * + * @author ruoyi + */ +public class AddTreeSelect implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 节点ID + */ + private Long id; + + /** + * 节点名称 + */ + private String label; + + + private String value; + + + /** + * 子节点 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; + + public AddTreeSelect() { + + } + + public AddTreeSelect(SysDept dept) { + this.id = dept.getDeptId(); + this.label = dept.getDeptName(); + this.children = dept.getChildren().stream().map(AddTreeSelect::new).collect(Collectors.toList()); + } + + public AddTreeSelect(SysMenu menu) { + this.id = menu.getMenuId(); + this.label = menu.getMenuName(); + this.children = menu.getChildren().stream().map(AddTreeSelect::new).collect(Collectors.toList()); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +}