新增磅单管理功能,支持免密接口和数据同步,更新相关控制器、实体和服务,优化权限管理,确保系统的灵活性和可扩展性。

This commit is contained in:
geht
2026-05-06 15:30:31 +08:00
parent b03cbeff9b
commit 71b8d94da8
48 changed files with 4205 additions and 3 deletions

View File

@@ -201,6 +201,8 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/xslmes/mesXslCustomer/anon/**", "anon");
// MES供应商管理免密接口供桌面端调用
filterChainDefinitionMap.put("/xslmes/mesXslSupplier/anon/**", "anon");
// MES磅单管理免密接口供桌面端调用
filterChainDefinitionMap.put("/xslmes/mesXslWeightRecord/anon/**", "anon");
// 桌面端用户反同步批量上报Outbox -> /sys/sync/batch
filterChainDefinitionMap.put("/sys/sync/batch", "anon");

View File

@@ -16,9 +16,11 @@ import org.jeecg.modules.xslmes.constant.MesXslCustomerBizStatus;
import org.jeecg.modules.xslmes.entity.MesXslCustomer;
import org.jeecg.modules.xslmes.entity.MesXslSupplier;
import org.jeecg.modules.xslmes.entity.MesXslVehicle;
import org.jeecg.modules.xslmes.entity.MesXslWeightRecord;
import org.jeecg.modules.xslmes.service.IMesXslCustomerService;
import org.jeecg.modules.xslmes.service.IMesXslSupplierService;
import org.jeecg.modules.xslmes.service.IMesXslVehicleService;
import org.jeecg.modules.xslmes.service.IMesXslWeightRecordService;
import org.jeecg.modules.xslmes.service.MesXslStompNotifyService;
import org.springframework.web.bind.annotation.*;
@@ -42,6 +44,7 @@ public class MesXslDesktopAnonController {
private final IMesXslVehicleService vehicleService;
private final IMesXslCustomerService customerService;
private final IMesXslSupplierService supplierService;
private final IMesXslWeightRecordService weightRecordService;
private final MesXslStompNotifyService stompNotify;
// ═══════════════════════════ 车辆管理 ═══════════════════════════
@@ -342,8 +345,97 @@ public class MesXslDesktopAnonController {
return ok ? Result.OK("操作成功") : Result.error("操作失败");
}
// ═══════════════════════════ 磅单管理 ═══════════════════════════
@Operation(summary = "磅单-免密分页列表查询")
@GetMapping("/xslmes/mesXslWeightRecord/anon/list")
public Result<IPage<MesXslWeightRecord>> weightRecordAnonList(
MesXslWeightRecord mesXslWeightRecord,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<MesXslWeightRecord> qw = QueryGenerator.initQueryWrapper(mesXslWeightRecord, req.getParameterMap());
qw.orderByDesc("create_time");
IPage<MesXslWeightRecord> page = weightRecordService.page(new Page<>(pageNo, pageSize), qw);
return Result.OK(page);
}
@Operation(summary = "磅单-免密通过id查询")
@GetMapping("/xslmes/mesXslWeightRecord/anon/queryById")
public Result<MesXslWeightRecord> weightRecordAnonQueryById(@RequestParam(name = "id") String id) {
MesXslWeightRecord entity = weightRecordService.getById(id);
return entity != null ? Result.OK(entity) : Result.error("未找到对应数据");
}
@Operation(summary = "磅单-免密添加")
@PostMapping("/xslmes/mesXslWeightRecord/anon/add")
public Result<String> weightRecordAnonAdd(@RequestBody MesXslWeightRecord mesXslWeightRecord) {
if (oConvertUtils.isEmpty(mesXslWeightRecord.getPlateNumber())) {
return Result.error("车牌号不能为空");
}
// 净重自动计算
if (mesXslWeightRecord.getGrossWeight() != null && mesXslWeightRecord.getTareWeight() != null) {
mesXslWeightRecord.setNetWeight(
mesXslWeightRecord.getGrossWeight().subtract(mesXslWeightRecord.getTareWeight()));
}
applyWeightBillType(mesXslWeightRecord);
weightRecordService.save(mesXslWeightRecord);
stompNotify.publishWeightRecordChanged("add", mesXslWeightRecord.getId());
return Result.OK("添加成功!");
}
@Operation(summary = "磅单-免密编辑")
@RequestMapping(value = "/xslmes/mesXslWeightRecord/anon/edit", method = {RequestMethod.PUT, RequestMethod.POST})
public Result<String> weightRecordAnonEdit(@RequestBody MesXslWeightRecord mesXslWeightRecord) {
if (oConvertUtils.isEmpty(mesXslWeightRecord.getId())) {
return Result.error("主键不能为空");
}
// 净重自动计算
if (mesXslWeightRecord.getGrossWeight() != null && mesXslWeightRecord.getTareWeight() != null) {
mesXslWeightRecord.setNetWeight(
mesXslWeightRecord.getGrossWeight().subtract(mesXslWeightRecord.getTareWeight()));
}
applyWeightBillType(mesXslWeightRecord);
boolean ok = weightRecordService.updateById(mesXslWeightRecord);
if (!ok) {
return Result.error("数据已被他人修改,请刷新后重试");
}
stompNotify.publishWeightRecordChanged("edit", mesXslWeightRecord.getId());
return Result.OK("编辑成功!");
}
@Operation(summary = "磅单-免密删除")
@DeleteMapping("/xslmes/mesXslWeightRecord/anon/delete")
public Result<String> weightRecordAnonDelete(@RequestParam(name = "id") String id) {
weightRecordService.removeById(id);
stompNotify.publishWeightRecordChanged("delete", id);
return Result.OK("删除成功!");
}
@Operation(summary = "磅单-免密批量删除")
@DeleteMapping("/xslmes/mesXslWeightRecord/anon/deleteBatch")
public Result<String> weightRecordAnonDeleteBatch(@RequestParam(name = "ids") String ids) {
weightRecordService.removeByIds(Arrays.asList(ids.split(",")));
stompNotify.publishWeightRecordChanged("batchDelete", ids);
return Result.OK("批量删除成功!");
}
// ─────────────────────────── 车辆私有辅助 ────────────────────────────
private void applyWeightBillType(MesXslWeightRecord record) {
if (record.getGrossWeight() != null && record.getTareWeight() != null) {
record.setBillType("2");
return;
}
if (record.getGrossWeight() != null) {
record.setBillType("1");
return;
}
if (record.getTareWeight() != null) {
record.setBillType("3");
}
}
private void applyVehicleBelong(MesXslVehicle v) {
if (oConvertUtils.isEmpty(v.getVehicleBelong())) {
return;

View File

@@ -15,6 +15,7 @@ import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.xslmes.entity.MesXslWeightRecord;
import org.jeecg.modules.xslmes.service.IMesXslWeightRecordService;
import org.jeecg.modules.xslmes.service.MesXslStompNotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@@ -36,6 +37,8 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
@Autowired
private IMesXslWeightRecordService mesXslWeightRecordService;
@Autowired
private MesXslStompNotifyService stompNotifyService;
@Operation(summary = "地磅数据记录-分页列表查询")
@GetMapping(value = "/list")
@@ -61,8 +64,10 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
String seq = String.format("%03d", new Random().nextInt(1000));
mesXslWeightRecord.setBillNo("BDH-" + dateStr + seq);
}
computeBillType(mesXslWeightRecord);
computeNetWeight(mesXslWeightRecord);
mesXslWeightRecordService.save(mesXslWeightRecord);
stompNotifyService.publishWeightRecordChanged("add", mesXslWeightRecord.getId());
return Result.OK("添加成功!");
}
@@ -71,8 +76,10 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
@RequiresPermissions("xslmes:mes_xsl_weight_record:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
public Result<String> edit(@RequestBody MesXslWeightRecord mesXslWeightRecord) {
computeBillType(mesXslWeightRecord);
computeNetWeight(mesXslWeightRecord);
mesXslWeightRecordService.updateById(mesXslWeightRecord);
stompNotifyService.publishWeightRecordChanged("edit", mesXslWeightRecord.getId());
return Result.OK("编辑成功!");
}
@@ -82,6 +89,7 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
@DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
mesXslWeightRecordService.removeById(id);
stompNotifyService.publishWeightRecordChanged("delete", id);
return Result.OK("删除成功!");
}
@@ -91,6 +99,7 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
@DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
this.mesXslWeightRecordService.removeByIds(Arrays.asList(ids.split(",")));
stompNotifyService.publishWeightRecordChanged("deleteBatch", null);
return Result.OK("批量删除成功!");
}
@@ -124,4 +133,18 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
record.setNetWeight(net.compareTo(BigDecimal.ZERO) >= 0 ? net : BigDecimal.ZERO);
}
}
private void computeBillType(MesXslWeightRecord record) {
if (record.getGrossWeight() != null && record.getTareWeight() != null) {
record.setBillType("2");
return;
}
if (record.getGrossWeight() != null) {
record.setBillType("1");
return;
}
if (record.getTareWeight() != null) {
record.setBillType("3");
}
}
}

View File

@@ -81,6 +81,11 @@ public class MesXslWeightRecord extends JeecgEntity implements Serializable {
@Schema(description = "手机号")
private String driverPhone;
@Excel(name = "单据类型", width = 12, dicCode = "xslmes_weight_bill_type")
@Dict(dicCode = "xslmes_weight_bill_type")
@Schema(description = "单据类型1已称毛重 2称重完成")
private String billType;
@Schema(description = "租户ID")
private Integer tenantId;
}

View File

@@ -35,6 +35,11 @@ public class MesXslStompNotifyService {
publish("/topic/sync/mes-suppliers", "MES_SUPPLIER_CHANGED", "supplierId", supplierId, action);
}
/** 广播磅单数据变更事件到 /topic/sync/mes-weight-records */
public void publishWeightRecordChanged(String action, String weightRecordId) {
publish("/topic/sync/mes-weight-records", "MES_WEIGHT_RECORD_CHANGED", "weightRecordId", weightRecordId, action);
}
// ─────────────────────────── 私有辅助 ────────────────────────────
private void publish(String topic, String cmd, String idKey, String idValue, String action) {

View File

@@ -0,0 +1,63 @@
-- 磅单新增单据类型字段 + 字典幂等
-- 1) 表结构单据类型1已称毛重 2称重完成 3已称皮重
SET @bill_type_exists := (
SELECT COUNT(1)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'mes_xsl_weight_record'
AND COLUMN_NAME = 'bill_type'
);
SET @ddl_sql := IF(
@bill_type_exists = 0,
'ALTER TABLE `mes_xsl_weight_record` ADD COLUMN `bill_type` varchar(10) DEFAULT NULL COMMENT ''单据类型字典xslmes_weight_bill_type1已称毛重 2称重完成 3已称皮重'' AFTER `driver_phone`',
'SELECT 1'
);
PREPARE stmt_bill_type FROM @ddl_sql;
EXECUTE stmt_bill_type;
DEALLOCATE PREPARE stmt_bill_type;
-- 2) 初始化历史数据按当前重量信息推导
UPDATE `mes_xsl_weight_record`
SET `bill_type` = CASE
WHEN `gross_weight` IS NOT NULL AND `tare_weight` IS NOT NULL THEN '2'
WHEN `gross_weight` IS NOT NULL THEN '1'
WHEN `tare_weight` IS NOT NULL THEN '3'
ELSE `bill_type`
END
WHERE `bill_type` IS NULL OR `bill_type` = '';
-- 3) 字典主表
INSERT INTO `sys_dict` (`id`, `dict_name`, `dict_code`, `description`, `del_flag`, `create_by`, `create_time`, `type`, `tenant_id`)
SELECT REPLACE(UUID(), '-', ''), 'MES磅单单据类型', 'xslmes_weight_bill_type', '磅单当前状态已称毛重/称重完成/已称皮重', 0, 'admin', NOW(), 0, 0
WHERE NOT EXISTS (SELECT 1 FROM `sys_dict` WHERE `dict_code` = 'xslmes_weight_bill_type' AND `del_flag` = 0);
-- 4) 字典项已称毛重
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`)
SELECT REPLACE(UUID(), '-', ''), d.id, '已称毛重', '1', 1, 1, 'admin', NOW()
FROM `sys_dict` d
WHERE d.`dict_code` = 'xslmes_weight_bill_type'
AND NOT EXISTS (
SELECT 1 FROM `sys_dict_item` i
WHERE i.`dict_id` = d.`id` AND i.`item_value` = '1'
);
-- 5) 字典项称重完成
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`)
SELECT REPLACE(UUID(), '-', ''), d.id, '称重完成', '2', 2, 1, 'admin', NOW()
FROM `sys_dict` d
WHERE d.`dict_code` = 'xslmes_weight_bill_type'
AND NOT EXISTS (
SELECT 1 FROM `sys_dict_item` i
WHERE i.`dict_id` = d.`id` AND i.`item_value` = '2'
);
-- 6) 字典项已称皮重
INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`)
SELECT REPLACE(UUID(), '-', ''), d.id, '已称皮重', '3', 3, 1, 'admin', NOW()
FROM `sys_dict` d
WHERE d.`dict_code` = 'xslmes_weight_bill_type'
AND NOT EXISTS (
SELECT 1 FROM `sys_dict_item` i
WHERE i.`dict_id` = d.`id` AND i.`item_value` = '3'
);