|
@@ -318,23 +318,36 @@ class GLJController extends BaseController {
|
|
|
async changeUnitPriceFile(request, response) {
|
|
|
let projectId = request.body.project_id;
|
|
|
let changeUnitPriceId = request.body.change_id;
|
|
|
+ let type = request.body.type;
|
|
|
+ type = parseInt(type);
|
|
|
let responseData = {
|
|
|
err: 0,
|
|
|
msg: ''
|
|
|
};
|
|
|
try {
|
|
|
let currentUnitPriceId = await ProjectModel.getUnitPriceFileId(projectId);
|
|
|
+ let unitPriceFileModel = new UnitPriceFileModel();
|
|
|
|
|
|
+ let insertData = null;
|
|
|
+ if (type > 0) {
|
|
|
+ let currentUnitPrice = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
|
|
|
+ if (currentUnitPrice === null) {
|
|
|
+ throw '不存在对应单价文件';
|
|
|
+ }
|
|
|
+ insertData = JSON.parse(JSON.stringify(currentUnitPrice));
|
|
|
+ delete insertData._id;
|
|
|
+ delete insertData.ID;
|
|
|
+ }
|
|
|
// 获取即将更改的单价文件信息
|
|
|
- let unitPriceFileModel = new UnitPriceFileModel();
|
|
|
- let targetUnitPriceFile = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
|
|
|
+ let targetUnitPriceFile = type === 0 ? await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId}) :
|
|
|
+ await unitPriceFileModel.add(insertData);
|
|
|
if (targetUnitPriceFile === null) {
|
|
|
throw '没有找到对应的单价文件';
|
|
|
}
|
|
|
|
|
|
// 查找对应单价文件的项目工料机数据
|
|
|
let unitPriceModel = new UnitPriceModel();
|
|
|
- let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, changeUnitPriceId);
|
|
|
+ let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id);
|
|
|
// 复制成功后更改project数据
|
|
|
if (!copyResult) {
|
|
|
throw '复制数据失败';
|