diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java new file mode 100644 index 0000000..7360078 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/contants/TaskContant.java @@ -0,0 +1,19 @@ +package com.ningdatech.pmapi.scheduler.contants; + +import java.math.BigDecimal; + +/** + * @author PoffyZhang + * @Classname TaskContant + * @Description + * @Date 2023/1/18 11:00 + */ +public interface TaskContant { + class Host { + public static final String HOST_ZPF = "LAPTOP-NQGEQP03"; + public static final String HOST_CMM2 = "DESKTOP-KN1L6HL"; + public static final String HOST_CMM = "LAPTOP-PCISPN2O"; + + public static final String HOST_207 = "iZbp13nwyvib53j4j1p2xoZ"; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java new file mode 100644 index 0000000..bda6402 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java @@ -0,0 +1,58 @@ +package com.ningdatech.pmapi.scheduler.task; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.StopWatch; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.pmapi.scheduler.contants.TaskContant; +import com.ningdatech.pmapi.sys.contants.RegionContant; +import com.ningdatech.pmapi.sys.entity.Region; +import com.ningdatech.pmapi.sys.service.IRegionService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; + +/** + * @author ZPF + * @description + * @since 2023/1/18 08:54 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class InitProcessTask { + + private final IRegionService regionService; + + // 定时更新车辆状态 + @Scheduled(cron = "0 52 15 18 1 ?") + public void doTask() throws UnknownHostException { + if (TaskContant.Host.HOST_ZPF.equals(InetAddress.getLocalHost().getHostName())) { + log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务开始"); + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + //1.查出丽水市下的 区县 分别去初始化 表单和流程配置数据 + List regions = regionService.list(Wrappers.lambdaQuery(Region.class) + .eq(Region::getDeleted,Boolean.FALSE) + .eq(Region::getParentCode, RegionContant.LS_REGION_CODE)); + + if(CollUtil.isEmpty(regions)){ + throw new BizException("丽水地区数据为空 任务结束!"); + } + + //2.首先插入表单默认配置 + for(Region region : regions){ + log.info("当前初始化的是 【{}】",region.getName()); + + } + + stopWatch.stop(); + log.info("=========== 更新车辆在线状态 ======== 任务结束 {}s",stopWatch.getTotalTimeSeconds()); + } + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java new file mode 100644 index 0000000..ef900c6 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.sys.contants; + +/** + * @Classname RegionContant + * @Description + * @Date 2023/1/18 9:37 + * @Created by PoffyZhang + */ +public interface RegionContant { + + public static final Integer FIRST_LEVEL = 1; + + public static final Integer SECOND_LEVEL = 2; + + public static final Integer THIRD_LEVEL = 3; + + public static final Long EMPTY_PARENT_ID = 0L; + //丽水地区CODE + public static final String LS_REGION_CODE = "331100"; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysFormController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysFormController.java new file mode 100644 index 0000000..e0cc4c2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysFormController.java @@ -0,0 +1,10 @@ +package com.ningdatech.pmapi.sys.controller; + +/** + * @Classname SysProcdefController + * @Description + * @Date 2023/1/18 14:28 + * @Author PoffyZhang + */ +public class SysFormController { +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcdefController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcdefController.java new file mode 100644 index 0000000..05284fd --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcdefController.java @@ -0,0 +1,39 @@ +package com.ningdatech.pmapi.sys.controller; + +import com.ningdatech.basic.model.PageVo; +import com.wflow.bean.vo.OrgProcdefVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Classname SysProcdefController + * @Description + * @Date 2023/1/18 14:28 + * @Author PoffyZhang + */ +@Slf4j +@Validated +@RestController +@RequestMapping("/api/v1/sys/procdef") +@Api(value = "SysProcdef", tags = "系统管理-流程配置") +@RequiredArgsConstructor +public class SysProcdefController { + +// private final + + @ApiOperation(value = "系统流程配置列表", notes = "系统流程配置列表") + @GetMapping("/list") + public PageVo list(@RequestParam String regionCode, @RequestParam(defaultValue = "1") Integer pageNum, + @RequestParam(defaultValue = "10") Integer pageSize) { +// return orgProcdefService.getOrgProcessByOrgCode(orgCode,pageNum,pageSize); + return PageVo.empty(); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/convert/RegionConverter.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/convert/RegionConverter.java new file mode 100644 index 0000000..57f0692 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/convert/RegionConverter.java @@ -0,0 +1,86 @@ +package com.ningdatech.pmapi.sys.convert; + +import cn.hutool.core.util.ObjectUtil; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.sys.entity.Region; +import com.ningdatech.pmapi.sys.entity.dto.RegionDTO; +import com.ningdatech.pmapi.sys.entity.dto.RegionTreeDTO; +import com.ningdatech.pmapi.sys.entity.vo.RegionTreeVO; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + *

+ * RegionConverter + *

+ * + * @author WendyYang + * @since 10:31 2022/10/12 + */ +public class RegionConverter { + + public static RegionDTO toRegionDTO(Region region) { + RegionDTO dto = new RegionDTO(); + dto.setRegionLevel(region.getRegionLevel()); + dto.setRegionName(region.getName()); + dto.setParentCode(region.getParentCode()); + dto.setRegionCode(region.getRegionCode()); + dto.setId(region.getId()); + dto.setDeleted(region.getDeleted()); + dto.setGovUnit(region.getGovUnit()); + dto.setParentId(region.getParentId()); + dto.unionCode(); + return dto; + } + + public static List toRegionTreeDTOList(List regionDTOList) { + if (CollectionUtils.isEmpty(regionDTOList)) { + return new ArrayList<>(); + } + return regionDTOList.stream().map(RegionConverter::toRegionTreeDTO).collect(Collectors.toList()); + } + + public static RegionTreeDTO toRegionTreeDTO(RegionDTO regionDTO) { + RegionTreeDTO treeDto = new RegionTreeDTO(); + treeDto.setLevel(regionDTO.getRegionLevel()); + treeDto.setName(regionDTO.getRegionName()); + treeDto.setParentCode(regionDTO.getParentCode()); + treeDto.setRegionCode(regionDTO.getRegionCode()); + treeDto.setUnionCode(regionDTO.getUnionCode()); + treeDto.setId(regionDTO.getId()); + treeDto.setDeleted(regionDTO.getDeleted()); + treeDto.setGovUnit(regionDTO.getGovUnit()); + return treeDto; + } + + public static List toRegionTree(Long parentId, Map> regions, + boolean showDeleted) { + List treeList = new ArrayList<>(); + List children = regions.getOrDefault(parentId, Collections.emptyList()); + for (RegionDTO region : children) { + if (!showDeleted && region.getDeleted()) { + continue; + } + RegionTreeVO treeNode = new RegionTreeVO(); + treeNode.setRegionLevel(region.getRegionLevel()); + treeNode.setName(region.getRegionName()); + treeNode.setParentCode(region.getParentCode()); + treeNode.setRegionCode(region.getRegionCode()); + List regionList = regions.get(region.getId()); + if (CollectionUtils.isNotEmpty(regionList)) { + treeNode.setChildren(toRegionTree(region.getId(), regions, showDeleted)); + } + treeNode.setId(region.getId()); + treeNode.setUnionCode(region.getUnionCode()); + treeNode.setGovUnit(region.getGovUnit()); + treeList.add(treeNode); + } + return treeList; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Region.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Region.java new file mode 100644 index 0000000..b9c55b1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Region.java @@ -0,0 +1,46 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * Region - 地域实体 + *

+ * + * @author WendyYang + * @since 10:33 2022/10/12 + */ +@Data +@TableName("nd_region") +public class Region implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + private String regionCode; + + private String name; + + private Integer regionLevel; + + private String govUnit; + + private String parentCode; + + private Long parentId; + + private LocalDateTime createOn; + + private LocalDateTime updateOn; + + private Boolean deleted; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RegionDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RegionDTO.java new file mode 100644 index 0000000..e3f2db8 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RegionDTO.java @@ -0,0 +1,56 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.experimental.Tolerate; + +/** + * @author liuxinxin + * @date 2022/7/22 上午9:12 + */ +@Data +@Builder +public class RegionDTO { + + @Tolerate + public RegionDTO() { + } + + /** + * 区域码 + */ + private String regionCode; + + /** + * 地区名 + */ + private String regionName; + + /** + * 地区级别 + */ + private Integer regionLevel; + + /** + * 地区父级code 当parent_code 为 -1 时为顶级区域 + */ + private String parentCode; + + /** + * 唯一编码:regionCode##regionName##regionLevel + */ + private String unionCode; + + private Long id; + + private Boolean deleted; + + private String govUnit; + + private Long parentId; + + public void unionCode() { + this.unionCode = String.format("%s##%s##%s", this.regionCode, this.regionName, this.regionLevel); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RegionTreeDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RegionTreeDTO.java new file mode 100644 index 0000000..c120ff8 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RegionTreeDTO.java @@ -0,0 +1,46 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @author liuxinxin + * @date 2022/7/22 上午9:08 + */ +@Data +public class RegionTreeDTO { + + /** + * 区域码 + */ + private String regionCode; + + /** + * 地区名 + */ + private String name; + + /** + * 地区级别 + */ + private Integer level; + + /** + * 地区父级code 当parent_code 为 -1 时为顶级区域 + */ + private String parentCode; + + private String unionCode; + + private List children; + + private Long id; + + private String mapData; + + private Boolean deleted; + + private String govUnit; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/RegionTreeVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/RegionTreeVO.java new file mode 100644 index 0000000..cc06d5f --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/RegionTreeVO.java @@ -0,0 +1,53 @@ +package com.ningdatech.pmapi.sys.entity.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + *

+ * RegionTreeVO + *

+ * + * @author WendyYang + * @since 10:35 2022/10/12 + */ +@Data +@ToString(callSuper = true) +@ApiModel(value = "RegionTreeVO", description = "区域树状结构VO") +public class RegionTreeVO { + + private Long id; + + @ApiModelProperty("区域码") + @NotBlank(message = "地区编码不能为空") + private String regionCode; + + @ApiModelProperty("地区名") + @NotBlank(message = "地区名称不能为空") + private String name; + + @ApiModelProperty("级别") + @NotNull(message = "级别不能为空") + private Integer regionLevel; + + @ApiModelProperty("区域级别") + @NotBlank(message = "区域级别不能为空") + private String govUnit; + + @ApiModelProperty("地区父级编码:-1为顶级区域") + @NotBlank(message = "地区父级编码不能为空") + private String parentCode; + + @ApiModelProperty("子区域") + private List children; + + @ApiModelProperty("唯一编码:regionCode##name##level") + private String unionCode; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RegionManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RegionManage.java new file mode 100644 index 0000000..3f5e946 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RegionManage.java @@ -0,0 +1,35 @@ +package com.ningdatech.pmapi.sys.manage; + +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.sys.convert.RegionConverter; +import com.ningdatech.pmapi.sys.entity.dto.RegionDTO; +import com.ningdatech.pmapi.sys.entity.vo.RegionTreeVO; +import com.ningdatech.pmapi.sys.service.IRegionService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; + +/** + *

+ * RegionManage + *

+ * + * @author ZPF + * @since 10:39 2023/1/18 + */ +@Component +@RequiredArgsConstructor +public class RegionManage { + + private final IRegionService regionService; + + private final static Long ROOT_PARENT_ID = 1L; + + public List getRegionTree() { + List regions = regionService.queryAll(); + Map> regionMap = CollUtils.group(regions, RegionDTO::getParentId); + return RegionConverter.toRegionTree(ROOT_PARENT_ID, regionMap, false); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RegionMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RegionMapper.java new file mode 100644 index 0000000..ff3bc43 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RegionMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.entity.Region; + +/** + *

+ * Mapper 接口 + *

+ * + * @author ZPF + * @since 2023-1-18 + */ +public interface RegionMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RegionMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RegionMapper.xml new file mode 100644 index 0000000..074d142 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RegionMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRegionService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRegionService.java new file mode 100644 index 0000000..62d493e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRegionService.java @@ -0,0 +1,51 @@ +package com.ningdatech.pmapi.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.sys.entity.Region; +import com.ningdatech.pmapi.sys.entity.dto.RegionDTO; + +import java.util.List; + +/** + *

+ * 地域管理 服务类 + *

+ * + * @author zpf + * @since 2023-1-18 + */ +public interface IRegionService extends IService { + + /** + * 查询所有区域 + * + * @return 所有区域 + */ + List queryAll(); + + /** + * 查询大于等与该级别的所有区域 + * + * @param regionLevel + * @return 区域集合 + */ + List listGeLevel(int regionLevel); + + /** + * 是否为父节点 + * + * @param regionId 区域ID + * @return boolean + **/ + boolean isParentRegion(Long regionId); + + /** + * 获取当前区域的本级 + * + * @param parentId 区域ID + * @param regionCode 区域code + * @return 区域ID + **/ + Long getRegionIdByParentIdWithSameRegionCode(Long parentId, String regionCode); + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RegionServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RegionServiceImpl.java new file mode 100644 index 0000000..8b81fb5 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RegionServiceImpl.java @@ -0,0 +1,56 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.sys.convert.RegionConverter; +import com.ningdatech.pmapi.sys.entity.Region; +import com.ningdatech.pmapi.sys.entity.dto.RegionDTO; +import com.ningdatech.pmapi.sys.mapper.RegionMapper; +import com.ningdatech.pmapi.sys.service.IRegionService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author zpf + * @since 2023-1-18 + */ +@Service +public class RegionServiceImpl extends ServiceImpl implements IRegionService { + + @Override + public List queryAll() { + List allRegions = this.lambdaQuery().ne(Region::getId, -1).list(); + return CollUtils.convert(allRegions, RegionConverter::toRegionDTO); + } + + @Override + public List listGeLevel(int regionLevel) { + List regionsByLevel = lambdaQuery().ne(Region::getId, -1) + .le(Region::getRegionLevel, regionLevel).list(); + return CollUtils.convert(regionsByLevel, RegionConverter::toRegionDTO); + } + + @Override + public boolean isParentRegion(Long regionId) { + return baseMapper.exists(Wrappers.lambdaQuery(Region.class) + .eq(Region::getParentId, regionId) + .eq(Region::getDeleted, false)); + } + + @Override + public Long getRegionIdByParentIdWithSameRegionCode(Long parentId, String regionCode) { + return baseMapper.selectOne(Wrappers.lambdaQuery(Region.class) + .eq(Region::getParentId, parentId) + .eq(Region::getRegionCode, regionCode) + .eq(Region::getDeleted, false)) + .getId(); + } + + +}