You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.8 KiB

#include "util.h"
#include "test.h"
#include "SQLUtil.cpp"
#include <tccore/uom.h>
#include <epm/epm_task_template_itk.h>
typedef struct
{
string pmpcCode; //分类码
string goodsCode; //物料编码
string goodsName; //物料名称
string unitCode; //单位
string spec; //型号规格
string bpNo; //图样代号
string state; //封存状态
int code; //Code
string teRe; //技术要求
string companyCode; //工厂代码
string userID; //用户ID
string puid; //版本UID
} MaterialBean;
class db
{
public :
SACommand *command;
public :
//查找传递过来的状态为0的未更新物料信息
vector<MaterialBean> getMaterials()
{
vector<MaterialBean> vecs;
command->setCommandText("select \"PmpcCode\",\"GoodsCode\",\"GoodsName\",\"UnitCode\",\"Spec\",\"BpNo\",\"State\",\"Code\",\"TeRe\",\"CompanyCode\",\"User\" from chint_material where \"CompanyCode\" in('M005','M006','M008') and p_status = '0' ORDER BY \"Time\" ");
command->Execute();
while(command->FetchNext())
{
MaterialBean bean;
bean.pmpcCode = command->Field(1).asString().GetMultiByteChars();
bean.goodsCode = command->Field(2).asString().GetMultiByteChars();
bean.goodsName = command->Field(3).asString().GetMultiByteChars();
bean.unitCode = command->Field(4).asString().GetMultiByteChars();
bean.spec = command->Field(5).asString().GetMultiByteChars();
bean.bpNo = command->Field(6).asString().GetMultiByteChars();
bean.state = command->Field(7).asString().GetMultiByteChars();
bean.code = command->Field(8).asLong();
bean.teRe = command->Field(9).asString().GetMultiByteChars();
bean.companyCode = command->Field(10).asString().GetMultiByteChars();
bean.userID = command->Field(11).asString().GetMultiByteChars();
bean.puid = "";
if(bean.userID.empty())
bean.userID="";
vecs.push_back(bean);
}
return vecs;
}
//根据物料编码获取Code
long getCodeByGoodsCode(string &goodsCode)
{
command->setCommandText("select \"Code\" from chint_material where \"GoodsCode\"=:1 ");
*command << goodsCode.c_str();
command->Execute();
if(command->FetchNext())
{
return command->Field(1).asLong();
}
return 0;
}
//从序列[CHINT_MATERIAL_SEQ] 获得下一个code
int getCode()
{
command->setCommandText("select CHINT_MATERIAL_SEQ.nextval as sid from dual");
command->Execute();
if(command->FetchNext())
{
return command->Field(1).asLong();
}
return 1;
}
void updateMaterial1(string &p_status,string &P_REC_DATE,string &PUID,string &User,long code,string &goodsCode)
{
command->setCommandText("update chint_material set p_status=:1 , P_REC_DATE = to_date(:2,'yyyy-mm-dd HH24:mi:ss'), \"PUID\"=:3,\"User\"=:4 , \"Code\"= :5 where \"GoodsCode\"=:6 and p_status = '0' ");
(*command)<<p_status.c_str()<<P_REC_DATE.c_str()<<PUID.c_str()<<User.c_str()<<code<<goodsCode.c_str();
command->Execute();
}
void updateMaterial2(string &p_status,long code,string &goodsCode)
{
command->setCommandText("update chint_material set p_status=:1 , \"GoodsCode\" = :2, \"Condition\"='已通过' where \"Code\"=:3 and nvl(p_status,'3') = '3'");
(*command)<<p_status.c_str()<<goodsCode.c_str()<<code;
command->Execute();
}
//根据物料编码获取Code
vector<string> queryByCode(long code)
{
vector<string> vecs;
command->setCommandText("select \"PUID\",\"User\",p_status from chint_material where \"CompanyCode\" in('M005','M006','M008') and \"Code\" =:1");
*command << code;
command->Execute();
string puid="",user="";
bool flag = false;
while(command->FetchNext())
{
if(puid.empty())
{
puid = command->Field(1).asString().GetMultiByteChars();
}
if(user.empty())
{
user = command->Field(2).asString().GetMultiByteChars();
}
flag = true;
}
if(flag)
{
vecs.push_back(puid);
vecs.push_back(user);
}
return vecs;
}
//根据id查询物料信息
void getMaterialsByGoodsCode(set<string> &ids,map<string,MaterialBean> &maps,vector<string> &not_founds)
{
vector<MaterialBean> vecs;
printf("sql:%s\r\n","select \"PmpcCode\",\"GoodsCode\",\"GoodsName\",\"UnitCode\",\"Spec\",\"BpNo\",\"State\",\"Code\",\"TeRe\",\"CompanyCode\",\"User\" from chint_material where \"GoodsCode\"=:1 ");
command->setCommandText("select \"PmpcCode\",\"GoodsCode\",\"GoodsName\",\"UnitCode\",\"Spec\",\"BpNo\",\"State\",\"Code\",\"TeRe\",\"CompanyCode\",\"User\" from chint_material where \"GoodsCode\"=:1 ");
for(auto it=ids.begin();it!=ids.end();it++)
{
printf("id:%s\r\n",(*it).c_str());
*command << (*it).c_str();
command->Execute();
if(command->FetchNext())
{
//printf("%s存在\r\n",(*it));
MaterialBean bean;
bean.pmpcCode = command->Field(1).asString().GetMultiByteChars();
bean.goodsCode = command->Field(2).asString().GetMultiByteChars();
bean.goodsName = command->Field(3).asString().GetMultiByteChars();
bean.unitCode = command->Field(4).asString().GetMultiByteChars();
bean.spec = command->Field(5).asString().GetMultiByteChars();
bean.bpNo = command->Field(6).asString().GetMultiByteChars();
bean.state = command->Field(7).asString().GetMultiByteChars();
bean.code = command->Field(8).asLong();
bean.teRe = command->Field(9).asString().GetMultiByteChars();
bean.companyCode = command->Field(10).asString().GetMultiByteChars();
bean.userID = command->Field(11).asString().GetMultiByteChars();
bean.puid = "";
if(bean.userID.empty())
bean.userID="";
maps[*it] = bean;
}else
{
//printf("%s不存在\r\n",(*it));
not_founds.push_back(*it);
}
}
}
};
tag_t createPart(string &id);
//物料更新
void updatePart(tag_t rev,MaterialBean bean,bool flag);
//物料更新,不更新状态
void updatePart2(tag_t rev,MaterialBean bean,bool flag);
//打印物料对象
void printfMaterial(MaterialBean bean);
//物料创建
tag_t createPart(MaterialBean bean);
string GBKToUTF8(const std::string& strGBK);
string proProcessCreate(tag_t rev,string &process_name);