import { default as BaseController } from "../../baseController";
|
import { BaseStorage } from "../../../entity/basicInfo/base/baseStorage";
|
import { Post } from "egg-shell-decorators";
|
import { BasePosition } from "../../../entity/basicInfo/base/basePosition";
|
import { BaseDestination } from "../../../entity/basicInfo/workshop/baseDestination";
|
|
export default class Storagetroller extends BaseController {
|
//#region getList 获得仓库列表
|
/**
|
* 获得仓库列表
|
*/
|
@Post()
|
public async getList() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
try {
|
let whereStr = "";
|
var where: any = {};
|
|
// 超级管理员不需要走仓库权限
|
if (userInfo.isAdministrator || body.isAll) {
|
whereStr = `userProduct_Id=:userProduct_Id`;
|
where = {
|
userProduct_Id: userInfo.userProduct_Id
|
};
|
} else if (userInfo.userType === "consignor") {
|
// 前端货主登录权限
|
whereStr = `userProduct_Id=:userProduct_Id`;
|
where = {
|
userProduct_Id: userInfo.userProduct_Id
|
};
|
} else {
|
// whereStr = `userProduct_Id=:userProduct_Id
|
// And Storage_Id in(SELECT Node_Id FROM dbo.Sys_RoleAuthData WHERE DataType_Id=2 AND User_Id=:user_Id And AuthValue=1)`;
|
whereStr = await this.ctx.service.auth.getStorageAuth("string");
|
where = {
|
userProduct_Id: userInfo.userProduct_Id,
|
user_Id: userInfo.user_Id
|
};
|
}
|
// 关键词查询条件
|
if (body.name) {
|
let name = this.ctx.helper.sqlSecurity(body.name);
|
if (whereStr) whereStr += ` AND `;
|
whereStr += `(storageName LIKE '%' + :name + '%' OR storageCode LIKE '%' + :name + '%')`;
|
where.name = name;
|
}
|
let fields = ["storage_Id", "storageCode", "storageName"];
|
// 自定义查询字段
|
if (body.searchFields) {
|
fields = body.searchFields;
|
}
|
if (body.appendField === "*") {
|
fields = [];
|
}
|
let builder = this.dbRead.createQueryBuilder(BaseStorage, "t").where(whereStr, where);
|
if (fields.length) {
|
builder.select(fields);
|
}
|
builder.take(200);
|
let dataList = [];
|
if (body.appendField === "*") {
|
dataList = await builder.getMany();
|
} else {
|
dataList = await builder.getRawMany();
|
}
|
|
this.info.result = true;
|
this.info.data = dataList;
|
|
ctx.body = this.info;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region getDestination 获得目的地名称
|
/**
|
* 获得目的地名称
|
*/
|
@Post()
|
public async getDestination() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
let whereStr = "";
|
var where: any = {};
|
|
// 关键词查询条件
|
if (body.query) {
|
let query = this.ctx.helper.sqlSecurity(body.query);
|
whereStr += `(destinationName LIKE '%' + :query + '%' OR destinationCode LIKE '%' + :query + '%')`;
|
where.query = query;
|
}
|
let fields = ["destination_Id", "destinationCode", "destinationName"];
|
// 自定义查询字段
|
if (body.searchFields) {
|
fields = body.searchFields;
|
}
|
if (body.appendField === "*") {
|
fields = [];
|
}
|
let builder = this.dbRead.createQueryBuilder(BaseDestination, "t").where(whereStr, where);
|
if (fields.length) {
|
builder.select(fields);
|
}
|
builder.take(200);
|
let dataList = [];
|
if (body.appendField === "*") {
|
dataList = await builder.getMany();
|
} else {
|
dataList = await builder.getRawMany();
|
}
|
|
this.info.result = true;
|
this.info.data = dataList.map(item => {
|
item.value = item.destination_Id;
|
item.label = item.destinationName;
|
return item;
|
});
|
|
ctx.body = this.info;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region getPositionList 根据仓库ID和货位类型获取货位
|
/**
|
* 根据仓库ID和货位类型获取货位
|
*/
|
@Post()
|
public async getPositionList() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
|
try {
|
var dataList = await this.dbRead.find(BasePosition, {
|
select: ["positionName"],
|
where: {
|
storage_Id: body.storage_Id,
|
positionType: body.positionType
|
}
|
});
|
|
this.info.result = true;
|
this.info.data = dataList;
|
|
ctx.body = this.info;
|
return;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
ctx.body = this.info;
|
return;
|
}
|
}
|
//#endregion
|
|
//#region 新增仓库信息
|
/**
|
* 新增仓库信息
|
*/
|
@Post()
|
public async add() {
|
let { ctx } = this;
|
let body = ctx.body;
|
let userInfo = await this.userInfo;
|
if (!userInfo && !userInfo.userProduct_Id) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
ctx.body = this.info;
|
return;
|
}
|
let userProduct_Id = userInfo.userProduct_Id;
|
|
if (!body.storageCode) {
|
this.info.result = false;
|
this.info.msg = "仓库编号不能为空";
|
ctx.body = this.info;
|
return;
|
}
|
|
if (!body.storageName) {
|
this.info.result = false;
|
this.info.msg = "仓库名称不能为空";
|
ctx.body = this.info;
|
return;
|
}
|
|
try {
|
let dataInfo = await this.dbRead.findOne(BaseStorage, {
|
where: {
|
storageCode: body.storageCode,
|
userProduct_Id: userProduct_Id
|
}
|
});
|
if (dataInfo) {
|
dataInfo = Object.assign(dataInfo, this.body);
|
await this.dbWrite.save(dataInfo);
|
|
this.info.result = true;
|
this.info.msg = "仓库更新成功";
|
ctx.body = this.info;
|
return;
|
}
|
|
dataInfo = await this.dbRead.findOne(BaseStorage, {
|
where: {
|
storageCode: body.storageCode,
|
userProduct_Id: userProduct_Id
|
}
|
});
|
if (dataInfo) {
|
this.info.result = false;
|
this.info.msg = "仓库已存在,不能重复推送";
|
ctx.body = this.info;
|
return;
|
}
|
|
dataInfo = new BaseStorage();
|
dataInfo = Object.assign(dataInfo, this.body);
|
await this.setAccountInfo(dataInfo);
|
await this.dbWrite.save(dataInfo);
|
|
this.info.result = true;
|
this.info.msg = "仓库信息保存成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|