1、调整IAM权限

2、新增常用地址模块
This commit is contained in:
2026-07-17 18:23:56 +08:00
parent 31c68a857a
commit f13963f5b8
18 changed files with 1445 additions and 4 deletions

View File

@@ -0,0 +1,209 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.transport.excel.CommonAddressExcel;
import org.springblade.transport.pojo.entity.CommonAddress;
import org.springblade.transport.pojo.vo.CommonAddressRemoveResultVO;
import org.springblade.transport.pojo.vo.CommonAddressVO;
import org.springblade.transport.service.ICommonAddressService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Objects;
/**
* 常用地址 控制器
*
* @author Chill
*/
@RestController
@AllArgsConstructor
@PreAuth(menu = "common_address")
@RequestMapping("/common-address")
@Tag(name = "常用地址", description = "常用地址")
public class CommonAddressController extends BladeController {
private static final int DEFAULT_CURRENT = 1;
private static final int DEFAULT_SIZE = 10;
private static final int MAX_SIZE = 100;
private static final String NORMAL_SITE_CODE = "/";
private final ICommonAddressService commonAddressService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "详情", description = "传入id")
public R<CommonAddressVO> detail(@Parameter(description = "主键", required = true) @RequestParam Long id) {
return R.data(commonAddressService.detail(id));
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "分页", description = "传入commonAddress")
public R<IPage<CommonAddressVO>> list(CommonAddressVO commonAddress, Query query) {
IPage<CommonAddressVO> pages = commonAddressService.selectCommonAddressPage(Condition.getPage(normalizeQuery(query)), commonAddress);
return R.data(pages);
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 3)
@Operation(summary = "新增或修改", description = "传入commonAddress")
public R submit(@RequestBody CommonAddress commonAddress) {
return R.status(commonAddressService.submit(commonAddress));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 4)
@Operation(summary = "逻辑删除", description = "传入ids")
public R<CommonAddressRemoveResultVO> remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
return R.data(commonAddressService.removeAddress(ids));
}
/**
* 来源地址选项
*/
@GetMapping("/source-options")
@ApiOperationSupport(order = 5)
@Operation(summary = "来源地址选项", description = "传入addressType和keyword")
public R<List<CommonAddressVO>> sourceOptions(@RequestParam String addressType,
@RequestParam(required = false) String keyword) {
return R.data(commonAddressService.sourceOptions(addressType, keyword));
}
/**
* 导出常用地址
*/
@GetMapping("/export-common-address")
@ApiOperationSupport(order = 6)
@Operation(summary = "导出常用地址")
public void exportCommonAddress(CommonAddressVO commonAddress,
@RequestParam(required = false) String ids,
HttpServletResponse response) {
List<CommonAddressExcel> list = commonAddressService.exportCommonAddress(buildExportQuery(commonAddress, ids));
ExcelUtil.export(response, "常用地址" + DateUtil.time(), "常用地址", list, CommonAddressExcel.class);
}
private Query normalizeQuery(Query query) {
if (query == null) {
query = new Query();
}
if (query.getCurrent() == null || query.getCurrent() < DEFAULT_CURRENT) {
query.setCurrent(DEFAULT_CURRENT);
}
if (query.getSize() == null || query.getSize() <= 0) {
query.setSize(DEFAULT_SIZE);
}
if (query.getSize() > MAX_SIZE) {
query.setSize(MAX_SIZE);
}
return query;
}
private LambdaQueryWrapper<CommonAddress> buildExportQuery(CommonAddressVO commonAddress, String ids) {
LambdaQueryWrapper<CommonAddress> queryWrapper = Wrappers.<CommonAddress>lambdaQuery()
.eq(CommonAddress::getIsDeleted, 0)
.orderByDesc(CommonAddress::getUpdateTime)
.orderByDesc(CommonAddress::getCreateTime);
if (Func.isNotEmpty(ids)) {
queryWrapper.in(CommonAddress::getId, Func.toLongList(ids));
}
if (Objects.equals(commonAddress.getAllDept(), 1)) {
if (!AuthUtil.isAdministrator()) {
throw new ServiceException("无权导出全部组织常用地址");
}
} else {
queryWrapper.eq(CommonAddress::getDeptId, currentDeptId());
}
if (Objects.equals(commonAddress.getAllDept(), 1) && Func.isNotEmpty(commonAddress.getDeptId())) {
queryWrapper.eq(CommonAddress::getDeptId, commonAddress.getDeptId());
}
if (Func.isNotEmpty(commonAddress.getAddressName())) {
queryWrapper.like(CommonAddress::getAddressName, commonAddress.getAddressName().trim());
}
if (Func.isNotEmpty(commonAddress.getAddressType())) {
queryWrapper.eq(CommonAddress::getAddressType, commonAddress.getAddressType().trim());
}
if (Func.isNotEmpty(commonAddress.getDetailAddress())) {
queryWrapper.like(CommonAddress::getDetailAddress, commonAddress.getDetailAddress().trim());
}
if (Func.isNotEmpty(commonAddress.getRegionName())) {
queryWrapper.like(CommonAddress::getRegionName, commonAddress.getRegionName().trim());
}
if (Func.isNotEmpty(commonAddress.getSiteCode()) && !NORMAL_SITE_CODE.equals(commonAddress.getSiteCode().trim())) {
queryWrapper.eq(CommonAddress::getSiteCode, commonAddress.getSiteCode().trim());
}
if (Func.isNotEmpty(commonAddress.getContactName())) {
queryWrapper.like(CommonAddress::getContactName, commonAddress.getContactName().trim());
}
if (Func.isNotEmpty(commonAddress.getContactPhone())) {
queryWrapper.like(CommonAddress::getContactPhone, commonAddress.getContactPhone().trim());
}
return queryWrapper;
}
private Long currentDeptId() {
Long deptId = Func.firstLong(AuthUtil.getDeptId());
if (Func.isEmpty(deptId) || deptId <= 0) {
throw new ServiceException("当前用户所属组织为空,无法导出常用地址");
}
return deptId;
}
}

