import BaseController from "../../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { BaseProductInfo } from "../../../entity/basicInfo/base/baseProductInfo";
|
import { BaseProvider } from "../../../entity/basicInfo/base/baseProvider";
|
import { BaseBrand } from "../../../entity/basicInfo/base/baseBrand";
|
import { SysParamValue } from "../../../entity/sys/core/sysParamValue";
|
|
/**
|
* 物料信息
|
*/
|
export default class ProductController extends BaseController {
|
//#region 查询物料信息
|
/// <summary>
|
/// 查询物料信息
|
/// </summary>
|
/// <returns>返回物料信息列表</returns>
|
@Post()
|
public async searchProductList() {
|
let userInfo = await this.userInfo;
|
|
try {
|
//#region 校验数据
|
if (!this.body.code) {
|
this.info.result = false;
|
this.info.msg = "查询条件不能为空";
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
let where =
|
"userProduct_Id=:userProduct_Id and productCode like :productCode OR productModel like :productModel OR productName like :productName";
|
var productList = await this.dbRead
|
.createQueryBuilder(BaseProductInfo, "t")
|
.where(where, {
|
userProduct_Id: userInfo.userProduct_Id,
|
productCode: "%" + this.body.code + "%",
|
productModel: "%" + this.body.code + "%",
|
productName: "%" + this.body.code + "%"
|
})
|
.take(30)
|
.getMany();
|
|
// var productList = await this.dbRead.find(BaseProductInfo, {
|
// where: [
|
// {
|
// userProduct_Id: userInfo.userProduct_Id
|
// },
|
// {
|
// productCode: Like("%" + this.body.code + "%"),
|
// productModel: Like("%" + this.body.code + "%"),
|
// productName: Like("%" + this.body.code + "%")
|
// }
|
// ],
|
// take: 30
|
// });
|
|
this.info.result = true;
|
this.info.data = productList;
|
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "出现异常:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region 初始化数据
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
/// <returns>返回下拉框数据列表</returns>
|
@Post()
|
public async initData() {
|
let userInfo = await this.userInfo;
|
try {
|
// 供应商
|
var providerList = await this.dbRead.find(BaseProvider, {
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
// 品牌
|
var brandList = await this.dbRead.find(BaseBrand, {
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
|
// 品牌
|
var unitList = await this.dbRead.find(SysParamValue, {
|
type_Id: 522,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (!unitList.length) {
|
// 获得默认参数
|
let where = "type_Id=522 And ISNULL(userProduct_Id, 0)=0";
|
unitList = await this.dbRead.createQueryBuilder(SysParamValue, "t").where(where).getMany();
|
}
|
|
// 获得类目集合树
|
let where = { parentId: 0, userProduct_Id: userInfo.userProduct_Id };
|
var loadInfo = {
|
folder: "basicInfo/base",
|
dbServer: "Sys",
|
tableName: "Base_ProductType",
|
tableView: "Base_ProductType",
|
keyName: "type_Id",
|
nodeName: "typeName",
|
fixHasChild: false,
|
isBreakWay: false,
|
displayBreakWay: false,
|
parentName: "parentId",
|
orderBy: "OrderNo desc, type_Id",
|
where: where,
|
extendColumns: ""
|
};
|
var typeList = await this.ctx.service.common.getTreeDataAll(loadInfo, 10);
|
|
this.info.result = true;
|
this.info.data = {
|
providerList: providerList,
|
brandList: brandList,
|
unitList: unitList,
|
typeList: typeList
|
};
|
this.info.msg = "";
|
} catch (ex) {
|
let msg = "出现异常:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 新建物料信息
|
/// <summary>
|
/// 新建物料信息
|
/// </summary>
|
@Post()
|
public async addProduct() {
|
let userInfo = await this.userInfo;
|
try {
|
//#region
|
if (!this.body.productModel) {
|
this.info.result = false;
|
this.info.msg = "物料信息不能为空";
|
|
this.ctx.body = this.info;
|
return;
|
}
|
|
var productList = await this.dbRead.find(BaseProductInfo, {
|
productModel: this.body.productModel
|
});
|
if (productList.length > 0) {
|
this.info.result = false;
|
this.info.msg = this.body.productModel + "物料条码已存在,不能重复添加";
|
|
this.ctx.body = this.info;
|
}
|
|
productList = await this.dbRead.find(BaseProductInfo, {
|
productName: this.body.productName,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (productList.length > 0) {
|
this.info.result = false;
|
this.info.msg = this.body.productName + "物料名称已存在,不能重复添加";
|
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
let prodInfo = new BaseProductInfo();
|
prodInfo = Object.assign(prodInfo, this.body);
|
await this.setAccountInfo(prodInfo);
|
|
prodInfo.consignorCode = userInfo.consignorCode;
|
prodInfo.consignorName = userInfo.consignorName;
|
prodInfo.consignor_Id = userInfo.consignor_Id;
|
prodInfo.auditing = 0;
|
prodInfo.productStatus = 1;
|
prodInfo.productCode = await this.service.common.getCodeRegular(254);
|
await this.dbWrite.save(prodInfo);
|
|
this.info.result = true;
|
this.info.msg = "新增成功,等待管理员审核";
|
} catch (ex) {
|
let msg = "出现异常:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getUnitList 获得单位
|
/// <summary>
|
/// 获得单位
|
/// </summary>
|
@Post()
|
public async getUnitList() {
|
let userInfo = await this.userInfo;
|
try {
|
var unitList = await this.dbRead.find(SysParamValue, {
|
type_Id: 522,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (unitList.length <= 0) {
|
// 获得默认参数
|
let where = "type_Id=522 And ISNULL(userProduct_Id, 0)=0";
|
unitList = await this.dbRead.createQueryBuilder(SysParamValue, "t").where(where).getMany();
|
}
|
this.info.data = unitList.map(item => {
|
return {
|
smallUnit: item.value02
|
};
|
});
|
this.info.result = true;
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "出现异常:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
//#endregion
|
}
|