// 获取当月最大流水号接口
app.get('/api/afterSales/maxSerial', async (req, res) => {
const prefix = req.query.prefix; // 接收前缀如 RS202510
// SQL查询当月最大单号
const sql = `
SELECT MAX(service_number) AS maxSerial
FROM after_sales_service
WHERE service_number LIKE ?
`;
try {
const [results] = await db.query(sql, [`${prefix}%`]);
res.json({
maxSerial: results[0].maxSerial // 返回如 "RS202510001"
});
} catch (err) {
res.status(500).json({ error: err.message });
}
});
这个方法如何在<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.salesserver.mapper.CoolingServiceRequestMapper">
<!-- 结果集映射 -->
<resultMap type="com.ruoyi.salesserver.domain.CoolingServiceRequest" id="CoolingServiceRequestResult">
<result property="id" column="id" />
<result property="customerId" column="customer_id" />
<result property="seviceRecno" column="sevice_recno"/>
<result property="customerName" column="custome_rname" />
<result property="departmentPhone" column="department_phone" />
<result property="serviceAddress" column="service_address"/>
<result property="serviceType" column="service_type"/>
<result property="systemStatus" column="system_status" />
<result property="problemDescription" column="problem_description" />
<result property="urgencyLevel" column="urgency_level" />
<result property="customerResponsibility" column="customer_responsibility" />
<result property="exchangeRepair" column="exchange_repair" />
<result property="processingTime" column="processing_time" />
<result property="assignedEngineerId" column="assigned_engineer_id" />
<result property="engineerName" column="engineer_name"/>
<result property="currentStatus" column="current_status" />
<result property="handlingNotes" column="handling_notes" />
<result property="completionDate" column="completion_date" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<!-- 查询字段片段 -->
<sql id="selectCoolingServiceRequestVo">
select
id, customer_id, sevice_recno, custome_rname, department_phone, service_address, service_type, system_status, problem_description,
urgency_level, customer_responsibility, exchange_repair, processing_time,
assigned_engineer_id,engineer_name, current_status, handling_notes, completion_date,
create_by, create_time, update_by, update_time, remark
from cooling_service_request
</sql>
<sql id="selectCoolingSeviceRecno">
SELECT MAX(sevice_recno) AS maxSerial
FROM cooling_service_request
WHERE sevice_recno LIKE ?
</sql>
<!-- 分页查询 -->
<select id="selectCoolingServiceRequestList" parameterType="com.ruoyi.salesserver.domain.CoolingServiceRequest" resultMap="CoolingServiceRequestResult">
<include refid="selectCoolingServiceRequestVo"/>
<where>
<if test="customerId != null"> and customer_id = #{customerId}</if>
<if test="seviceRecno != null and seviceRecno != ''"> and sevice_recno = #{seviceRecno}</if>
<if test="customerName != null and customerName != ''"> and custome_rname like concat('%', #{customerName}, '%')</if>
<if test="departmentPhone != null and departmentPhone != ''"> and department_phone like concat('%', #{departmentPhone}, '%')</if>
<if test="systemStatus != null and systemStatus != ''"> and system_status like concat('%', #{systemStatus}, '%')</if>
<if test="urgencyLevel != null and urgencyLevel != ''"> and urgency_level = #{urgencyLevel}</if>
<if test="customerResponsibility != null and customerResponsibility != ''"> and customer_responsibility = #{customerResponsibility}</if>
<if test="assignedEngineerId != null"> and assigned_engineer_id = #{assignedEngineerId}</if>
<if test="currentStatus != null and currentStatus != ''"> and current_status = #{currentStatus}</if>
</where>
order by create_time desc
</select>
<!-- 根据ID查询 -->
<select id="selectCoolingServiceRequestById" parameterType="Long" resultMap="CoolingServiceRequestResult">
<include refid="selectCoolingServiceRequestVo"/>
where id = #{id}
</select>
<!-- 查询服务请求编号 -->
<select id="getSerialNumber" parameterType="String" resultMap="CoolingServiceRequestResult">
<include refid="selectCoolingSeviceRecno"/>
<trim prefix="%" suffix="%">
#{prefix}
</trim>
</select>
<!-- ✅ 新增服务请求(修正版:customer_id 不加 if,必须传) -->
<insert id="insertCoolingServiceRequest"
parameterType="com.ruoyi.salesserver.domain.CoolingServiceRequest"
useGeneratedKeys="true"
keyProperty="id">
INSERT INTO cooling_service_request (
customer_id,
<trim suffixOverrides=",">
<!-- 注意:修正字段名拼写 -->
<if test="seviceRecno != null and seviceRecno != ''">sevice_recno,</if>
<if test="customerName != null and customerName != ''">custome_rname,</if>
<if test="departmentPhone != null and departmentPhone != ''">department_phone,</if>
<if test="serviceAddress != null and serviceAddress != ''">service_address,</if>
<if test="serviceType != null and serviceType != ''">service_type,</if>
<if test="systemStatus != null and systemStatus != ''">system_status,</if>
<if test="problemDescription != null and problemDescription != ''">problem_description,</if>
<if test="urgencyLevel != null and urgencyLevel != ''">urgency_level,</if>
<if test="customerResponsibility != null and customerResponsibility != ''">customer_responsibility,</if>
<if test="exchangeRepair != null and exchangeRepair != ''">exchange_repair,</if>
<if test="processingTime != null">processing_time,</if>
<if test="assignedEngineerId != null">assigned_engineer_id,</if>
<if test="engineerName != null and engineerName != ''">engineer_name,</if>
<if test="currentStatus != null and currentStatus != ''">current_status,</if>
<if test="handlingNotes != null and handlingNotes != ''">handling_notes,</if>
<if test="completionDate != null">completion_date,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time,
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
) VALUES (
#{customerId, jdbcType=BIGINT},
<trim suffixOverrides=",">
<if test="seviceRecno != null and seviceRecno != ''">#{seviceRecno},</if>
<if test="customerName != null and customerName != ''">#{customerName},</if>
<if test="departmentPhone != null and departmentPhone != ''">#{departmentPhone},</if>
<if test="serviceAddress != null and serviceAddress != ''">#{serviceAddress},</if>
<if test="serviceType != null and serviceType != ''">#{serviceType},</if>
<if test="systemStatus != null and systemStatus != ''">#{systemStatus},</if>
<if test="problemDescription != null and problemDescription != ''">#{problemDescription},</if>
<if test="urgencyLevel != null and urgencyLevel != ''">#{urgencyLevel},</if>
<if test="customerResponsibility != null and customerResponsibility != ''">#{customerResponsibility},</if>
<if test="exchangeRepair != null and exchangeRepair != ''">#{exchangeRepair},</if>
<if test="processingTime != null">#{processingTime},</if>
<if test="assignedEngineerId != null">#{assignedEngineerId},</if>
<if test="engineerName != null and engineerName != ''">#{engineerName},</if>
<if test="currentStatus != null and currentStatus != ''">#{currentStatus},</if>
<if test="handlingNotes != null and handlingNotes != ''">#{handlingNotes},</if>
<if test="completionDate != null">#{completionDate},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE(),
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
)
</insert>
<!-- 更新服务请求 -->
<update id="updateCoolingServiceRequest" parameterType="com.ruoyi.salesserver.domain.CoolingServiceRequest">
UPDATE cooling_service_request
<trim prefix="SET" suffixOverrides=",">
customer_id = #{customerId, jdbcType=BIGINT},
<if test="seviceRecno != null and seviceRecno != ''">sevice_recno = #{seviceRecno},</if>
<if test="departmentPhone != null and departmentPhone != ''">department_phone = #{departmentPhone},</if>
<if test="serviceAddress != null and serviceAddress != ''">service_address = #{serviceAddress},</if>
<if test="serviceType != null and serviceType != ''">service_type = #{serviceType},</if>
<if test="customerName != null and customerName != ''">custome_rname = #{customerName},</if>
<if test="systemStatus != null and systemStatus != ''">system_status = #{systemStatus},</if>
<if test="problemDescription != null and problemDescription != ''">problem_description = #{problemDescription},</if>
<if test="urgencyLevel != null and urgencyLevel != ''">urgency_level = #{urgencyLevel},</if>
<if test="customerResponsibility != null and customerResponsibility != ''">customer_responsibility = #{customerResponsibility},</if>
<if test="exchangeRepair != null and exchangeRepair != ''">exchange_repair = #{exchangeRepair},</if>
<if test="processingTime != null">processing_time = #{processingTime},</if>
<if test="assignedEngineerId != null">assigned_engineer_id = #{assignedEngineerId},</if>
<if test="engineerName != null and engineerName != ''">engineer_name = #{engineerName},</if>
<if test="currentStatus != null and currentStatus != ''">current_status = #{currentStatus},</if>
<if test="handlingNotes != null and handlingNotes != ''">handling_notes = #{handlingNotes},</if>
<if test="completionDate != null">completion_date = #{completionDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = SYSDATE(),
<if test="remark != null">remark = #{remark}</if>
</trim>
WHERE id = #{id}
</update>
<!-- 删除单个 -->
<delete id="deleteCoolingServiceRequestById" parameterType="Long">
DELETE FROM cooling_service_request WHERE id = #{id}
</delete>
<!-- 批量删除 -->
<delete id="deleteCoolingServiceRequestByIds" parameterType="Long[]">
DELETE FROM cooling_service_request WHERE id IN
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>实现
最新发布