View File

@@ -0,0 +1,96 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.excel;
import cn.idev.excel.annotation.ExcelIgnore;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.write.style.ColumnWidth;
import cn.idev.excel.annotation.write.style.ContentRowHeight;
import cn.idev.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 常用地址 Excel
*
* @author Chill
*/
@Data
@ColumnWidth(18)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class CommonAddressExcel implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@ExcelIgnore
private Long id;
@ExcelProperty("地址名称")
private String addressName;
@ExcelProperty("地址编号")
private String addressCode;
@ExcelProperty("类型")
private String addressType;
@ExcelProperty("站点编码")
private String siteCodeDisplay;
@ExcelProperty("详细地址")
private String detailAddress;
@ExcelProperty("经度")
private BigDecimal longitude;
@ExcelProperty("纬度")
private BigDecimal latitude;
@ExcelProperty("行政区划")
private String regionName;
@ExcelProperty("联系人")
private String contactName;
@ExcelProperty("联系方式")
private String contactPhone;
@ExcelProperty("组织")
private String deptName;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("更新时间")
private LocalDateTime updateTime;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,97 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.transport.pojo.entity.CommonAddress;
import org.springblade.transport.pojo.vo.CommonAddressVO;
import java.util.List;
/**
* 常用地址 Mapper 接口
*
* @author Chill
*/
public interface CommonAddressMapper extends BaseMapper<CommonAddress> {
/**
* 自定义分页
*
* @param page 分页参数
* @param address 查询参数
* @return 常用地址列表
*/
List<CommonAddressVO> selectCommonAddressPage(IPage<CommonAddressVO> page, @Param("address") CommonAddressVO address);
/**
* 查询当前最大地址编号
*
* @return 最大地址编号
*/
String selectMaxAddressCode();
/**
* 查询港口码头来源
*
* @param id 主键
* @return 来源地址
*/
CommonAddressVO selectPortTerminalSource(@Param("id") Long id);
/**
* 查询铁路车站来源
*
* @param id 主键
* @return 来源地址
*/
CommonAddressVO selectRailwayStationSource(@Param("id") Long id);
/**
* 查询空港机场来源
*
* @param id 主键
* @return 来源地址
*/
CommonAddressVO selectAirportMasterSource(@Param("id") Long id);
/**
* 查询可选来源地址
*
* @param addressType 地址类型
* @param keyword 关键字
* @return 来源地址
*/
List<CommonAddressVO> selectSourceOptions(@Param("addressType") String addressType, @Param("keyword") String keyword);
/**
* 查询业务引用数
*
* @param addressId 常用地址ID
* @return 引用数
*/
Integer countBusinessReference(@Param("addressId") Long addressId);
}

