Commit e00c6397 authored by fangxinjiang's avatar fangxinjiang

B端服务添加:字典区域调整

parent 73700e94
package com.yifu.cloud.plus.v1.business.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @description: 前端要求返回结构
* @author: hgw
* @create: 2021-8-12 17:02:43
**/
@Data
public class BusFileVo implements Serializable {
private String uid;
private String name;
private String status;
private String url;
protected String type;
public BusFileVo(String uid, String name, String url) {
this.uid = uid;
this.name = name;
this.status = "done";
this.url = url;
}
}
package com.yifu.cloud.plus.v1.business.controller.system;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.business.entity.system.SysBusDict;
import com.yifu.cloud.plus.v1.business.service.system.SysBusDictService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map;
/**
* @author fxj
* @date 2021-08-18 14:51:15
*/
@RestController
@AllArgsConstructor
@RequestMapping("/sysbusdict")
@Tag(name = "B端字典数据表")
public class SysBusDictController {
private final SysBusDictService sysBusDictService;
/**
* 简单分页查询
*
* @param page 分页对象
* @param sysBusDict
* @return
*/
@Operation(description = "简单分页查询")
@GetMapping("/page")
public R<IPage<SysBusDict>> getSysBusDictPage(Page<SysBusDict> page, SysBusDict sysBusDict) {
return new R<>(sysBusDictService.getSysBusDictPage(page, sysBusDict));
}
/**
* 通过id查询单条记录
*
* @param id
* @return R
*/
@Operation(description = "id查询")
@GetMapping("/{id}")
public R<SysBusDict> getById(@PathVariable("id") String id) {
return new R<>(sysBusDictService.getById(id));
}
/**
* 新增记录
*
* @param sysBusDict
* @return R
*/
@Operation(description = "新增(yifu-hro-business:sysbusdict_add)")
@PostMapping
@PreAuthorize("@pms.hasPermission('yifu-hro-business:sysbusdict_add')")
public R<Boolean> save(@Valid @RequestBody SysBusDict sysBusDict) {
return new R<>(sysBusDictService.save(sysBusDict));
}
/**
* 修改记录
*
* @param sysBusDict
* @return R
*/
@Operation(description = "修改(yifu-hro-business:sysbusdict_edit)")
@SysLog("修改")
@PutMapping
@PreAuthorize("@pms.hasPermission('yifu-hro-business:sysbusdict_edit')")
public R<Boolean> update(@RequestBody SysBusDict sysBusDict) {
return new R<>(sysBusDictService.updateById(sysBusDict));
}
/**
* 通过id删除一条记录
*
* @param id
* @return R
*/
@Operation(description = "删除(yifu-hro-business:sysbusdict_del)")
@SysLog("删除")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('yifu-hro-business:sysbusdict_del')")
public R<Boolean> removeById(@PathVariable String id) {
return new R<>(sysBusDictService.removeById(id));
}
/**
* 获取字典map
* @param type type:0(key=value value=label) 1(key=lable value=value)
* @date 2021-08-24
* @author fxj
* @return
*/
@Operation(description = "B端字典表:返回 map 参数:type:0(key=value value=label) 1(key=lable value=value)")
@GetMapping("/getBusiDicMap")
public R<Map<String,String>> getBusiDicMap(@RequestParam(value = "type", required = true)String type,
@RequestParam(value = "itemType", required = true)String itemType) {
return sysBusDictService.getBusiDicMap(type,itemType);
}
}
package com.yifu.cloud.plus.v1.business.controller.system;
import com.yifu.cloud.plus.v1.business.entity.system.TBusAttaInfo;
import com.yifu.cloud.plus.v1.business.service.system.TBusAttaInfoService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* B端附件表
*
* @author hgw
* @date 2021-08-12 16:38:51
*/
@RestController
@AllArgsConstructor
@RequestMapping("/tbusattainfo")
@Tag(name = "B端附件表")
public class TBusAttaInfoController {
private final TBusAttaInfoService tBusAttaInfoService;
/**
* 获取附件list,一般传参relationId即可
*
* @param tBusAttaInfo B端附件表
* @return
*/
@Operation(description = "获取附件list,一般传参relationId即可")
@GetMapping("/getBusAttaList")
public R<List<TBusAttaInfo>> getBusAttaList(TBusAttaInfo tBusAttaInfo) {
return new R<>(tBusAttaInfoService.getBusAttaList(tBusAttaInfo));
}
/**
* 通过id查询单条记录
*
* @param id
* @return R
*/
@Operation(description = "id查询")
@GetMapping("/{id}")
public R<TBusAttaInfo> getById(@PathVariable("id") String id) {
return new R<>(tBusAttaInfoService.getUrlByid(id));
}
}
package com.yifu.cloud.plus.v1.business.mapper.system;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.business.entity.system.SysBusDict;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @author fxj
* @date 2021-08-18 14:51:15
*/
@Mapper
public interface SysBusDictMapper extends BaseMapper<SysBusDict> {
/**
* 简单分页查询
*
* @param sysBusDict
* @return
*/
IPage<SysBusDict> getSysBusDictPage(Page<SysBusDict> page, @Param("sysBusDict") SysBusDict sysBusDict);
}
package com.yifu.cloud.plus.v1.business.mapper.system;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.business.entity.system.TBusAttaInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* B端附件表
*
* @author hgw
* @date 2021-08-12 16:38:51
*/
@Mapper
public interface TBusAttaInfoMapper extends BaseMapper<TBusAttaInfo> {
/**
* B端附件表简单分页查询
*
* @param tBusAttaInfo B端附件表
* @return
*/
List<TBusAttaInfo> getBusAttaList(@Param("tBusAttaInfo") TBusAttaInfo tBusAttaInfo);
}
package com.yifu.cloud.plus.v1.business.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.business.entity.system.SysBusDict;
import com.yifu.cloud.plus.v1.business.mapper.system.SysBusDictMapper;
import com.yifu.cloud.plus.v1.business.service.system.SysBusDictService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author fxj
* @date 2021-08-18 14:51:15
*/
@Service
public class SysBusDictServiceImpl extends ServiceImpl<SysBusDictMapper, SysBusDict> implements SysBusDictService {
/**
* 简单分页查询
*
* @param sysBusDict
* @return
*/
@Override
public IPage<SysBusDict> getSysBusDictPage(Page<SysBusDict> page, SysBusDict sysBusDict) {
return baseMapper.getSysBusDictPage(page, sysBusDict);
}
/**
* 获取字典的MAP 数据
* @param itemType
* @param type 0 key = value 1 key = label
* @return
*/
@Override
public Map<String, SysBusDict> getSysBusDictByItemType(String itemType, String type) {
Map<String, SysBusDict> busDictMap = new HashMap<>();
List<SysBusDict> dicts = baseMapper.selectList(Wrappers.<SysBusDict>query()
.lambda().eq(SysBusDict::getItemType,itemType));
if (Common.isNotNull(dicts)){
for (SysBusDict dict:dicts){
if (CommonConstants.ZERO_STRING.equals(type)){
busDictMap.put(dict.getValue(),dict);
}else if (CommonConstants.ONE_STRING.equals(type)){
busDictMap.put(dict.getLabel(),dict);
}
}
}
return busDictMap;
}
@Override
public R<Map<String, String>> getBusiDicMap(String type, String itemType) {
Map<String, String> dictMap = new HashMap<>();
List<SysBusDict> dicts = baseMapper.selectList(Wrappers.<SysBusDict>query()
.lambda().eq(SysBusDict::getItemType,itemType));
if (Common.isNotNull(dicts)){
for (SysBusDict dict:dicts){
if (CommonConstants.ZERO_STRING.equals(type)){
dictMap.put(dict.getValue(),dict.getLabel());
}else if (CommonConstants.ONE_STRING.equals(type)){
dictMap.put(dict.getLabel(),dict.getValue());
}
}
}
return R.ok(dictMap,CommonConstants.RESULT_DATA_SUCESS);
}
}
package com.yifu.cloud.plus.v1.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.business.entity.system.TBusAttaInfo;
import com.yifu.cloud.plus.v1.business.mapper.system.TBusAttaInfoMapper;
import com.yifu.cloud.plus.v1.business.service.system.TBusAttaInfoService;
import com.yifu.cloud.plus.v1.business.vo.BusFileVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.List;
/**
* B端附件表
*
* @author hgw
* @date 2021-08-12 16:38:51
*/
@Slf4j
@Service
public class TBusAttaInfoServiceImpl extends ServiceImpl<TBusAttaInfoMapper, TBusAttaInfo> implements TBusAttaInfoService {
@Autowired
private OSSUtil ossUtil;
/**
* B端附件表简单分页查询
*
* @param tBusAttaInfo B端附件表
* @return list,含url
*/
@Override
public List<TBusAttaInfo> getBusAttaList(TBusAttaInfo tBusAttaInfo) {
List<TBusAttaInfo> list = baseMapper.getBusAttaList(tBusAttaInfo);
if (list != null && !list.isEmpty()) {
for (TBusAttaInfo info : list) {
this.setOssSrc(info);
}
}
return list;
}
@Override
public R<BusFileVo> uploadFile(@RequestBody MultipartFile file, String filePath, Integer type, String domain) throws IOException {
if (null == file) {
return R.failed("文件异常,请重新上传!");
}
String fileName = file.getOriginalFilename();
if (Common.isEmpty(fileName)) {
return R.failed("文件名不能为空!");
}
if (fileName.length() > 50) {
return R.failed("文件名不能超过50个字符!");
}
//filePath不传默认存储空间的根目录
//jpg,jpeg,png,bmp
String key;
if (Common.isNotNull(filePath)) {
key = filePath + "/" + System.currentTimeMillis() + fileName;
} else {
key = System.currentTimeMillis() + fileName;
}
if (!Common.checkFile(key)) {
return R.failed("非法上传类型!");
}
boolean flag = ossUtil.uploadFileByStream(file.getInputStream(), key, null);
BusFileVo fileVo;
TBusAttaInfo busAtta;
URL url;
if (flag) {
log.info("文件:" + fileName + "上传至存储空间" + ossUtil.getBucketName() + "成功!");
if (null != type) {
busAtta = this.initTBusAttaInfo(fileName, key, file.getSize(), type, domain);
try {
this.save(busAtta);
} catch (Exception e) {
log.error("上传保存文件失败:" + e.getMessage());
ossUtil.deleteObject(null, key);
return R.failed("上传保存文件失败:" + e.getMessage());
}
url = ossUtil.getObjectUrl(null, busAtta.getAttaSrc());
fileVo = new BusFileVo(busAtta.getId(), busAtta.getAttaName(), url.toString().replace("http","https"));
return R.ok(fileVo, "success");
} else {
return R.failed("类型不可为空!");
}
} else {
return R.failed("fail:上传失败");
}
}
/**
* @Description: 初始化附件表
* @Author: hgw
* @Date: 2021/8/12 17:52
* @return: com.yifu.cloud.v1.hrobusiness.api.entity.system.TBusAttaInfo
**/
private TBusAttaInfo initTBusAttaInfo(String fileName, String key, Long fileSize
, Integer type, String domain) {
YifuUser user = SecurityUtils.getUser();
TBusAttaInfo empAtta = new TBusAttaInfo();
if (user == null || Common.isEmpty(user.getId())) {
return empAtta;
}
char point = '.';
char slash = '/';
if (fileName.lastIndexOf(slash) >= 0) {
empAtta.setAttaName(fileName.substring(fileName.lastIndexOf(slash)));
} else {
empAtta.setAttaName(fileName);
}
if (key.lastIndexOf(point) >= 0) {
empAtta.setAttaType(key.substring(key.lastIndexOf(point)));
}
empAtta.setAttaSize(fileSize);
empAtta.setAttaSrc(key);
empAtta.setCreateTime(LocalDateTime.now());
empAtta.setCreateUserId(String.valueOf(user.getId()));
empAtta.setCreateUserName(user.getNickname());
empAtta.setRelationType(type);
empAtta.setRelationId(domain);
return empAtta;
}
/**
* @param id
* @Description: 单个查询url
* @Author: hgw
* @Date: 2021/8/20 14:37
* @return: com.yifu.cloud.v1.hrobusiness.api.entity.system.TBusAttaInfo
**/
@Override
public TBusAttaInfo getUrlByid(String id) {
TBusAttaInfo busAtta = this.getById(id);
if (null != busAtta) {
this.setOssSrc(busAtta);
}
return busAtta;
}
/**
* @param busAtta
* @Description: 获取附件的阿里云地址
* @Author: hgw
* @Date: 2021/8/20 14:36
* @return: void
**/
private void setOssSrc(TBusAttaInfo busAtta) {
URL url = ossUtil.getObjectUrl(null, busAtta.getAttaSrc());
busAtta.setAttaSrc(url.toString().replace("http","https"));
}
}
package com.yifu.cloud.plus.v1.business.service.system;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.business.entity.system.SysBusDict;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import java.util.Map;
/**
* @author fxj
* @date 2021-08-18 14:51:15
*/
public interface SysBusDictService extends IService<SysBusDict> {
/**
* 简单分页查询
*
* @param sysBusDict
* @return
*/
IPage<SysBusDict> getSysBusDictPage(Page<SysBusDict> page, SysBusDict sysBusDict);
/**
* 获取B端字典数据Map
* @param itemType
* @param type 0 key = value 1 key = label
* @return
*/
Map<String, SysBusDict> getSysBusDictByItemType(String itemType,String type);
R<Map<String, String>> getBusiDicMap(String type, String itemType);
}
package com.yifu.cloud.plus.v1.business.service.system;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.business.entity.system.TBusAttaInfo;
import com.yifu.cloud.plus.v1.business.vo.BusFileVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
* B端附件表
*
* @author hgw
* @date 2021-08-12 16:38:51
*/
public interface TBusAttaInfoService extends IService<TBusAttaInfo> {
/**
* @param tBusAttaInfo B端附件表
* @return list ,返回url
*/
List<TBusAttaInfo> getBusAttaList(TBusAttaInfo tBusAttaInfo);
/**
* @param file
* @param filePath
* @param type
* @param domain
* @Description: 附件上传
* @Author: hgw
* @Date: 2021/8/19 9:16
* @return: com.yifu.cloud.v1.common.core.util.R<com.yifu.cloud.v1.hrobusiness.api.dto.system.BusFileVo>
**/
R<BusFileVo> uploadFile(MultipartFile file, String filePath, Integer type, String domain) throws IOException;
/**
* @param id
* @Description: 单个查询,返回url
* @Author: hgw
* @Date: 2021/8/20 14:38
* @return: com.yifu.cloud.v1.hrobusiness.api.entity.system.TBusAttaInfo
**/
TBusAttaInfo getUrlByid(String id);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.business.mapper.system.SysBusDictMapper">
<resultMap id="sysBusDictMap" type="com.yifu.cloud.plus.v1.business.entity.system.SysBusDict">
<id property="id" column="id"/>
<result property="label" column="label"/>
<result property="value" column="value"/>
<result property="itemType" column="item_type"/>
<result property="status" column="status"/>
</resultMap>
<sql id="Base_Column_List">
a.id,
a.label,
a.value,
a.item_type,
a.status
</sql>
<sql id="sysBusDict_where">
<if test="sysBusDict != null">
<if test="sysBusDict.id != null and sysBusDict.id.trim() != ''">
AND a.id = #{sysBusDict.id}
</if>
<if test="sysBusDict.label != null and sysBusDict.label.trim() != ''">
AND a.label = #{sysBusDict.label}
</if>
<if test="sysBusDict.value != null and sysBusDict.value.trim() != ''">
AND a.value = #{sysBusDict.value}
</if>
<if test="sysBusDict.itemType != null and sysBusDict.itemType.trim() != ''">
AND a.item_type = #{sysBusDict.itemType}
</if>
<if test="sysBusDict.status != null and sysBusDict.status.trim() != ''">
AND a.status = #{sysBusDict.status}
</if>
</if>
</sql>
<!--sysBusDict简单分页查询-->
<select id="getSysBusDictPage" resultMap="sysBusDictMap">
SELECT
<include refid="Base_Column_List"/>
FROM sys_bus_dict a
<where>
1=1
<include refid="sysBusDict_where"/>
</where>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yifu.cloud.plus.v1.business.mapper.system.TBusAttaInfoMapper">
<resultMap id="tBusAttaInfoMap" type="com.yifu.cloud.plus.v1.business.entity.system.TBusAttaInfo">
<id property="id" column="id"/>
<result property="attaName" column="atta_name"/>
<result property="attaSrc" column="atta_src"/>
<result property="attaSize" column="atta_size"/>
<result property="attaType" column="atta_type"/>
<result property="createUserId" column="create_user_id"/>
<result property="createUserName" column="create_user_name"/>
<result property="createTime" column="create_time"/>
<result property="relationId" column="relation_id"/>
<result property="relationType" column="relation_type"/>
</resultMap>
<sql id="Base_Column_List">
a.id,
a.atta_name,
a.atta_src,
a.atta_size,
a.atta_type,
a.create_user_id,
a.create_user_name,
a.create_time,
a.relation_id,
a.relation_type
</sql>
<sql id="tBusAttaInfo_where">
<if test="tBusAttaInfo != null">
<if test="tBusAttaInfo.id != null and tBusAttaInfo.id.trim() != ''">
AND a.id = #{tBusAttaInfo.id}
</if>
<if test="tBusAttaInfo.attaName != null and tBusAttaInfo.attaName.trim() != ''">
AND a.atta_name = #{tBusAttaInfo.attaName}
</if>
<if test="tBusAttaInfo.attaSrc != null and tBusAttaInfo.attaSrc.trim() != ''">
AND a.atta_src = #{tBusAttaInfo.attaSrc}
</if>
<if test="tBusAttaInfo.attaSize != null">
AND a.atta_size = #{tBusAttaInfo.attaSize}
</if>
<if test="tBusAttaInfo.attaType != null and tBusAttaInfo.attaType.trim() != ''">
AND a.atta_type = #{tBusAttaInfo.attaType}
</if>
<if test="tBusAttaInfo.createUserId != null and tBusAttaInfo.createUserId.trim() != ''">
AND a.create_user_id = #{tBusAttaInfo.createUserId}
</if>
<if test="tBusAttaInfo.createUserName != null and tBusAttaInfo.createUserName.trim() != ''">
AND a.create_user_name = #{tBusAttaInfo.createUserName}
</if>
<if test="tBusAttaInfo.createTime != null">
AND a.create_time = #{tBusAttaInfo.createTime}
</if>
<if test="tBusAttaInfo.relationId != null and tBusAttaInfo.relationId.trim() != ''">
AND a.relation_id = #{tBusAttaInfo.relationId}
</if>
<if test="tBusAttaInfo.relationType != null and tBusAttaInfo.relationType.trim() != ''">
AND a.relation_type = #{tBusAttaInfo.relationType}
</if>
</if>
</sql>
<!--list-->
<select id="getBusAttaList" resultMap="tBusAttaInfoMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_bus_atta_info a
<where>
1=1
<include refid="tBusAttaInfo_where"/>
</where>
</select>
</mapper>
...@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; ...@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -14,7 +15,7 @@ import java.time.LocalDateTime; ...@@ -14,7 +15,7 @@ import java.time.LocalDateTime;
*/ */
@Data @Data
@Schema(description ="区域") @Schema(description ="区域")
public class SysArea { public class SysArea implements Serializable {
private Integer id; private Integer id;
......
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.yifu.cloud.plus.v1.yifu.admin.api.vo; package com.yifu.cloud.plus.v1.yifu.admin.api.vo;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea; import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/**
* @author lengleng
* @date 2020/2/10
*/
@Data @Data
@Schema(description = "区域Vo") @EqualsAndHashCode(callSuper = true)
public class AreaVo { public class AreaVo extends SysArea {
private static final long serialVersionUID = 1L;
private Integer id;
private String areaName;
private String areaCode;
private Integer parentId;
private LocalDateTime updateDate;
private Integer status;
private Integer createUser;
/**
*车牌简称
*/
private String areaShort;
private List<AreaVo> children;
/**
* 角色id
*/
private List<SysArea> sysAreaList; private List<SysArea> sysAreaList;
} }
...@@ -27,17 +27,15 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.Common; ...@@ -27,17 +27,15 @@ import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil; import com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner; import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
...@@ -156,5 +154,41 @@ public class AreaController { ...@@ -156,5 +154,41 @@ public class AreaController {
redisUtil.set(CacheConstants.AREA_VALUE_GROUP,labelIdMap); redisUtil.set(CacheConstants.AREA_VALUE_GROUP,labelIdMap);
} }
} }
/**
* @Author fxj
* @Description 地区map
* @Date 14:56 2023/1/4
* @Param
* @return
**/
@Operation(description = "地区map")
@GetMapping("/getAreaMap")
public R<Map<Integer,SysArea>> getAreaMapUpms() {
return new R<>(sysAreaService.getSysAreaMap());
}
/**
* @Author fxj
* @Description 区划树形结构
* @Date 15:09 2023/1/4
* @Param
* @return
**/
@Operation(description = "区划树形结构")
@GetMapping("/tree")
public R getTree() {
return new R<>(sysAreaService.getAreaTree());
}
/**
* 通过id查询单条记录
*
* @param id
* @return R
*/
@Operation(description = "id查询")
@GetMapping("/{id}")
public R<SysArea> getById(@PathVariable("id") Integer id) {
return new R<>(sysAreaService.getById(id));
}
} }
...@@ -18,8 +18,11 @@ package com.yifu.cloud.plus.v1.yifu.admin.mapper; ...@@ -18,8 +18,11 @@ package com.yifu.cloud.plus.v1.yifu.admin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea; import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.AreaVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* <p> * <p>
* 区域表 Mapper 接口 * 区域表 Mapper 接口
...@@ -31,4 +34,5 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -31,4 +34,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SysAreaMapper extends BaseMapper<SysArea> { public interface SysAreaMapper extends BaseMapper<SysArea> {
List<AreaVo> getVoArea();
} }
...@@ -17,6 +17,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.service; ...@@ -17,6 +17,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea; import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.AreaVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import java.util.List; import java.util.List;
...@@ -49,4 +50,7 @@ public interface SysAreaService extends IService<SysArea> { ...@@ -49,4 +50,7 @@ public interface SysAreaService extends IService<SysArea> {
List<SysArea> getAllArea(); List<SysArea> getAllArea();
Map<Integer,SysArea> getSysAreaMap();
List<AreaVo> getAreaTree();
} }
...@@ -18,13 +18,17 @@ package com.yifu.cloud.plus.v1.yifu.admin.service.impl; ...@@ -18,13 +18,17 @@ package com.yifu.cloud.plus.v1.yifu.admin.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea; import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysArea;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.AreaVo;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysAreaMapper; import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysAreaMapper;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysAreaService; import com.yifu.cloud.plus.v1.yifu.admin.service.SysAreaService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ServiceNameConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common; import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -80,5 +84,70 @@ public class SysAreaServiceImpl extends ServiceImpl<SysAreaMapper, SysArea> impl ...@@ -80,5 +84,70 @@ public class SysAreaServiceImpl extends ServiceImpl<SysAreaMapper, SysArea> impl
} }
} }
} }
@Override
@Cacheable(value = ServiceNameConstants.UMPS_SERVICE + "_permanent", key = "#root.targetClass+#root.methodName")
public Map<Integer,SysArea> getSysAreaMap() {
List<SysArea> list = this.list();
Map<Integer,SysArea> sysAreaMap = null;
if(Common.isNotNull(list)){
sysAreaMap = new HashMap();
for(SysArea area : list){
sysAreaMap.put(area.getId(),area);
}
}
return sysAreaMap;
}
@Override
@Cacheable(value = ServiceNameConstants.UMPS_SERVICE + "_permanent", key = "#root.targetClass+#root.methodName")
public List<AreaVo> getAreaTree() {
List<AreaVo> pArea = new ArrayList<>();
List<AreaVo> list = baseMapper.getVoArea();
if (Common.isNotNull(list)) {
List<AreaVo> tArea = new ArrayList<>();
Map<Integer, AreaVo> pMap = new HashMap<>();
Map<Integer, AreaVo> cAreaMap = new HashMap<>();
for (AreaVo area : list) {
if (CommonConstants.dingleDigitIntArray[0] == area.getParentId().intValue()) {
pArea.add(area);
pMap.put(area.getId(), area);
}
}
list.removeAll(pArea);
for (AreaVo area : list) {
if (null != pMap.get(area.getParentId())) {
cAreaMap.put(area.getId(), area);
} else {
tArea.add(area);
}
}
AreaVo tempArea = null;
List<AreaVo> tempList = null;
//所有县级节点挂到市级节点上
for (AreaVo area : tArea) {
tempArea = cAreaMap.get(area.getParentId());
tempList = tempArea.getChildren();
if (null == tempList) {
tempList = new ArrayList<>();
tempList.add(area);
tempArea.setChildren(tempList);
} else {
tempList.add(area);
}
}
for (AreaVo area : cAreaMap.values()) {
tempArea = pMap.get(area.getParentId());
tempList = tempArea.getChildren();
if (null == tempList) {
tempList = new ArrayList<>();
tempList.add(area);
tempArea.setChildren(tempList);
} else {
tempList.add(area);
}
}
}
return pArea;
}
} }
...@@ -33,5 +33,15 @@ ...@@ -33,5 +33,15 @@
<result property="createUser" column="CREATE_USER"/> <result property="createUser" column="CREATE_USER"/>
<result property="areaShort" column="AREA_SHORT"/> <result property="areaShort" column="AREA_SHORT"/>
</resultMap> </resultMap>
<select id="getVoArea" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.vo.AreaVo">
select id,
AREA_NAME,
AREA_CODE,
PARENT_ID,
UPDATE_DATE,
STATUS,
CREATE_USER,
AREA_SHORT
FROM sys_area
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment