public without sharing class DiscountProductApplicationController {
|
|
//获取经销商信息
|
public Agency_Hospital_Link__c ahl { get; set; }
|
//public Account acc { get; set; }
|
//特价申请
|
public DiscountProductApplication__c dpa { get; set; }
|
//新建页面发送的经销商ID
|
public String accountId;
|
//编辑页面发送的经销商ID
|
public String dpaId;
|
//经销商名
|
public String AimsAccount { get; set; }
|
//医院id
|
public String AimsAccountId { get; set; }
|
//页面请求明细展示构造类
|
public List<DiscountProductApplicationDetail> DiscountProductApplicationDetailList { get; set; }
|
//查询用请求明细
|
public List<DiscountProductApplicationDetail__c> dpadlList;
|
//更新用请求明细
|
public List<DiscountProductApplicationDetail__c> dpadList;
|
//经销商医院
|
public List<Agency_Hospital_Link__c> ahlList;
|
//public String RawAccountc{ get; set; }
|
//全部检索list
|
public List<String> dpadIdList;
|
//text1,text1是检索输入参数
|
public String text1 { get; set; }
|
public String text2 { get; set; }
|
public String soql;
|
public Boolean ApplicationStatus;
|
public Integer unCheckedDpadCount {
|
get {
|
return DiscountProductApplicationDetailList == null ? 0 : DiscountProductApplicationDetailList.size();
|
}
|
}
|
//add by rentx 2021-2-20
|
public Boolean isPage {get;set;}
|
public String tempVal {get;set;}
|
public String rawAccountId {get;set;}
|
public String rawAccountName {get;set;}
|
//add by rentx 2021-2-20
|
|
public DiscountProductApplicationController(ApexPages.StandardController stdController) {
|
//新建页面发送的经销商ID
|
accountId = ApexPages.currentPage().getParameters().get('accId');
|
//编辑页面发送的经销商ID
|
dpaId = ApexPages.currentPage().getParameters().get('Id');
|
DiscountProductApplicationDetailList = new List<DiscountProductApplicationDetail>();
|
dpadIdList = new List<String>();
|
}
|
//add by rentx 2021-2-22
|
//add by rentx 2021-2-22
|
|
//查询初期数据
|
public void init(){
|
if (String.isBlank(accountId) && String.isBlank(dpaId)) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '请选择经销商'));
|
dpa = new DiscountProductApplication__c();
|
isPage = true;
|
}else{
|
isPage = false;
|
}
|
String message;
|
//String RawAccount;
|
if(!String.isBlank(accountId)){
|
dpa = new DiscountProductApplication__c();
|
dpa.RawAccount__c = accountId;
|
rawAccountId = accountId;
|
// List<Account> accList = [select id,Name from Account where id = :accountId ];
|
// if(accList.size()>0){
|
// this.accountName = accList[0].Name;
|
// }
|
}
|
if(!String.isBlank(dpaId)){
|
List<DiscountProductApplication__c> dpaList =[select RawAccount__c from DiscountProductApplication__c where id =: dpaId];
|
dpa = new DiscountProductApplication__c();
|
if(dpaList.size()>0){
|
dpa = dpaList.get(0);
|
}
|
accountId = dpa.RawAccount__c;
|
}
|
|
if((String.isBlank(dpaId) && !String.isBlank(accountId)) || isPage == true){
|
//新建特价申请
|
//dpa = new DiscountProductApplication__c();
|
//dpain = true;
|
// List<Account> accList = [select id,name from Account where id = :accountId ];
|
|
List<Product2__c> Product2List = new List<Product2__c>();
|
soql = this.makeSoql1('','');
|
Product2List = Database.query(soql);
|
if(Product2List.size()>=1){
|
for(Product2__c Pro2 : Product2List){
|
DiscountProductApplicationDetail dpad =
|
new DiscountProductApplicationDetail(Pro2);
|
DiscountProductApplicationDetailList.add(dpad);
|
}
|
}
|
//ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, acc.name));
|
}else if(!String.isBlank(dpaId)){
|
//查询已存在的特价申请
|
List<DiscountProductApplication__c> dpaList = [select id,name,ApplicationStatus__c,RawAccount__c,RawAccount__r.name,AimsAccount__c,AimsAccount__r.name from DiscountProductApplication__c where id = :dpaId ];
|
if(dpaList.size()>0){
|
dpa = dpaList[0];
|
}
|
String dpadId = dpa.Id;
|
AimsAccountId = dpa.AimsAccount__c;
|
AimsAccount = dpa.AimsAccount__r.name;
|
if(String.isBlank(AimsAccountId)){
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '医院没有选择'));
|
}
|
//ahl = new Agency_Hospital_Link__c();
|
//ahl.Agency__c = dpa.RawAccount__c;
|
List<DiscountProductApplicationDetail__c> dpadList = new List<DiscountProductApplicationDetail__c>();
|
//申请明细查询
|
dpadList = [select id,name,DiscountProductApplication__c,ProductDiscount__c,Product2__c,Product2__r.name,Product2__r.name__c,Product2__r.OT_CODE_Text__c,
|
Product2__r.SFDA_Status__c,Product2__r.Intra_Trade_List_RMB__c,Product2__r.Foreign_Trade_List_US__c,
|
Product2__r.Category2__c,Product2__r.Category3__c,Product2__r.Category4__c,Product2__r.Category5__c
|
from DiscountProductApplicationDetail__c where DiscountProductApplication__c =: dpadId];
|
|
//赋值给临时class类
|
for(DiscountProductApplicationDetail__c dpadc:dpadList){
|
|
DiscountProductApplicationDetail dpad =
|
new DiscountProductApplicationDetail(dpadc);
|
DiscountProductApplicationDetailList.add(dpad);
|
}
|
}
|
}
|
//保存更新
|
public PageReference savesaveDiscountProduct(){
|
Integer FLG = 0;
|
Integer Count = 0;
|
for(DiscountProductApplicationDetail dpadl: DiscountProductApplicationDetailList){
|
FLG = FLG + 1;
|
if(dpadl.check == false){
|
Count = Count + 1;
|
}
|
}
|
if(Count == FLG){
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请选择要维护的特价产品'));
|
return null;
|
}
|
|
|
if(!String.isBlank(AimsAccountId) && !String.isBlank(dpa.RawAccount__c)){
|
|
dpa.AimsAccount__c = AimsAccountId;
|
dpa.RawAccount__c = dpa.RawAccount__c;
|
dpa.ApplicationStatus__c = '草案中';
|
//add by rentx start 2021-01-22 设置记录类型
|
dpa.RecordTypeId = [select Id from RecordType where IsActive = true and DeveloperName = 'HospitalSpecials'].Id;
|
//add by rentx end 2021-01-22 设置记录类型
|
|
upsert dpa;
|
} else {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '医院没有选择'));
|
return null;
|
}
|
dpadlList = new List<DiscountProductApplicationDetail__c>();
|
List<DiscountProductApplicationDetail__c> dpadDeleteList = new List<DiscountProductApplicationDetail__c>();
|
for(DiscountProductApplicationDetail dpadl: DiscountProductApplicationDetailList){
|
//特价产品申请明细
|
DiscountProductApplicationDetail__c dpad = new DiscountProductApplicationDetail__c();
|
//更新
|
if(!String.isBlank(dpadl.dp.id)){
|
if(dpadl.check == true && dpadl.dp.ProductDiscount__c != null){
|
//dpad.DiscountProductApplication__c = dpadUpsert.id;
|
dpad.id = dpadl.dp.id;
|
|
dpad.ProductDiscount__c = dpadl.dp.ProductDiscount__c;
|
dpad.Product2__c = dpadl.Pr2.id;
|
dpadlList.add(dpad);
|
}else{
|
dpad.id = dpadl.dp.id;
|
dpadDeleteList.add(dpad);
|
}
|
|
}else if(dpadl.check == true){
|
//新规
|
//特价产品申请
|
dpad.DiscountProductApplication__c = dpa.id;
|
dpad.ProductDiscount__c = dpadl.dp.ProductDiscount__c;
|
dpad.Product2__c = dpadl.Pr2.id;
|
dpadlList.add(dpad);
|
|
}
|
//产品价格输入警告 为null是删除
|
// else if (dpadl.check == true && dpadl.dp.ProductDiscount__c == null) {
|
//throw new ControllerUtil.myException('选中的产品特价不可为空');
|
|
// ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '选中的产品特价不可为空'));
|
//dpadlFalg = false;
|
// return null;
|
// }
|
}
|
upsert dpadlList;
|
delete dpadDeleteList;
|
dpaId = dpa.id;
|
return ProductApplicationEdit();
|
}
|
|
// 进入特价申请页面
|
public PageReference ProductApplicationEdit() {
|
PageReference pg;
|
pg = new PageReference('/' + dpaId);
|
return pg;
|
}
|
|
//查询全部商品检索
|
/*public void searchAllProduct2(){
|
|
|
List<DiscountProductApplicationDetail> dpadNewList = new List<DiscountProductApplicationDetail>();
|
for (DiscountProductApplicationDetail dpad : DiscountProductApplicationDetailList) {
|
if (dpad.check == true) {
|
dpadNewList.add(dpad);
|
dpadIdList.add(dpad.pr2.id);
|
}
|
}
|
|
List<Product2__c> Product2FalseList = new List<Product2__c>();
|
soql = this.makeSoql1(text1,text2);
|
Product2FalseList = Database.query(soql);
|
|
if(Product2FalseList.size() >=1 ){
|
for(Product2__c Pro2False : Product2FalseList){
|
DiscountProductApplicationDetail dpad =
|
new DiscountProductApplicationDetail(Pro2False);
|
dpad.check = false;
|
dpadNewList.add(dpad);
|
|
}
|
}
|
DiscountProductApplicationDetailList = new List<DiscountProductApplicationDetail>();
|
for(DiscountProductApplicationDetail dpad : dpadNewList){
|
DiscountProductApplicationDetailList.add(dpad);
|
}
|
}*/
|
public void beforeSearch(){}
|
public void searchAllProduct2(){
|
if (String.isBlank(AimsAccountId)) {
|
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, '请选择医院'));
|
|
}
|
|
//查询该经销商医院下的所有特价产品
|
// gzw 修复数据源查询问题
|
List<hospitalprice__c> hpList = [Select id,product__c,mPrice__c from hospitalprice__c where account__c = :dpa.RawAccount__c and hospital__c = :AimsAccountId];
|
// List<hospitalprice__c> hpList = [Select id,product__c,mPrice__c from hospitalprice__c where hospital__c = :AimsAccountId];
|
Map<Id,Decimal> pdMap = new Map<Id,Decimal>();
|
if (hpList != null && hpList.size() > 0) {
|
for (hospitalprice__c hp : hpList) {
|
pdMap.put(hp.product__c, hp.mPrice__c);
|
}
|
}
|
|
List<DiscountProductApplicationDetail> dpadNewList = new List<DiscountProductApplicationDetail>();
|
for (DiscountProductApplicationDetail dpad : DiscountProductApplicationDetailList) {
|
if (dpad.check == true) {
|
dpadNewList.add(dpad);
|
dpadIdList.add(dpad.pr2.id);
|
}
|
}
|
//查询所有产品
|
List<Product2__c> Product2FalseList = new List<Product2__c>();
|
soql = this.makeSoql1(text1,text2);
|
Product2FalseList = Database.query(soql);
|
List<DiscountProductApplicationDetail> dpadNewList1 = new List<DiscountProductApplicationDetail>();
|
|
if(Product2FalseList.size() >=1 ){
|
for(Product2__c Pro2False : Product2FalseList){
|
DiscountProductApplicationDetail dpad =
|
new DiscountProductApplicationDetail(Pro2False);
|
dpad.check = false;
|
dpadNewList1.add(dpad);
|
}
|
}
|
DiscountProductApplicationDetailList = new List<DiscountProductApplicationDetail>();
|
for(DiscountProductApplicationDetail dpad : dpadNewList){
|
DiscountProductApplicationDetailList.add(dpad);
|
}
|
for(DiscountProductApplicationDetail dpad : dpadNewList1){
|
if (pdMap.containsKey(dpad.Pr2.Id)) {
|
dpad.dismoney = pdMap.get(dpad.Pr2.Id);
|
dpad.dp.ProductDiscount__c = pdMap.get(dpad.Pr2.Id);
|
}
|
DiscountProductApplicationDetailList.add(dpad);
|
}
|
}
|
|
//拼接检索产品检索soql
|
private String makeSoql1(String text1,String text2) {
|
|
soql = 'select id,name,OT_CODE_Text__c,SFDA_Status__c,Intra_Trade_List_RMB__c,Foreign_Trade_List_US__c,Category2__c,Category3__c,Category4__c,Category5__c,Name__c from Product2__c where Pro2_Dealer_ENG__c = true and id not in:dpadIdList';
|
soql += ' and Estimation_Entry_Possibility__c = \'○\'';
|
if (!String.isBlank(text1)) {
|
soql += ' and Name__c like \'%' + text1 + '%\' ';
|
}
|
if (!String.isBlank(text2)) {
|
soql += ' and OT_CODE_Text__c like \'%' + text2 + '%\' ';
|
}
|
return soql;
|
}
|
|
//页面显示产品明细构造类
|
class DiscountProductApplicationDetail {
|
public Product2__c Pr2 { get; set; }
|
public DiscountProductApplicationDetail__c dp { get; set; }
|
public Boolean check { get; set; }
|
public Decimal dismoney {get;set;}
|
public DiscountProductApplicationDetail(){
|
|
}
|
public DiscountProductApplicationDetail(Product2__c Pro2){
|
Pr2 = Pro2;
|
dp = new DiscountProductApplicationDetail__c();
|
check = false;
|
}
|
public DiscountProductApplicationDetail(DiscountProductApplicationDetail__c dpadc){
|
dp = dpadc;
|
pr2 = dpadc.Product2__r;
|
check = true;
|
dismoney = dpadc.ProductDiscount__c;
|
}
|
}
|
|
}
|