YYC
2023-11-05 a6013fee1895815cda77bfdcb5e5b9f4d190640b
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package com.ld.igds.inout.service;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.ld.igds.constant.Constant;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.InoutParam;
import com.ld.igds.models.InoutRecord;
 
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Component;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.bstek.dorado.data.provider.Page;
import com.ld.igds.models.InoutSettle;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.DateUtil;
 
@Component
public class HInoutSettleService extends HibernateDao {
 
 
    public void pageIoutRecord(Page<InoutRecord> page, InoutParam param) throws Exception {
        String hql = " from " + InoutRecord.class.getName()
                + " where companyId =:companyId and progress =:progress";
        Map<String, Object> args = new HashMap<String, Object>();
 
        args.put("companyId", ContextUtil.getCompanyId());
        args.put("progress", InoutConstant.PROGRESS_RECORD);
 
        if (StringUtils.isNotEmpty(param.getType())) {
            hql += " and type =:type";
            args.put("type", param.getType());
        }
 
        if (StringUtils.isNotEmpty(param.getId())) {
            hql += " and id like:id";
            args.put("id", "%" + param.getId() + "%");
        }
 
        if (StringUtils.isNotEmpty(param.getPlateNum())) {
            hql += " and plateNum like:plateNum";
            args.put("plateNum", "%" + param.getPlateNum() + "%");
        }
 
        if (StringUtils.isNotEmpty(param.getCustomerId())) {
            hql += " and customerId =:customerId";
            args.put("customerId", param.getCustomerId());
        }
 
        if (StringUtils.isNotEmpty(param.getDepotId())) {
            hql += " and depotId =:depotId";
            args.put("depotId", param.getDepotId());
        }
 
        if (StringUtils.isNotEmpty(param.getFoodVariety())) {
            hql += " and foodVariety =:foodVariety";
            args.put("foodVariety", param.getFoodVariety());
        }
 
 
        if (null != param.getStart()) {
            hql += " and completeTime >=:start";
            args.put("start", DateUtil.getCurZero(param.getStart()));
        }
 
        if (null != param.getEnd()) {
            hql += " and completeTime <=:end";
            args.put("end", DateUtil.getNextZero(param.getEnd()));
        }
 
        hql += " and RECORD_STATUS_ <> 'ERROR' and RECORD_STATUS_ <> 'DEL'";
 
        String countHql = " select count(*) " + hql;
 
        hql += " order by id desc ";
 
        this.pagingQuery(page, hql, countHql, args);
    }
 
    public InoutSettle getSettleById(String companyId, String id) {
        String hql = " from " + InoutSettle.class.getName()
                + " where companyId=:companyId";
 
        Map<String, Object> args = new HashMap<String, Object>();
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        args.put("companyId", ContextUtil.getCompanyId());
        if (StringUtils.isNotEmpty(id)) {
            hql += " and id=:id";
            args.put("id", id);
        }
 
        hql += " order by payTime desc";
        List<InoutSettle> list = this.query(hql, args);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
 
    public String saveOrUpdateData(InoutSettle data) {
        Session session = this.getSessionFactory().openSession();
 
        try {
            if (null == data.getPayTime()) {
                data.setPayTime(new Date());
            }
 
            if (null == data.getCompanyId()) {
                data.setCompanyId(ContextUtil.getCompanyId());
                session.save(data);
            } else {
                session.update(data);
            }
        } finally {
            session.flush();
            session.close();
        }
        return null;
    }
 
    public void updateInoutRecordPay(String id) {
        String hql = " update " + InoutRecord.class.getName() + " set settleTag=:settleTag where id=:id";
        Session session = this.getSessionFactory().openSession();
        try {
            Query query = session.createQuery(hql);
            query.setString("settleTag", Constant.YN_Y);
            query.setString("id", id);
            query.executeUpdate();
        } finally {
            session.flush();
            session.close();
        }
    }
 
    /**
     * 根据条件分页获取结算信息
     *
     * @param page
     * @param param
     */
    public void pageSettle(Page<InoutSettle> page, InoutParam param) throws Exception {
        String hql = " from " + InoutSettle.class.getName()
                + " where companyId =:companyId and deptId=:deptId";
        Map<String, Object> args = new HashMap<>();
 
        args.put("companyId", param.getCompanyId());
        args.put("deptId", param.getDeptId());
 
        if (StringUtils.isNotEmpty(param.getType())) {
            hql += " and inoutType =:inoutType";
            args.put("inoutType", param.getType());
        }
 
        if (StringUtils.isNotEmpty(param.getId())) {
            hql += " and id like:id";
            args.put("id", "%" + param.getId() + "%");
        }
 
        if (StringUtils.isNotEmpty(param.getDepotId())) {
            hql += " and depotId =:depotId";
            args.put("depotId", param.getDepotId());
        }
        if (null != param.getStart()) {
            hql += " and payTime >=:start";
            args.put("start", DateUtil.getCurZero(param.getStart()));
        }
        if (null != param.getEnd()) {
            hql += " and payTime <=:end";
            args.put("end", DateUtil.getNextZero(param.getEnd()));
        }
 
        String countHql = " select count(*) " + hql;
 
        hql += " order by id desc ";
 
        this.pagingQuery(page, hql, countHql, args);
    }
 
 
}