AdaKing88
2023-08-23 ae35159387a55199e8ab150ebb97d89d68a235bd
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
package org.jeecg.modules.arj.controller;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.arj.config.AjaxResult;
import org.jeecg.modules.arj.entity.Head;
import org.jeecg.modules.arj.entity.ShengchanTj;
import org.jeecg.modules.arj.mapper.HeadMapper;
import org.jeecg.modules.arj.service.HeadService;
import org.jeecg.modules.arj.service.ShengchanTjService;
import org.jeecg.modules.arj.vo.ShengchanTJVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
/*其中com.terra.arj.service就等于 com.example.demo.service,ShengchanTjService就等于SpiderdataSpiderxrmmwService*/
/*其中com.terra.arj.entity就等于com.example.demo.entity,ShengchanTj就等于SpiderdataSpiderxrmmw,一种Java的模板引擎语法*/
 
/**
 * <p>
 * 生产停机记录表 前端控制器
 * </p>
 *
 * @author hyy
 * @since 2022-12-21
 */
@Api(tags = "A9生产停机记录接口")
@RestController
@RequestMapping("/shengchan-tj")
public class ShengchanTjVoController {
    @Autowired
    private HeadService headService;
 
 
    @Autowired
    private HeadMapper headMapper;
 
    @Resource
    private ShengchanTjService shengchanTjService;
 
    /**
     * 新增数据
     *
     * @param shengchanTJVo 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public AjaxResult save(@RequestBody ShengchanTJVo shengchanTJVo) {
        //新增或者更新
        Head h = headService.insert(shengchanTJVo.getHead());
        if (shengchanTJVo.getShengchanTjList() != null) {
            shengchanTJVo.getShengchanTjList().stream().forEach(item -> item.setHeadId(h.getId()));
            shengchanTjService.saveBatch(shengchanTJVo.getShengchanTjList());
        }
        return AjaxResult.success(h.getId());
    }
 
    /**
     * 更新数据
     *
     * @param shengchanTJVo 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ShengchanTJVo shengchanTJVo) {
        Head h2 = shengchanTJVo.getHead();
        h2.setId("");
        Head h = headService.insert(h2);
 
        if (shengchanTJVo.getShengchanTjList() != null) {
            shengchanTJVo.getShengchanTjList().stream().forEach(item -> item.setHeadId(h.getId()));
            shengchanTjService.saveOrUpdateBatch(shengchanTJVo.getShengchanTjList());
        }
        return AjaxResult.success(h.getId());
    }
 
    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping
    public AjaxResult deleteById(String id) {
        return AjaxResult.success(headService.deleteById(id));
    }
 
    //查询所有内容接口
    @GetMapping("/findAll")
    public List<ShengchanTj> findAll() {
        return shengchanTjService.list();   //返回查询到的所有数据
    }
 
    //根据id查询
    @GetMapping("/id")
    public ShengchanTj findOne(@PathVariable Integer id) {
        return shengchanTjService.getById(id);   //返回查询到指定id的数据
    }
 
 
    /**
     * 获取最新数据
     *
     * @return 实例对象
     */
    @ApiOperation("获取最新数据")
    @PostMapping("/last")
    public AjaxResult getlastRecord(@RequestBody String leixing) {
 
       // Head head = headService.queryLast(leixing==null?"A9":leixing);
        JSONObject j = JSONObject.parseObject(leixing);
        HashMap<String, String > myMap  = new HashMap<String, String>(){{
            put("0","一");
            put("2","二");
            put("3","三");
            put("4","四");
            put("5","五");
            put("6","六");
            put("7","七");
            put("8","八");
            put("9","九");
        }};
 
        Head head =  headService.queryLeixingChanxian("A9",myMap.get(j.getString("leixing")));
        ShengchanTJVo hanjiVo = new ShengchanTJVo();
 
        if (head == null) return AjaxResult.error("访问无数据");
        hanjiVo.setHead(head);
        hanjiVo.setShengchanTjList(shengchanTjService.queryByHeadId(head.getId()));
 
        return AjaxResult.success(hanjiVo);
    }
    @PostMapping("/page")
    public AjaxResult findPage( @RequestParam(defaultValue = "1") Integer pageNum ,  @RequestParam(defaultValue = "10") Integer pageSize) {
 
 
        List<Head> headList = headMapper.queryPage2((pageNum - 1) * pageSize, pageSize);
        IPage iPage = new Page();
        List<ShengchanTJVo> records = new ArrayList<>();
        for (Head h : headList) {
 
            ShengchanTJVo shengchanTJVo = new ShengchanTJVo();
            Head head = headService.queryById(h.getId());
 
            if (head == null) return AjaxResult.error("访问无数据");
            shengchanTJVo.setHead(head);
            shengchanTJVo.setShengchanTjList(shengchanTjService.queryByHeadId(head.getId()));
 
            records.add(shengchanTJVo);
        }
        int n = headMapper.queryCount();
        iPage.setPages(n % pageSize == 0 ? n / pageSize : n / pageSize + 1);
        iPage.setRecords(records);
        iPage.setTotal(headMapper.queryCount());
        iPage.setSize(pageSize);
        iPage.setCurrent(pageNum);
 
        return AjaxResult.success(iPage);
    }
}