8 changed files with 591 additions and 0 deletions
-
165src/main/java/com/gaotao/modules/warehouse/controller/PalletController.java
-
34src/main/java/com/gaotao/modules/warehouse/dao/PalletMapper.java
-
51src/main/java/com/gaotao/modules/warehouse/entity/Pallet.java
-
24src/main/java/com/gaotao/modules/warehouse/entity/dto/PalletQueryDto.java
-
41src/main/java/com/gaotao/modules/warehouse/entity/vo/PalletVo.java
-
63src/main/java/com/gaotao/modules/warehouse/service/PalletService.java
-
137src/main/java/com/gaotao/modules/warehouse/service/impl/PalletServiceImpl.java
-
76src/main/resources/mapper/warehouse/PalletMapper.xml
@ -0,0 +1,165 @@ |
|||
package com.gaotao.modules.warehouse.controller; |
|||
|
|||
import com.gaotao.common.utils.PageUtils; |
|||
import com.gaotao.common.utils.R; |
|||
import com.gaotao.modules.factory.service.AccessSiteService; |
|||
import com.gaotao.modules.warehouse.entity.Pallet; |
|||
import com.gaotao.modules.warehouse.entity.dto.PalletQueryDto; |
|||
import com.gaotao.modules.warehouse.entity.vo.PalletVo; |
|||
import com.gaotao.modules.warehouse.service.PalletService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 托盘管理控制器 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/warehouse/pallet") |
|||
public class PalletController { |
|||
|
|||
@Autowired |
|||
private PalletService palletService; |
|||
|
|||
@Autowired |
|||
private AccessSiteService accessSiteService; |
|||
|
|||
/** |
|||
* 获取托盘列表 |
|||
*/ |
|||
@PostMapping("/list") |
|||
public R list(@RequestBody PalletQueryDto queryDto) { |
|||
PageUtils page = palletService.queryPage(queryDto); |
|||
return R.ok().put("page", page); |
|||
} |
|||
|
|||
/** |
|||
* 根据托盘ID获取托盘信息 |
|||
*/ |
|||
@PostMapping("/info") |
|||
public R info(@RequestBody Pallet pallet) { |
|||
PalletVo palletVo = palletService.getPalletByPalletId(pallet.getPalletId()); |
|||
return R.ok().put("pallet", palletVo); |
|||
} |
|||
|
|||
/** |
|||
* 根据主键ID获取托盘信息 |
|||
*/ |
|||
@GetMapping("/info/{id}") |
|||
public R info(@PathVariable("id") Long id) { |
|||
Pallet pallet = palletService.getById(id); |
|||
return R.ok().put("pallet", pallet); |
|||
} |
|||
|
|||
/** |
|||
* 保存托盘信息 |
|||
*/ |
|||
@PostMapping("/save") |
|||
public R save(@RequestBody Pallet pallet) { |
|||
try { |
|||
palletService.savePallet(pallet); |
|||
return R.ok("托盘信息保存成功"); |
|||
} catch (Exception e) { |
|||
return R.error(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 修改托盘信息 |
|||
*/ |
|||
@PostMapping("/update") |
|||
public R update(@RequestBody Pallet pallet) { |
|||
try { |
|||
palletService.updatePallet(pallet); |
|||
return R.ok("托盘信息修改成功"); |
|||
} catch (Exception e) { |
|||
return R.error(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 删除托盘 |
|||
*/ |
|||
@PostMapping("/delete") |
|||
public R delete(@RequestBody Long[] ids) { |
|||
try { |
|||
palletService.deletePalletBatch(ids); |
|||
return R.ok("托盘删除成功"); |
|||
} catch (Exception e) { |
|||
return R.error(e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检查托盘ID是否存在 |
|||
*/ |
|||
@PostMapping("/checkPalletId") |
|||
public R checkPalletId(@RequestBody Pallet pallet) { |
|||
boolean exists = palletService.checkPalletIdExists(pallet.getPalletId(), pallet.getId()); |
|||
return R.ok().put("exists", exists); |
|||
} |
|||
|
|||
/** |
|||
* 获取托盘状态选项 |
|||
*/ |
|||
@GetMapping("/statusOptions") |
|||
public R getStatusOptions() { |
|||
return R.ok().put("options", Arrays.asList( |
|||
new StatusOption("AVAILABLE", "可用"), |
|||
new StatusOption("OCCUPIED", "使用中"), |
|||
new StatusOption("DAMAGED", "损坏"), |
|||
new StatusOption("DISABLED", "禁用") |
|||
)); |
|||
} |
|||
|
|||
/** |
|||
* 获取用户授权站点列表 |
|||
*/ |
|||
@PostMapping("/getUserAuthorizedSites") |
|||
public R getUserAuthorizedSites(@RequestBody Map<String, Object> params) { |
|||
String userName = (String) params.get("userName"); |
|||
|
|||
if (userName == null || userName.trim().isEmpty()) { |
|||
return R.error("用户名不能为空"); |
|||
} |
|||
|
|||
try { |
|||
List<Map<String, Object>> siteList = accessSiteService.getUserAuthorizedSites(userName.trim()); |
|||
return R.ok().put("data", siteList); |
|||
} catch (Exception e) { |
|||
return R.error("获取站点列表失败:" + e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 状态选项内部类 |
|||
*/ |
|||
public static class StatusOption { |
|||
private String value; |
|||
private String label; |
|||
|
|||
public StatusOption(String value, String label) { |
|||
this.value = value; |
|||
this.label = label; |
|||
} |
|||
|
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
|
|||
public void setValue(String value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public String getLabel() { |
|||
return label; |
|||
} |
|||
|
|||
public void setLabel(String label) { |
|||
this.label = label; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package com.gaotao.modules.warehouse.dao; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.gaotao.modules.warehouse.entity.Pallet; |
|||
import com.gaotao.modules.warehouse.entity.dto.PalletQueryDto; |
|||
import com.gaotao.modules.warehouse.entity.vo.PalletVo; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 托盘信息Mapper接口 |
|||
*/ |
|||
@Mapper |
|||
public interface PalletMapper extends BaseMapper<Pallet> { |
|||
|
|||
/** |
|||
* 查询托盘列表 |
|||
* @param page 分页参数 |
|||
* @param queryDto 查询条件 |
|||
* @return 托盘列表 |
|||
*/ |
|||
IPage<PalletVo> selectPalletList(IPage<PalletVo> page, @Param("query") PalletQueryDto queryDto); |
|||
|
|||
/** |
|||
* 根据托盘ID查询托盘信息 |
|||
* @param palletId 托盘ID |
|||
* @return 托盘信息 |
|||
*/ |
|||
PalletVo selectPalletByPalletId(@Param("palletId") String palletId); |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
package com.gaotao.modules.warehouse.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 托盘信息实体类 |
|||
*/ |
|||
@Data |
|||
@TableName("pallet") |
|||
public class Pallet { |
|||
|
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; // 自增主键(内部用) |
|||
|
|||
private String site; // 站点 |
|||
|
|||
private String palletId; // 固定身份ID(唯一,不可重复,不随变更修改) |
|||
|
|||
private String palletType; // 托盘类型(如木质、塑料、铁制) |
|||
|
|||
private String palletSize; // 托盘尺寸(如 1200x1000) |
|||
|
|||
private BigDecimal maxLoad; // 最大承重(kg) |
|||
|
|||
private String status; // 托盘状态: AVAILABLE=可用, OCCUPIED=使用中, DAMAGED=损坏, DISABLED=禁用 |
|||
|
|||
private String locationCode; // 所在库位编码(可选) |
|||
|
|||
private String remark; // 备注信息 |
|||
|
|||
private String createdBy; // 创建人 |
|||
|
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Date createdTime; // 创建时间 |
|||
|
|||
private String updatedBy; // 最后修改人 |
|||
|
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
private Date updatedTime; // 最后修改时间 |
|||
|
|||
// 分页参数 |
|||
@TableField(exist = false) |
|||
private int page = 1; |
|||
|
|||
@TableField(exist = false) |
|||
private int size = 20; |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.gaotao.modules.warehouse.entity.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 托盘查询DTO |
|||
*/ |
|||
@Data |
|||
public class PalletQueryDto { |
|||
|
|||
private String site; // 站点 |
|||
|
|||
private String palletId; // 托盘ID |
|||
|
|||
private String palletType; // 托盘类型 |
|||
|
|||
private String status; // 托盘状态 |
|||
|
|||
private String locationCode; // 所在库位编码 |
|||
|
|||
private Integer page = 1; // 页码 |
|||
|
|||
private Integer limit = 20; // 每页数量 |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
package com.gaotao.modules.warehouse.entity.vo; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 托盘信息VO |
|||
*/ |
|||
@Data |
|||
public class PalletVo { |
|||
|
|||
private Long id; // 主键ID |
|||
|
|||
private String site; // 站点 |
|||
|
|||
private String palletId; // 托盘ID |
|||
|
|||
private String palletType; // 托盘类型 |
|||
|
|||
private String palletSize; // 托盘尺寸 |
|||
|
|||
private BigDecimal maxLoad; // 最大承重(kg) |
|||
|
|||
private String status; // 托盘状态 |
|||
|
|||
private String statusText; // 状态文本 |
|||
|
|||
private String locationCode; // 所在库位编码 |
|||
|
|||
private String remark; // 备注信息 |
|||
|
|||
private String createdBy; // 创建人 |
|||
|
|||
private Date createdTime; // 创建时间 |
|||
|
|||
private String updatedBy; // 最后修改人 |
|||
|
|||
private Date updatedTime; // 最后修改时间 |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
package com.gaotao.modules.warehouse.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.gaotao.common.utils.PageUtils; |
|||
import com.gaotao.modules.warehouse.entity.Pallet; |
|||
import com.gaotao.modules.warehouse.entity.dto.PalletQueryDto; |
|||
import com.gaotao.modules.warehouse.entity.vo.PalletVo; |
|||
|
|||
/** |
|||
* 托盘服务接口 |
|||
*/ |
|||
public interface PalletService extends IService<Pallet> { |
|||
|
|||
/** |
|||
* 分页查询托盘列表 |
|||
* @param queryDto 查询条件 |
|||
* @return 分页结果 |
|||
*/ |
|||
PageUtils queryPage(PalletQueryDto queryDto); |
|||
|
|||
/** |
|||
* 根据托盘ID查询托盘信息 |
|||
* @param palletId 托盘ID |
|||
* @return 托盘信息 |
|||
*/ |
|||
PalletVo getPalletByPalletId(String palletId); |
|||
|
|||
/** |
|||
* 保存托盘信息 |
|||
* @param pallet 托盘信息 |
|||
* @return 是否成功 |
|||
*/ |
|||
boolean savePallet(Pallet pallet); |
|||
|
|||
/** |
|||
* 更新托盘信息 |
|||
* @param pallet 托盘信息 |
|||
* @return 是否成功 |
|||
*/ |
|||
boolean updatePallet(Pallet pallet); |
|||
|
|||
/** |
|||
* 删除托盘 |
|||
* @param id 主键ID |
|||
* @return 是否成功 |
|||
*/ |
|||
boolean deletePallet(Long id); |
|||
|
|||
/** |
|||
* 批量删除托盘 |
|||
* @param ids 主键ID数组 |
|||
* @return 是否成功 |
|||
*/ |
|||
boolean deletePalletBatch(Long[] ids); |
|||
|
|||
/** |
|||
* 检查托盘ID是否存在 |
|||
* @param palletId 托盘ID |
|||
* @param excludeId 排除的主键ID(编辑时使用) |
|||
* @return 是否存在 |
|||
*/ |
|||
boolean checkPalletIdExists(String palletId, Long excludeId); |
|||
} |
|||
@ -0,0 +1,137 @@ |
|||
package com.gaotao.modules.warehouse.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.gaotao.common.exception.XJException; |
|||
import com.gaotao.common.utils.PageUtils; |
|||
import com.gaotao.modules.trans.entity.TransNoControl; |
|||
import com.gaotao.modules.trans.service.TransNoControlService; |
|||
import com.gaotao.modules.warehouse.dao.PalletMapper; |
|||
import com.gaotao.modules.warehouse.entity.Pallet; |
|||
import com.gaotao.modules.warehouse.entity.dto.PalletQueryDto; |
|||
import com.gaotao.modules.warehouse.entity.vo.PalletVo; |
|||
import com.gaotao.modules.warehouse.service.PalletService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 托盘服务实现类 |
|||
*/ |
|||
@Service |
|||
public class PalletServiceImpl extends ServiceImpl<PalletMapper, Pallet> implements PalletService { |
|||
|
|||
@Autowired |
|||
private PalletMapper palletMapper; |
|||
|
|||
@Autowired |
|||
private TransNoControlService transNoControlService; |
|||
|
|||
@Override |
|||
public PageUtils queryPage(PalletQueryDto queryDto) { |
|||
if (queryDto.getPage() == null) { |
|||
queryDto.setPage(1); |
|||
} |
|||
if (queryDto.getLimit() == null) { |
|||
queryDto.setLimit(20); |
|||
} |
|||
|
|||
IPage<PalletVo> ipage = palletMapper.selectPalletList(new Page<PalletVo>(queryDto.getPage(), queryDto.getLimit()), queryDto); |
|||
return new PageUtils(ipage); |
|||
} |
|||
|
|||
@Override |
|||
public PalletVo getPalletByPalletId(String palletId) { |
|||
if (!StringUtils.hasText(palletId)) { |
|||
return null; |
|||
} |
|||
return palletMapper.selectPalletByPalletId(palletId); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public boolean savePallet(Pallet pallet) { |
|||
// 验证站点信息 |
|||
if (!StringUtils.hasText(pallet.getSite())) { |
|||
throw new XJException("站点信息不能为空"); |
|||
} |
|||
|
|||
// 如果托盘ID为空,则自动生成 |
|||
if (!StringUtils.hasText(pallet.getPalletId())) { |
|||
// 使用TransNoControlService生成托盘ID |
|||
TransNoControl palletNoControl = transNoControlService.getTransNo(pallet.getSite(), "PALLET", 8); |
|||
pallet.setPalletId(palletNoControl.getNewTransNo()); |
|||
} else { |
|||
// 如果手动指定了托盘ID,检查是否已存在 |
|||
if (checkPalletIdExists(pallet.getPalletId(), null)) { |
|||
throw new XJException("托盘ID [" + pallet.getPalletId() + "] 已存在"); |
|||
} |
|||
} |
|||
|
|||
// 设置默认值 |
|||
if (!StringUtils.hasText(pallet.getStatus())) { |
|||
pallet.setStatus("AVAILABLE"); |
|||
} |
|||
|
|||
pallet.setCreatedTime(new Date()); |
|||
return this.save(pallet); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public boolean updatePallet(Pallet pallet) { |
|||
// 检查托盘ID是否已被其他记录使用 |
|||
if (checkPalletIdExists(pallet.getPalletId(), pallet.getId())) { |
|||
throw new XJException("托盘ID [" + pallet.getPalletId() + "] 已被其他记录使用"); |
|||
} |
|||
|
|||
pallet.setUpdatedTime(new Date()); |
|||
return this.updateById(pallet); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public boolean deletePallet(Long id) { |
|||
if (id == null) { |
|||
throw new XJException("托盘ID不能为空"); |
|||
} |
|||
return this.removeById(id); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public boolean deletePalletBatch(Long[] ids) { |
|||
if (ids == null || ids.length == 0) { |
|||
throw new XJException("请选择要删除的托盘"); |
|||
} |
|||
|
|||
for (Long id : ids) { |
|||
deletePallet(id); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
@Override |
|||
public boolean checkPalletIdExists(String palletId, Long excludeId) { |
|||
if (!StringUtils.hasText(palletId)) { |
|||
return false; |
|||
} |
|||
|
|||
QueryWrapper<Pallet> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq("pallet_id", palletId); |
|||
// 由于使用真实删除,不需要检查is_deleted字段 |
|||
|
|||
if (excludeId != null) { |
|||
wrapper.ne("id", excludeId); |
|||
} |
|||
|
|||
return this.count(wrapper) > 0; |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
<?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.gaotao.modules.warehouse.dao.PalletMapper"> |
|||
|
|||
<!-- 查询托盘列表 --> |
|||
<select id="selectPalletList" resultType="com.gaotao.modules.warehouse.entity.vo.PalletVo"> |
|||
SELECT |
|||
p.id, |
|||
p.site, |
|||
p.pallet_id as palletId, |
|||
p.pallet_type as palletType, |
|||
p.pallet_size as palletSize, |
|||
p.max_load as maxLoad, |
|||
p.status, |
|||
CASE p.status |
|||
WHEN 'AVAILABLE' THEN '可用' |
|||
WHEN 'OCCUPIED' THEN '使用中' |
|||
WHEN 'DAMAGED' THEN '损坏' |
|||
WHEN 'DISABLED' THEN '禁用' |
|||
ELSE p.status |
|||
END as statusText, |
|||
p.location_code as locationCode, |
|||
p.remark, |
|||
p.created_by as createdBy, |
|||
p.created_time as createdTime, |
|||
p.updated_by as updatedBy, |
|||
p.updated_time as updatedTime |
|||
FROM pallet p |
|||
<if test="query.site != null and query.site != ''"> |
|||
AND p.site = #{query.site} |
|||
</if> |
|||
<if test="query.palletId != null and query.palletId != ''"> |
|||
AND p.pallet_id LIKE CONCAT('%', #{query.palletId}, '%') |
|||
</if> |
|||
<if test="query.palletType != null and query.palletType != ''"> |
|||
AND p.pallet_type = #{query.palletType} |
|||
</if> |
|||
<if test="query.status != null and query.status != ''"> |
|||
AND p.status = #{query.status} |
|||
</if> |
|||
<if test="query.locationCode != null and query.locationCode != ''"> |
|||
AND p.location_code LIKE CONCAT('%', #{query.locationCode}, '%') |
|||
</if> |
|||
ORDER BY p.created_time DESC |
|||
</select> |
|||
|
|||
<!-- 根据托盘ID查询托盘信息 --> |
|||
<select id="selectPalletByPalletId" resultType="com.gaotao.modules.warehouse.entity.vo.PalletVo"> |
|||
SELECT |
|||
p.id, |
|||
p.site, |
|||
p.pallet_id as palletId, |
|||
p.pallet_type as palletType, |
|||
p.pallet_size as palletSize, |
|||
p.max_load as maxLoad, |
|||
p.status, |
|||
CASE p.status |
|||
WHEN 'AVAILABLE' THEN '可用' |
|||
WHEN 'OCCUPIED' THEN '使用中' |
|||
WHEN 'DAMAGED' THEN '损坏' |
|||
WHEN 'DISABLED' THEN '禁用' |
|||
ELSE p.status |
|||
END as statusText, |
|||
p.location_code as locationCode, |
|||
p.remark, |
|||
p.created_by as createdBy, |
|||
p.created_time as createdTime, |
|||
p.updated_by as updatedBy, |
|||
p.updated_time as updatedTime |
|||
FROM pallet p |
|||
WHERE 1=1 |
|||
AND p.pallet_id = #{palletId} |
|||
</select> |
|||
|
|||
</mapper> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue