zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.shlanbao.tzsc.pms.sch.shiftexchg.service.impl;
 
import java.util.ArrayList;
import java.util.List;
 
import com.shlanbao.tzsc.utils.tools.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.dao.SchShiftExchgDaoI;
import com.shlanbao.tzsc.base.dao.SchShiftExchgDetDaoI;
import com.shlanbao.tzsc.base.mapping.MdMat;
import com.shlanbao.tzsc.base.mapping.MdShift;
import com.shlanbao.tzsc.base.mapping.MdTeam;
import com.shlanbao.tzsc.base.mapping.MdUnit;
import com.shlanbao.tzsc.base.mapping.SchShiftExchg;
import com.shlanbao.tzsc.base.mapping.SchShiftExchgDet;
import com.shlanbao.tzsc.base.mapping.SchWorkorder;
import com.shlanbao.tzsc.base.mapping.SysUser;
import com.shlanbao.tzsc.base.model.Combobox;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.pms.sch.shiftexchg.beans.ShiftExchgBean;
import com.shlanbao.tzsc.pms.sch.shiftexchg.beans.ShiftExchgDetBean;
import com.shlanbao.tzsc.pms.sch.shiftexchg.service.ShiftExchgServiceI;
 
import javax.servlet.http.HttpServletRequest;
 
