/** MySQL **/

GRANT ALL PRIVILEGES ON *.* TO 'ecep'@'10.84.209.89' WITH GRANT OPTION;


/** 修改用户密码 **/
ALTER USER 'mianli.wang'@'10.84.209.38' IDENTIFIED WITH mysql_native_password BY 'A2025b0512#';


/* 查询CLOUD_YU表中VEN_CODE不以 | 开头的记录 */
select *
from CLOUD_YU
where EX_MSG not like '|%';


select *
from VENDOR;

/* 查询一级行业分类 */
SELECT SUBSTRING_INDEX(INDUSTRY, '-', 1) as title, COUNT(*) as total
FROM `COMPANY`
where COMPANY.INDUSTRY is not null
  and length(INDUSTRY) > 0
GROUP BY title
order by total DESC;

/* 查询一级二级行业分类 */
SELECT SUBSTRING_INDEX(INDUSTRY, '-', 2) as title, COUNT(*) as total
FROM `COMPANY`
where SUBSTRING_INDEX(INDUSTRY, '-', 1) = '交通运输、仓储和邮政业'
GROUP BY title
order by total desc;

select COMPANY_ID, count(*)
from COMPANY_CONTRACT
group by COMPANY_ID;


select *
from CONTRACT
         left join supplier_ms.COMPANY_CONTRACT CC on CONTRACT.ID = CC.CONTRACT_ID
where CC.ID is null;

select *
from CONTRACT
where CODE = 'S23108';

select *, locate('-', CODE)
from CONTRACT
# where PARENT_CODE is null    or length(PARENT_CODE) = 0
where locate('-', CODE) = 0
order by CREATED desc

limit 100;

select *
from COMPANY_VENDOR
where VEN_CODE like '%|shykwlyxgs|%';

select *
from COMPANY_VENDOR
where COMPANY_ID = 3;

select *
from COMPANY_CUSTOMER
where CUS_CODE like '%|shykwlyxgs|%';
select *
from COMPANY_CUSTOMER
where COMPANY_ID = 795;



select *
from CONTRACT
where GUID = '7A839F83-70FF-4F3F-9063-F930B93F1445';

select *
from COMPANY
where NAME = '德州六顺电气自动化设备有限公司';


select GUID, COUNT(*)
from CONTRACT
group by GUID
having count(*) > 1;

select COMPANY_ID, count(*) as total
from COMPANY_VENDOR
group by COMPANY_ID
having total > 1;

select COMPANY_ID, count(*) as total
from COMPANY_CUSTOMER
group by COMPANY_ID
having total > 1;

select NAME, count(*) as total
from VENDOR
group by NAME
having total > 1;



select *
from COMPANY_CUSTOMER_FILE CCF
         left join COMPANY_CUSTOMER_EVALUATION_FORM_FILE on CCF.ID = COMPANY_CUSTOMER_EVALUATION_FORM_FILE.ID
where CUSTOMER_ID = 1266
  and CCF.TYPE = 'EvaluationForm';

select cceff1_0.ID,
       cceff1_1.CUSTOMER_ID,
       cceff1_1.EDIT_FILE_PATH,
       cceff1_1.FILE_PATH,
       cceff1_1.SIGN_DATE,
       cceff1_1.TYPE,
       cceff1_1.VALID,
       cceff1_0.CATALOG,
       cceff1_0.CREDIT_LEVEL,
       cceff1_0.LEVEL,
       cceff1_0.score1,
       cceff1_0.score2,
       cceff1_0.score3,
       cceff1_0.score4,
       cceff1_0.score5,
       cceff1_0.SCORE_TEMPLATE_VER
from COMPANY_CUSTOMER_FILE ccf1_0
         left join (COMPANY_CUSTOMER_EVALUATION_FORM_FILE cceff1_0 join COMPANY_CUSTOMER_FILE cceff1_1
                    on cceff1_0.ID = cceff1_1.ID) on ccf1_0.ID = cceff1_0.ID
where ccf1_0.CUSTOMER_ID = 1266
  and ccf1_0.TYPE = 'EvaluationForm';


/**
 * 统计合同的State数量
 */
select STATE, COUNT(*)
from CONTRACT
group by STATE
having count(*) > 1;

/**
 * 统计从2024年合同的GROUP数量
 */
select GROUP_ID, COUNT(*)
from CONTRACT
where CONTRACT.SETUP_DATE between '2024-01-01' and '2024-12-31'
group by GROUP_ID
having count(*) > 1;



INSERT INTO PRODUCT_DELIVERY_SIGN_METHOD (NAME, CODE)
VALUES ('到货签收', 'A');
INSERT INTO PRODUCT_DELIVERY_SIGN_METHOD (NAME, CODE)
VALUES ('到货签收+拼装签收', 'P');

