425 lines
13 KiB
JavaScript
425 lines
13 KiB
JavaScript
import http from '../utils/http';
|
||
|
||
// --- Typedefs ---
|
||
|
||
/**
|
||
* @typedef {object} Response
|
||
* @property {number} code - 业务状态码
|
||
* @property {object} [data] - 业务数据
|
||
* @property {string} [message] - 提示信息
|
||
*/
|
||
|
||
/**
|
||
* @typedef {('自繁'|'外购')} PigBatchOriginType
|
||
*/
|
||
|
||
/**
|
||
* @typedef {('保育'|'生长'|'育肥'|'待售'|'已出售'|'已归档')} PigBatchStatus
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} PigBatchResponseDTO
|
||
* @property {number} id - 批次ID
|
||
* @property {string} batch_number - 批次编号
|
||
* @property {PigBatchOriginType} origin_type - 批次来源
|
||
* @property {string} [start_date] - 批次开始日期
|
||
* @property {string} [end_date] - 批次结束日期
|
||
* @property {number} initial_count - 初始数量
|
||
* @property {PigBatchStatus} status - 批次状态
|
||
* @property {boolean} is_active - 是否活跃
|
||
* @property {string} create_time - 创建时间
|
||
* @property {string} update_time - 更新时间
|
||
* @property {number} current_total_quantity - 当前总数
|
||
* @property {number} current_total_pigs_in_pens - 当前存栏总数
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} PigBatchesParams
|
||
* @property {boolean} [is_active] - 是否活跃 (true/false)
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} PigBatchCreateDTO
|
||
* @property {string} batch_number - 批次编号,必填
|
||
* @property {PigBatchOriginType} origin_type - 批次来源,必填
|
||
* @property {string} start_date - 批次开始日期,必填
|
||
* @property {number} initial_count - 初始数量,必填,最小为1
|
||
* @property {PigBatchStatus} status - 批次状态,必填
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} PigBatchUpdateDTO
|
||
* @property {string} [batch_number] - 批次编号,可选
|
||
* @property {PigBatchOriginType} [origin_type] - 批次来源,可选
|
||
* @property {string} [start_date] - 批次开始日期,可选
|
||
* @property {string} [end_date] - 批次结束日期,可选
|
||
* @property {number} [initial_count] - 初始数量,可选
|
||
* @property {PigBatchStatus} [status] - 批次状态,可选
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} AssignEmptyPensToBatchRequest
|
||
* @property {Array<number>} pen_ids - 待分配的猪栏ID列表
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} BuyPigsRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 买入猪只数量
|
||
* @property {number} unit_price - 单价
|
||
* @property {number} total_price - 总价
|
||
* @property {string} trader_name - 交易方名称
|
||
* @property {string} trade_date - 交易日期
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} SellPigsRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 卖出猪只数量
|
||
* @property {number} unit_price - 单价
|
||
* @property {number} total_price - 总价
|
||
* @property {string} trader_name - 交易方名称
|
||
* @property {string} trade_date - 交易日期
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} MovePigsIntoPenRequest
|
||
* @property {number} to_pen_id - 目标猪栏ID
|
||
* @property {number} quantity - 移入猪只数量
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} TransferPigsWithinBatchRequest
|
||
* @property {number} from_pen_id - 源猪栏ID
|
||
* @property {number} to_pen_id - 目标猪栏ID
|
||
* @property {number} quantity - 调栏猪只数量
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} TransferPigsAcrossBatchesRequest
|
||
* @property {number} dest_batch_id - 目标猪批次ID
|
||
* @property {number} from_pen_id - 源猪栏ID
|
||
* @property {number} to_pen_id - 目标猪栏ID
|
||
* @property {number} quantity - 调栏猪只数量
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} ReclassifyPenToNewBatchRequest
|
||
* @property {number} pen_id - 待划拨的猪栏ID
|
||
* @property {number} to_batch_id - 目标猪批次ID
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {('原地治疗'|'病猪栏治疗')} PigBatchSickPigTreatmentLocation
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} RecordSickPigsRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 病猪数量
|
||
* @property {PigBatchSickPigTreatmentLocation} treatment_location - 治疗地点
|
||
* @property {string} happened_at - 发生时间
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} RecordSickPigRecoveryRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 康复猪数量
|
||
* @property {PigBatchSickPigTreatmentLocation} treatment_location - 治疗地点
|
||
* @property {string} happened_at - 发生时间
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} RecordSickPigDeathRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 死亡猪数量
|
||
* @property {PigBatchSickPigTreatmentLocation} treatment_location - 治疗地点
|
||
* @property {string} happened_at - 发生时间
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} RecordSickPigCullRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 淘汰猪数量
|
||
* @property {PigBatchSickPigTreatmentLocation} treatment_location - 治疗地点
|
||
* @property {string} happened_at - 发生时间
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} RecordDeathRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 死亡猪数量
|
||
* @property {string} happened_at - 发生时间
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} RecordCullRequest
|
||
* @property {number} pen_id - 猪栏ID
|
||
* @property {number} quantity - 淘汰猪数量
|
||
* @property {string} happened_at - 发生时间
|
||
* @property {string} [remarks] - 备注
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} PenResponse
|
||
* @property {number} id
|
||
* @property {number} house_id
|
||
* @property {string} pen_number
|
||
* @property {number} capacity
|
||
* @property {number} current_pig_count
|
||
* @property {number} pig_batch_id
|
||
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
||
*/
|
||
|
||
/**
|
||
* @typedef {object} PigHouseResponse
|
||
* @property {number} id
|
||
* @property {string} name
|
||
* @property {string} description
|
||
*/
|
||
|
||
// --- 猪批次基础操作 ---
|
||
|
||
/**
|
||
* 获取所有猪批次的列表
|
||
* @param {PigBatchesParams} params - 查询参数
|
||
* @returns {Promise<Array<PigBatchResponseDTO>>}
|
||
*/
|
||
export const getPigBatches = (params) => {
|
||
return http.get('/api/v1/pig-batches', params);
|
||
};
|
||
|
||
/**
|
||
* 创建一个新的猪批次
|
||
* @param {PigBatchCreateDTO} batchData - 猪批次信息
|
||
* @returns {Promise<PigBatchResponseDTO>}
|
||
*/
|
||
export const createPigBatch = (batchData) => {
|
||
return http.post('/api/v1/pig-batches', batchData);
|
||
};
|
||
|
||
/**
|
||
* 根据ID获取单个猪批次信息
|
||
* @param {number} id - 猪批次ID
|
||
* @returns {Promise<PigBatchResponseDTO>}
|
||
*/
|
||
export const getPigBatchById = (id) => {
|
||
return http.get(`/api/v1/pig-batches/${id}`);
|
||
};
|
||
|
||
/**
|
||
* 更新一个已存在的猪批次信息
|
||
* @param {number} id - 猪批次ID
|
||
* @param {PigBatchUpdateDTO} batchData - 猪批次信息
|
||
* @returns {Promise<PigBatchResponseDTO>}
|
||
*/
|
||
export const updatePigBatch = (id, batchData) => {
|
||
return http.put(`/api/v1/pig-batches/${id}`, batchData);
|
||
};
|
||
|
||
/**
|
||
* 根据ID删除一个猪批次
|
||
* @param {number} id - 猪批次ID
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const deletePigBatch = (id) => {
|
||
return http.delete(`/api/v1/pig-batches/${id}`);
|
||
};
|
||
|
||
// --- 猪批次业务操作 ---
|
||
|
||
/**
|
||
* 为猪批次分配空栏
|
||
* @param {number} id - 猪批次ID
|
||
* @param {AssignEmptyPensToBatchRequest} pensData - 待分配的猪栏ID列表
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const assignPensToBatch = (id, pensData) => {
|
||
return http.post(`/api/v1/pig-batches/assign-pens/${id}`, pensData);
|
||
};
|
||
|
||
/**
|
||
* 从猪批次移除空栏
|
||
* @param {number} penID - 待移除的猪栏ID
|
||
* @param {number} batchID - 猪批次ID
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const removePenFromBatch = (penID, batchID) => {
|
||
return http.delete(`/api/v1/pig-batches/remove-pen/${penID}/${batchID}`);
|
||
};
|
||
|
||
/**
|
||
* 处理买猪的业务逻辑
|
||
* @param {number} id - 猪批次ID
|
||
* @param {BuyPigsRequest} buyData - 买猪请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const buyPigsForBatch = (id, buyData) => {
|
||
return http.post(`/api/v1/pig-batches/buy-pigs/${id}`, buyData);
|
||
};
|
||
|
||
/**
|
||
* 处理卖猪的业务逻辑
|
||
* @param {number} id - 猪批次ID
|
||
* @param {SellPigsRequest} sellData - 卖猪请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const sellPigsFromBatch = (id, sellData) => {
|
||
return http.post(`/api/v1/pig-batches/sell-pigs/${id}`, sellData);
|
||
};
|
||
|
||
/**
|
||
* 将猪只从“虚拟库存”移入指定猪栏
|
||
* @param {number} id - 猪批次ID
|
||
* @param {MovePigsIntoPenRequest} moveData - 移入猪只请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const movePigsIntoPen = (id, moveData) => {
|
||
return http.post(`/api/v1/pig-batches/move-pigs-into-pen/${id}`, moveData);
|
||
};
|
||
|
||
/**
|
||
* 群内调栏
|
||
* @param {number} id - 猪批次ID
|
||
* @param {TransferPigsWithinBatchRequest} transferData - 群内调栏请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const transferPigsWithinBatch = (id, transferData) => {
|
||
return http.post(`/api/v1/pig-batches/transfer-within-batch/${id}`, transferData);
|
||
};
|
||
|
||
/**
|
||
* 跨猪群调栏
|
||
* @param {number} sourceBatchID - 源猪批次ID
|
||
* @param {TransferPigsAcrossBatchesRequest} transferData - 跨群调栏请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const transferPigsAcrossBatches = (sourceBatchID, transferData) => {
|
||
return http.post(`/api/v1/pig-batches/transfer-across-batches/${sourceBatchID}`, transferData);
|
||
};
|
||
|
||
/**
|
||
* 将猪栏划拨到新批次
|
||
* @param {number} fromBatchID - 源猪批次ID
|
||
* @param {ReclassifyPenToNewBatchRequest} reclassifyData - 划拨请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const reclassifyPenToNewBatch = (fromBatchID, reclassifyData) => {
|
||
return http.post(`/api/v1/pig-batches/reclassify-pen/${fromBatchID}`, reclassifyData);
|
||
};
|
||
|
||
// --- 猪只数量变更记录 ---
|
||
|
||
/**
|
||
* 记录新增病猪事件
|
||
* @param {number} id - 猪批次ID
|
||
* @param {RecordSickPigsRequest} sickData - 记录病猪请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const recordSickPigsInBatch = (id, sickData) => {
|
||
return http.post(`/api/v1/pig-batches/record-sick-pigs/${id}`, sickData);
|
||
};
|
||
|
||
/**
|
||
* 记录病猪康复事件
|
||
* @param {number} id - 猪批次ID
|
||
* @param {RecordSickPigRecoveryRequest} recoveryData - 记录病猪康复请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const recordSickPigRecoveryInBatch = (id, recoveryData) => {
|
||
return http.post(`/api/v1/pig-batches/record-sick-pig-recovery/${id}`, recoveryData);
|
||
};
|
||
|
||
/**
|
||
* 记录病猪死亡事件
|
||
* @param {number} id - 猪批次ID
|
||
* @param {RecordSickPigDeathRequest} deathData - 记录病猪死亡请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const recordSickPigDeathInBatch = (id, deathData) => {
|
||
return http.post(`/api/v1/pig-batches/record-sick-pig-death/${id}`, deathData);
|
||
};
|
||
|
||
/**
|
||
* 记录病猪淘汰事件
|
||
* @param {number} id - 猪批次ID
|
||
* @param {RecordSickPigCullRequest} cullData - 记录病猪淘汰请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const recordSickPigCullInBatch = (id, cullData) => {
|
||
return http.post(`/api/v1/pig-batches/record-sick-pig-cull/${id}`, cullData);
|
||
};
|
||
|
||
/**
|
||
* 记录正常猪只死亡事件
|
||
* @param {number} id - 猪批次ID
|
||
* @param {RecordDeathRequest} deathData - 记录正常猪只死亡请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const recordDeathInBatch = (id, deathData) => {
|
||
return http.post(`/api/v1/pig-batches/record-death/${id}`, deathData);
|
||
};
|
||
|
||
/**
|
||
* 记录正常猪只淘汰事件
|
||
* @param {number} id - 猪批次ID
|
||
* @param {RecordCullRequest} cullData - 记录正常猪只淘汰请求信息
|
||
* @returns {Promise<Response>}
|
||
*/
|
||
export const recordCullInBatch = (id, cullData) => {
|
||
return http.post(`/api/v1/pig-batches/record-cull/${id}`, cullData);
|
||
};
|
||
|
||
// --- 新增的猪栏和猪舍API ---
|
||
|
||
/**
|
||
* 获取所有猪栏的列表
|
||
* @returns {Promise<Array<PenResponse>>}
|
||
*/
|
||
export const getAllPens = () => {
|
||
return http.get('/api/v1/pens');
|
||
};
|
||
|
||
/**
|
||
* 获取所有猪舍的列表
|
||
* @returns {Promise<Array<PigHouseResponse>>}
|
||
*/
|
||
export const getAllPigHouses = () => {
|
||
return http.get('/api/v1/pig-houses');
|
||
};
|
||
|
||
export const PigBatchApi = {
|
||
getPigBatches,
|
||
createPigBatch,
|
||
getPigBatchById,
|
||
updatePigBatch,
|
||
deletePigBatch,
|
||
assignPensToBatch,
|
||
removePenFromBatch,
|
||
buyPigsForBatch,
|
||
sellPigsFromBatch,
|
||
movePigsIntoPen,
|
||
transferPigsWithinBatch,
|
||
transferPigsAcrossBatches,
|
||
reclassifyPenToNewBatch,
|
||
recordSickPigsInBatch,
|
||
recordSickPigRecoveryInBatch,
|
||
recordSickPigDeathInBatch,
|
||
recordSickPigCullInBatch,
|
||
recordDeathInBatch,
|
||
recordCullInBatch,
|
||
getAllPens,
|
||
getAllPigHouses,
|
||
};
|