初步完善2.0

This commit is contained in:
xuqiuyun
2025-12-10 16:49:35 +08:00
parent 980ffb39b9
commit ec9061fd82
61 changed files with 2638 additions and 2323 deletions

View File

@@ -0,0 +1,100 @@
package com.aiotagro.cattletrade.business.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordCreateDto;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordDto;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordEditDto;
import com.aiotagro.cattletrade.business.entity.SlaughterRecord;
import com.aiotagro.cattletrade.business.service.ISlaughterRecordService;
import com.aiotagro.common.core.web.domain.AjaxResult;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 屠宰记录管理控制器
*
* @author System
* @date 2025-12-10
*/
@RestController
@RequestMapping("/slaughter/record")
public class SlaughterRecordController {
@Autowired
private ISlaughterRecordService slaughterRecordService;
/**
* 分页查询屠宰记录
*/
@SaCheckPermission("slaughterRecord:query")
@PostMapping("/list")
public AjaxResult list(@RequestBody SlaughterRecordDto dto) {
try {
PageResultResponse<SlaughterRecord> result = slaughterRecordService.pageQuery(dto);
return AjaxResult.success(result);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("查询屠宰记录失败:" + e.getMessage());
}
}
/**
* 新增屠宰记录
*/
@SaCheckPermission("slaughterRecord:add")
@PostMapping("/add")
public AjaxResult add(@Validated @RequestBody SlaughterRecordCreateDto dto) {
try {
return slaughterRecordService.addRecord(dto);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("新增屠宰记录失败:" + e.getMessage());
}
}
/**
* 编辑屠宰记录
*/
@SaCheckPermission("slaughterRecord:edit")
@PostMapping("/edit")
public AjaxResult edit(@Validated @RequestBody SlaughterRecordEditDto dto) {
try {
return slaughterRecordService.updateRecord(dto);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("编辑屠宰记录失败:" + e.getMessage());
}
}
/**
* 删除屠宰记录
*/
@SaCheckPermission("slaughterRecord:delete")
@GetMapping("/delete")
public AjaxResult delete(@RequestParam Integer id) {
try {
return slaughterRecordService.deleteRecord(id);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("删除屠宰记录失败:" + e.getMessage());
}
}
/**
* 详情
*/
@SaCheckPermission("slaughterRecord:query")
@GetMapping("/detail")
public AjaxResult detail(@RequestParam Integer id) {
try {
return slaughterRecordService.detail(id);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error("查询屠宰记录详情失败:" + e.getMessage());
}
}
}

View File

