调整 基础数据、运力、车船务
This commit is contained in:
+137
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* 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>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
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.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
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.tenant.annotation.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.system.pojo.entity.MeasurementUnit;
|
||||
import org.springblade.system.pojo.vo.MeasurementUnitVO;
|
||||
import org.springblade.system.service.IMeasurementUnitService;
|
||||
import org.springblade.system.wrapper.MeasurementUnitWrapper;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 计量单位控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@PreAuth(menu = "measurement_unit")
|
||||
@RequestMapping("/measurement-unit")
|
||||
@Tag(name = "计量单位", description = "计量单位")
|
||||
public class MeasurementUnitController extends BladeController {
|
||||
|
||||
private final IMeasurementUnitService measurementUnitService;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param measurementUnit 查询条件
|
||||
* @return 计量单位详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "详情", description = "传入measurementUnit")
|
||||
public R<MeasurementUnitVO> detail(MeasurementUnit measurementUnit) {
|
||||
MeasurementUnit detail = measurementUnitService.getOne(Condition.getQueryWrapper(measurementUnit));
|
||||
if (detail == null) {
|
||||
return R.fail("数据不存在");
|
||||
}
|
||||
return R.data(MeasurementUnitWrapper.build().entityVO(detail));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param measurementUnit 查询条件
|
||||
* @param query 分页参数
|
||||
* @return 计量单位分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入measurementUnit")
|
||||
public R<IPage<MeasurementUnitVO>> list(MeasurementUnitVO measurementUnit, Query query) {
|
||||
IPage<MeasurementUnitVO> pages = measurementUnitService.selectMeasurementUnitPage(
|
||||
Condition.getPage(query), measurementUnit
|
||||
);
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改
|
||||
*
|
||||
* @param measurementUnit 计量单位
|
||||
* @return 操作结果
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "新增或修改", description = "传入measurementUnit")
|
||||
public R submit(@Valid @RequestBody MeasurementUnit measurementUnit) {
|
||||
return R.status(measurementUnitService.submit(measurementUnit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids 主键集合
|
||||
* @return 操作结果
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(measurementUnitService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用或停用
|
||||
*
|
||||
* @param id 主键
|
||||
* @param status 状态
|
||||
* @return 操作结果
|
||||
*/
|
||||
@PostMapping("/status")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "启用或停用", description = "传入id和status")
|
||||
public R status(@Parameter(description = "主键", required = true) @RequestParam Long id,
|
||||
@Parameter(description = "状态", required = true) @RequestParam Integer status) {
|
||||
return R.status(measurementUnitService.changeStatus(id, status));
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springblade.system.pojo.entity.MeasurementUnit;
|
||||
import org.springblade.system.pojo.vo.MeasurementUnitVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计量单位 Mapper 接口
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface MeasurementUnitMapper extends BaseMapper<MeasurementUnit> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param measurementUnit 查询参数
|
||||
* @return 计量单位分页
|
||||
*/
|
||||
List<MeasurementUnitVO> selectMeasurementUnitPage(IPage<MeasurementUnitVO> page,
|
||||
@Param("measurementUnit") MeasurementUnitVO measurementUnit);
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?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.system.mapper.MeasurementUnitMapper">
|
||||
|
||||
<resultMap id="measurementUnitResultMap" type="org.springblade.system.pojo.vo.MeasurementUnitVO">
|
||||
<result column="id" property="id"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_user_name" property="createUserName"/>
|
||||
<result column="create_dept" property="createDept"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_user_name" property="updateUserName"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="unit_name" property="unitName"/>
|
||||
<result column="dimension" property="dimension"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectMeasurementUnitPage" resultMap="measurementUnitResultMap">
|
||||
SELECT
|
||||
mmu.id,
|
||||
mmu.create_user,
|
||||
cu.real_name AS create_user_name,
|
||||
mmu.create_dept,
|
||||
mmu.create_time,
|
||||
mmu.update_user,
|
||||
uu.real_name AS update_user_name,
|
||||
mmu.update_time,
|
||||
mmu.status,
|
||||
mmu.is_deleted,
|
||||
mmu.unit_name,
|
||||
mmu.dimension,
|
||||
mmu.remark
|
||||
FROM
|
||||
blade_measurement_unit mmu
|
||||
LEFT JOIN blade_user cu ON cu.id = mmu.create_user
|
||||
LEFT JOIN blade_user uu ON uu.id = mmu.update_user
|
||||
WHERE
|
||||
mmu.is_deleted = 0
|
||||
<if test="measurementUnit.unitName != null and measurementUnit.unitName != ''">
|
||||
<bind name="unitNameLike" value="'%' + measurementUnit.unitName + '%'"/>
|
||||
AND mmu.unit_name LIKE #{unitNameLike}
|
||||
</if>
|
||||
<if test="measurementUnit.dimension != null and measurementUnit.dimension != ''">
|
||||
AND mmu.dimension = #{measurementUnit.dimension}
|
||||
</if>
|
||||
<if test="measurementUnit.status != null">
|
||||
AND mmu.status = #{measurementUnit.status}
|
||||
</if>
|
||||
ORDER BY mmu.create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.system.pojo.entity.MeasurementUnit;
|
||||
import org.springblade.system.pojo.vo.MeasurementUnitVO;
|
||||
|
||||
/**
|
||||
* 计量单位服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface IMeasurementUnitService extends BaseService<MeasurementUnit> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param measurementUnit 查询参数
|
||||
* @return 计量单位分页
|
||||
*/
|
||||
IPage<MeasurementUnitVO> selectMeasurementUnitPage(IPage<MeasurementUnitVO> page,
|
||||
MeasurementUnitVO measurementUnit);
|
||||
|
||||
/**
|
||||
* 新增或修改计量单位
|
||||
*
|
||||
* @param measurementUnit 计量单位
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean submit(MeasurementUnit measurementUnit);
|
||||
|
||||
/**
|
||||
* 启用或停用计量单位
|
||||
*
|
||||
* @param id 主键
|
||||
* @param status 状态
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean changeStatus(Long id, Integer status);
|
||||
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* 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>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.system.mapper.MeasurementUnitMapper;
|
||||
import org.springblade.system.pojo.entity.MeasurementUnit;
|
||||
import org.springblade.system.pojo.vo.MeasurementUnitVO;
|
||||
import org.springblade.system.service.IMeasurementUnitService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 计量单位服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Service
|
||||
public class MeasurementUnitServiceImpl extends BaseServiceImpl<MeasurementUnitMapper, MeasurementUnit>
|
||||
implements IMeasurementUnitService {
|
||||
|
||||
private static final int STATUS_ENABLED = 1;
|
||||
private static final int STATUS_DISABLED = 2;
|
||||
private static final int UNIT_NAME_MAX_LENGTH = 50;
|
||||
private static final int DIMENSION_MAX_LENGTH = 20;
|
||||
private static final int REMARK_MAX_LENGTH = 200;
|
||||
private static final Set<String> DIMENSIONS = Set.of("重量", "体积", "数量");
|
||||
|
||||
@Override
|
||||
public IPage<MeasurementUnitVO> selectMeasurementUnitPage(IPage<MeasurementUnitVO> page,
|
||||
MeasurementUnitVO measurementUnit) {
|
||||
return page.setRecords(baseMapper.selectMeasurementUnitPage(page, measurementUnit));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean submit(MeasurementUnit measurementUnit) {
|
||||
prepare(measurementUnit);
|
||||
validate(measurementUnit);
|
||||
return saveOrUpdate(measurementUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean changeStatus(Long id, Integer status) {
|
||||
if (Func.isEmpty(id)) {
|
||||
throw new ServiceException("主键不能为空");
|
||||
}
|
||||
MeasurementUnit measurementUnit = getById(id);
|
||||
if (Func.isEmpty(measurementUnit)) {
|
||||
throw new ServiceException("计量单位不存在");
|
||||
}
|
||||
if (!Objects.equals(status, STATUS_ENABLED) && !Objects.equals(status, STATUS_DISABLED)) {
|
||||
throw new ServiceException("启停状态不正确");
|
||||
}
|
||||
MeasurementUnit update = new MeasurementUnit();
|
||||
update.setId(id);
|
||||
update.setStatus(status);
|
||||
return updateById(update);
|
||||
}
|
||||
|
||||
private void prepare(MeasurementUnit measurementUnit) {
|
||||
measurementUnit.setUnitName(trimToEmpty(measurementUnit.getUnitName()));
|
||||
measurementUnit.setDimension(trimToEmpty(measurementUnit.getDimension()));
|
||||
measurementUnit.setRemark(trimToNull(measurementUnit.getRemark()));
|
||||
if (Func.isEmpty(measurementUnit.getStatus())) {
|
||||
measurementUnit.setStatus(STATUS_ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
private void validate(MeasurementUnit measurementUnit) {
|
||||
if (Func.isEmpty(measurementUnit.getUnitName())) {
|
||||
throw new ServiceException("计量单位不能为空");
|
||||
}
|
||||
if (measurementUnit.getUnitName().length() > UNIT_NAME_MAX_LENGTH) {
|
||||
throw new ServiceException("计量单位不能超过50字");
|
||||
}
|
||||
if (Func.isEmpty(measurementUnit.getDimension())) {
|
||||
throw new ServiceException("计量维度不能为空");
|
||||
}
|
||||
if (measurementUnit.getDimension().length() > DIMENSION_MAX_LENGTH
|
||||
|| !DIMENSIONS.contains(measurementUnit.getDimension())) {
|
||||
throw new ServiceException("计量维度不正确");
|
||||
}
|
||||
if (Func.isNotEmpty(measurementUnit.getRemark())
|
||||
&& measurementUnit.getRemark().length() > REMARK_MAX_LENGTH) {
|
||||
throw new ServiceException("备注不能超过200个字");
|
||||
}
|
||||
if (!Objects.equals(measurementUnit.getStatus(), STATUS_ENABLED)
|
||||
&& !Objects.equals(measurementUnit.getStatus(), STATUS_DISABLED)) {
|
||||
throw new ServiceException("启停状态不正确");
|
||||
}
|
||||
validateUniqueUnitName(measurementUnit);
|
||||
}
|
||||
|
||||
private void validateUniqueUnitName(MeasurementUnit measurementUnit) {
|
||||
LambdaQueryWrapper<MeasurementUnit> queryWrapper = Wrappers.<MeasurementUnit>lambdaQuery()
|
||||
.eq(MeasurementUnit::getUnitName, measurementUnit.getUnitName())
|
||||
.eq(MeasurementUnit::getIsDeleted, 0);
|
||||
if (Func.isNotEmpty(measurementUnit.getId())) {
|
||||
queryWrapper.ne(MeasurementUnit::getId, measurementUnit.getId());
|
||||
}
|
||||
if (count(queryWrapper) > 0L) {
|
||||
throw new ServiceException("该计量单位已存在");
|
||||
}
|
||||
}
|
||||
|
||||
private String trimToEmpty(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
String trimValue = trimToEmpty(value);
|
||||
return trimValue.isEmpty() ? null : trimValue;
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 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>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.system.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springblade.system.pojo.entity.MeasurementUnit;
|
||||
import org.springblade.system.pojo.vo.MeasurementUnitVO;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 计量单位包装类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class MeasurementUnitWrapper extends BaseEntityWrapper<MeasurementUnit, MeasurementUnitVO> {
|
||||
|
||||
public static MeasurementUnitWrapper build() {
|
||||
return new MeasurementUnitWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MeasurementUnitVO entityVO(MeasurementUnit measurementUnit) {
|
||||
MeasurementUnitVO measurementUnitVO = Objects.requireNonNull(
|
||||
BeanUtil.copyProperties(measurementUnit, MeasurementUnitVO.class)
|
||||
);
|
||||
measurementUnitVO.setCreateUserName(UserCache.getUserRealName(measurementUnit.getCreateUser()));
|
||||
measurementUnitVO.setUpdateUserName(UserCache.getUserRealName(measurementUnit.getUpdateUser()));
|
||||
return measurementUnitVO;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user