View File

@@ -0,0 +1,215 @@
<?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="org.springblade.transport.mapper.CommonAddressMapper">
<resultMap id="commonAddressResultMap" type="org.springblade.transport.pojo.vo.CommonAddressVO">
<result column="id" property="id"/>
<result column="tenant_id" property="tenantId"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>
<result column="address_code" property="addressCode"/>
<result column="address_name" property="addressName"/>
<result column="address_type" property="addressType"/>
<result column="source_id" property="sourceId"/>
<result column="site_code" property="siteCode"/>
<result column="detail_address" property="detailAddress"/>
<result column="region_code" property="regionCode"/>
<result column="region_name" property="regionName"/>
<result column="longitude" property="longitude"/>
<result column="latitude" property="latitude"/>
<result column="dept_id" property="deptId"/>
<result column="dept_name" property="deptName"/>
<result column="contact_name" property="contactName"/>
<result column="contact_phone" property="contactPhone"/>
<result column="remark" property="remark"/>
</resultMap>
<sql id="BaseColumn">
id,
tenant_id,
create_user,
create_dept,
create_time,
update_user,
update_time,
status,
is_deleted,
address_code,
address_name,
address_type,
source_id,
site_code,
detail_address,
region_code,
region_name,
longitude,
latitude,
dept_id,
dept_name,
contact_name,
contact_phone,
remark
</sql>
<sql id="QueryCondition">
is_deleted = 0
<if test="address.addressName != null and address.addressName != ''">
<bind name="addressNameLike" value="'%' + address.addressName + '%'"/>
AND address_name LIKE #{addressNameLike}
</if>
<if test="address.addressType != null and address.addressType != ''">
AND address_type = #{address.addressType}
</if>
<if test="address.detailAddress != null and address.detailAddress != ''">
<bind name="detailAddressLike" value="'%' + address.detailAddress + '%'"/>
AND detail_address LIKE #{detailAddressLike}
</if>
<if test="address.regionName != null and address.regionName != ''">
<bind name="regionNameLike" value="'%' + address.regionName + '%'"/>
AND region_name LIKE #{regionNameLike}
</if>
<if test="address.siteCode != null and address.siteCode != ''">
AND site_code = #{address.siteCode}
</if>
<if test="address.deptId != null">
AND dept_id = #{address.deptId}
</if>
<if test="address.contactName != null and address.contactName != ''">
<bind name="contactNameLike" value="'%' + address.contactName + '%'"/>
AND contact_name LIKE #{contactNameLike}
</if>
<if test="address.contactPhone != null and address.contactPhone != ''">
<bind name="contactPhoneLike" value="'%' + address.contactPhone + '%'"/>
AND contact_phone LIKE #{contactPhoneLike}
</if>
</sql>
<select id="selectCommonAddressPage" resultMap="commonAddressResultMap">
SELECT
<include refid="BaseColumn"/>
FROM
blade_common_address
WHERE
<include refid="QueryCondition"/>
ORDER BY update_time DESC, create_time DESC
</select>
<select id="selectMaxAddressCode" resultType="java.lang.String">
SELECT MAX(address_code)
FROM blade_common_address
WHERE address_code LIKE 'DZ%'
</select>
<select id="selectPortTerminalSource" resultMap="commonAddressResultMap">
SELECT
id AS source_id,
code AS site_code,
name AS address_name,
CONCAT_WS('', country, city) AS region_name,
city AS detail_address,
longitude,
latitude
FROM blade_port_terminal
WHERE id = #{id} AND status = 1 AND is_deleted = 0
</select>
<select id="selectRailwayStationSource" resultMap="commonAddressResultMap">
SELECT
id AS source_id,
code AS site_code,
name AS address_name,
CONCAT_WS('', province_name, city_name) AS region_name,
CONCAT_WS('', province_name, city_name, name) AS detail_address,
longitude,
latitude
FROM blade_railway_station
WHERE id = #{id} AND status = 1 AND is_deleted = 0
</select>
<select id="selectAirportMasterSource" resultMap="commonAddressResultMap">
SELECT
id AS source_id,
code AS site_code,
name AS address_name,
CONCAT_WS('', province_name, city_name) AS region_name,
CONCAT_WS('', province_name, city_name, name) AS detail_address,
longitude,
latitude
FROM blade_airport_master
WHERE id = #{id} AND status = 1 AND is_deleted = 0
</select>
<select id="selectSourceOptions" resultMap="commonAddressResultMap">
<choose>
<when test="addressType == '港口/码头'">
SELECT
id AS source_id,
code AS site_code,
name AS address_name,
CONCAT_WS('', country, city) AS region_name,
city AS detail_address,
longitude,
latitude
FROM blade_port_terminal
WHERE status = 1 AND is_deleted = 0
<if test="keyword != null and keyword != ''">
<bind name="keywordLike" value="'%' + keyword + '%'"/>
AND (name LIKE #{keywordLike} OR code LIKE #{keywordLike})
</if>
ORDER BY code ASC
LIMIT 50
</when>
<when test="addressType == '铁路车站'">
SELECT
id AS source_id,
code AS site_code,
name AS address_name,
CONCAT_WS('', province_name, city_name) AS region_name,
CONCAT_WS('', province_name, city_name, name) AS detail_address,
longitude,
latitude
FROM blade_railway_station
WHERE status = 1 AND is_deleted = 0
<if test="keyword != null and keyword != ''">
<bind name="keywordLike" value="'%' + keyword + '%'"/>
AND (name LIKE #{keywordLike} OR code LIKE #{keywordLike})
</if>
ORDER BY code ASC
LIMIT 50
</when>
<when test="addressType == '空港机场'">
SELECT
id AS source_id,
code AS site_code,
name AS address_name,
CONCAT_WS('', province_name, city_name) AS region_name,
CONCAT_WS('', province_name, city_name, name) AS detail_address,
longitude,
latitude
FROM blade_airport_master
WHERE status = 1 AND is_deleted = 0
<if test="keyword != null and keyword != ''">
<bind name="keywordLike" value="'%' + keyword + '%'"/>
AND (name LIKE #{keywordLike} OR code LIKE #{keywordLike} OR iata_code LIKE #{keywordLike})
</if>
ORDER BY code ASC
LIMIT 50
</when>
<otherwise>
SELECT NULL AS source_id, NULL AS site_code, NULL AS address_name, NULL AS region_name,
NULL AS detail_address, NULL AS longitude, NULL AS latitude
WHERE 1 = 0
</otherwise>
</choose>
</select>
<select id="countBusinessReference" resultType="java.lang.Integer">
SELECT 0
</select>
</mapper>

View File

@@ -0,0 +1,92 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.transport.excel.CommonAddressExcel;
import org.springblade.transport.pojo.entity.CommonAddress;
import org.springblade.transport.pojo.vo.CommonAddressRemoveResultVO;
import org.springblade.transport.pojo.vo.CommonAddressVO;
import java.util.List;
/**
* 常用地址 服务类
*
* @author Chill
*/
public interface ICommonAddressService extends BaseService<CommonAddress> {
/**
* 自定义分页
*
* @param page 分页参数
* @param address 查询参数
* @return 常用地址分页
*/
IPage<CommonAddressVO> selectCommonAddressPage(IPage<CommonAddressVO> page, CommonAddressVO address);
/**
* 详情
*
* @param id 主键
* @return 常用地址
*/
CommonAddressVO detail(Long id);
/**
* 新增或修改
*
* @param address 常用地址
* @return 是否成功
*/
boolean submit(CommonAddress address);
/**
* 删除常用地址
*
* @param ids 主键集合
* @return 删除结果
*/
CommonAddressRemoveResultVO removeAddress(String ids);
/**
* 来源地址选项
*
* @param addressType 地址类型
* @param keyword 关键字
* @return 来源地址
*/
List<CommonAddressVO> sourceOptions(String addressType, String keyword);
/**
* 导出常用地址
*
* @param queryWrapper 查询条件
* @return 导出数据
*/
List<CommonAddressExcel> exportCommonAddress(Wrapper<CommonAddress> queryWrapper);
}

View File

@@ -0,0 +1,345 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.SysCache;
import org.springblade.system.cache.UserCache;
import org.springblade.system.pojo.entity.Dept;
import org.springblade.transport.excel.CommonAddressExcel;
import org.springblade.transport.mapper.CommonAddressMapper;
import org.springblade.transport.pojo.entity.CommonAddress;
import org.springblade.transport.pojo.vo.CommonAddressRemoveResultVO;
import org.springblade.transport.pojo.vo.CommonAddressVO;
import org.springblade.transport.service.ICommonAddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 常用地址 服务实现类
*
* @author Chill
*/
@Service
public class CommonAddressServiceImpl extends BaseServiceImpl<CommonAddressMapper, CommonAddress> implements ICommonAddressService {
private static final String TYPE_NORMAL = "常规地址";
private static final String TYPE_PORT = "港口/码头";
private static final String TYPE_RAILWAY = "铁路车站";
private static final String TYPE_AIRPORT = "空港机场";
private static final String NORMAL_SITE_CODE = "/";
private static final String ADDRESS_CODE_PREFIX = "DZ";
private static final int ADDRESS_CODE_LENGTH = 5;
private static final int NAME_MAX_LENGTH = 100;
private static final int DETAIL_MAX_LENGTH = 255;
private static final int REGION_MAX_LENGTH = 100;
private static final int CONTACT_MAX_LENGTH = 50;
private static final int PHONE_MAX_LENGTH = 30;
private static final int REMARK_MAX_LENGTH = 200;
private static final BigDecimal MIN_LONGITUDE = new BigDecimal("-180");
private static final BigDecimal MAX_LONGITUDE = new BigDecimal("180");
private static final BigDecimal MIN_LATITUDE = new BigDecimal("-90");
private static final BigDecimal MAX_LATITUDE = new BigDecimal("90");
@Override
public IPage<CommonAddressVO> selectCommonAddressPage(IPage<CommonAddressVO> page, CommonAddressVO address) {
prepareQuery(address);
IPage<CommonAddressVO> result = page.setRecords(baseMapper.selectCommonAddressPage(page, address));
result.getRecords().forEach(this::fillDisplay);
return result;
}
@Override
public CommonAddressVO detail(Long id) {
if (Func.isEmpty(id)) {
throw new ServiceException("主键不能为空");
}
CommonAddress address = getById(id);
if (Func.isEmpty(address) || Objects.equals(address.getIsDeleted(), 1)) {
throw new ServiceException("常用地址不存在");
}
CommonAddressVO addressVO = Objects.requireNonNull(BeanUtil.copyProperties(address, CommonAddressVO.class));
fillDisplay(addressVO);
return addressVO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean submit(CommonAddress address) {
boolean created = Func.isEmpty(address.getId());
if (!created) {
CommonAddress oldAddress = getEditableAddress(address.getId());
address.setAddressCode(oldAddress.getAddressCode());
address.setDeptId(oldAddress.getDeptId());
address.setDeptName(oldAddress.getDeptName());
}
prepare(address);
validate(address);
if (created) {
address.setAddressCode(nextAddressCode());
}
return saveOrUpdate(address);
}
@Override
@Transactional(rollbackFor = Exception.class)
public CommonAddressRemoveResultVO removeAddress(String ids) {
List<Long> idList = Func.toLongList(ids);
if (Func.isEmpty(idList)) {
throw new ServiceException("请选择需要删除的数据");
}
CommonAddressRemoveResultVO result = new CommonAddressRemoveResultVO();
List<Long> deleteIdList = new ArrayList<>();
for (CommonAddress address : listByIds(idList)) {
validateCurrentDept(address);
Integer referenceCount = baseMapper.countBusinessReference(address.getId());
if (referenceCount != null && referenceCount > 0) {
result.setSkippedCount(result.getSkippedCount() + 1);
result.getSkippedAddressCodes().add(address.getAddressCode());
continue;
}
deleteIdList.add(address.getId());
}
if (Func.isNotEmpty(deleteIdList)) {
deleteLogic(deleteIdList);
}
result.setSuccessCount(deleteIdList.size());
return result;
}
@Override
public List<CommonAddressVO> sourceOptions(String addressType, String keyword) {
String type = trimToEmpty(addressType);
if (TYPE_NORMAL.equals(type)) {
return new ArrayList<>();
}
validateAddressType(type);
List<CommonAddressVO> sourceList = baseMapper.selectSourceOptions(type, trimToNull(keyword));
sourceList.forEach(source -> {
source.setAddressType(type);
source.setSiteCodeDisplay(source.getSiteCode());
});
return sourceList;
}
@Override
public List<CommonAddressExcel> exportCommonAddress(Wrapper<CommonAddress> queryWrapper) {
return list(queryWrapper).stream().map(address -> {
CommonAddressExcel excel = Objects.requireNonNull(BeanUtil.copyProperties(address, CommonAddressExcel.class));
excel.setSiteCodeDisplay(TYPE_NORMAL.equals(address.getAddressType()) ? NORMAL_SITE_CODE : address.getSiteCode());
return excel;
}).toList();
}
private void prepareQuery(CommonAddressVO address) {
if (Objects.equals(address.getAllDept(), 1)) {
if (!AuthUtil.isAdministrator()) {
throw new ServiceException("无权查看全部组织常用地址");
}
} else {
address.setDeptId(currentDeptId());
}
address.setAddressName(trimToNull(address.getAddressName()));
address.setAddressType(trimToNull(address.getAddressType()));
address.setDetailAddress(trimToNull(address.getDetailAddress()));
address.setRegionName(trimToNull(address.getRegionName()));
address.setSiteCode(trimToNull(address.getSiteCode()));
address.setContactName(trimToNull(address.getContactName()));
address.setContactPhone(trimToNull(address.getContactPhone()));
if (NORMAL_SITE_CODE.equals(address.getSiteCode())) {
address.setSiteCode(null);
}
}
private void prepare(CommonAddress address) {
address.setAddressName(trimToEmpty(address.getAddressName()));
address.setAddressType(trimToEmpty(address.getAddressType()));
address.setDetailAddress(trimToEmpty(address.getDetailAddress()));
address.setRegionCode(trimToNull(address.getRegionCode()));
address.setRegionName(trimToNull(address.getRegionName()));
address.setContactName(trimToNull(address.getContactName()));
address.setContactPhone(trimToNull(address.getContactPhone()));
address.setRemark(trimToNull(address.getRemark()));
if (address.getStatus() == null) {
address.setStatus(1);
}
if (Func.isEmpty(address.getDeptId())) {
fillCurrentDept(address);
}
if (TYPE_NORMAL.equals(address.getAddressType())) {
address.setSourceId(null);
address.setSiteCode(NORMAL_SITE_CODE);
address.setLongitude(scale(address.getLongitude()));
address.setLatitude(scale(address.getLatitude()));
return;
}
CommonAddressVO source = loadSource(address.getAddressType(), address.getSourceId());
address.setSourceId(source.getSourceId());
address.setSiteCode(source.getSiteCode());
address.setDetailAddress(source.getDetailAddress());
address.setRegionName(source.getRegionName());
address.setLongitude(scale(source.getLongitude()));
address.setLatitude(scale(source.getLatitude()));
if (Func.isEmpty(address.getAddressName())) {
address.setAddressName(source.getAddressName());
}
}
private void fillCurrentDept(CommonAddress address) {
Long deptId = currentDeptId();
Dept dept = SysCache.getDept(deptId);
if (Func.isEmpty(dept)) {
throw new ServiceException("当前用户所属组织异常,请重新登录后再试");
}
address.setDeptId(deptId);
address.setDeptName(dept.getDeptName());
}
private CommonAddressVO loadSource(String addressType, Long sourceId) {
if (Func.isEmpty(sourceId)) {
throw new ServiceException(addressType + "主数据不能为空");
}
CommonAddressVO source;
if (TYPE_PORT.equals(addressType)) {
source = baseMapper.selectPortTerminalSource(sourceId);
} else if (TYPE_RAILWAY.equals(addressType)) {
source = baseMapper.selectRailwayStationSource(sourceId);
} else if (TYPE_AIRPORT.equals(addressType)) {
source = baseMapper.selectAirportMasterSource(sourceId);
} else {
throw new ServiceException("地址类型不正确");
}
if (Func.isEmpty(source)) {
throw new ServiceException(addressType + "主数据不存在或已停用");
}
return source;
}
private void validate(CommonAddress address) {
validateAddressType(address.getAddressType());
if (Func.isEmpty(address.getAddressName())) {
throw new ServiceException("地址名称不能为空");
}
if (Func.isEmpty(address.getDetailAddress())) {
throw new ServiceException("详细地址不能为空");
}
validateLength(address.getAddressName(), NAME_MAX_LENGTH, "地址名称不能超过100字");
validateLength(address.getDetailAddress(), DETAIL_MAX_LENGTH, "详细地址不能超过255字");
validateLength(address.getRegionName(), REGION_MAX_LENGTH, "行政区划不能超过100字");
validateLength(address.getContactName(), CONTACT_MAX_LENGTH, "联系人不能超过50字");
validateLength(address.getContactPhone(), PHONE_MAX_LENGTH, "联系方式不能超过30字");
validateLength(address.getRemark(), REMARK_MAX_LENGTH, "备注不能超过200字");
validateRange(address.getLongitude(), MIN_LONGITUDE, MAX_LONGITUDE, "经度范围为 -180 到 180");
validateRange(address.getLatitude(), MIN_LATITUDE, MAX_LATITUDE, "纬度范围为 -90 到 90");
if (!TYPE_NORMAL.equals(address.getAddressType()) && Func.isEmpty(address.getSiteCode())) {
throw new ServiceException("站点编码不能为空");
}
}
private void validateAddressType(String addressType) {
if (!TYPE_NORMAL.equals(addressType) && !TYPE_PORT.equals(addressType)
&& !TYPE_RAILWAY.equals(addressType) && !TYPE_AIRPORT.equals(addressType)) {
throw new ServiceException("地址类型不正确");
}
}
private CommonAddress getEditableAddress(Long id) {
CommonAddress address = getById(id);
if (Func.isEmpty(address) || Objects.equals(address.getIsDeleted(), 1)) {
throw new ServiceException("常用地址不存在");
}
validateCurrentDept(address);
return address;
}
private void validateCurrentDept(CommonAddress address) {
if (!Objects.equals(address.getDeptId(), currentDeptId())) {
throw new ServiceException("无权操作其他组织常用地址");
}
}
private void fillDisplay(CommonAddressVO address) {
address.setSiteCodeDisplay(TYPE_NORMAL.equals(address.getAddressType()) ? NORMAL_SITE_CODE : address.getSiteCode());
address.setReadonly(!Objects.equals(address.getDeptId(), currentDeptId()));
address.setCreateUserName(UserCache.getUserRealName(address.getCreateUser()));
address.setUpdateUserName(UserCache.getUserRealName(address.getUpdateUser()));
}
private Long currentDeptId() {
Long deptId = Func.firstLong(AuthUtil.getDeptId());
if (Func.isEmpty(deptId) || deptId <= 0) {
throw new ServiceException("当前用户所属组织为空,无法查询常用地址");
}
return deptId;
}
private synchronized String nextAddressCode() {
String maxAddressCode = baseMapper.selectMaxAddressCode();
int next = 1;
if (Func.isNotEmpty(maxAddressCode) && maxAddressCode.length() > ADDRESS_CODE_PREFIX.length()) {
String number = maxAddressCode.substring(ADDRESS_CODE_PREFIX.length());
if (number.chars().allMatch(Character::isDigit)) {
next = Integer.parseInt(number) + 1;
}
}
return ADDRESS_CODE_PREFIX + String.format("%0" + ADDRESS_CODE_LENGTH + "d", next);
}
private BigDecimal scale(BigDecimal value) {
return value == null ? null : value.setScale(6, RoundingMode.HALF_UP);
}
private void validateLength(String value, int maxLength, String message) {
if (Func.isNotEmpty(value) && value.length() > maxLength) {
throw new ServiceException(message);
}
}
private void validateRange(BigDecimal value, BigDecimal min, BigDecimal max, String message) {
if (Func.isNotEmpty(value) && (value.compareTo(min) < 0 || value.compareTo(max) > 0)) {
throw new ServiceException(message);
}
}
private String trimToEmpty(String value) {
return value == null ? "" : value.trim();
}
private String trimToNull(String value) {
String trimValue = trimToEmpty(value);
return trimValue.isEmpty() ? null : trimValue;
}
}

View File

@@ -0,0 +1,52 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.wrapper;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.system.cache.UserCache;
import org.springblade.transport.pojo.entity.CommonAddress;
import org.springblade.transport.pojo.vo.CommonAddressVO;
import java.util.Objects;
/**
* 常用地址包装类
*
* @author Chill
*/
public class CommonAddressWrapper extends BaseEntityWrapper<CommonAddress, CommonAddressVO> {
public static CommonAddressWrapper build() {
return new CommonAddressWrapper();
}
@Override
public CommonAddressVO entityVO(CommonAddress address) {
CommonAddressVO addressVO = Objects.requireNonNull(BeanUtil.copyProperties(address, CommonAddressVO.class));
addressVO.setCreateUserName(UserCache.getUserRealName(address.getCreateUser()));
addressVO.setUpdateUserName(UserCache.getUserRealName(address.getUpdateUser()));
return addressVO;
}
}