INSERT INTO PRODUCT_USAGE (NAME, CODE)
VALUES ('高效机房', 'H');
INSERT INTO PRODUCT_USAGE (NAME, CODE)
VALUES ('能源站', 'E');
INSERT INTO PRODUCT_USAGE (NAME, CODE)
VALUES ('高效机房+能源站', 'F');
INSERT INTO PRODUCT_USAGE (NAME, CODE)
VALUES ('其他', 'O');

INSERT INTO PROJECT_TYPE (NAME, CODE)
VALUES ('既有建筑', 'R');
INSERT INTO PROJECT_TYPE (NAME, CODE)
VALUES ('新建项目', 'N');
INSERT INTO PROJECT_TYPE (NAME, CODE)
VALUES ('家装', 'Z');


INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('开利设备', 'C');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('净化设备', 'J');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('东芝设备', 'T');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('其他设备', 'Q');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('多种设备混合', 'X');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('应急维修', 'M');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('年度保养', 'A');
INSERT INTO PRODUCT_TYPE (NAME, CODE)
VALUES ('技术咨询服务', 'F');


INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('汽车行业', 'A');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('电子行业', 'B');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('医药行业', 'C');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('食品行业', 'D');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('化工行业', 'E');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('太阳能光伏', 'F');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('农林行业', 'G');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('数据中心', 'H');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('机械加工', 'I');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('医院', 'J');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('机场高铁', 'K');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('文化体育', 'L');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('商业楼宇', 'M');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('住宅楼宇', 'N');
INSERT INTO PROJECT_INDUSTRY (NAME, CODE)
VALUES ('其它', 'O');


INSERT INTO PROJECT_SALE_TYPE (NAME, CODE)
VALUES ('设备销售', 'S');
INSERT INTO PROJECT_SALE_TYPE (NAME, CODE)
VALUES ('工程安装', 'G');
INSERT INTO PROJECT_SALE_TYPE (NAME, CODE)
VALUES ('服务', 'M');


INSERT INTO PRODUCT_DELIVERY_SIGN_METHOD (NAME, CODE)
VALUES ('按进度结算', 'P');

ALTER USER 'ecep'@'10.84.209.229' IDENTIFIED WITH mysql_native_password BY 'ecep.62335656';

UPDATE supplier_ms.CONTRACT t
SET t.STANDARD_PAY_WAY = false;

# \\\\\\\\10.84.209.8\\\\项目信息\\\\相关方信息\\\\%
select *, replace(FILE_PATH, '\\相关方信息\\', '\\B-相关方\\')
from COMPANY_FILE
where FILE_PATH like '\\\\\\\\10.84.209.8\\\\项目信息\\\\相关方信息\\\\%';

#
update COMPANY f
set f.PATH = replace(PATH, '\\相关方信息\\', '\\B-相关方\\')
where PATH like '\\\\\\\\10.84.209.8\\\\项目信息\\\\相关方信息\\\\%';
update COMPANY_FILE f
set f.FILE_PATH = replace(FILE_PATH, '\\相关方信息\\', '\\B-相关方\\')
where FILE_PATH like '\\\\\\\\10.84.209.8\\\\项目信息\\\\相关方信息\\\\%';


delete
from COMPANY_VENDOR_ENTITY
where VEN_CODE is null;

alter table CONTRACT
    add TOTAL_QUANTITY decimal(10, 2) default 0.00 not null;
alter table CONTRACT
    add TOTAL_AMOUNT decimal(10, 2) default 0.00 not null;
alter table CONTRACT
    add TOTAL_UNTAX_AMOUNT decimal(10, 2) default 0.00 not null;


select i1_0.ID,
       i1_0.CATALOG_ID,
       i1_0.CODE,
       i1_0.CREATE_DATE,
       i1_0.DESCRIPTION,
       i1_0.NAME,
       i1_0.PURCHASE_PRICE,
       i1_0.PURCHASE_TAX,
       i1_0.SALE_PRICE,
       i1_0.SALE_TAX,
       i1_0.SPEC,
       i1_0.UNIT,
       i1_0.UPDATE_DATE
from INVENTORY i1_0
         left join INVENTORY_CATALOG c1_0 on c1_0.ID = i1_0.CATALOG_ID
where i1_0.CATALOG_ID is not null and c1_0.NAME = ?
   or i1_0.CODE like ? escape '' or i1_0.SPEC like ? escape '' or i1_0.NAME like ? escape ''
order by i1_0.ID desc
limit ?,?