@@ -8,6 +8,8 @@ import com.aiotagro.cattletrade.business.service.IWarehouseOutService;
import com.aiotagro.cattletrade.business.vo.WarehouseOutVo;
import com.aiotagro.common.core.web.domain.AjaxResult;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -22,6 +24,8 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/warehouseOut")
public class WarehouseOutController {
private static final Logger logger = LoggerFactory.getLogger(WarehouseOutController.class);
@Autowired
private IWarehouseOutService warehouseOutService;
@@ -61,8 +65,20 @@ public class WarehouseOutController {
@PostMapping("/edit")
public AjaxResult edit(@Validated @RequestBody WarehouseOutEditDto dto) {
try {
// 记录接收到的编辑参数
logger.info("========== 编辑出仓记录 - 接收参数 ==========");
logger.info("出仓记录ID: {}", dto.getId());
logger.info("中转仓ID: {}", dto.getWarehouseId());
logger.info("进仓记录ID (warehouseInId): {}", dto.getWarehouseInId());
logger.info("牛只数量: {}", dto.getCattleCount());
logger.info("运送清单ID: {}", dto.getDeliveryId());
logger.info("订单ID: {}", dto.getOrderId());
logger.info("完整DTO对象: {}", dto);
logger.info("==========================================");
return warehouseOutService.updateWarehouseOut(dto);
} catch (Exception e) {
logger.error("编辑出仓记录失败", e);
e.printStackTrace();
return AjaxResult.error("编辑出仓记录失败:" + e.getMessage());
}

View File

@@ -3,7 +3,6 @@ package com.aiotagro.cattletrade.business.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
* 进场记录创建DTO
@@ -14,6 +13,11 @@ import java.math.BigDecimal;
@Data
public class SlaughterEntryCreateDto {
/**
* 进场编码
*/
private String entryCode;
/**
* 屠宰场ID
*/
@@ -77,9 +81,14 @@ public class SlaughterEntryCreateDto {
private String licensePlate;
/**
* 出肉率(%
* 牛只数量
*/
private BigDecimal yieldRate;
private Integer capacity;
/**
* 剩余牛只数量
*/
private Integer remainingCapacity;
/**
* 备注

View File

@@ -27,5 +27,15 @@ public class SlaughterEntryDto extends BaseDto {
* 订单ID
*/
private Integer orderId;
/**
* 运送清单号(模糊查询)
*/
private String deliveryNumber;
/**
* 订单关键词(用于查询买方或卖方公司名称)
*/
private String orderKeyword;
}

View File

@@ -3,7 +3,6 @@ package com.aiotagro.cattletrade.business.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
* 进场记录编辑DTO
@@ -20,6 +19,11 @@ public class SlaughterEntryEditDto {
@NotNull(message = "主键ID不能为空")
private Integer id;
/**
* 进场编码
*/
private String entryCode;
/**
* 屠宰场ID
*/
@@ -83,9 +87,14 @@ public class SlaughterEntryEditDto {
private String licensePlate;
/**
* 出肉率(%
* 牛只数量
*/
private BigDecimal yieldRate;
private Integer capacity;
/**
* 剩余牛只数量
*/
private Integer remainingCapacity;
/**
* 备注

View File

@@ -0,0 +1,42 @@
package com.aiotagro.cattletrade.business.dto;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
* 屠宰记录创建DTO
*
* @author System
* @date 2025-12-10
*/
@Data
public class SlaughterRecordCreateDto {
/**
* 屠宰记录编码(可选,未填则自动生成)
*/
private String recordCode;
/**
* 进场记录ID
*/
@NotNull(message = "进场记录ID不能为空")
private Integer entryId;
/**
* 屠宰头数
*/
@NotNull(message = "屠宰头数不能为空")
@Min(value = 1, message = "屠宰头数必须大于0")
private Integer slaughterCount;
/**
* 出肉率0-100百分比
*/
private BigDecimal yieldRate;
}

View File

@@ -0,0 +1,37 @@
package com.aiotagro.cattletrade.business.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 屠宰记录查询DTO
*
* @author System
* @date 2025-12-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SlaughterRecordDto extends BaseDto {
/**
* 屠宰记录编码(模糊)
*/
private String recordCode;
/**
* 进场记录ID
*/
private Integer entryId;
/**
* 进场编码(模糊)
*/
private String entryCode;
/**
* 屠宰场ID
*/
private Integer slaughterHouseId;
}

View File

@@ -0,0 +1,25 @@
package com.aiotagro.cattletrade.business.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
* 屠宰记录编辑DTO
*
* @author System
* @date 2025-12-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SlaughterRecordEditDto extends SlaughterRecordCreateDto {
/**
* 主键ID
*/
@NotNull(message = "主键ID不能为空")
private Integer id;
}

View File

@@ -0,0 +1,24 @@
package com.aiotagro.cattletrade.business.dto;
import lombok.Data;
/**
* 进仓记录关联DTO用于多对多关系
*
* @author System
* @date 2025-12-10
*/
@Data
public class WarehouseInRelationDto {
/**
* 进仓记录ID
*/
private Integer warehouseInId;
/**
* 本次出仓数量
*/
private Integer outCount;
}

View File

@@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 出仓创建DTO
@@ -24,9 +25,16 @@ public class WarehouseOutCreateDto {
/**
* 进仓记录ID可选
* 保留用于兼容旧数据格式
*/
private Integer warehouseInId;
/**
* 进仓记录关联数组(多对多关系,每个元素包含 warehouseInId 和 outCount
* 优先使用此字段,如果没有则使用 warehouseInId 和 cattleCount 进行平均分配
*/
private List<WarehouseInRelationDto> warehouseInRelations;
/**
* 订单ID多个订单用逗号分隔
*/

View File

@@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 出仓编辑DTO
@@ -29,9 +30,16 @@ public class WarehouseOutEditDto {
private Integer warehouseId;
/**
* 进仓记录ID可选
* 进仓记录ID可选支持多个ID用逗号分隔1,2,3
* 保留用于兼容旧数据格式
*/
private Integer warehouseInId;
private String warehouseInId;
/**
* 进仓记录关联数组(多对多关系,每个元素包含 warehouseInId 和 outCount
* 优先使用此字段,如果没有则使用 warehouseInId 和 cattleCount 进行平均分配
*/
private List<WarehouseInRelationDto> warehouseInRelations;
/**
* 订单ID多个订单用逗号分隔

View File

@@ -9,7 +9,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
@@ -30,6 +29,12 @@ public class SlaughterEntry implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 进场编码
*/
@TableField("entry_code")
private String entryCode;
/**
* 屠宰场ID
*/
@@ -103,10 +108,16 @@ public class SlaughterEntry implements Serializable {
private String licensePlate;
/**
* 出肉率(%
* 牛只数量
*/
@TableField("yield_rate")
private BigDecimal yieldRate;
@TableField("capacity")
private Integer capacity;
/**
* 剩余牛只数量
*/
@TableField("remaining_capacity")
private Integer remainingCapacity;
/**
* 备注
@@ -146,5 +157,23 @@ public class SlaughterEntry implements Serializable {
*/
@TableField("updated_by")
private Integer updatedBy;
/**
* 运送清单号(关联查询,不存储在数据库中)
*/
@TableField(exist = false)
private String deliveryNumber;
/**
* 订单买方名称(关联查询,不存储在数据库中)
*/
@TableField(exist = false)
private String orderBuyerName;
/**
* 订单卖方名称(关联查询,不存储在数据库中)
*/
@TableField(exist = false)
private String orderSellerName;
}

View File

@@ -0,0 +1,115 @@
package com.aiotagro.cattletrade.business.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 屠宰记录实体
*
* @author System
* @date 2025-12-10
*/
@Data
@TableName("slaughter_record")
public class SlaughterRecord implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 屠宰记录编码
*/
@TableField("record_code")
private String recordCode;
/**
* 进场记录ID
*/
@TableField("entry_id")
private Integer entryId;
/**
* 屠宰头数
*/
@TableField("slaughter_count")
private Integer slaughterCount;
/**
* 出肉率0-100百分比
*/
@TableField("yield_rate")
private BigDecimal yieldRate;
/**
* 逻辑删除标记(0-正常,1-已删除)
*/
@TableLogic(value = "0", delval = "1")
@TableField("is_delete")
private Integer isDelete;
/**
* 创建时间
*/
@TableField("create_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* 更新时间
*/
@TableField("update_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
/**
* 创建人
*/
@TableField("created_by")
private Integer createdBy;
/**
* 更新人
*/
@TableField("updated_by")
private Integer updatedBy;
/**
* 进场编码(关联查询)
*/
@TableField(exist = false)
private String entryCode;
/**
* 屠宰场ID关联查询
*/
@TableField(exist = false)
private Integer slaughterHouseId;
/**
* 屠宰场名称(关联查询)
*/
@TableField(exist = false)
private String slaughterHouseName;
/**
* 进场剩余牛只数量(关联查询)
*/
@TableField(exist = false)
private Integer remainingCapacity;
}

View File

@@ -78,6 +78,12 @@ public class WarehouseIn implements Serializable {
@TableField("cattle_count")
private Integer cattleCount;
/**
* 剩余头数(总数量 - 已出仓数量)
*/
@TableField("remaining_count")
private Integer remainingCount;
/**
* 重量(公斤)
*/

View File

@@ -43,10 +43,10 @@ public class WarehouseOut implements Serializable {
private Integer warehouseId;
/**
* 进仓记录ID可选
* 进仓记录ID可选支持多个ID用逗号分隔1,2,3
*/
@TableField("warehouse_in_id")
private Integer warehouseInId;
private String warehouseInId;
/**
* 订单ID多个订单用逗号分隔

View File

@@ -3,6 +3,8 @@ package com.aiotagro.cattletrade.business.mapper;
import com.aiotagro.cattletrade.business.entity.SlaughterEntry;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* 进场记录 Mapper
@@ -12,5 +14,13 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface SlaughterEntryMapper extends BaseMapper<SlaughterEntry> {
/**
* 根据编码前缀查询最后一个编码(用于生成新编码)
* @param prefixPattern 编码前缀模式,如 "SE20251210%"
* @return 最后一个进场记录
*/
@Select("SELECT * FROM slaughter_entry WHERE entry_code LIKE #{prefixPattern} AND is_delete = 0 ORDER BY entry_code DESC LIMIT 1")
SlaughterEntry selectLastCode(@Param("prefixPattern") String prefixPattern);
}

View File

@@ -0,0 +1,28 @@
package com.aiotagro.cattletrade.business.mapper;
import com.aiotagro.cattletrade.business.entity.SlaughterRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* 屠宰记录 Mapper
*
* @author System
* @date 2025-12-10
*/
@Mapper
public interface SlaughterRecordMapper extends BaseMapper<SlaughterRecord> {
/**
* 根据编码前缀查询最后一个编码(用于生成新编码)
*
* @param prefixPattern 编码前缀模式,如 "SL20251210%"
* @return 最后一个屠宰记录
*/
@Select("SELECT * FROM slaughter_record WHERE record_code LIKE #{prefixPattern} AND is_delete = 0 ORDER BY record_code DESC LIMIT 1")
SlaughterRecord selectLastCode(@Param("prefixPattern") String prefixPattern);
}

View File

@@ -0,0 +1,45 @@
package com.aiotagro.cattletrade.business.service;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordCreateDto;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordDto;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordEditDto;
import com.aiotagro.cattletrade.business.entity.SlaughterRecord;
import com.aiotagro.common.core.web.domain.AjaxResult;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* 屠宰记录服务接口
*
* @author System
* @date 2025-12-10
*/
public interface ISlaughterRecordService extends IService<SlaughterRecord> {
/**
* 分页查询屠宰记录
*/
PageResultResponse<SlaughterRecord> pageQuery(SlaughterRecordDto dto);
/**
* 新增屠宰记录
*/
AjaxResult addRecord(SlaughterRecordCreateDto dto);
/**
* 更新屠宰记录
*/
AjaxResult updateRecord(SlaughterRecordEditDto dto);
/**
* 删除屠宰记录
*/
AjaxResult deleteRecord(Integer id);
/**
* 详情
*/
AjaxResult detail(Integer id);
}

View File

@@ -8,6 +8,7 @@ import com.aiotagro.cattletrade.business.entity.Order;
import com.aiotagro.cattletrade.business.entity.SlaughterEntry;
import com.aiotagro.cattletrade.business.entity.SlaughterHouse;
import com.aiotagro.cattletrade.business.mapper.DeliveryMapper;
import com.aiotagro.cattletrade.business.mapper.MemberMapper;
import com.aiotagro.cattletrade.business.mapper.OrderMapper;
import com.aiotagro.cattletrade.business.mapper.SlaughterEntryMapper;
import com.aiotagro.cattletrade.business.mapper.SlaughterHouseMapper;
@@ -24,9 +25,14 @@ import com.github.pagehelper.PageHelper;
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.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 进场管理服务实现
@@ -45,6 +51,8 @@ public class SlaughterEntryServiceImpl extends ServiceImpl<SlaughterEntryMapper,
private DeliveryMapper deliveryMapper;
@Autowired
private OrderMapper orderMapper;
@Autowired
private MemberMapper memberMapper;
@Override
public PageResultResponse<SlaughterEntry> pageQuery(SlaughterEntryDto dto) {
@@ -65,12 +73,156 @@ public class SlaughterEntryServiceImpl extends ServiceImpl<SlaughterEntryMapper,
if (dto.getOrderId() != null) {
wrapper.eq(SlaughterEntry::getOrderId, dto.getOrderId());
}
// 运送清单号模糊查询
if (StringUtils.hasText(dto.getDeliveryNumber())) {
// 先查询符合条件的运送清单ID
LambdaQueryWrapper<Delivery> deliveryWrapper = new LambdaQueryWrapper<>();
deliveryWrapper.like(Delivery::getDeliveryNumber, dto.getDeliveryNumber());
List<Delivery> deliveries = deliveryMapper.selectList(deliveryWrapper);
if (deliveries != null && !deliveries.isEmpty()) {
List<Integer> deliveryIds = deliveries.stream()
.map(Delivery::getId)
.collect(java.util.stream.Collectors.toList());
wrapper.in(SlaughterEntry::getDeliveryId, deliveryIds);
} else {
// 如果没有匹配的运送清单,返回空结果
wrapper.eq(SlaughterEntry::getId, -1);
}
}
// 订单关键词查询(买方或卖方公司名称)
if (StringUtils.hasText(dto.getOrderKeyword())) {
// 先查询符合条件的订单ID
// 需要关联查询 Order 表和 Member 表
// 由于需要查询 Member 表的用户名,这里先查询所有订单,然后在内存中过滤
List<Order> allOrders = orderMapper.selectList(null);
List<Integer> matchedOrderIds = new java.util.ArrayList<>();
String keyword = dto.getOrderKeyword().trim();
for (Order order : allOrders) {
boolean matched = false;
// 检查买方
if (order.getBuyerId() != null && !order.getBuyerId().isEmpty()) {
String[] buyerIds = order.getBuyerId().split(",");
for (String buyerId : buyerIds) {
try {
Map<String, Object> memberUser = memberMapper.selectMemberUserById(Integer.parseInt(buyerId.trim()));
if (memberUser != null && memberUser.get("username") != null) {
String username = (String) memberUser.get("username");
if (username != null && username.contains(keyword)) {
matched = true;
break;
}
}
} catch (Exception e) {
// 忽略错误
}
}
}
// 检查卖方
if (!matched && order.getSellerId() != null && !order.getSellerId().isEmpty()) {
String[] sellerIds = order.getSellerId().split(",");
for (String sellerId : sellerIds) {
try {
Map<String, Object> memberUser = memberMapper.selectMemberUserById(Integer.parseInt(sellerId.trim()));
if (memberUser != null && memberUser.get("username") != null) {
String username = (String) memberUser.get("username");
if (username != null && username.contains(keyword)) {
matched = true;
break;
}
}
} catch (Exception e) {
// 忽略错误
}
}
}
if (matched) {
matchedOrderIds.add(order.getId());
}
}
if (!matchedOrderIds.isEmpty()) {
wrapper.in(SlaughterEntry::getOrderId, matchedOrderIds);
} else {
// 如果没有匹配的订单,返回空结果
wrapper.eq(SlaughterEntry::getId, -1);
}
}
wrapper.orderByDesc(SlaughterEntry::getCreateTime);
List<SlaughterEntry> list = slaughterEntryMapper.selectList(wrapper);
// 填充关联信息:运送清单号和订单买卖双方
fillRelatedInfo(list);
return new PageResultResponse<>(page.getTotal(), list);
}
/**
* 填充关联信息:运送清单号和订单买卖双方
*/
private void fillRelatedInfo(List<SlaughterEntry> list) {
if (list == null || list.isEmpty()) {
return;
}
for (SlaughterEntry entry : list) {
// 填充运送清单号
if (entry.getDeliveryId() != null) {
Delivery delivery = deliveryMapper.selectById(entry.getDeliveryId());
if (delivery != null) {
entry.setDeliveryNumber(delivery.getDeliveryNumber());
}
}
// 填充订单买卖双方信息
if (entry.getOrderId() != null) {
Order order = orderMapper.selectById(entry.getOrderId());
if (order != null) {
// 填充买方名称
if (order.getBuyerId() != null && !order.getBuyerId().isEmpty()) {
String buyerNames = Arrays.stream(order.getBuyerId().split(","))
.map(buyerId -> {
try {
Map<String, Object> memberUser = memberMapper.selectMemberUserById(Integer.parseInt(buyerId.trim()));
if (memberUser != null && memberUser.get("username") != null) {
return (String) memberUser.get("username");
}
} catch (Exception e) {
// 忽略错误
}
return "";
})
.filter(name -> !name.isEmpty())
.collect(Collectors.joining(", "));
entry.setOrderBuyerName(buyerNames);
}
// 填充卖方名称
if (order.getSellerId() != null && !order.getSellerId().isEmpty()) {
String sellerNames = Arrays.stream(order.getSellerId().split(","))
.map(sellerId -> {
try {
Map<String, Object> memberUser = memberMapper.selectMemberUserById(Integer.parseInt(sellerId.trim()));
if (memberUser != null && memberUser.get("username") != null) {
return (String) memberUser.get("username");
}
} catch (Exception e) {
// 忽略错误
}
return "";
})
.filter(name -> !name.isEmpty())
.collect(Collectors.joining(", "));
entry.setOrderSellerName(sellerNames);
}
}
}
}
}
@Override
@Transactional
@@ -83,6 +235,11 @@ public class SlaughterEntryServiceImpl extends ServiceImpl<SlaughterEntryMapper,
SlaughterEntry entry = new SlaughterEntry();
BeanUtils.copyProperties(dto, entry);
// 如果编码为空,自动生成
if (!StringUtils.hasText(entry.getEntryCode())) {
entry.setEntryCode(generateEntryCode());
}
Integer userId = SecurityUtil.getCurrentUserId();
entry.setCreatedBy(userId);
entry.setCreateTime(new Date());
@@ -149,6 +306,10 @@ public class SlaughterEntryServiceImpl extends ServiceImpl<SlaughterEntryMapper,
if (entry == null || (entry.getIsDelete() != null && entry.getIsDelete() == 1)) {
return AjaxResult.error("进场记录不存在");
}
// 填充关联信息
fillRelatedInfo(Arrays.asList(entry));
return AjaxResult.success("查询成功", entry);
}
@@ -174,5 +335,27 @@ public class SlaughterEntryServiceImpl extends ServiceImpl<SlaughterEntryMapper,
}
return null;
}
/**
* 生成进场编码SE + yyyyMMdd + 4位流水号
*/
private String generateEntryCode() {
String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
String prefix = "SE" + dateStr;
SlaughterEntry last = slaughterEntryMapper.selectLastCode(prefix + "%");
int next = 1;
if (last != null && StringUtils.hasText(last.getEntryCode())) {
String lastCode = last.getEntryCode();
if (lastCode.startsWith(prefix)) {
String seq = lastCode.substring(prefix.length());
try {
next = Integer.parseInt(seq) + 1;
} catch (NumberFormatException ignored) {
next = 1;
}
}
}
return String.format("%s%04d", prefix, next);
}
}

View File

@@ -0,0 +1,380 @@
package com.aiotagro.cattletrade.business.service.impl;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordCreateDto;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordDto;
import com.aiotagro.cattletrade.business.dto.SlaughterRecordEditDto;
import com.aiotagro.cattletrade.business.entity.SlaughterEntry;
import com.aiotagro.cattletrade.business.entity.SlaughterHouse;
import com.aiotagro.cattletrade.business.entity.SlaughterRecord;
import com.aiotagro.cattletrade.business.mapper.SlaughterEntryMapper;
import com.aiotagro.cattletrade.business.mapper.SlaughterHouseMapper;
import com.aiotagro.cattletrade.business.mapper.SlaughterRecordMapper;
import com.aiotagro.cattletrade.business.service.ISlaughterRecordService;
import com.aiotagro.common.core.utils.SecurityUtil;
import com.aiotagro.common.core.utils.bean.BeanUtils;
import com.aiotagro.common.core.web.domain.AjaxResult;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 屠宰记录服务实现
*
* @author System
* @date 2025-12-10
*/
@Service
public class SlaughterRecordServiceImpl extends ServiceImpl<SlaughterRecordMapper, SlaughterRecord> implements ISlaughterRecordService {
@Autowired
private SlaughterRecordMapper slaughterRecordMapper;
@Autowired
private SlaughterEntryMapper slaughterEntryMapper;
@Autowired
private SlaughterHouseMapper slaughterHouseMapper;
@Override
public PageResultResponse<SlaughterRecord> pageQuery(SlaughterRecordDto dto) {
Integer pageNum = dto.getPageNum() != null ? dto.getPageNum() : 1;
Integer pageSize = dto.getPageSize() != null ? dto.getPageSize() : 10;
Page<SlaughterRecord> page = PageHelper.startPage(pageNum, pageSize);
LambdaQueryWrapper<SlaughterRecord> wrapper = new LambdaQueryWrapper<>();
wrapper.and(q -> q.eq(SlaughterRecord::getIsDelete, 0).or().isNull(SlaughterRecord::getIsDelete));
if (StringUtils.hasText(dto.getRecordCode())) {
wrapper.like(SlaughterRecord::getRecordCode, dto.getRecordCode().trim());
}
if (dto.getEntryId() != null) {
wrapper.eq(SlaughterRecord::getEntryId, dto.getEntryId());
}
// 按进场编码模糊查询
if (StringUtils.hasText(dto.getEntryCode())) {
List<SlaughterEntry> matchedEntries = slaughterEntryMapper.selectList(new LambdaQueryWrapper<SlaughterEntry>()
.like(SlaughterEntry::getEntryCode, dto.getEntryCode().trim())
.and(q -> q.eq(SlaughterEntry::getIsDelete, 0).or().isNull(SlaughterEntry::getIsDelete)));
if (CollectionUtils.isEmpty(matchedEntries)) {
wrapper.eq(SlaughterRecord::getId, -1);
} else {
Set<Integer> entryIds = matchedEntries.stream().map(SlaughterEntry::getId).collect(Collectors.toSet());
wrapper.in(SlaughterRecord::getEntryId, entryIds);
}
}
// 按屠宰场过滤
if (dto.getSlaughterHouseId() != null) {
List<SlaughterEntry> matchedEntries = slaughterEntryMapper.selectList(new LambdaQueryWrapper<SlaughterEntry>()
.eq(SlaughterEntry::getSlaughterHouseId, dto.getSlaughterHouseId())
.and(q -> q.eq(SlaughterEntry::getIsDelete, 0).or().isNull(SlaughterEntry::getIsDelete)));
if (CollectionUtils.isEmpty(matchedEntries)) {
wrapper.eq(SlaughterRecord::getId, -1);
} else {
Set<Integer> entryIds = matchedEntries.stream().map(SlaughterEntry::getId).collect(Collectors.toSet());
wrapper.in(SlaughterRecord::getEntryId, entryIds);
}
}
wrapper.orderByDesc(SlaughterRecord::getCreateTime);
List<SlaughterRecord> list = slaughterRecordMapper.selectList(wrapper);
fillRelatedInfo(list);
return new PageResultResponse<>(page.getTotal(), list);
}
@Override
@Transactional
public AjaxResult addRecord(SlaughterRecordCreateDto dto) {
String yieldCheck = validateYieldRate(dto.getYieldRate());
if (yieldCheck != null) {
return AjaxResult.error(yieldCheck);
}
SlaughterEntry entry = loadEntry(dto.getEntryId());
if (entry == null) {
return AjaxResult.error("进场记录不存在");
}
int remaining = entry.getRemainingCapacity() == null ? 0 : entry.getRemainingCapacity();
if (dto.getSlaughterCount() > remaining) {
return AjaxResult.error("屠宰头数不能超过进场剩余头数,当前剩余:" + remaining);
}
SlaughterRecord record = new SlaughterRecord();
BeanUtils.copyProperties(dto, record);
if (!StringUtils.hasText(record.getRecordCode())) {
record.setRecordCode(generateRecordCode());
}
Integer userId = SecurityUtil.getCurrentUserId();
Date now = new Date();
record.setCreatedBy(userId);
record.setCreateTime(now);
record.setIsDelete(0);
int inserted = slaughterRecordMapper.insert(record);
if (inserted <= 0) {
return AjaxResult.error("新增屠宰记录失败");
}
// 扣减剩余头数
if (!updateRemainingCapacity(entry.getId(), -dto.getSlaughterCount(), userId, now)) {
throw new RuntimeException("扣减进场剩余头数失败");
}
return AjaxResult.success("新增屠宰记录成功");
}
@Override
@Transactional
public AjaxResult updateRecord(SlaughterRecordEditDto dto) {
String yieldCheck = validateYieldRate(dto.getYieldRate());
if (yieldCheck != null) {
return AjaxResult.error(yieldCheck);
}
SlaughterRecord existing = slaughterRecordMapper.selectById(dto.getId());
if (existing == null || (existing.getIsDelete() != null && existing.getIsDelete() == 1)) {
return AjaxResult.error("屠宰记录不存在");
}
if (!Objects.equals(existing.getEntryId(), dto.getEntryId())) {
return AjaxResult.error("暂不支持变更进场记录,请删除后重新新增");
}
SlaughterEntry entry = loadEntry(existing.getEntryId());
if (entry == null) {
return AjaxResult.error("进场记录不存在");
}
int remaining = entry.getRemainingCapacity() == null ? 0 : entry.getRemainingCapacity();
int available = remaining + (existing.getSlaughterCount() == null ? 0 : existing.getSlaughterCount());
if (dto.getSlaughterCount() > available) {
return AjaxResult.error("屠宰头数不能超过进场剩余头数,当前可用:" + available);
}
SlaughterRecord record = new SlaughterRecord();
BeanUtils.copyProperties(dto, record);
if (!StringUtils.hasText(record.getRecordCode())) {
record.setRecordCode(existing.getRecordCode());
}
Integer userId = SecurityUtil.getCurrentUserId();
Date now = new Date();
record.setUpdatedBy(userId);
record.setUpdateTime(now);
record.setIsDelete(0);
int updated = slaughterRecordMapper.updateById(record);
if (updated <= 0) {
return AjaxResult.error("更新屠宰记录失败");
}
int adjust = (existing.getSlaughterCount() == null ? 0 : existing.getSlaughterCount()) - dto.getSlaughterCount();
if (adjust != 0 && !updateRemainingCapacity(entry.getId(), adjust, userId, now)) {
throw new RuntimeException("调整进场剩余头数失败");
}
return AjaxResult.success("更新屠宰记录成功");
}
@Override
@Transactional
public AjaxResult deleteRecord(Integer id) {
if (id == null) {
return AjaxResult.error("屠宰记录ID不能为空");
}
SlaughterRecord existing = slaughterRecordMapper.selectById(id);
if (existing == null || (existing.getIsDelete() != null && existing.getIsDelete() == 1)) {
return AjaxResult.error("屠宰记录不存在");
}
Integer userId = SecurityUtil.getCurrentUserId();
Date now = new Date();
UpdateWrapper<SlaughterRecord> wrapper = new UpdateWrapper<>();
wrapper.eq("id", id)
.eq("is_delete", 0)
.set("is_delete", 1)
.set("updated_by", userId)
.set("update_time", now);
int result = slaughterRecordMapper.update(null, wrapper);
if (result <= 0) {
return AjaxResult.error("删除屠宰记录失败");
}
int recover = existing.getSlaughterCount() == null ? 0 : existing.getSlaughterCount();
if (recover > 0 && !updateRemainingCapacity(existing.getEntryId(), recover, userId, now)) {
throw new RuntimeException("回补进场剩余头数失败");
}
return AjaxResult.success("删除屠宰记录成功");
}
@Override
public AjaxResult detail(Integer id) {
if (id == null) {
return AjaxResult.error("屠宰记录ID不能为空");
}
SlaughterRecord record = slaughterRecordMapper.selectById(id);
if (record == null || (record.getIsDelete() != null && record.getIsDelete() == 1)) {
return AjaxResult.error("屠宰记录不存在");
}
fillRelatedInfo(record);
return AjaxResult.success("查询成功", record);
}
/**
* 填充关联信息
*/
private void fillRelatedInfo(List<SlaughterRecord> list) {
if (CollectionUtils.isEmpty(list)) {
return;
}
Set<Integer> entryIds = list.stream()
.map(SlaughterRecord::getEntryId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (CollectionUtils.isEmpty(entryIds)) {
return;
}
List<SlaughterEntry> entries = slaughterEntryMapper.selectBatchIds(entryIds);
Map<Integer, SlaughterEntry> entryMap = entries.stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(SlaughterEntry::getId, e -> e));
Set<Integer> houseIds = entries.stream()
.map(SlaughterEntry::getSlaughterHouseId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Integer, SlaughterHouse> houseMap = new java.util.HashMap<>();
if (!CollectionUtils.isEmpty(houseIds)) {
houseMap = slaughterHouseMapper.selectBatchIds(houseIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(SlaughterHouse::getId, h -> h));
}
for (SlaughterRecord record : list) {
SlaughterEntry entry = entryMap.get(record.getEntryId());
if (entry != null) {
record.setEntryCode(entry.getEntryCode());
record.setSlaughterHouseId(entry.getSlaughterHouseId());
record.setRemainingCapacity(entry.getRemainingCapacity());
SlaughterHouse house = houseMap.get(entry.getSlaughterHouseId());
if (house != null) {
record.setSlaughterHouseName(house.getHouseName());
}
}
}
}
private void fillRelatedInfo(SlaughterRecord record) {
if (record == null) {
return;
}
fillRelatedInfo(Collections.singletonList(record));
}
private SlaughterEntry loadEntry(Integer entryId) {
if (entryId == null) {
return null;
}
SlaughterEntry entry = slaughterEntryMapper.selectById(entryId);
if (entry == null || (entry.getIsDelete() != null && entry.getIsDelete() == 1)) {
return null;
}
return entry;
}
/**
* 更新进场剩余头数delta为正表示回补为负表示扣减
*/
private boolean updateRemainingCapacity(Integer entryId, int delta, Integer userId, Date now) {
if (delta == 0) {
return true;
}
UpdateWrapper<SlaughterEntry> wrapper = new UpdateWrapper<>();
wrapper.eq("id", entryId)
.eq("is_delete", 0)
.set("updated_by", userId)
.set("update_time", now);
if (delta < 0) {
int decrease = Math.abs(delta);
wrapper.ge("remaining_capacity", decrease)
.setSql("remaining_capacity = remaining_capacity - " + decrease);
} else {
wrapper.setSql("remaining_capacity = remaining_capacity + " + delta);
}
int updated = slaughterEntryMapper.update(null, wrapper);
return updated > 0;
}
/**
* 校验出肉率范围
*/
private String validateYieldRate(BigDecimal yieldRate) {
if (yieldRate == null) {
return null;
}
if (yieldRate.compareTo(BigDecimal.ZERO) < 0 || yieldRate.compareTo(new BigDecimal("100")) > 0) {
return "出肉率需在0-100之间";
}
return null;
}
/**
* 生成屠宰记录编码SL + yyyyMMdd + 3位流水
*/
private String generateRecordCode() {
String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
String prefix = "SL" + dateStr;
SlaughterRecord last = slaughterRecordMapper.selectLastCode(prefix + "%");
int next = 1;
if (last != null && StringUtils.hasText(last.getRecordCode())) {
String lastCode = last.getRecordCode();
if (lastCode.startsWith(prefix)) {
String seq = lastCode.substring(prefix.length());
try {
next = Integer.parseInt(seq) + 1;
} catch (NumberFormatException ignored) {
next = 1;
}
}
}
return String.format("%s%03d", prefix, next);
}
}

View File

@@ -146,6 +146,8 @@ public class WarehouseInServiceImpl extends ServiceImpl<WarehouseInMapper, Wareh
BeanUtils.copyProperties(dto, warehouseIn);
warehouseIn.setInNumber(inNumber);
warehouseIn.setStatus(1); // 默认待进仓
// 初始化剩余头数 = 总数量
warehouseIn.setRemainingCount(dto.getCattleCount() != null ? dto.getCattleCount() : 0);
// 设置创建人和创建时间
Integer userId = SecurityUtil.getCurrentUserId();

View File

@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
@@ -42,6 +44,8 @@ import java.util.List;
@Service
public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, WarehouseOut> implements IWarehouseOutService {
private static final Logger logger = LoggerFactory.getLogger(WarehouseOutServiceImpl.class);
@Autowired
private WarehouseOutMapper warehouseOutMapper;
@@ -110,11 +114,23 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
}
}
// 关联查询进仓记录
if (warehouseOut.getWarehouseInId() != null) {
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseOut.getWarehouseInId());
if (warehouseIn != null) {
vo.setWarehouseInNumber(warehouseIn.getInNumber());
// 关联查询进仓记录支持多个ID用逗号分隔
if (warehouseOut.getWarehouseInId() != null && !warehouseOut.getWarehouseInId().trim().isEmpty()) {
String[] warehouseInIds = warehouseOut.getWarehouseInId().split(",");
List<String> warehouseInNumbers = new ArrayList<>();
for (String warehouseInIdStr : warehouseInIds) {
try {
Integer warehouseInId = Integer.parseInt(warehouseInIdStr.trim());
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseInId);
if (warehouseIn != null) {
warehouseInNumbers.add(warehouseIn.getInNumber());
}
} catch (NumberFormatException e) {
logger.warn("进仓记录ID格式错误: {}", warehouseInIdStr);
}
}
if (!warehouseInNumbers.isEmpty()) {
vo.setWarehouseInNumber(String.join(",", warehouseInNumbers));
}
}
@@ -185,6 +201,19 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
int result = warehouseOutMapper.insert(warehouseOut);
if (result > 0) {
// 更新相关进仓记录的剩余数量
// 优先使用 warehouseInRelations 数组,如果没有则使用 warehouseInId 和 cattleCount 进行平均分配
if (dto.getWarehouseInRelations() != null && !dto.getWarehouseInRelations().isEmpty()) {
// 使用 warehouseInRelations 数组,精确更新每个进仓记录的剩余数量
for (com.aiotagro.cattletrade.business.dto.WarehouseInRelationDto relation : dto.getWarehouseInRelations()) {
if (relation.getWarehouseInId() != null && relation.getOutCount() != null && relation.getOutCount() > 0) {
updateSingleWarehouseInRemainingCount(relation.getWarehouseInId(), relation.getOutCount(), true);
}
}
} else if (warehouseOut.getWarehouseInId() != null && warehouseOut.getCattleCount() != null) {
// 回退到平均分配逻辑(兼容旧数据)
updateWarehouseInRemainingCount(warehouseOut.getWarehouseInId(), warehouseOut.getCattleCount(), true);
}
return AjaxResult.success("新增出仓记录成功", warehouseOut);
} else {
return AjaxResult.error("新增出仓记录失败");
@@ -207,6 +236,9 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
@Override
@Transactional
public AjaxResult updateWarehouseOut(WarehouseOutEditDto dto) {
logger.info("========== 更新出仓记录 - Service层 ==========");
logger.info("接收到的DTO - ID: {}, warehouseInId: {}", dto.getId(), dto.getWarehouseInId());
if (dto.getId() == null) {
return AjaxResult.error("出仓记录ID不能为空");
}
@@ -216,6 +248,8 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
if (existingWarehouseOut == null) {
return AjaxResult.error("出仓记录不存在");
}
logger.info("更新前 - 原有记录 warehouse_in_id: {}", existingWarehouseOut.getWarehouseInId());
// 校验中转仓是否存在且启用
Warehouse warehouse = warehouseMapper.selectById(dto.getWarehouseId());
@@ -227,36 +261,91 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
}
// 如果关联了进仓记录,校验进仓记录是否存在
if (dto.getWarehouseInId() != null) {
WarehouseIn warehouseIn = warehouseInMapper.selectById(dto.getWarehouseInId());
if (warehouseIn == null || (warehouseIn.getIsDelete() != null && warehouseIn.getIsDelete() == 1)) {
return AjaxResult.error("进仓记录不存在");
}
// 校验出仓数量不能超过进仓数量
if (dto.getCattleCount() > warehouseIn.getCattleCount()) {
return AjaxResult.error("出仓数量不能超过进仓数量");
// 注意warehouseInId 现在可能是多个ID用逗号分隔需要分别校验
if (dto.getWarehouseInId() != null && !dto.getWarehouseInId().trim().isEmpty()) {
String[] warehouseInIds = dto.getWarehouseInId().split(",");
for (String warehouseInIdStr : warehouseInIds) {
try {
Integer warehouseInId = Integer.parseInt(warehouseInIdStr.trim());
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseInId);
if (warehouseIn == null || (warehouseIn.getIsDelete() != null && warehouseIn.getIsDelete() == 1)) {
logger.warn("进仓记录不存在ID: {}", warehouseInId);
return AjaxResult.error("进仓记录不存在ID: " + warehouseInId);
}
// 注意:多对多关系时,不能简单比较总数,需要在关联表中校验
// 这里暂时保留原有逻辑,后续可以优化
logger.info("校验进仓记录 - ID: {}, 进仓数量: {}", warehouseInId, warehouseIn.getCattleCount());
} catch (NumberFormatException e) {
logger.warn("进仓记录ID格式错误: {}", warehouseInIdStr, e);
return AjaxResult.error("进仓记录ID格式错误: " + warehouseInIdStr);
}
}
}
// 更新出仓信息
WarehouseOut warehouseOut = new WarehouseOut();
BeanUtils.copyProperties(dto, warehouseOut);
logger.info("BeanUtils.copyProperties 后 - warehouseOut.warehouseInId: {}", warehouseOut.getWarehouseInId());
logger.info("DTO中的warehouseInId类型: {}, 值: {}",
dto.getWarehouseInId() != null ? dto.getWarehouseInId().getClass().getName() : "null",
dto.getWarehouseInId());
// 设置更新人和更新时间
Integer userId = SecurityUtil.getCurrentUserId();
warehouseOut.setUpdatedBy(userId);
warehouseOut.setUpdateTime(new Date());
logger.info("准备保存到数据库 - warehouseOut对象详情:");
logger.info(" - id: {}", warehouseOut.getId());
logger.info(" - warehouseId: {}", warehouseOut.getWarehouseId());
logger.info(" - warehouseInId: {} (类型: {})",
warehouseOut.getWarehouseInId(),
warehouseOut.getWarehouseInId() != null ? warehouseOut.getWarehouseInId().getClass().getName() : "null");
logger.info(" - cattleCount: {}", warehouseOut.getCattleCount());
logger.info(" - deliveryId: {}", warehouseOut.getDeliveryId());
try {
// 先恢复旧的出仓数量(增加剩余数量)
if (existingWarehouseOut.getWarehouseInId() != null && existingWarehouseOut.getCattleCount() != null) {
updateWarehouseInRemainingCount(existingWarehouseOut.getWarehouseInId(), existingWarehouseOut.getCattleCount(), false);
}
// 更新数据库
int result = warehouseOutMapper.updateById(warehouseOut);
logger.info("数据库更新结果: {}", result > 0 ? "成功" : "失败");
// 查询更新后的数据,验证是否保存成功
if (result > 0) {
WarehouseOut updatedRecord = warehouseOutMapper.selectById(dto.getId());
if (updatedRecord != null) {
logger.info("更新后查询数据库 - warehouse_in_id: {}", updatedRecord.getWarehouseInId());
}
}
if (result > 0) {
// 减去新的出仓数量(减少剩余数量)
// 优先使用 warehouseInRelations 数组,如果没有则使用 warehouseInId 和 cattleCount 进行平均分配
if (dto.getWarehouseInRelations() != null && !dto.getWarehouseInRelations().isEmpty()) {
// 使用 warehouseInRelations 数组,精确更新每个进仓记录的剩余数量
for (com.aiotagro.cattletrade.business.dto.WarehouseInRelationDto relation : dto.getWarehouseInRelations()) {
if (relation.getWarehouseInId() != null && relation.getOutCount() != null && relation.getOutCount() > 0) {
updateSingleWarehouseInRemainingCount(relation.getWarehouseInId(), relation.getOutCount(), true);
}
}
} else if (warehouseOut.getWarehouseInId() != null && warehouseOut.getCattleCount() != null) {
// 回退到平均分配逻辑(兼容旧数据)
updateWarehouseInRemainingCount(warehouseOut.getWarehouseInId(), warehouseOut.getCattleCount(), true);
}
logger.info("========== 更新出仓记录成功 ==========");
return AjaxResult.success("更新出仓记录成功");
} else {
logger.warn("========== 更新出仓记录失败 - 影响行数为0 ==========");
return AjaxResult.error("更新出仓记录失败");
}
} catch (Exception e) {
logger.error("========== 更新出仓记录异常 ==========", e);
e.printStackTrace();
return AjaxResult.error("更新出仓记录失败:" + e.getMessage());
}
@@ -293,6 +382,10 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
int result = warehouseOutMapper.update(null, updateWrapper);
if (result > 0) {
// 恢复相关进仓记录的剩余数量(增加剩余数量)
if (warehouseOut.getWarehouseInId() != null && warehouseOut.getCattleCount() != null) {
updateWarehouseInRemainingCount(warehouseOut.getWarehouseInId(), warehouseOut.getCattleCount(), false);
}
return AjaxResult.success("删除出仓记录成功");
} else {
return AjaxResult.error("删除出仓记录失败");
@@ -325,11 +418,23 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
}
}
// 关联查询进仓记录
if (warehouseOut.getWarehouseInId() != null) {
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseOut.getWarehouseInId());
if (warehouseIn != null) {
vo.setWarehouseInNumber(warehouseIn.getInNumber());
// 关联查询进仓记录支持多个ID用逗号分隔
if (warehouseOut.getWarehouseInId() != null && !warehouseOut.getWarehouseInId().trim().isEmpty()) {
String[] warehouseInIds = warehouseOut.getWarehouseInId().split(",");
List<String> warehouseInNumbers = new ArrayList<>();
for (String warehouseInIdStr : warehouseInIds) {
try {
Integer warehouseInId = Integer.parseInt(warehouseInIdStr.trim());
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseInId);
if (warehouseIn != null) {
warehouseInNumbers.add(warehouseIn.getInNumber());
}
} catch (NumberFormatException e) {
logger.warn("进仓记录ID格式错误: {}", warehouseInIdStr);
}
}
if (!warehouseInNumbers.isEmpty()) {
vo.setWarehouseInNumber(String.join(",", warehouseInNumbers));
}
}
@@ -369,6 +474,98 @@ public class WarehouseOutServiceImpl extends ServiceImpl<WarehouseOutMapper, War
return String.format("%s%04d", datePrefix, nextSequence);
}
/**
* 更新单个进仓记录的剩余数量
* @param warehouseInId 进仓记录ID
* @param outCount 出仓数量
* @param isSubtract true-减去出仓数量减少剩余数量false-增加出仓数量(恢复剩余数量)
*/
private void updateSingleWarehouseInRemainingCount(Integer warehouseInId, Integer outCount, boolean isSubtract) {
if (warehouseInId == null || outCount == null || outCount <= 0) {
return;
}
try {
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseInId);
if (warehouseIn != null && warehouseIn.getIsDelete() != null && warehouseIn.getIsDelete() == 0) {
int currentRemaining = warehouseIn.getRemainingCount() != null ? warehouseIn.getRemainingCount() : warehouseIn.getCattleCount();
int newRemaining;
if (isSubtract) {
// 减去出仓数量
newRemaining = Math.max(0, currentRemaining - outCount);
} else {
// 恢复出仓数量
newRemaining = Math.min(warehouseIn.getCattleCount(), currentRemaining + outCount);
}
UpdateWrapper<WarehouseIn> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", warehouseInId)
.eq("is_delete", 0)
.set("remaining_count", newRemaining)
.set("update_time", new Date());
warehouseInMapper.update(null, updateWrapper);
logger.info("更新进仓记录 {} 的剩余数量: {} -> {} (出仓数量: {}, 操作: {})",
warehouseInId, currentRemaining, newRemaining, outCount, isSubtract ? "减去" : "恢复");
}
} catch (Exception e) {
logger.error("更新进仓记录剩余数量失败进仓记录ID: {}", warehouseInId, e);
}
}
/**
* 更新进仓记录的剩余数量(平均分配方式,用于兼容旧数据)
* @param warehouseInIdStr 进仓记录ID可能是单个ID或逗号分隔的多个ID
* @param outCount 出仓数量
* @param isSubtract true-减去出仓数量减少剩余数量false-增加出仓数量(恢复剩余数量)
*/
private void updateWarehouseInRemainingCount(String warehouseInIdStr, Integer outCount, boolean isSubtract) {
if (warehouseInIdStr == null || warehouseInIdStr.trim().isEmpty() || outCount == null || outCount <= 0) {
return;
}
try {
String[] warehouseInIds = warehouseInIdStr.split(",");
int countPerIn = outCount / warehouseInIds.length; // 平均分配出仓数量
int remainder = outCount % warehouseInIds.length; // 余数分配给第一个
for (int i = 0; i < warehouseInIds.length; i++) {
try {
Integer warehouseInId = Integer.parseInt(warehouseInIds[i].trim());
WarehouseIn warehouseIn = warehouseInMapper.selectById(warehouseInId);
if (warehouseIn != null && warehouseIn.getIsDelete() != null && warehouseIn.getIsDelete() == 0) {
int currentRemaining = warehouseIn.getRemainingCount() != null ? warehouseIn.getRemainingCount() : warehouseIn.getCattleCount();
int outCountForThis = countPerIn + (i == 0 ? remainder : 0); // 第一个分配余数
int newRemaining;
if (isSubtract) {
// 减去出仓数量
newRemaining = Math.max(0, currentRemaining - outCountForThis);
} else {
// 恢复出仓数量
newRemaining = Math.min(warehouseIn.getCattleCount(), currentRemaining + outCountForThis);
}
UpdateWrapper<WarehouseIn> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", warehouseInId)
.eq("is_delete", 0)
.set("remaining_count", newRemaining)
.set("update_time", new Date());
warehouseInMapper.update(null, updateWrapper);
logger.info("更新进仓记录 {} 的剩余数量: {} -> {} (出仓数量: {}, 操作: {})",
warehouseInId, currentRemaining, newRemaining, outCountForThis, isSubtract ? "减去" : "恢复");
}
} catch (NumberFormatException e) {
logger.warn("进仓记录ID格式错误: {}", warehouseInIds[i], e);
}
}
} catch (Exception e) {
logger.error("更新进仓记录剩余数量失败", e);
}
}
/**
* 获取状态描述
*/

View File

@@ -85,6 +85,11 @@ public class WarehouseInVo {
*/
private Integer cattleCount;
/**
* 剩余头数(总数量 - 已出仓数量)
*/
private Integer remainingCount;
/**
* 重量(公斤)
*/

View File

@@ -36,9 +36,9 @@ public class WarehouseOutVo {
private String warehouseName;
/**
* 进仓记录ID可选
* 进仓记录ID可选支持多个ID用逗号分隔1,2,3
*/
private Integer warehouseInId;
private String warehouseInId;
/**
* 进仓单号通过warehouse_in_id关联查询

View File

@@ -95,3 +95,8 @@ openapi:
iot:
url: http://aiot.aiotagro.com/iotPlateform/iotBusiness/sendCmd
# 日志等级调整:抑制重复的 NotLoginException 警告,只保留错误级别
logging:
level:
org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver: error

View File

@@ -1,137 +0,0 @@
# 销售概览菜单配置说明
## 问题说明
如果销售概览页面可以访问,但侧边栏菜单中没有显示,通常是因为:
1. 菜单已插入数据库,但没有给用户/角色分配权限
2. 菜单的 `org_type` 配置与用户不匹配
## 解决步骤
### 步骤1检查菜单是否已插入
执行检查SQL
```sql
-- 文件check_salesoverview_menu.sql
USE cattletrade;
SELECT * FROM sys_menu WHERE name = '销售概览' AND is_delete = 0;
```
如果查询结果为空,说明菜单未插入,需要先执行 `insert_salesoverview_menu.sql`
### 步骤2分配菜单权限
有两种方式分配权限:
#### 方式A通过SQL脚本分配推荐
执行权限分配SQL
```sql
-- 文件assign_salesoverview_menu_permission.sql
-- 该脚本会为角色ID=1超级管理员分配销售概览菜单权限
```
**注意**如果您的超级管理员角色ID不是1请先查询
```sql
SELECT id, name FROM sys_role WHERE name LIKE '%管理员%' OR name LIKE '%admin%';
```
然后修改SQL脚本中的角色ID。
#### 方式B通过系统界面分配
1. 登录系统管理后台
2. 进入 **权限管理****操作权限管理**
3. 选择需要分配权限的角色
4. 勾选销售概览相关的菜单项:
- 销售概览(主菜单)
- 新增
- 编辑
- 删除
- 计算统计数据
5. 点击保存
### 步骤3检查菜单的org_type配置
菜单的 `org_type` 字段:
- 1 = 海关端
- 2 = 企业端
- 3 = 海关企业共用
如果您的用户是企业端,但菜单的 `org_type` 是1海关端菜单也不会显示。
**检查当前用户的org_type**
```sql
-- 查询用户所属机构类型
SELECT u.id, u.name, u.mobile, r.name AS role_name, r.org_type
FROM sys_user u
LEFT JOIN sys_role r ON u.role_id = r.id
WHERE u.mobile = '15900000000'; -- 替换为实际手机号
```
**如果需要修改菜单的org_type**
```sql
-- 将销售概览菜单设置为企业端和海关端共用
UPDATE sys_menu
SET org_type = 3
WHERE name = '销售概览' AND type = 1 AND is_delete = 0;
```
### 步骤4刷新页面
执行完SQL或分配权限后
1. 退出登录
2. 重新登录系统
3. 刷新页面
菜单应该会出现在侧边栏中。
## 快速修复SQL一键执行
如果确认菜单已插入只需要分配权限可以执行以下SQL
```sql
USE cattletrade;
-- 查询销售概览菜单ID
SET @menu_id = (SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1);
-- 为角色ID=1超级管理员分配主菜单权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @menu_id
WHERE NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = @menu_id)
AND @menu_id IS NOT NULL;
-- 为角色ID=1分配所有按钮权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, id
FROM sys_menu
WHERE parent_id = @menu_id AND type = 2 AND is_delete = 0
AND NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = sys_menu.id)
AND @menu_id IS NOT NULL;
```
## 验证
执行以下SQL验证权限是否分配成功
```sql
USE cattletrade;
-- 查询销售概览菜单权限分配情况
SELECT
r.id AS role_id,
r.name AS role_name,
m.id AS menu_id,
m.name AS menu_name,
m.type AS menu_type,
m.page_url
FROM sys_role_menu rm
INNER JOIN sys_role r ON rm.role_id = r.id
INNER JOIN sys_menu m ON rm.menu_id = m.id
WHERE m.name = '销售概览' OR m.parent_id = (SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1)
ORDER BY r.id, m.type, m.sort;
```
如果查询结果中有您的角色,说明权限已分配成功。

View File

@@ -1,14 +0,0 @@
-- 扩展耳标与项圈日志表的经纬度字段长度,避免坐标精度过高导致超长
USE cattletrade;
-- jbq_client_log智能耳标日志表
ALTER TABLE jbq_client_log
MODIFY COLUMN latitude VARCHAR(32) COMMENT '纬度',
MODIFY COLUMN longitude VARCHAR(32) COMMENT '经度';
-- xq_client_log项圈日志表
ALTER TABLE xq_client_log
MODIFY COLUMN latitude VARCHAR(32) COMMENT '纬度',
MODIFY COLUMN longitude VARCHAR(32) COMMENT '经度';

View File

@@ -1,16 +0,0 @@
-- 为 delivery 表添加 estimated_departure_time 字段(预计出发时间)
-- 此脚本已手动执行,保留作为参考文档
USE cattletrade;
-- 添加预计出发时间字段(如果字段已存在,此语句会报错,可以忽略)
-- ALTER TABLE delivery
-- ADD COLUMN estimated_departure_time DATETIME COMMENT '预计出发时间'
-- AFTER estimated_delivery_time;
-- 为现有记录设置默认值(使用创建时间作为默认的预计出发时间)
-- 如果字段中已有部分数据,可以执行此更新语句为 NULL 值设置默认值
UPDATE delivery
SET estimated_departure_time = create_time
WHERE estimated_departure_time IS NULL;

View File

@@ -1,12 +0,0 @@
USE cattletrade;
-- 为运送清单表新增百度鹰眼同步字段
ALTER TABLE `delivery`
ADD COLUMN `yingyan_entity_name` VARCHAR(64) NULL DEFAULT NULL COMMENT '百度鹰眼终端名称';
ALTER TABLE `delivery`
ADD COLUMN `yingyan_last_sync_time` DATETIME NULL DEFAULT NULL COMMENT '百度鹰眼最后同步时间';
ALTER TABLE `delivery`
ADD COLUMN `arrival_time` DATETIME NULL DEFAULT NULL COMMENT '自动判定的到达时间';

View File

@@ -1,14 +0,0 @@
USE cattletrade;
-- 修改 delivery 表的 order_id 字段类型为 VARCHAR用于存储多个订单ID逗号分隔
-- 将原来的 INTEGER 类型改为 VARCHAR(500)支持存储多个订单ID如 "1,2,3"
-- 注意:如果表中已有数据,需要先将现有的 order_id 值转换为字符串格式
-- 例如:如果 order_id = 123转换后仍为 "123"
ALTER TABLE `delivery`
MODIFY COLUMN `order_id` VARCHAR(500) NULL DEFAULT NULL COMMENT '订单ID多个订单ID用逗号分隔1,2,3';
-- 如果表中已有数据,将现有的整数 order_id 转换为字符串格式
-- UPDATE delivery SET order_id = CAST(order_id AS CHAR) WHERE order_id IS NOT NULL;

View File

@@ -1,18 +0,0 @@
-- 修复 vehicle 表 record_code 字段长度问题
-- 将 record_code 字段从当前长度扩展为 VARCHAR(1000) 以支持较长的图片URL
-- 同时扩展其他图片URL字段以确保一致性
-- 修改 record_code 字段
ALTER TABLE vehicle MODIFY COLUMN record_code VARCHAR(1000) COMMENT '牧运通备案码图片URL';
-- 修改其他图片URL字段如果需要建议也一起修改
ALTER TABLE vehicle MODIFY COLUMN car_front_photo VARCHAR(1000) COMMENT '车头照片URL';
ALTER TABLE vehicle MODIFY COLUMN car_rear_photo VARCHAR(1000) COMMENT '车尾照片URL';
ALTER TABLE vehicle MODIFY COLUMN driving_license_photo VARCHAR(1000) COMMENT '行驶证照片URL';
-- 如果您的数据库不支持修改字段长度,或者需要更大的容量,可以使用 TEXT 类型:
-- ALTER TABLE vehicle MODIFY COLUMN record_code TEXT COMMENT '牧运通备案码图片URL';
-- ALTER TABLE vehicle MODIFY COLUMN car_front_photo TEXT COMMENT '车头照片URL';
-- ALTER TABLE vehicle MODIFY COLUMN car_rear_photo TEXT COMMENT '车尾照片URL';
-- ALTER TABLE vehicle MODIFY COLUMN driving_license_photo TEXT COMMENT '行驶证照片URL';

View File

@@ -1,63 +0,0 @@
USE cattletrade;
-- 为 warning_log 表添加索引以优化预警列表查询性能
-- 优化目标getPageWarningLog 查询中的派生表查询和 JOIN 操作
--
-- 执行说明:
-- 1. 先执行检查脚本查看现有索引SHOW INDEX FROM warning_log;
-- 2. 如果索引已存在,会报错 "Duplicate key name",可以忽略该错误或注释掉对应语句
-- 3. 建议按顺序执行,遇到已存在的索引错误时跳过即可
-- ============================================
-- 第一步:检查现有索引(可选)
-- ============================================
-- 执行以下命令查看 warning_log 表的所有索引:
-- SHOW INDEX FROM warning_log;
-- ============================================
-- 第二步:创建索引(所有索引已存在,已全部注释)
-- ============================================
-- ✅ 状态:所有需要的索引已经存在,无需再次创建
-- 如需重新创建请先删除现有索引DROP INDEX idx_name ON warning_log;
-- 1. 添加 delivery_id 和 warning_type 的联合索引(用于派生表的 GROUP BY 查询)
-- 这个索引可以大幅提升 "SELECT delivery_id, warning_type, MAX(id) FROM warning_log WHERE warning_type IN (...) GROUP BY delivery_id, warning_type" 的性能
-- ✅ 索引已存在idx_delivery_warning_type
-- ALTER TABLE warning_log
-- ADD INDEX idx_delivery_warning_type (delivery_id, warning_type, id);
-- 2. 添加 warning_time 索引(用于 ORDER BY 排序)
-- ✅ 索引已存在idx_warning_time
-- ALTER TABLE warning_log
-- ADD INDEX idx_warning_time (warning_time DESC);
-- 3. 如果 delivery_id 还没有单独索引,添加一个(用于 JOIN 操作)
-- 注意:如果 delivery_id 已经是主键或唯一索引的一部分,可以跳过
-- 检查现有索引SHOW INDEX FROM warning_log;
-- 如果 delivery_id 没有索引,执行下面的语句
-- ALTER TABLE warning_log ADD INDEX idx_delivery_id (delivery_id);
-- ============================================
-- 索引说明和性能优化效果
-- ============================================
--
-- 已存在的索引:
-- 1. idx_delivery_warning_type: 覆盖索引,支持 WHERE warning_type IN (...) GROUP BY delivery_id, warning_type 的查询
-- 2. idx_warning_time: 支持 ORDER BY warning_time DESC 的排序操作
--
-- 性能提升效果:
-- ✅ 派生表查询从全表扫描优化为索引扫描
-- ✅ GROUP BY 操作可以使用索引,避免临时表排序
-- ✅ ORDER BY 可以使用索引,避免文件排序
--
-- ============================================
-- 验证索引是否生效
-- ============================================
-- 执行以下 SQL 验证索引:
-- SHOW INDEX FROM warning_log WHERE Key_name IN ('idx_delivery_warning_type', 'idx_warning_time');
--
-- 使用 EXPLAIN 分析查询性能:
-- EXPLAIN SELECT ... (使用优化后的 getPageWarningLog SQL)
--
-- 注意:所有索引已创建完成,脚本保留作为文档参考

View File

@@ -1,146 +0,0 @@
USE cattletrade;
-- 为角色分配销售概览菜单权限
-- 注意:需要根据实际情况修改 role_id
-- 1. 查询销售概览菜单ID包括主菜单和按钮权限
SET @salesoverview_menu_id = (SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1);
SET @salesoverview_add_id = (SELECT id FROM sys_menu WHERE name = '新增' AND parent_id = @salesoverview_menu_id AND type = 2 AND is_delete = 0 LIMIT 1);
SET @salesoverview_edit_id = (SELECT id FROM sys_menu WHERE name = '编辑' AND parent_id = @salesoverview_menu_id AND type = 2 AND is_delete = 0 LIMIT 1);
SET @salesoverview_delete_id = (SELECT id FROM sys_menu WHERE name = '删除' AND parent_id = @salesoverview_menu_id AND type = 2 AND is_delete = 0 LIMIT 1);
SET @salesoverview_calculate_id = (SELECT id FROM sys_menu WHERE name = '计算统计数据' AND parent_id = @salesoverview_menu_id AND type = 2 AND is_delete = 0 LIMIT 1);
-- 显示查询到的菜单ID用于调试
SELECT
@salesoverview_menu_id AS '主菜单ID',
@salesoverview_add_id AS '新增按钮ID',
@salesoverview_edit_id AS '编辑按钮ID',
@salesoverview_delete_id AS '删除按钮ID',
@salesoverview_calculate_id AS '计算按钮ID';
-- 2. 查询所有角色ID用于批量分配
-- SELECT id, name FROM sys_role WHERE is_delete = 0;
-- 3. 为指定角色分配销售概览菜单权限
-- 方式1为单个角色分配需要替换 @role_id 为实际角色ID
-- SET @role_id = 1; -- 替换为实际角色ID例如超级管理员角色ID
-- 删除该角色原有的销售概览权限(如果存在)
-- DELETE FROM sys_role_menu
-- WHERE role_id = @role_id
-- AND menu_id IN (@salesoverview_menu_id, @salesoverview_add_id, @salesoverview_edit_id, @salesoverview_delete_id, @salesoverview_calculate_id);
-- 插入新的权限
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- VALUES
-- (@role_id, @salesoverview_menu_id),
-- (@role_id, @salesoverview_add_id),
-- (@role_id, @salesoverview_edit_id),
-- (@role_id, @salesoverview_delete_id),
-- (@role_id, @salesoverview_calculate_id)
-- ON DUPLICATE KEY UPDATE role_id = role_id; -- 如果已存在则忽略
-- 方式2为所有角色分配销售概览菜单权限谨慎使用
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- SELECT r.id, @salesoverview_menu_id
-- FROM sys_role r
-- WHERE r.is_delete = 0
-- AND NOT EXISTS (
-- SELECT 1 FROM sys_role_menu rm
-- WHERE rm.role_id = r.id AND rm.menu_id = @salesoverview_menu_id
-- );
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- SELECT r.id, @salesoverview_add_id
-- FROM sys_role r
-- WHERE r.is_delete = 0
-- AND NOT EXISTS (
-- SELECT 1 FROM sys_role_menu rm
-- WHERE rm.role_id = r.id AND rm.menu_id = @salesoverview_add_id
-- );
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- SELECT r.id, @salesoverview_edit_id
-- FROM sys_role r
-- WHERE r.is_delete = 0
-- AND NOT EXISTS (
-- SELECT 1 FROM sys_role_menu rm
-- WHERE rm.role_id = r.id AND rm.menu_id = @salesoverview_edit_id
-- );
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- SELECT r.id, @salesoverview_delete_id
-- FROM sys_role r
-- WHERE r.is_delete = 0
-- AND NOT EXISTS (
-- SELECT 1 FROM sys_role_menu rm
-- WHERE rm.role_id = r.id AND rm.menu_id = @salesoverview_delete_id
-- );
-- INSERT INTO sys_role_menu (role_id, menu_id)
-- SELECT r.id, @salesoverview_calculate_id
-- FROM sys_role r
-- WHERE r.is_delete = 0
-- AND NOT EXISTS (
-- SELECT 1 FROM sys_role_menu rm
-- WHERE rm.role_id = r.id AND rm.menu_id = @salesoverview_calculate_id
-- );
-- 方式3为超级管理员角色分配推荐使用
-- 假设超级管理员角色ID为1需要根据实际情况调整
-- 如果角色ID不是1请先查询SELECT id, name FROM sys_role WHERE name LIKE '%管理员%' OR name LIKE '%admin%';
-- 为角色ID=1分配销售概览菜单权限请根据实际情况修改角色ID
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @salesoverview_menu_id
WHERE NOT EXISTS (
SELECT 1 FROM sys_role_menu rm
WHERE rm.role_id = 1 AND rm.menu_id = @salesoverview_menu_id
)
AND @salesoverview_menu_id IS NOT NULL;
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @salesoverview_add_id
WHERE NOT EXISTS (
SELECT 1 FROM sys_role_menu rm
WHERE rm.role_id = 1 AND rm.menu_id = @salesoverview_add_id
)
AND @salesoverview_add_id IS NOT NULL;
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @salesoverview_edit_id
WHERE NOT EXISTS (
SELECT 1 FROM sys_role_menu rm
WHERE rm.role_id = 1 AND rm.menu_id = @salesoverview_edit_id
)
AND @salesoverview_edit_id IS NOT NULL;
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @salesoverview_delete_id
WHERE NOT EXISTS (
SELECT 1 FROM sys_role_menu rm
WHERE rm.role_id = 1 AND rm.menu_id = @salesoverview_delete_id
)
AND @salesoverview_delete_id IS NOT NULL;
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @salesoverview_calculate_id
WHERE NOT EXISTS (
SELECT 1 FROM sys_role_menu rm
WHERE rm.role_id = 1 AND rm.menu_id = @salesoverview_calculate_id
)
AND @salesoverview_calculate_id IS NOT NULL;
-- 4. 验证权限分配结果
SELECT
rm.role_id,
r.name AS role_name,
rm.menu_id,
m.name AS menu_name,
m.type AS menu_type
FROM sys_role_menu rm
INNER JOIN sys_role r ON rm.role_id = r.id
INNER JOIN sys_menu m ON rm.menu_id = m.id
WHERE m.name = '销售概览' OR m.parent_id = (SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1)
ORDER BY rm.role_id, m.type, m.sort;

View File

@@ -1,40 +0,0 @@
USE cattletrade;
-- 检查销售概览菜单是否已插入
SELECT
id,
parent_id,
type,
icon,
name,
sort,
route_url,
page_url,
org_type,
authority,
is_delete,
create_time
FROM sys_menu
WHERE name = '销售概览'
ORDER BY type, sort;
-- 检查是否有重复的销售概览菜单
SELECT COUNT(*) as count, name, type
FROM sys_menu
WHERE name = '销售概览' AND is_delete = 0
GROUP BY name, type;
-- 查询所有顶级菜单parent_id = 0用于参考
SELECT
id,
name,
type,
icon,
sort,
page_url,
org_type,
authority
FROM sys_menu
WHERE parent_id = 0 AND is_delete = 0
ORDER BY sort;

View File

@@ -1,82 +0,0 @@
USE cattletrade;
-- 检查 sys_menu 表的字段长度
-- 用于诊断字段值被截断的问题
-- ============================================
-- 1. 检查 page_url 和 authority 字段的定义
-- ============================================
-- 执行以下查询查看字段定义:
SHOW COLUMNS FROM sys_menu WHERE Field IN ('page_url', 'authority');
-- 或者使用以下查询:
SELECT
COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'cattletrade'
AND TABLE_NAME = 'sys_menu'
AND COLUMN_NAME IN ('page_url', 'authority');
-- ============================================
-- 2. 检查当前菜单数据的字段长度
-- ============================================
SELECT
id,
parent_id,
type,
name,
route_url,
page_url,
LENGTH(page_url) as page_url_length,
authority,
LENGTH(authority) as authority_length
FROM sys_menu
WHERE (id = 82 OR parent_id = 82)
AND is_delete = 0
ORDER BY id, sort;
-- ============================================
-- 3. 检查是否有被截断的字段值
-- ============================================
-- 检查进仓管理菜单
SELECT
id,
name,
page_url,
LENGTH(page_url) as page_url_length,
'warehouse/warehouseIn' as expected_value,
LENGTH('warehouse/warehouseIn') as expected_length
FROM sys_menu
WHERE id = 88
AND is_delete = 0;
-- 检查出仓管理菜单
SELECT
id,
name,
page_url,
LENGTH(page_url) as page_url_length,
authority,
LENGTH(authority) as authority_length,
'warehouse/warehouseOut' as expected_page_url,
LENGTH('warehouse/warehouseOut') as expected_page_url_length,
'warehouseout:list' as expected_authority,
LENGTH('warehouseout:list') as expected_authority_length
FROM sys_menu
WHERE id = 93
AND is_delete = 0;
-- ============================================
-- 4. 如果需要扩展字段长度,执行以下语句(取消注释)
-- ============================================
-- 注意:执行前请先备份数据库!
-- 扩展 page_url 字段长度到 255
-- ALTER TABLE sys_menu MODIFY COLUMN page_url VARCHAR(255) COMMENT '前端路由地址';
-- 扩展 authority 字段长度到 100
-- ALTER TABLE sys_menu MODIFY COLUMN authority VARCHAR(100) COMMENT '权限字符串';

View File

@@ -1,68 +0,0 @@
USE cattletrade;
-- 创建屠宰场管理相关表
-- 1. 屠宰场表slaughter_house
-- 2. 进场表slaughter_entry
-- ============================================
-- 1. 屠宰场表slaughter_house
-- ============================================
CREATE TABLE IF NOT EXISTS `slaughter_house` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`house_name` VARCHAR(100) NOT NULL COMMENT '屠宰场名称',
`slaughter_code` VARCHAR(50) NOT NULL COMMENT '屠宰场编码格式SLyyyyMMddXXXX',
`capacity` INT(11) DEFAULT NULL COMMENT '容量(头数)',
`address` VARCHAR(255) DEFAULT NULL COMMENT '地址',
`longitude` VARCHAR(50) DEFAULT NULL COMMENT '经度',
`latitude` VARCHAR(50) DEFAULT NULL COMMENT '纬度',
`status` TINYINT(1) DEFAULT 1 COMMENT '状态1-启用0-禁用',
`remark` TEXT COMMENT '备注',
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`created_by` INT(11) DEFAULT NULL COMMENT '创建人ID',
`updated_by` INT(11) DEFAULT NULL COMMENT '更新人ID',
`is_delete` TINYINT(1) DEFAULT 0 COMMENT '逻辑删除0-未删除1-已删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_slaughter_code` (`slaughter_code`),
KEY `idx_house_name` (`house_name`),
KEY `idx_status` (`status`),
KEY `idx_is_delete` (`is_delete`),
KEY `idx_create_time` (`create_time`),
KEY `idx_status_is_delete` (`status`, `is_delete`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='屠宰场表';
-- ============================================
-- 2. 进场表slaughter_entry
-- ============================================
CREATE TABLE IF NOT EXISTS `slaughter_entry` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`slaughter_house_id` INT(11) NOT NULL COMMENT '屠宰场ID',
`delivery_id` INT(11) NOT NULL COMMENT '运送清单ID关联delivery表',
`order_id` INT(11) DEFAULT NULL COMMENT '订单ID关联order表',
`start_location` VARCHAR(255) DEFAULT NULL COMMENT '起始地',
`start_lon` VARCHAR(50) DEFAULT NULL COMMENT '起始经度',
`start_lat` VARCHAR(50) DEFAULT NULL COMMENT '起始纬度',
`end_location` VARCHAR(255) DEFAULT NULL COMMENT '目的地',
`end_lon` VARCHAR(50) DEFAULT NULL COMMENT '目的地经度',
`end_lat` VARCHAR(50) DEFAULT NULL COMMENT '目的地纬度',
`driver_name` VARCHAR(50) DEFAULT NULL COMMENT '司机姓名',
`driver_mobile` VARCHAR(20) DEFAULT NULL COMMENT '联系方式',
`license_plate` VARCHAR(20) DEFAULT NULL COMMENT '车牌号',
`yield_rate` DECIMAL(5,2) DEFAULT NULL COMMENT '出肉率(%',
`remark` TEXT COMMENT '备注',
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`created_by` INT(11) DEFAULT NULL COMMENT '创建人ID',
`updated_by` INT(11) DEFAULT NULL COMMENT '更新人ID',
`is_delete` TINYINT(1) DEFAULT 0 COMMENT '逻辑删除0-未删除1-已删除',
PRIMARY KEY (`id`),
KEY `idx_slaughter_house_id` (`slaughter_house_id`),
KEY `idx_delivery_id` (`delivery_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_is_delete` (`is_delete`),
KEY `idx_create_time` (`create_time`),
CONSTRAINT `fk_slaughter_entry_house` FOREIGN KEY (`slaughter_house_id`) REFERENCES `slaughter_house` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_slaughter_entry_delivery` FOREIGN KEY (`delivery_id`) REFERENCES `delivery` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_slaughter_entry_order` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='屠宰场进场表';

View File

@@ -1,113 +0,0 @@
USE cattletrade;
-- 创建中转仓管理相关表
-- 1. 中转仓表warehouse
-- 2. 进仓表warehouse_in
-- 3. 出仓表warehouse_out
-- ============================================
-- 1. 中转仓表warehouse
-- ============================================
CREATE TABLE IF NOT EXISTS `warehouse` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`warehouse_name` VARCHAR(100) NOT NULL COMMENT '中转仓名称',
`warehouse_code` VARCHAR(50) NOT NULL COMMENT '中转仓编码',
`address` VARCHAR(255) NOT NULL COMMENT '地址',
`longitude` VARCHAR(50) DEFAULT NULL COMMENT '经度',
`latitude` VARCHAR(50) DEFAULT NULL COMMENT '纬度',
`capacity` INT(11) NOT NULL COMMENT '容量(可存储牛只数量)',
`manager_name` VARCHAR(50) DEFAULT NULL COMMENT '负责人姓名',
`manager_mobile` VARCHAR(20) DEFAULT NULL COMMENT '负责人联系电话',
`status` TINYINT(1) DEFAULT 1 COMMENT '状态1-启用0-禁用',
`remark` TEXT COMMENT '备注',
`create_time` DATETIME DEFAULT NULL COMMENT '创建时间',
`update_time` DATETIME DEFAULT NULL COMMENT '更新时间',
`created_by` INT(11) DEFAULT NULL COMMENT '创建人ID',
`updated_by` INT(11) DEFAULT NULL COMMENT '更新人ID',
`is_delete` TINYINT(1) DEFAULT 0 COMMENT '逻辑删除0-未删除1-已删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_warehouse_code` (`warehouse_code`),
KEY `idx_status` (`status`),
KEY `idx_is_delete` (`is_delete`),
KEY `idx_warehouse_name` (`warehouse_name`),
KEY `idx_create_time` (`create_time`),
KEY `idx_status_is_delete` (`status`, `is_delete`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='中转仓表';
-- ============================================
-- 2. 进仓表warehouse_in
-- ============================================
CREATE TABLE IF NOT EXISTS `warehouse_in` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`in_number` VARCHAR(50) NOT NULL COMMENT '进仓单号',
`warehouse_id` INT(11) NOT NULL COMMENT '中转仓ID',
`order_id` VARCHAR(100) DEFAULT NULL COMMENT '订单ID多个订单用逗号分隔',
`delivery_id` INT(11) DEFAULT NULL COMMENT '运送清单ID',
`source_location` VARCHAR(255) DEFAULT NULL COMMENT '来源地',
`source_lon` VARCHAR(50) DEFAULT NULL COMMENT '来源地经度',
`source_lat` VARCHAR(50) DEFAULT NULL COMMENT '来源地纬度',
`cattle_count` INT(11) NOT NULL COMMENT '牛只数量',
`weight` DECIMAL(10,2) DEFAULT NULL COMMENT '重量(公斤)',
`in_time` DATETIME NOT NULL COMMENT '进仓时间',
`photos` TEXT COMMENT '照片URL多个用逗号分隔',
`videos` TEXT COMMENT '视频URL多个用逗号分隔',
`remark` TEXT COMMENT '备注',
`status` TINYINT(1) DEFAULT 1 COMMENT '状态1-待进仓2-已进仓3-已出仓',
`create_time` DATETIME DEFAULT NULL COMMENT '创建时间',
`update_time` DATETIME DEFAULT NULL COMMENT '更新时间',
`created_by` INT(11) DEFAULT NULL COMMENT '创建人ID',
`updated_by` INT(11) DEFAULT NULL COMMENT '更新人ID',
`is_delete` TINYINT(1) DEFAULT 0 COMMENT '逻辑删除0-未删除1-已删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_in_number` (`in_number`),
KEY `idx_warehouse_id` (`warehouse_id`),
KEY `idx_delivery_id` (`delivery_id`),
KEY `idx_in_time` (`in_time`),
KEY `idx_is_delete` (`is_delete`),
KEY `idx_status` (`status`),
KEY `idx_create_time` (`create_time`),
KEY `idx_warehouse_id_status` (`warehouse_id`, `status`),
KEY `idx_is_delete_create_time` (`is_delete`, `create_time`),
CONSTRAINT `fk_warehouse_in_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='进仓表';
-- ============================================
-- 3. 出仓表warehouse_out
-- ============================================
CREATE TABLE IF NOT EXISTS `warehouse_out` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`out_number` VARCHAR(50) NOT NULL COMMENT '出仓单号',
`warehouse_id` INT(11) NOT NULL COMMENT '中转仓ID',
`warehouse_in_id` INT(11) DEFAULT NULL COMMENT '进仓记录ID可选',
`order_id` VARCHAR(100) DEFAULT NULL COMMENT '订单ID多个订单用逗号分隔',
`delivery_id` INT(11) DEFAULT NULL COMMENT '运送清单ID',
`destination_location` VARCHAR(255) DEFAULT NULL COMMENT '目的地',
`destination_lon` VARCHAR(50) DEFAULT NULL COMMENT '目的地经度',
`destination_lat` VARCHAR(50) DEFAULT NULL COMMENT '目的地纬度',
`cattle_count` INT(11) NOT NULL COMMENT '牛只数量',
`weight` DECIMAL(10,2) DEFAULT NULL COMMENT '重量(公斤)',
`out_time` DATETIME NOT NULL COMMENT '出仓时间',
`photos` TEXT COMMENT '照片URL多个用逗号分隔',
`videos` TEXT COMMENT '视频URL多个用逗号分隔',
`remark` TEXT COMMENT '备注',
`status` TINYINT(1) DEFAULT 1 COMMENT '状态1-待出仓2-已出仓',
`create_time` DATETIME DEFAULT NULL COMMENT '创建时间',
`update_time` DATETIME DEFAULT NULL COMMENT '更新时间',
`created_by` INT(11) DEFAULT NULL COMMENT '创建人ID',
`updated_by` INT(11) DEFAULT NULL COMMENT '更新人ID',
`is_delete` TINYINT(1) DEFAULT 0 COMMENT '逻辑删除0-未删除1-已删除',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_out_number` (`out_number`),
KEY `idx_warehouse_id` (`warehouse_id`),
KEY `idx_warehouse_in_id` (`warehouse_in_id`),
KEY `idx_delivery_id` (`delivery_id`),
KEY `idx_out_time` (`out_time`),
KEY `idx_is_delete` (`is_delete`),
KEY `idx_status` (`status`),
KEY `idx_create_time` (`create_time`),
KEY `idx_warehouse_id_status` (`warehouse_id`, `status`),
KEY `idx_is_delete_create_time` (`is_delete`, `create_time`),
CONSTRAINT `fk_warehouse_out_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_warehouse_out_warehouse_in` FOREIGN KEY (`warehouse_in_id`) REFERENCES `warehouse_in` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='出仓表';

View File

@@ -1,105 +0,0 @@
USE cattletrade;
-- 诊断和修复脚本:检查问题并强制修复
-- ============================================
-- ============================================
-- 步骤1诊断当前状态
-- ============================================
SELECT
'=== 当前状态 ===' as info,
id,
name,
page_url,
CHAR_LENGTH(page_url) as page_url_len,
HEX(page_url) as page_url_hex,
authority,
CHAR_LENGTH(authority) as authority_len,
HEX(authority) as authority_hex
FROM sys_menu
WHERE id IN (88, 93);
-- ============================================
-- 步骤2检查是否有触发器
-- ============================================
SHOW TRIGGERS FROM cattletrade LIKE 'sys_menu';
-- ============================================
-- 步骤3检查字段定义和约束
-- ============================================
SHOW COLUMNS FROM sys_menu WHERE Field IN ('page_url', 'authority');
-- ============================================
-- 步骤4尝试强制更新使用不同的方法
-- ============================================
-- 方法1直接UPDATE不检查任何条件
UPDATE sys_menu
SET page_url = 'warehouse/warehouseIn'
WHERE id = 88;
-- 检查是否成功
SELECT
'=== 更新 id=88 后 ===' as info,
id,
name,
page_url,
CHAR_LENGTH(page_url) as page_url_len
FROM sys_menu
WHERE id = 88;
-- 方法2更新 id=93
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list'
WHERE id = 93;
-- 检查是否成功
SELECT
'=== 更新 id=93 后 ===' as info,
id,
name,
page_url,
CHAR_LENGTH(page_url) as page_url_len,
authority,
CHAR_LENGTH(authority) as authority_len
FROM sys_menu
WHERE id = 93;
-- ============================================
-- 步骤5如果上述方法失败尝试使用 REPLACE
-- ============================================
-- 注意REPLACE 会删除并重新插入,需要所有字段值
-- 先查询完整记录
SELECT * FROM sys_menu WHERE id = 88;
SELECT * FROM sys_menu WHERE id = 93;
-- 如果 UPDATE 失败,可以使用以下方法(需要根据实际字段值调整):
-- REPLACE INTO sys_menu (id, parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
-- SELECT id, parent_id, type, icon, name, sort, route_url, 'warehouse/warehouseIn', org_type, authority, create_time, NOW(), is_delete
-- FROM sys_menu WHERE id = 88;
-- ============================================
-- 步骤6最终验证
-- ============================================
SELECT
'=== 最终验证 ===' as info,
id,
name,
page_url,
CHAR_LENGTH(page_url) as page_url_len,
CASE
WHEN page_url = 'warehouse/warehouseIn' THEN '✓ 正确'
ELSE '✗ 错误'
END as page_url_status,
authority,
CHAR_LENGTH(authority) as authority_len,
CASE
WHEN authority = 'warehouseout:list' THEN '✓ 正确'
ELSE '✗ 错误'
END as authority_status
FROM sys_menu
WHERE id IN (88, 93);

View File

@@ -1,197 +0,0 @@
USE cattletrade;
-- 一键修复:确保销售概览菜单在侧边栏显示
-- 该脚本会:
-- 1. 检查菜单是否存在,不存在则插入
-- 2. 为超级管理员角色role_id=1分配菜单权限
-- 3. 将菜单的org_type设置为3海关企业共用确保所有用户都能看到
-- ========== 步骤1确保菜单已插入 ==========
-- 如果菜单不存在,则插入
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
0 AS parent_id,
1 AS type,
'el-icon-data-line' AS icon,
'销售概览' AS name,
50 AS sort,
NULL AS route_url,
'/salesOverview/list' AS page_url,
3 AS org_type, -- 设置为3海关企业共用确保所有用户都能看到
'salesoverview:list' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0
);
-- 获取销售概览菜单ID
SET @salesoverview_menu_id = (SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1);
-- 更新菜单的org_type为3如果已存在
UPDATE sys_menu
SET org_type = 3, update_time = NOW()
WHERE id = @salesoverview_menu_id AND org_type != 3;
-- ========== 步骤2确保按钮权限已插入 ==========
-- 插入新增按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@salesoverview_menu_id AS parent_id,
2 AS type,
NULL AS icon,
'新增' AS name,
2 AS sort,
NULL AS route_url,
NULL AS page_url,
3 AS org_type,
'salesoverview:add' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @salesoverview_menu_id AND name = '新增' AND type = 2 AND is_delete = 0
)
AND @salesoverview_menu_id IS NOT NULL;
-- 插入编辑按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@salesoverview_menu_id AS parent_id,
2 AS type,
NULL AS icon,
'编辑' AS name,
3 AS sort,
NULL AS route_url,
NULL AS page_url,
3 AS org_type,
'salesoverview:edit' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @salesoverview_menu_id AND name = '编辑' AND type = 2 AND is_delete = 0
)
AND @salesoverview_menu_id IS NOT NULL;
-- 插入删除按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@salesoverview_menu_id AS parent_id,
2 AS type,
NULL AS icon,
'删除' AS name,
4 AS sort,
NULL AS route_url,
NULL AS page_url,
3 AS org_type,
'salesoverview:delete' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @salesoverview_menu_id AND name = '删除' AND type = 2 AND is_delete = 0
)
AND @salesoverview_menu_id IS NOT NULL;
-- 插入计算统计数据按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@salesoverview_menu_id AS parent_id,
2 AS type,
NULL AS icon,
'计算统计数据' AS name,
5 AS sort,
NULL AS route_url,
NULL AS page_url,
3 AS org_type,
'salesoverview:calculate' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @salesoverview_menu_id AND name = '计算统计数据' AND type = 2 AND is_delete = 0
)
AND @salesoverview_menu_id IS NOT NULL;
-- ========== 步骤3为超级管理员角色分配权限 ==========
-- 查询所有销售概览相关的菜单ID
SET @menu_main = @salesoverview_menu_id;
SET @menu_add = (SELECT id FROM sys_menu WHERE parent_id = @salesoverview_menu_id AND name = '新增' AND type = 2 AND is_delete = 0 LIMIT 1);
SET @menu_edit = (SELECT id FROM sys_menu WHERE parent_id = @salesoverview_menu_id AND name = '编辑' AND type = 2 AND is_delete = 0 LIMIT 1);
SET @menu_delete = (SELECT id FROM sys_menu WHERE parent_id = @salesoverview_menu_id AND name = '删除' AND type = 2 AND is_delete = 0 LIMIT 1);
SET @menu_calculate = (SELECT id FROM sys_menu WHERE parent_id = @salesoverview_menu_id AND name = '计算统计数据' AND type = 2 AND is_delete = 0 LIMIT 1);
-- 为角色ID=1超级管理员分配主菜单权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @menu_main
WHERE NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = @menu_main)
AND @menu_main IS NOT NULL;
-- 为角色ID=1分配新增权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @menu_add
WHERE NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = @menu_add)
AND @menu_add IS NOT NULL;
-- 为角色ID=1分配编辑权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @menu_edit
WHERE NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = @menu_edit)
AND @menu_edit IS NOT NULL;
-- 为角色ID=1分配删除权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @menu_delete
WHERE NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = @menu_delete)
AND @menu_delete IS NOT NULL;
-- 为角色ID=1分配计算权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, @menu_calculate
WHERE NOT EXISTS (SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND menu_id = @menu_calculate)
AND @menu_calculate IS NOT NULL;
-- ========== 步骤4验证结果 ==========
-- 显示菜单信息
SELECT
'菜单信息' AS info_type,
id,
name,
type,
parent_id,
page_url,
org_type,
authority
FROM sys_menu
WHERE name = '销售概览' OR parent_id = @salesoverview_menu_id
ORDER BY type, sort;
-- 显示权限分配情况
SELECT
'权限分配' AS info_type,
rm.role_id,
r.name AS role_name,
rm.menu_id,
m.name AS menu_name,
m.type AS menu_type
FROM sys_role_menu rm
INNER JOIN sys_role r ON rm.role_id = r.id
INNER JOIN sys_menu m ON rm.menu_id = m.id
WHERE m.name = '销售概览' OR m.parent_id = @salesoverview_menu_id
ORDER BY rm.role_id, m.type, m.sort;
-- 提示信息
SELECT
'提示' AS info_type,
CONCAT('销售概览菜单ID: ', @salesoverview_menu_id) AS message
UNION ALL
SELECT
'提示' AS info_type,
'请重新登录系统以刷新菜单' AS message;

View File

@@ -1,31 +0,0 @@
USE cattletrade;
-- 修复 salesoverview 表的 id 字段,设置为 AUTO_INCREMENT
-- 如果表不存在,先创建表;如果表存在但 id 字段不是自增,则修改字段
-- 检查表是否存在
-- 如果表不存在,创建表
CREATE TABLE IF NOT EXISTS `salesoverview` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`toal_procurement_amount` DECIMAL(18,2) DEFAULT 0.00 COMMENT '采购总额(元)',
`toal_sales_amount` DECIMAL(18,2) DEFAULT 0.00 COMMENT '销售总额(元)',
`profits` DECIMAL(18,2) DEFAULT 0.00 COMMENT '利润(元)',
`accounts_receivable` DECIMAL(18,2) DEFAULT 0.00 COMMENT '应收货款(元)',
`uncollected_payment` DECIMAL(18,2) DEFAULT 0.00 COMMENT '未收货款(元)',
`actual_payment` DECIMAL(18,2) DEFAULT 0.00 COMMENT '实收货款(元)',
`total_purchase` INT(11) DEFAULT 0 COMMENT '采购数量(头)',
`total_order` INT(11) DEFAULT 0 COMMENT '采购单数(车)',
`total_sales` INT(11) DEFAULT 0 COMMENT '销售单数(单)',
`create_time` DATETIME DEFAULT NULL COMMENT '创建时间',
`up_time` DATETIME DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='销售概览表';
-- 如果表已存在,修改 id 字段为 AUTO_INCREMENT
-- 注意:如果表中已有数据,需要先备份
ALTER TABLE `salesoverview`
MODIFY COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID';
-- 验证表结构
SHOW CREATE TABLE `salesoverview`;

View File

@@ -1,118 +0,0 @@
USE cattletrade;
-- 完整修复中转仓管理菜单数据
-- 1. 检查并扩展字段长度(如果需要)
-- 2. 修复被截断的字段值
-- 3. 删除重复的菜单数据
-- ============================================
-- 步骤0检查并扩展字段长度如果需要
-- ============================================
-- 如果 page_url 或 authority 字段长度不足,先扩展字段长度
-- 注意:执行前请先检查当前字段长度,如果已经足够则不需要执行
-- 扩展 page_url 字段长度(如果需要)
-- ALTER TABLE sys_menu MODIFY COLUMN page_url VARCHAR(255) COMMENT '前端路由地址';
-- 扩展 authority 字段长度(如果需要)
-- ALTER TABLE sys_menu MODIFY COLUMN authority VARCHAR(100) COMMENT '权限字符串';
-- ============================================
-- 步骤1删除重复的菜单数据
-- ============================================
-- 删除 id=98 的子菜单的按钮权限(如果存在)
DELETE FROM sys_menu
WHERE parent_id IN (99, 104, 109)
AND type = 2
AND is_delete = 0;
-- 删除 id=98 的子菜单(二级菜单)
DELETE FROM sys_menu
WHERE id IN (99, 104, 109)
AND parent_id = 98
AND type = 1
AND is_delete = 0;
-- 删除 id=98 的父菜单(如果存在)
DELETE FROM sys_menu
WHERE id = 98
AND name = '中转仓管理'
AND parent_id = 0
AND (type = 0 OR type IS NULL)
AND is_delete = 0;
-- ============================================
-- 步骤2修复被截断的字段值直接通过ID修复
-- ============================================
-- 修复进仓管理菜单id=88的 page_url
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE id = 88
AND is_delete = 0;
-- 修复出仓管理菜单id=93的 page_url 和 authority
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE id = 93
AND is_delete = 0;
-- ============================================
-- 步骤3确保所有字段值正确通过名称修复作为后备
-- ============================================
-- 修复进仓管理菜单的 page_url通过名称匹配
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE name = '进仓管理'
AND type = 1
AND parent_id = 82
AND page_url != 'warehouse/warehouseIn'
AND is_delete = 0;
-- 修复出仓管理菜单的 page_url 和 authority通过名称匹配
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE name = '出仓管理'
AND type = 1
AND parent_id = 82
AND (page_url != 'warehouse/warehouseOut' OR authority != 'warehouseout:list')
AND is_delete = 0;
-- ============================================
-- 步骤4确保父菜单的 type 字段正确
-- ============================================
UPDATE sys_menu
SET
type = 0,
update_time = NOW()
WHERE id = 82
AND (type IS NULL OR type != 0)
AND is_delete = 0;
-- ============================================
-- 步骤5验证修复结果
-- ============================================
-- 执行以下查询验证数据是否正确:
-- SELECT id, parent_id, type, name, route_url, page_url, authority, LENGTH(page_url) as page_url_len, LENGTH(authority) as authority_len
-- FROM sys_menu
-- WHERE (id = 82 OR parent_id = 82)
-- AND is_delete = 0
-- ORDER BY id, sort;
--
-- 预期结果:
-- id=82: type = 0, page_url = NULL, authority = NULL
-- id=83: route_url = 'list', page_url = 'warehouse/warehouse', authority = 'warehouse:list'
-- id=88: route_url = 'in', page_url = 'warehouse/warehouseIn', authority = 'warehousein:list'
-- id=93: route_url = 'out', page_url = 'warehouse/warehouseOut', authority = 'warehouseout:list'

View File

@@ -1,83 +0,0 @@
USE cattletrade;
-- 修复中转仓管理菜单的组件路径
-- 该脚本用于修复已存在的菜单记录,确保组件路径正确
-- ============================================
-- 1. 修复中转仓管理菜单list
-- ============================================
UPDATE sys_menu
SET
route_url = 'list',
page_url = 'warehouse/warehouse',
update_time = NOW()
WHERE name = '中转仓管理'
AND parent_id IN (SELECT id FROM (SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0) AS temp)
AND type = 1
AND is_delete = 0
AND page_url != 'warehouse/warehouse';
-- ============================================
-- 2. 修复进仓管理菜单in
-- ============================================
UPDATE sys_menu
SET
route_url = 'in',
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE name = '进仓管理'
AND parent_id IN (SELECT id FROM (SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0) AS temp)
AND type = 1
AND is_delete = 0
AND page_url != 'warehouse/warehouseIn';
-- ============================================
-- 3. 修复出仓管理菜单out
-- ============================================
UPDATE sys_menu
SET
route_url = 'out',
page_url = 'warehouse/warehouseOut',
update_time = NOW()
WHERE name = '出仓管理'
AND parent_id IN (SELECT id FROM (SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0) AS temp)
AND type = 1
AND is_delete = 0
AND page_url != 'warehouse/warehouseOut';
-- ============================================
-- 4. 修复运输管理菜单中的shippingList如果存在
-- ============================================
-- 注意:如果数据库中存在 shipping/shippinglist 的菜单,需要手动修复
-- 实际文件是 shipping/shippingList.vue注意大小写
-- 修复所有可能的变体shipping/shippinglist, shipping/ShippingList, shipping/SHIPPINGLIST 等
-- 使用 LOWER() 函数进行大小写不敏感匹配
UPDATE sys_menu
SET
page_url = 'shipping/shippingList',
update_time = NOW()
WHERE LOWER(page_url) = 'shipping/shippinglist'
AND page_url != 'shipping/shippingList'
AND is_delete = 0;
-- 修复其他可能的变体(包含路径的情况,包括带前导斜杠的情况)
UPDATE sys_menu
SET
page_url = 'shipping/shippingList',
update_time = NOW()
WHERE (LOWER(page_url) LIKE '%shipping/shippinglist%'
OR LOWER(page_url) LIKE '%/shipping/shippinglist%'
OR page_url LIKE '%shipping/ShippingList%'
OR page_url LIKE '%shipping/SHIPPINGLIST%')
AND page_url != 'shipping/shippingList'
AND page_url != '/shipping/shippingList'
AND is_delete = 0;
-- 修复带前导斜杠的情况(如 /shipping/shippinglist -> shipping/shippingList
UPDATE sys_menu
SET
page_url = 'shipping/shippingList',
update_time = NOW()
WHERE LOWER(page_url) = '/shipping/shippinglist'
AND is_delete = 0;

View File

@@ -1,96 +0,0 @@
USE cattletrade;
-- 修复中转仓管理菜单数据
-- 1. 删除重复的菜单数据(保留较早创建的,删除较晚创建的)
-- 2. 修复被截断的字段值
-- ============================================
-- 步骤1删除重复的菜单数据
-- 保留 id=82 的父菜单及其子菜单,删除 id=98 的父菜单及其子菜单
-- ============================================
-- 删除 id=98 的子菜单的按钮权限(如果存在)
-- 先删除所有以 id=99, 104, 109 为父菜单的按钮权限
DELETE FROM sys_menu
WHERE parent_id IN (99, 104, 109)
AND type = 2
AND is_delete = 0;
-- 删除 id=98 的子菜单(二级菜单)
DELETE FROM sys_menu
WHERE id IN (99, 104, 109)
AND parent_id = 98
AND type = 1
AND is_delete = 0;
-- 删除 id=98 的父菜单(如果存在)
DELETE FROM sys_menu
WHERE id = 98
AND name = '中转仓管理'
AND parent_id = 0
AND (type = 0 OR type IS NULL)
AND is_delete = 0;
-- ============================================
-- 步骤2修复被截断的字段值
-- ============================================
-- 修复进仓管理菜单的 page_url修复所有被截断的情况
-- 包括warehouse/warehouselr, warehouse/warehouselr* 等
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE name = '进仓管理'
AND type = 1
AND parent_id = 82
AND (page_url LIKE 'warehouse/warehouselr%'
OR page_url = 'warehouse/warehouselr'
OR page_url LIKE 'warehouse/warehouseIn%' AND page_url != 'warehouse/warehouseIn'
OR page_url IS NULL
OR LENGTH(page_url) < 20) -- 如果长度小于20可能是被截断了
AND is_delete = 0;
-- 修复出仓管理菜单的 page_url 和 authority修复所有被截断的情况
-- 包括warehouse/warehouseO, warehouse/warehouseO* 等
-- 以及warehouseout:li, warehouseout:li* 等
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE name = '出仓管理'
AND type = 1
AND parent_id = 82
AND (page_url LIKE 'warehouse/warehouseO%' AND page_url != 'warehouse/warehouseOut'
OR page_url = 'warehouse/warehouseO'
OR page_url LIKE 'warehouse/warehouseOut%' AND page_url != 'warehouse/warehouseOut'
OR page_url IS NULL
OR LENGTH(page_url) < 20 -- 如果长度小于20可能是被截断了
OR authority LIKE 'warehouseout:li%' AND authority != 'warehouseout:list'
OR authority = 'warehouseout:li'
OR authority IS NULL
OR LENGTH(authority) < 15) -- 如果长度小于15可能是被截断了
AND is_delete = 0;
-- ============================================
-- 步骤3确保父菜单的 type 字段正确(应该是 0
-- ============================================
UPDATE sys_menu
SET
type = 0,
update_time = NOW()
WHERE id = 82
AND (type IS NULL OR type != 0)
AND is_delete = 0;
-- ============================================
-- 步骤4验证修复结果
-- ============================================
-- 执行以下查询验证数据是否正确:
-- SELECT id, parent_id, type, name, route_url, page_url, authority
-- FROM sys_menu
-- WHERE (id = 82 OR parent_id = 82)
-- AND is_delete = 0
-- ORDER BY id, sort;

View File

@@ -1,82 +0,0 @@
USE cattletrade;
-- 直接修复脚本:强制更新被截断的字段值
-- 使用最直接的方式,确保更新成功
-- ============================================
-- 步骤1先查看当前值用于确认
-- ============================================
-- SELECT id, name, page_url, authority FROM sys_menu WHERE id IN (88, 93) AND is_delete = 0;
-- ============================================
-- 步骤2修复进仓管理菜单id=88
-- ============================================
-- 当前错误值warehouse/warehouselr
-- 目标正确值warehouse/warehouseIn
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE id = 88;
-- 验证更新是否成功
SELECT
id,
name,
page_url,
CHAR_LENGTH(page_url) as page_url_len,
'warehouse/warehouseIn' as expected,
CHAR_LENGTH('warehouse/warehouseIn') as expected_len
FROM sys_menu
WHERE id = 88;
-- ============================================
-- 步骤3修复出仓管理菜单id=93
-- ============================================
-- 当前错误值page_url = warehouse/warehouseO, authority = warehouseout:li
-- 目标正确值page_url = warehouse/warehouseOut, authority = warehouseout:list
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE id = 93;
-- 验证更新是否成功
SELECT
id,
name,
page_url,
CHAR_LENGTH(page_url) as page_url_len,
authority,
CHAR_LENGTH(authority) as authority_len,
'warehouse/warehouseOut' as expected_page_url,
CHAR_LENGTH('warehouse/warehouseOut') as expected_page_url_len,
'warehouseout:list' as expected_authority,
CHAR_LENGTH('warehouseout:list') as expected_authority_len
FROM sys_menu
WHERE id = 93;
-- ============================================
-- 步骤4最终验证执行后运行此查询
-- ============================================
SELECT
id,
parent_id,
type,
name,
route_url,
page_url,
CHAR_LENGTH(page_url) as page_url_len,
authority,
CHAR_LENGTH(authority) as authority_len
FROM sys_menu
WHERE id IN (88, 93)
AND is_delete = 0;
-- 预期结果:
-- id=88: page_url='warehouse/warehouseIn', page_url_len=20
-- id=93: page_url='warehouse/warehouseOut', page_url_len=21, authority='warehouseout:list', authority_len=16

View File

@@ -1,122 +0,0 @@
USE cattletrade;
-- 最终修复中转仓管理菜单数据
-- 根据表结构page_url VARCHAR(100), authority VARCHAR(50)
-- 需要存储的值:
-- warehouse/warehouseIn = 20 字符在100以内足够
-- warehouse/warehouseOut = 21 字符在100以内足够
-- warehouseout:list = 16 字符在50以内足够
--
-- 字段长度足够问题可能是插入时被截断直接UPDATE修复即可
-- ============================================
-- 步骤1删除重复的菜单数据如果存在
-- ============================================
-- 删除 id=98 的子菜单的按钮权限(如果存在)
DELETE FROM sys_menu
WHERE parent_id IN (99, 104, 109)
AND type = 2
AND is_delete = 0;
-- 删除 id=98 的子菜单(二级菜单)
DELETE FROM sys_menu
WHERE id IN (99, 104, 109)
AND parent_id = 98
AND type = 1
AND is_delete = 0;
-- 删除 id=98 的父菜单(如果存在)
DELETE FROM sys_menu
WHERE id = 98
AND name = '中转仓管理'
AND parent_id = 0
AND (type = 0 OR type IS NULL)
AND is_delete = 0;
-- ============================================
-- 步骤2修复被截断的字段值直接通过ID修复最可靠
-- ============================================
-- 修复进仓管理菜单id=88的 page_url
-- 修复warehouse/warehouselr -> warehouse/warehouseIn
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE id = 88
AND is_delete = 0;
-- 修复出仓管理菜单id=93的 page_url 和 authority
-- 修复warehouse/warehouseO -> warehouse/warehouseOut
-- 修复warehouseout:li -> warehouseout:list
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE id = 93
AND is_delete = 0;
-- ============================================
-- 步骤3通过名称匹配修复作为后备方案确保所有记录都被修复
-- ============================================
-- 修复进仓管理菜单的 page_url通过名称匹配
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE name = '进仓管理'
AND type = 1
AND parent_id = 82
AND page_url != 'warehouse/warehouseIn'
AND is_delete = 0;
-- 修复出仓管理菜单的 page_url 和 authority通过名称匹配
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE name = '出仓管理'
AND type = 1
AND parent_id = 82
AND (page_url != 'warehouse/warehouseOut' OR authority != 'warehouseout:list')
AND is_delete = 0;
-- ============================================
-- 步骤4确保父菜单的 type 字段正确(应该是 0
-- ============================================
UPDATE sys_menu
SET
type = 0,
update_time = NOW()
WHERE id = 82
AND (type IS NULL OR type != 0)
AND is_delete = 0;
-- ============================================
-- 步骤5验证修复结果
-- ============================================
-- 执行以下查询验证数据是否正确:
SELECT
id,
parent_id,
type,
name,
route_url,
page_url,
LENGTH(page_url) as page_url_len,
authority,
LENGTH(authority) as authority_len
FROM sys_menu
WHERE (id = 82 OR parent_id = 82)
AND is_delete = 0
ORDER BY id, sort;
-- 预期结果:
-- id=82: type=0, page_url=NULL, authority=NULL
-- id=83: route_url='list', page_url='warehouse/warehouse', authority='warehouse:list'
-- id=88: route_url='in', page_url='warehouse/warehouseIn' (长度=20), authority='warehousein:list'
-- id=93: route_url='out', page_url='warehouse/warehouseOut' (长度=21), authority='warehouseout:list' (长度=16)

View File

@@ -1,51 +0,0 @@
USE cattletrade;
-- 简单直接的修复脚本:修复被截断的字段值
-- 直接通过ID更新确保修复成功
-- ============================================
-- 修复进仓管理菜单id=88的 page_url
-- 当前值warehouse/warehouselr (长度21)
-- 目标值warehouse/warehouseIn (长度20)
-- ============================================
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE id = 88
AND is_delete = 0;
-- ============================================
-- 修复出仓管理菜单id=93的 page_url 和 authority
-- 当前值page_url = warehouse/warehouseO (长度22), authority = warehouseout:li (长度17)
-- 目标值page_url = warehouse/warehouseOut (长度21), authority = warehouseout:list (长度16)
-- ============================================
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE id = 93
AND is_delete = 0;
-- ============================================
-- 验证修复结果(执行后运行此查询)
-- ============================================
SELECT
id,
parent_id,
type,
name,
route_url,
page_url,
LENGTH(page_url) as page_url_len,
authority,
LENGTH(authority) as authority_len
FROM sys_menu
WHERE id IN (88, 93)
AND is_delete = 0;
-- 预期结果:
-- id=88: page_url='warehouse/warehouseIn', page_url_len=20
-- id=93: page_url='warehouse/warehouseOut', page_url_len=21, authority='warehouseout:list', authority_len=16

View File

@@ -1,83 +0,0 @@
USE cattletrade;
-- 修复中转仓管理菜单中被截断的字段值
-- 该脚本专门用于修复字段值被截断的问题
-- ============================================
-- 修复进仓管理菜单id=88的 page_url
-- ============================================
-- 修复warehouse/warehouselr -> warehouse/warehouseIn
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE id = 88
AND name = '进仓管理'
AND type = 1
AND parent_id = 82
AND page_url != 'warehouse/warehouseIn'
AND is_delete = 0;
-- 如果上面的更新没有生效,尝试更宽泛的条件
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseIn',
update_time = NOW()
WHERE name = '进仓管理'
AND type = 1
AND parent_id = 82
AND (page_url LIKE 'warehouse/warehouselr%'
OR page_url = 'warehouse/warehouselr'
OR page_url LIKE 'warehouse/warehouseIn%' AND page_url != 'warehouse/warehouseIn'
OR LENGTH(page_url) < 20)
AND is_delete = 0;
-- ============================================
-- 修复出仓管理菜单id=93的 page_url 和 authority
-- ============================================
-- 修复warehouse/warehouseO -> warehouse/warehouseOut
-- 修复warehouseout:li -> warehouseout:list
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE id = 93
AND name = '出仓管理'
AND type = 1
AND parent_id = 82
AND (page_url != 'warehouse/warehouseOut' OR authority != 'warehouseout:list')
AND is_delete = 0;
-- 如果上面的更新没有生效,尝试更宽泛的条件
UPDATE sys_menu
SET
page_url = 'warehouse/warehouseOut',
authority = 'warehouseout:list',
update_time = NOW()
WHERE name = '出仓管理'
AND type = 1
AND parent_id = 82
AND (page_url LIKE 'warehouse/warehouseO%' AND page_url != 'warehouse/warehouseOut'
OR page_url = 'warehouse/warehouseO'
OR page_url LIKE 'warehouse/warehouseOut%' AND page_url != 'warehouse/warehouseOut'
OR LENGTH(page_url) < 20
OR authority LIKE 'warehouseout:li%' AND authority != 'warehouseout:list'
OR authority = 'warehouseout:li'
OR LENGTH(authority) < 15)
AND is_delete = 0;
-- ============================================
-- 验证修复结果
-- ============================================
-- 执行以下查询验证数据是否正确:
-- SELECT id, parent_id, type, name, route_url, page_url, authority
-- FROM sys_menu
-- WHERE (id = 82 OR parent_id = 82)
-- AND is_delete = 0
-- ORDER BY id, sort;
--
-- 预期结果:
-- id=88: page_url = 'warehouse/warehouseIn'
-- id=93: page_url = 'warehouse/warehouseOut', authority = 'warehouseout:list'

View File

@@ -1,94 +0,0 @@
USE cattletrade;
-- 插入销售概览菜单
-- 菜单类型0-目录1-菜单2-按钮
-- 排序:数字越小越靠前
-- 1. 插入销售概览主菜单type=1菜单
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
0, -- parent_id: 0表示顶级菜单
1, -- type: 1-菜单
'el-icon-data-line', -- icon: 数据统计图标
'销售概览', -- name: 菜单名称
50, -- sort: 排序(可以根据实际情况调整)
NULL, -- route_url: 后端路由地址(菜单不需要)
'/salesOverview/list', -- page_url: 前端路由地址
2, -- org_type: 2-企业端(根据实际情况调整)
'salesoverview:list', -- authority: 权限字符串
NOW(), -- create_time
NOW(), -- update_time
0 -- is_delete: 0-未删除
);
-- 2. 插入销售概览相关按钮权限type=2按钮
-- 使用子查询获取刚插入的菜单ID作为parent_id
-- 2.1 新增权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
(SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1) AS parent_id,
2 AS type,
NULL AS icon,
'新增' AS name,
2 AS sort,
NULL AS route_url,
NULL AS page_url,
2 AS org_type,
'salesoverview:add' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE EXISTS (SELECT 1 FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0);
-- 2.2 编辑权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
(SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1) AS parent_id,
2 AS type,
NULL AS icon,
'编辑' AS name,
3 AS sort,
NULL AS route_url,
NULL AS page_url,
2 AS org_type,
'salesoverview:edit' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE EXISTS (SELECT 1 FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0);
-- 2.3 删除权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
(SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1) AS parent_id,
2 AS type,
NULL AS icon,
'删除' AS name,
4 AS sort,
NULL AS route_url,
NULL AS page_url,
2 AS org_type,
'salesoverview:delete' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE EXISTS (SELECT 1 FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0);
-- 2.4 计算统计数据权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
(SELECT id FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0 LIMIT 1) AS parent_id,
2 AS type,
NULL AS icon,
'计算统计数据' AS name,
5 AS sort,
NULL AS route_url,
NULL AS page_url,
2 AS org_type,
'salesoverview:calculate' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE EXISTS (SELECT 1 FROM sys_menu WHERE name = '销售概览' AND type = 1 AND is_delete = 0);

View File

@@ -1,74 +0,0 @@
USE cattletrade;
-- 插入屠宰场管理菜单(一级目录 + 两个二级菜单 + 按钮权限)
-- 菜单类型0-目录1-菜单2-按钮
-- 1) 一级菜单:屠宰场管理
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
0,
0,
'el-icon-knife-fork',
'屠宰场管理',
70,
NULL,
NULL,
2,
NULL,
NOW(),
NOW(),
0
);
SET @slaughter_parent_id = LAST_INSERT_ID();
-- 2) 二级菜单:屠宰场管理(列表页)
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
@slaughter_parent_id,
1,
'el-icon-office-building',
'屠宰场管理',
1,
'house',
'slaughter/house',
2,
'slaughterHouse:list',
NOW(),
NOW(),
0
);
SET @slaughter_house_menu_id = LAST_INSERT_ID();
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES
(@slaughter_house_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'slaughterHouse:add', NOW(), NOW(), 0),
(@slaughter_house_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'slaughterHouse:edit', NOW(), NOW(), 0),
(@slaughter_house_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'slaughterHouse:delete', NOW(), NOW(), 0),
(@slaughter_house_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'slaughterHouse:query', NOW(), NOW(), 0);
-- 3) 二级菜单:进场管理
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
@slaughter_parent_id,
1,
'el-icon-truck',
'进场管理',
2,
'entry',
'slaughter/entry',
2,
'slaughterEntry:list',
NOW(),
NOW(),
0
);
SET @slaughter_entry_menu_id = LAST_INSERT_ID();
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES
(@slaughter_entry_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'slaughterEntry:add', NOW(), NOW(), 0),
(@slaughter_entry_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'slaughterEntry:edit', NOW(), NOW(), 0),
(@slaughter_entry_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'slaughterEntry:delete', NOW(), NOW(), 0),
(@slaughter_entry_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'slaughterEntry:query', NOW(), NOW(), 0);

View File

@@ -1,115 +0,0 @@
USE cattletrade;
-- 插入中转仓管理菜单
-- 菜单类型0-目录1-菜单2-按钮
-- 排序:数字越小越靠前
-- ============================================
-- 1. 插入一级菜单中转仓管理type=0目录
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
0, -- parent_id: 0表示顶级菜单
0, -- type: 0-目录
'el-icon-office-building', -- icon: 仓库图标
'中转仓管理', -- name: 菜单名称
60, -- sort: 排序(可以根据实际情况调整)
NULL, -- route_url: 后端路由地址(目录不需要)
NULL, -- page_url: 前端路由地址(目录不需要)
2, -- org_type: 2-企业端
NULL, -- authority: 权限字符串(目录不需要)
NOW(), -- create_time
NOW(), -- update_time
0 -- is_delete: 0-未删除
);
-- 获取刚插入的一级菜单ID
SET @warehouse_parent_id = LAST_INSERT_ID();
-- ============================================
-- 2. 插入二级菜单中转仓管理type=1菜单
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
@warehouse_parent_id, -- parent_id: 一级菜单ID
1, -- type: 1-菜单
'el-icon-office-building', -- icon: 仓库图标
'中转仓管理', -- name: 菜单名称
1, -- sort: 排序
'list', -- route_url: 路由路径(相对于父菜单)
'warehouse/warehouse', -- page_url: 前端组件路径相对于views目录
2, -- org_type: 2-企业端
'warehouse:list', -- authority: 权限字符串
NOW(), -- create_time
NOW(), -- update_time
0 -- is_delete: 0-未删除
);
SET @warehouse_list_menu_id = LAST_INSERT_ID();
-- 中转仓管理按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES
(@warehouse_list_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'warehouse:add', NOW(), NOW(), 0),
(@warehouse_list_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'warehouse:edit', NOW(), NOW(), 0),
(@warehouse_list_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'warehouse:delete', NOW(), NOW(), 0),
(@warehouse_list_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'warehouse:query', NOW(), NOW(), 0);
-- ============================================
-- 3. 插入二级菜单进仓管理type=1菜单
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
@warehouse_parent_id, -- parent_id: 一级菜单ID
1, -- type: 1-菜单
'el-icon-upload', -- icon: 上传图标
'进仓管理', -- name: 菜单名称
2, -- sort: 排序
'in', -- route_url: 路由路径(相对于父菜单)
'warehouse/warehouseIn', -- page_url: 前端组件路径相对于views目录
2, -- org_type: 2-企业端
'warehousein:list', -- authority: 权限字符串
NOW(), -- create_time
NOW(), -- update_time
0 -- is_delete: 0-未删除
);
SET @warehouse_in_menu_id = LAST_INSERT_ID();
-- 进仓管理按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES
(@warehouse_in_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'warehousein:add', NOW(), NOW(), 0),
(@warehouse_in_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'warehousein:edit', NOW(), NOW(), 0),
(@warehouse_in_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'warehousein:delete', NOW(), NOW(), 0),
(@warehouse_in_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'warehousein:query', NOW(), NOW(), 0);
-- ============================================
-- 4. 插入二级菜单出仓管理type=1菜单
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES (
@warehouse_parent_id, -- parent_id: 一级菜单ID
1, -- type: 1-菜单
'el-icon-download', -- icon: 下载图标
'出仓管理', -- name: 菜单名称
3, -- sort: 排序
'out', -- route_url: 路由路径(相对于父菜单)
'warehouse/warehouseOut', -- page_url: 前端组件路径相对于views目录
2, -- org_type: 2-企业端
'warehouseout:list', -- authority: 权限字符串
NOW(), -- create_time
NOW(), -- update_time
0 -- is_delete: 0-未删除
);
SET @warehouse_out_menu_id = LAST_INSERT_ID();
-- 出仓管理按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
VALUES
(@warehouse_out_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'warehouseout:add', NOW(), NOW(), 0),
(@warehouse_out_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'warehouseout:edit', NOW(), NOW(), 0),
(@warehouse_out_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'warehouseout:delete', NOW(), NOW(), 0),
(@warehouse_out_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'warehouseout:query', NOW(), NOW(), 0);

View File

@@ -1,213 +0,0 @@
USE cattletrade;
-- 安全插入中转仓管理菜单(可重复执行,不会重复插入)
-- 菜单类型0-目录1-菜单2-按钮
-- 排序:数字越小越靠前
-- ============================================
-- 1. 插入一级菜单中转仓管理type=0目录
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
0 AS parent_id,
0 AS type,
'el-icon-office-building' AS icon,
'中转仓管理' AS name,
60 AS sort,
NULL AS route_url,
NULL AS page_url,
2 AS org_type,
NULL AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0
);
-- 获取一级菜单ID如果已存在则查询否则使用刚插入的ID
SET @warehouse_parent_id = COALESCE(
(SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0 LIMIT 1),
LAST_INSERT_ID()
);
-- ============================================
-- 2. 插入二级菜单中转仓管理type=1菜单
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@warehouse_parent_id AS parent_id,
1 AS type,
'el-icon-office-building' AS icon,
'中转仓管理' AS name,
1 AS sort,
'list' AS route_url,
'warehouse/warehouse' AS page_url,
2 AS org_type,
'warehouse:list' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @warehouse_parent_id
AND name = '中转仓管理'
AND type = 1
AND is_delete = 0
)
AND @warehouse_parent_id IS NOT NULL;
SET @warehouse_list_menu_id = COALESCE(
(SELECT id FROM sys_menu WHERE parent_id = @warehouse_parent_id AND name = '中转仓管理' AND type = 1 AND is_delete = 0 LIMIT 1),
LAST_INSERT_ID()
);
-- 中转仓管理按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_list_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'warehouse:add', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_list_menu_id AND name = '新增' AND type = 2 AND authority = 'warehouse:add' AND is_delete = 0
)
AND @warehouse_list_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_list_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'warehouse:edit', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_list_menu_id AND name = '编辑' AND type = 2 AND authority = 'warehouse:edit' AND is_delete = 0
)
AND @warehouse_list_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_list_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'warehouse:delete', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_list_menu_id AND name = '删除' AND type = 2 AND authority = 'warehouse:delete' AND is_delete = 0
)
AND @warehouse_list_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_list_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'warehouse:query', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_list_menu_id AND name = '查询' AND type = 2 AND authority = 'warehouse:query' AND is_delete = 0
)
AND @warehouse_list_menu_id IS NOT NULL;
-- ============================================
-- 3. 插入二级菜单进仓管理type=1菜单
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@warehouse_parent_id AS parent_id,
1 AS type,
'el-icon-upload' AS icon,
'进仓管理' AS name,
2 AS sort,
'in' AS route_url,
'warehouse/warehouseIn' AS page_url,
2 AS org_type,
'warehousein:list' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @warehouse_parent_id
AND name = '进仓管理'
AND type = 1
AND is_delete = 0
)
AND @warehouse_parent_id IS NOT NULL;
SET @warehouse_in_menu_id = COALESCE(
(SELECT id FROM sys_menu WHERE parent_id = @warehouse_parent_id AND name = '进仓管理' AND type = 1 AND is_delete = 0 LIMIT 1),
LAST_INSERT_ID()
);
-- 进仓管理按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_in_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'warehousein:add', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_in_menu_id AND name = '新增' AND type = 2 AND authority = 'warehousein:add' AND is_delete = 0
)
AND @warehouse_in_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_in_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'warehousein:edit', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_in_menu_id AND name = '编辑' AND type = 2 AND authority = 'warehousein:edit' AND is_delete = 0
)
AND @warehouse_in_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_in_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'warehousein:delete', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_in_menu_id AND name = '删除' AND type = 2 AND authority = 'warehousein:delete' AND is_delete = 0
)
AND @warehouse_in_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_in_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'warehousein:query', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_in_menu_id AND name = '查询' AND type = 2 AND authority = 'warehousein:query' AND is_delete = 0
)
AND @warehouse_in_menu_id IS NOT NULL;
-- ============================================
-- 4. 插入二级菜单出仓管理type=1菜单
-- ============================================
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT
@warehouse_parent_id AS parent_id,
1 AS type,
'el-icon-download' AS icon,
'出仓管理' AS name,
3 AS sort,
'out' AS route_url,
'warehouse/warehouseOut' AS page_url,
2 AS org_type,
'warehouseout:list' AS authority,
NOW() AS create_time,
NOW() AS update_time,
0 AS is_delete
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu
WHERE parent_id = @warehouse_parent_id
AND name = '出仓管理'
AND type = 1
AND is_delete = 0
)
AND @warehouse_parent_id IS NOT NULL;
SET @warehouse_out_menu_id = COALESCE(
(SELECT id FROM sys_menu WHERE parent_id = @warehouse_parent_id AND name = '出仓管理' AND type = 1 AND is_delete = 0 LIMIT 1),
LAST_INSERT_ID()
);
-- 出仓管理按钮权限
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_out_menu_id, 2, NULL, '新增', 1, NULL, NULL, 2, 'warehouseout:add', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_out_menu_id AND name = '新增' AND type = 2 AND authority = 'warehouseout:add' AND is_delete = 0
)
AND @warehouse_out_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_out_menu_id, 2, NULL, '编辑', 2, NULL, NULL, 2, 'warehouseout:edit', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_out_menu_id AND name = '编辑' AND type = 2 AND authority = 'warehouseout:edit' AND is_delete = 0
)
AND @warehouse_out_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_out_menu_id, 2, NULL, '删除', 3, NULL, NULL, 2, 'warehouseout:delete', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_out_menu_id AND name = '删除' AND type = 2 AND authority = 'warehouseout:delete' AND is_delete = 0
)
AND @warehouse_out_menu_id IS NOT NULL;
INSERT INTO sys_menu (parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
SELECT @warehouse_out_menu_id, 2, NULL, '查询', 4, NULL, NULL, 2, 'warehouseout:query', NOW(), NOW(), 0
WHERE NOT EXISTS (
SELECT 1 FROM sys_menu WHERE parent_id = @warehouse_out_menu_id AND name = '查询' AND type = 2 AND authority = 'warehouseout:query' AND is_delete = 0
)
AND @warehouse_out_menu_id IS NOT NULL;

View File

@@ -13,6 +13,7 @@
<result column="source_lon" property="sourceLon" />
<result column="source_lat" property="sourceLat" />
<result column="cattle_count" property="cattleCount" />
<result column="remaining_count" property="remainingCount" />
<result column="weight" property="weight" />
<result column="in_time" property="inTime" />
<result column="photos" property="photos" />
@@ -28,7 +29,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, in_number, warehouse_id, order_id, delivery_id, source_location, source_lon, source_lat, cattle_count, weight, in_time, photos, videos, remark, status, create_time, update_time, created_by, updated_by, is_delete
id, in_number, warehouse_id, order_id, delivery_id, source_location, source_lon, source_lat, cattle_count, remaining_count, weight, in_time, photos, videos, remark, status, create_time, update_time, created_by, updated_by, is_delete
</sql>
</mapper>