whyclxw
3 天以前 51726e56a2d4b55f0e37b2b22adc4413113d43d0
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.MaterialHistoryMapper;
import com.whyc.pojo.Material;
import com.whyc.pojo.MaterialHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class MaterialHistoryService {
 
    @Resource
    private MaterialHistoryMapper mapper;
 
    @Autowired
    @Lazy
    private MaterialService materialService;
 
    public void insert(MaterialHistory mh) {
        mapper.insert(mh);
    }
 
    public void addBatch(List<MaterialHistory> materialHistoryList) {
        mapper.insertBatchSomeColumn(materialHistoryList);
    }
 
    //根据物料id查询dwg历史
    public Response getDwgHisById(int materialId,  int pageCurr,  int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("material_id",materialId);
        wrapper.isNotNull("dwg_url");
        wrapper.orderByDesc("create_time");
        List list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"根据物料id查询dwg历史");
    }
 
    //根据物料id查询pic历史
    public Response getPicHisById(int materialId,  int pageCurr,  int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("material_id",materialId);
        wrapper.isNotNull("picture_url");
        wrapper.orderByDesc("create_time");
        List list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"根据物料id查询pic历史");
    }
 
    public Response moveFromMaterialTable(int checkNum) {
        List<Material> list = materialService.getList();
        list = list.stream().filter(temp-> temp.getPictureUrl()!=null || temp.getDwgUrl()!=null).collect(Collectors.toList());
        List<MaterialHistory> materialHistories = new LinkedList<>();
        Date now = new Date();
        for (Material material : list) {
            MaterialHistory history = new MaterialHistory();
            history.setProductId(0);
            history.setMaterialId(material.getId());
            history.setPictureUrl(material.getPictureUrl());
            history.setDwgUrl(material.getDwgUrl());
            history.setUpUserId(material.getUpUserId()==null?null:material.getUpUserId().intValue());
            history.setCreateTime(now);
 
            materialHistories.add(history);
        }
        mapper.insertBatchSomeColumn(materialHistories);
        return new Response().set(1,true,"首次的物料图纸转移保存完成");
    }
}