#
Junjie
2024-08-02 e83dacb5066a86db29dbdc232218d8aba6adc95f
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
package com.zy.asrs.wms.asrs.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.asrs.wms.asrs.entity.LocDetlField;
import com.zy.asrs.wms.asrs.entity.ViewLocDetl;
import com.zy.asrs.wms.asrs.entity.param.FieldParam;
import com.zy.asrs.wms.asrs.mapper.LocDetlMapper;
import com.zy.asrs.wms.asrs.entity.LocDetl;
import com.zy.asrs.wms.asrs.mapper.ViewLocDetlMapper;
import com.zy.asrs.wms.asrs.service.LocDetlFieldService;
import com.zy.asrs.wms.asrs.service.LocDetlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.asrs.wms.common.domain.BaseParam;
import com.zy.asrs.wms.common.domain.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
@Service("locDetlService")
public class LocDetlServiceImpl extends ServiceImpl<LocDetlMapper, LocDetl> implements LocDetlService {
 
    @Autowired
    private ViewLocDetlMapper viewLocDetlMapper;
    @Autowired
    private LocDetlFieldService locDetlFieldService;
 
    @Override
    public PageParam<ViewLocDetl, BaseParam> getPage(PageParam<ViewLocDetl, BaseParam> pageParam, QueryWrapper<ViewLocDetl> buildWrapper) {
        PageParam<ViewLocDetl, BaseParam> result = viewLocDetlMapper.selectPage(pageParam, buildWrapper);
 
        //解析动态字段
        JSONObject data = JSON.parseObject(JSON.toJSONString(result));
        List<ViewLocDetl> records = result.getRecords();
        data.put("records", records);
        for (ViewLocDetl locDetl : records) {
            Map<String, Object> resultMap = viewLocDetlMapper.getById(locDetl.getId());
            locDetl.syncFieldMap(resultMap);
        }
        return result;
    }
 
    @Override
    public List<LocDetl> getLocDetlList(Map<String, Object> map) {
        String matnr = null;
        String batch = null;
        if (map.containsKey("matnr")) {
            matnr = map.get("matnr").toString();
            map.remove("matnr");
        }
        if (map.containsKey("batch")) {
            batch = map.get("batch").toString();
            map.remove("batch");
        }
        ArrayList<FieldParam> param = new ArrayList<>();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            if (entry.getValue() == null) {
                continue;
            }
            FieldParam fieldParam = new FieldParam();
            fieldParam.setName(entry.getKey());
            fieldParam.setValue(entry.getValue());
            param.add(fieldParam);
        }
 
        List<Map<String, Object>> list2 = viewLocDetlMapper.getList(matnr, batch, param);
        List<LocDetl> locDetls = new ArrayList<>();
        for (Map<String, Object> objectMap : list2) {
            LocDetl locDetl = JSON.parseObject(JSON.toJSONString(objectMap), LocDetl.class);
            locDetl.syncFieldMap(objectMap);
            locDetls.add(locDetl);
        }
        return locDetls;
    }
 
    @Override
    public List<LocDetl> parseLocDetl(List<LocDetl> list) {
        for (LocDetl locDetl : list) {
            List<LocDetlField> locDetlFieldList = locDetlFieldService.list(new LambdaQueryWrapper<LocDetlField>().eq(LocDetlField::getDetlId, locDetl.getId()));
            locDetl.syncField(locDetlFieldList);
        }
        return list;
    }
}