@Service
public class ShiftExchgServiceImpl extends BaseService implements ShiftExchgServiceI{
    @Autowired
    private SchShiftExchgDaoI schShiftExchgDao;
    @Autowired
    private SchShiftExchgDetDaoI schShiftExchgDetDao;
    @Autowired
    private HttpServletRequest request;
    @SuppressWarnings("null")
    @Override
    public DataGrid getExchgs(ShiftExchgBean shiftExchgBean,
            PageParams pageParams) {
        StringBuffer hql=new StringBuffer(1000);
        hql.append("from SchShiftExchg o  ");
        hql.append("left join fetch o.hoOrder.mdEquipment.mdWorkshop hoe  ");
        hql.append("left join fetch o.toOrder.mdEquipment toe  ");
        hql.append("left join fetch o.sysUserByHoUser hsu ");
        hql.append("left join fetch o.sysUserByToUser tsu ");
        hql.append("left join fetch o.mdMatByHoMat hmm ");
        hql.append("left join fetch o.mdMatByToMat tmm ");
        hql.append("left join fetch o.mdShiftByHoShift hms ");
        hql.append("left join fetch o.mdShiftByToShift tms ");
        hql.append("left join fetch o.mdTeamByHoTeam hmt ");
        hql.append("left join fetch o.mdTeamByToTeam tmt ");
        hql.append("where o.del=0 ");
 
        String params="";
        params = params.concat(" and hoe.code ="+shiftExchgBean.getWorkshop());
 
        params = params.concat(" and o.type ="+shiftExchgBean.getType());
 
        if(StringUtil.notNull(shiftExchgBean.getHoShift()))
            params = params.concat(" and hms.id="+shiftExchgBean.getHoShift());
        if(StringUtil.notNull(shiftExchgBean.getToShift()))
            params = params.concat(" and tms.id="+shiftExchgBean.getToShift());
 
        if(StringUtil.notNull(shiftExchgBean.getHoTeam()))
            params = params.concat(" and hmt.id="+shiftExchgBean.getHoTeam());
        if(StringUtil.notNull(shiftExchgBean.getToTeam()))
            params = params.concat(" and tmt.id="+shiftExchgBean.getToTeam());
 
        if(StringUtil.notNull(shiftExchgBean.getHoMat()))
            params = params.concat(" and hmm.id='"+shiftExchgBean.getHoMat())+"'";
        if(StringUtil.notNull(shiftExchgBean.getToMat()))
            params = params.concat(" and tmm.id='"+shiftExchgBean.getToMat())+"'";
 
        if(StringUtil.notNull(shiftExchgBean.getDate()))
            params = params.concat(" and to_char(o.date,'yyyy-MM-dd') >= '"+shiftExchgBean.getDate()+"'");
        if(StringUtil.notNull(shiftExchgBean.getDate2()))
            params = params.concat(" and to_char(o.date,'yyyy-MM-dd') <= '"+shiftExchgBean.getDate2()+"'");
 
        params = params.concat(" order by o.date desc ");
        String hql2=hql.toString();
        List<SchShiftExchg> rows=schShiftExchgDao.queryByPage(hql2.concat(params), pageParams);
 
        List<ShiftExchgBean> outputBeans = new ArrayList<ShiftExchgBean>();
 
        ShiftExchgBean bean = null;
 
        try {
            if(rows.size()>0 && rows!=null){
                for (SchShiftExchg schShiftExchg : rows) {
                    bean = BeanConvertor.copyProperties(schShiftExchg, ShiftExchgBean.class);
                    if(schShiftExchg.getHoOrder()!=null&&schShiftExchg.getHoOrder().getMdEquipment().getEquipmentName()!=null&&schShiftExchg.getHoOrder().getId()!=null){
                        bean.setEquipment(schShiftExchg.getHoOrder().getMdEquipment().getEquipmentName());
                        bean.setHoOrderId(schShiftExchg.getHoOrder().getId());
                    }
                    if(schShiftExchg.getMdMatByHoMat()!=null&&schShiftExchg.getMdMatByHoMat().getName()!=null){
                        bean.setHoMat(schShiftExchg.getMdMatByHoMat().getName());
                    }
                    if(schShiftExchg.getMdShiftByHoShift()!=null&&schShiftExchg.getMdShiftByHoShift().getName()!=null){
                        bean.setHoShift(schShiftExchg.getMdShiftByHoShift().getName());
                    }
                    if(schShiftExchg.getMdTeamByHoTeam()!=null&&schShiftExchg.getMdTeamByHoTeam().getName()!=null){
                        bean.setHoTeam(schShiftExchg.getMdTeamByHoTeam().getName());
                    }
                    if(schShiftExchg.getSysUserByHoUser()!=null&&schShiftExchg.getSysUserByHoUser().getName()!=null){
                        bean.setHoUser(schShiftExchg.getSysUserByHoUser().getName());
                    }
                    if(schShiftExchg.getMdMatByToMat()!=null&&schShiftExchg.getMdMatByToMat().getName()!=null){
                        bean.setToMat(schShiftExchg.getMdMatByToMat().getName());
                    }
                    if(schShiftExchg.getMdShiftByToShift()!=null&&schShiftExchg.getMdShiftByToShift().getName()!=null){
                        bean.setToShift(schShiftExchg.getMdShiftByToShift().getName());
                    }
                    if(schShiftExchg.getMdTeamByToTeam()!=null&&schShiftExchg.getMdTeamByToTeam().getName()!=null){
                        bean.setToTeam(schShiftExchg.getMdTeamByToTeam().getName());
                    }
                    if(schShiftExchg.getSysUserByToUser()!=null&&schShiftExchg.getSysUserByToUser().getName()!=null){
                        bean.setToUser(schShiftExchg.getSysUserByToUser().getName());
                    }
                    FillUserInfoUtil.fillCreateAndUpdateUserInfo(schShiftExchg,bean);
                    outputBeans.add(bean);
                    bean = null;
                }
            }
            hql2= "select count(o) ".concat(hql2.replace("fetch", ""));
            long total=schShiftExchgDao.queryTotal(hql2.concat(params));
            return new DataGrid(outputBeans, total);
        } catch (Exception e) {
            log.error("POVO转换异常", e);
        }
        return null;
    }
    @Override
    public void addExchg(ShiftExchgBean shiftExchgBean) {
        SchShiftExchg o = new SchShiftExchg();
        o.setDate(DateUtil.formatStringToDate(shiftExchgBean.getDate(), "yyyy-MM-dd"));
        //交班部分
        o.setSysUserByHoUser(new SysUser(shiftExchgBean.getHoUser()));
 
        o.setMdMatByHoMat(new MdMat(shiftExchgBean.getHoMat()));
 
        o.setMdShiftByHoShift(new MdShift(shiftExchgBean.getHoShift()));
 
        o.setMdTeamByHoTeam(new MdTeam(shiftExchgBean.getHoTeam()));
 
        o.setHoTime(DateUtil.formatStringToDate(shiftExchgBean.getHoTime(), "yyyy-MM-dd HH:mm"));
 
        o.setHoOrder(new SchWorkorder(shiftExchgBean.getHoOrderId()));
        //接班部分,可能会先填写交班,后填写接班
        if(StringUtil.notNull(shiftExchgBean.getToOrderId())){
 
            if(StringUtil.notNull(shiftExchgBean.getToUser()))
            o.setSysUserByToUser(new SysUser(shiftExchgBean.getToUser()));
 
            if(StringUtil.notNull(shiftExchgBean.getToMat()))
            o.setMdMatByToMat(new MdMat(shiftExchgBean.getToMat()));
 
            if(StringUtil.notNull(shiftExchgBean.getToShift()))
            o.setMdShiftByToShift(new MdShift(shiftExchgBean.getToShift()));
 
            if(StringUtil.notNull(shiftExchgBean.getToTeam()))
            o.setMdTeamByToTeam(new MdTeam(shiftExchgBean.getToTeam()));
 
            if(StringUtil.notNull(shiftExchgBean.getToTime()))
            o.setToTime(DateUtil.formatStringToDate(shiftExchgBean.getToTime(), "yyyy-MM-dd HH:mm"));
 
            if(StringUtil.notNull(shiftExchgBean.getToOrderId()))
            o.setToOrder(new SchWorkorder(shiftExchgBean.getToOrderId()));
 
        }
 
 
        o.setType(shiftExchgBean.getType());
 
        o.setDel(0L);
 
        schShiftExchgDao.save(o);
    }
    @LogAnno(operateType = "编辑换班记录")
    @Override
    public void editExchg(ShiftExchgBean shiftExchgBean) {
 
        SchShiftExchg o = schShiftExchgDao.findById(SchShiftExchg.class, shiftExchgBean.getId());
        if(StringUtil.notNull(shiftExchgBean.getHoTime())){
            o.setHoTime(DateUtil.formatStringToDate(shiftExchgBean.getHoTime(), "yyyy-MM-dd HH:mm"));
        }
        if(StringUtil.notNull(shiftExchgBean.getHoUser())){
            o.setSysUserByHoUser(new SysUser(shiftExchgBean.getHoUser()));
        }
        if(StringUtil.notNull(shiftExchgBean.getToUser())){
            o.setSysUserByToUser(new SysUser(shiftExchgBean.getToUser()));
        }
        if(StringUtil.notNull(shiftExchgBean.getToTime())){
            o.setToTime(DateUtil.formatStringToDate(shiftExchgBean.getToTime(), "yyyy-MM-dd HH:mm"));
        }
        FillUserInfoUtil.fillUpdateUserInfo(o,request);
    }
    @Override
    public void addExchgDet(ShiftExchgDetBean shiftExchgDetBean) {
        SchShiftExchgDet o = new SchShiftExchgDet();
 
        o.setSchShiftExchg(new SchShiftExchg(shiftExchgDetBean.getExchg()));
 
        o.setMdMat(new MdMat(shiftExchgDetBean.getMat()));
 
        o.setMdUnit(new MdUnit(shiftExchgDetBean.getUnit()));
 
        o.setQty(shiftExchgDetBean.getQty());
 
        o.setDel(0L);
 
        schShiftExchgDetDao.save(o);
    }
    @Override
    public void editExchgDet(ShiftExchgDetBean shiftExchgDetBean) {
 
        SchShiftExchgDet o = schShiftExchgDetDao.findById(SchShiftExchgDet.class, shiftExchgDetBean.getId());
 
        o.setQty(shiftExchgDetBean.getQty());
    }
    @LogAnno(operateType = "删除换班换牌记录")
    @Override
    public void deleteExchg(String id) {
        schShiftExchgDao.updateByParams("update SchShiftExchg o set o.del=1 where o.id=?", id);
    }
    @Override
    public void deleteExchgDet(String id) {
        schShiftExchgDetDao.updateByParams("update SchShiftExchgDet o set o.del=1 where o.id=?", id);
    }
    @Override
    public DataGrid getExchgDetsByExchgId(String id) throws Exception {
        String hql = "from SchShiftExchgDet o  left join fetch o.mdMat mt left join fetch o.mdUnit mu where o.del=0 and o.schShiftExchg.id=?";
        List<SchShiftExchgDet> list = schShiftExchgDetDao.query(hql, id);
        List<ShiftExchgDetBean> rows = new ArrayList<ShiftExchgDetBean>();
        for (SchShiftExchgDet schShiftExchgDet : list) {
            ShiftExchgDetBean bean = BeanConvertor.copyProperties(schShiftExchgDet, ShiftExchgDetBean.class);
            bean.setMat(schShiftExchgDet.getMdMat().getName());
            bean.setUnit(schShiftExchgDet.getMdUnit().getName());
            rows.add(bean);
        }
        return new DataGrid(rows, 0L);
    }
    @Override
    public List<Combobox> getBomsWorkorderId(String workorderId, String exchgId)
            throws Exception {
        String hql = "select o.mdMat from SchWorkorderBom o where o.schWorkorder.id=? and o.mdMat.id not in (select i.mdMat.id from SchShiftExchgDet i where i.schShiftExchg.id=?)";
        return BeanConvertor.copyList(schShiftExchgDetDao.query(List.class, hql,workorderId,exchgId), Combobox.class);
    }
    @Override
    public ShiftExchgBean getExchgById(String id) throws Exception {
        SchShiftExchg schShiftExchg = schShiftExchgDao.findById(SchShiftExchg.class, id);
        ShiftExchgBean bean =BeanConvertor.copyProperties(schShiftExchg,ShiftExchgBean.class);
        if(schShiftExchg.getHoOrder()!=null){
            bean.setEquipment(schShiftExchg.getHoOrder().getMdEquipment().getEquipmentName());
            bean.setHoOrderId(schShiftExchg.getHoOrder().getCode());
        }
        if(schShiftExchg.getToOrder()!=null){
            bean.setToOrderId(schShiftExchg.getToOrder().getCode());
        }
        if(schShiftExchg.getMdMatByHoMat()!=null){
            bean.setHoMat(schShiftExchg.getMdMatByHoMat().getName());
        }
 
        if(schShiftExchg.getMdShiftByHoShift()!=null){
            bean.setHoShift(schShiftExchg.getMdShiftByHoShift().getName());
        }
 
        if(schShiftExchg.getMdTeamByHoTeam()!=null){
            bean.setHoTeam(schShiftExchg.getMdTeamByHoTeam().getName());
        }
 
        if(schShiftExchg.getSysUserByHoUser()!=null){
            bean.setHoUser(schShiftExchg.getSysUserByHoUser().getName());
        }
 
        if(schShiftExchg.getMdMatByToMat()!=null){
            bean.setToMat(schShiftExchg.getMdMatByToMat().getName());
        }
 
        if(schShiftExchg.getMdShiftByToShift()!=null){
            bean.setToShift(schShiftExchg.getMdShiftByToShift().getName());
        }
 
        if(schShiftExchg.getMdTeamByToTeam()!=null){
            bean.setToTeam(schShiftExchg.getMdTeamByToTeam().getName());
        }
 
        if(schShiftExchg.getSysUserByToUser()!=null){
            bean.setToUser(schShiftExchg.getSysUserByToUser().getName());
        }
 
        return bean;
    }
    @Override
    public ShiftExchgDetBean getExchgDetById(String id) throws Exception {
        SchShiftExchgDet det = schShiftExchgDetDao.findById(SchShiftExchgDet.class, id);
        ShiftExchgDetBean bean = new ShiftExchgDetBean();
        bean.setId(det.getId());
        bean.setQty(det.getQty());
        bean.setUnit(det.getMdUnit().getName());
        bean.setMat(det.getMdMat().getName());
        return bean;
    }
 
    @Override
    public void batchDeleteExchgDet(String ids) {
        String[] id=ids.split(",");
        for (int i = 0; i < id.length; i++) {
            this.deleteExchg(id[i]);
        }
    }
 
}