liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//测试类 InventoryTemperatureHumidityCtlTest
 
public class InventoryTemperatureHumidityController {
 
    public String bieCunFangDi { get; set; } 
    public Temperature_And_Humidity_Check__c tahcObj { get; set; }
    public String temperatureHumidityZone { get; set; }     //温湿度区
    public String YYYYMM { get; set; }
 
    public PageReference init() {
        Datetime now = Datetime.now();
        YYYYMM = formatYYYYMM(now.format('YYYYMM'));
 
        if (String.isBlank(temperatureHumidityZone)) {
            temperatureHumidityZone = 'A区';
        }
 
        User currUser = [
                Select Id, Name,Dept__c, Default_Referable_Apply_Equipment_Center__c, JingliEquipmentId__c
                From User
                Where Id = :UserInfo.getUserId()];
 
        if (String.isBlank(currUser.Default_Referable_Apply_Equipment_Center__c)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '当前用户所在地不能为空'));
            return null;
        }
 
        bieCunFangDi = currUser.Default_Referable_Apply_Equipment_Center__c;
        getTAHCObj();
        return null;
    }
 
    public void changeZone() {
        getTAHCObj();
    }
 
    public void getTAHCObj() {
 
        /*String QueryString = 'SELECT SUM(You_Xiao_Ku_Cun__c) sumQuantity FROM Asset WHERE Internal_asset_location__c = :bieCunFangDi and Delete_Flag__c = False and Quantity > 0 and Asset_Owner__c = \'Olympus\' and Temperature_And_Humidity_Zone__c =: temperatureHumidityZone and ' + FixtureUtil.getAssetSoqlBase();
        AggregateResult[] sumResults = Database.query(QueryString);*/
 
        Integer sumAsset = 0;
        AggregateResult[] sumResults1 = [Select sum(Amount__c) sumQuantity
                                        From Inventory_Detail__c
                                        WHERE Inventory_Header__r.Inventory_Status__c <> '已批准' 
                                        AND Inventory_Header__r.Internal_asset_location__c =: bieCunFangDi
                                        AND Inventory_Header__r.Inventory_Start_Date__c = LAST_N_DAYS:30
                                        AND Asset_Status__c IN ('在库', '冻结')
                                        AND Asset__r.Temperature_And_Humidity_Zone__c =: temperatureHumidityZone];
 
        for (AggregateResult ar : sumResults1) {
            if (ar.get('sumQuantity') != null) {
                sumAsset += Integer.valueOf(ar.get('sumQuantity'));
            }
        }
 
        AggregateResult[] sumResults2 = [Select sum(Amount__c) sumQuantity
                                        From Consum_Inventory_Detail__c
                                        WHERE Inventory_Header__r.Inventory_Status__c <> '已批准' 
                                        AND Inventory_Header__r.Internal_asset_location__c =: bieCunFangDi
                                        AND Inventory_Header__r.Inventory_Start_Date__c = LAST_N_DAYS:30
                                        AND Asset_Status__c IN ('在库', '冻结')
                                        AND Asset__r.Temperature_And_Humidity_Zone__c =: temperatureHumidityZone];
 
        for (AggregateResult ar : sumResults2) {
            if (ar.get('sumQuantity') != null) {
                sumAsset += Integer.valueOf(ar.get('sumQuantity'));
            }
        }
 
        List<Temperature_And_Humidity_Check__c> tahcTemp = [
                    SELECT Id, Temperature_And_Humidity_Zone__c, Asset_Count__c, Internal_asset_location__c, Inventory_Time__c, Temperature_Storage_Information__c,
                        Humidity_Storage_Information__c, Temperature_Check_Result__c, Temperature_Note__c, Humidity_Check_Result__c, Humidity_Note__c
                    FROM Temperature_And_Humidity_Check__c 
                    WHERE Internal_asset_location__c =: bieCunFangDi AND Inventory_Time__c =: YYYYMM AND Temperature_And_Humidity_Zone__c =: temperatureHumidityZone];
 
        if (tahcTemp.isEmpty()) {
            tahcObj = new Temperature_And_Humidity_Check__c();
            tahcObj.Inventory_Time__c = YYYYMM;
            tahcObj.Internal_asset_location__c = bieCunFangDi;
            tahcObj.Asset_Count__c = sumAsset;
            tahcObj.Temperature_And_Humidity_Zone__c = temperatureHumidityZone;
            tahcObj.Temperature_Storage_Information__c = FixtureUtil.zoneTemperatureMap.get(temperatureHumidityZone);
            tahcObj.Humidity_Storage_Information__c = FixtureUtil.zoneHumidityMap.get(temperatureHumidityZone);
        } else {
            tahcObj = tahcTemp[0];
        }
    }
 
    //温湿度区 SelectOption
    public List<SelectOption> gettemperatureHumidityZoneOps() {
 
        List<SelectOption> opList = new List<selectOption>();
        List<Schema.PicklistEntry> pick_list_values = Temperature_And_Humidity_Check__c.Temperature_And_Humidity_Zone__c.getDescribe().getPicklistValues();
 
        for (Schema.PicklistEntry a : pick_list_values) {
            opList.add(new selectOption(a.getValue(), a.getLabel()));
        }
        return opList;
    }
 
    public String formatYYYYMM(String YYYYMM) {
        return YYYYMM.substring(0, 4) + '年' + YYYYMM.substring(4, 6) + '月';
    }
    
    public PageReference save() {
        if (String.isBlank(tahcObj.Temperature_Check_Result__c)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请填写温度检查结果'));
            return null;
        }
        if (String.isBlank(tahcObj.Humidity_Check_Result__c)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请填写湿度检查结果'));
            return null;
        }
        insert tahcObj;
 
        return null;
    }
}