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
package org.jeecg.modules.arj.controller;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; //导包
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.service.HeadService;
import org.jeecg.modules.arj.vo.BianxkVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.modules.arj.service.BianxkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;  //导包
 
import javax.annotation.Resource; //导包
import java.util.HashMap;
import java.util.List; //导包
 
/*其中com.terra.arj.service就等于 com.example.demo.service,BianxkService就等于SpiderdataSpiderxrmmwService*/
import org.jeecg.modules.arj.entity.Bianxk;
/*其中com.terra.arj.entity就等于com.example.demo.entity,Bianxk就等于SpiderdataSpiderxrmmw,一种Java的模板引擎语法*/
 
import org.springframework.web.bind.annotation.RestController;
 
/**
 * <p>
 * 边线库 前端控制器
 * </p>
 *
 * @author hyy
 * @since 2023-02-20
 */
@Api(tags = "A0-边线库接口")
@RestController
@RequestMapping("/bianxk")
public class BianxkController {
 
    @Resource
    private BianxkService bianxkService;
 
    @Autowired
    private HeadService headService;
 
    //新增和修改接口
    @ApiOperation("增加数据")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BianxkVo bianxkVo) {
        //新增或者更新
        Head h = headService.insert(bianxkVo.getHead());
 
        if (bianxkVo.getBainxkVoList() != null) {
            bianxkVo.getBainxkVoList().stream().forEach(item -> item.setHeadId(h.getId()));
            bianxkService.saveBatch(bianxkVo.getBainxkVoList());
        }
 
        return AjaxResult.success(h.getId());
 
    }
    @ApiOperation("编辑数据")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BianxkVo bianxkVo) {
        //新增或者更新
 
        Head h2 = bianxkVo.getHead();
        h2.setId("");
        Head hh = headService.insert(h2);
        if (bianxkVo.getBainxkVoList() != null) {
 
            bianxkVo.getBainxkVoList().stream().forEach(item -> item.setHeadId(hh.getId()));
            bianxkService.saveOrUpdateBatch(bianxkVo.getBainxkVoList());
        }
 
        return AjaxResult.success(hh.getId());
 
    }
    //删除接口
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Integer id) {
        return bianxkService.removeById(id);
    }
 
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/id")
    public AjaxResult queryById(String id) {
        BianxkVo hanjiVo = new BianxkVo();
        Head head = headService.queryById(id);
 
        if (head == null) return AjaxResult.error("访问无数据");
        hanjiVo.setHead(head);
 
 
        hanjiVo.setBainxkVoList(bianxkService.queryByHeadId(head.getId()));
 
        return AjaxResult.success(hanjiVo);
    }
    //查询所有内容接口
    @GetMapping("/list")
    public List<Bianxk> findAll() {
        return bianxkService.list();
    }
 
    //根据id查询
    @GetMapping("/{id}")
    public Bianxk findOne(@PathVariable Integer id) {
        return bianxkService.getById(id);
    }
 
    //分页查询
    @GetMapping("/page")
    public IPage<Bianxk> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        //此处没有写查询条件逻辑,因为太活了,所有不在模板中写了
        IPage<Bianxk> page = new Page<>(pageNum, pageSize);  //新建一个page
        QueryWrapper<Bianxk> queryWrapper = new QueryWrapper<>();  //新建一个queryWrapper
 
        queryWrapper.orderByDesc("id");   //通过id倒序显示
        return bianxkService.page(page, queryWrapper);  //返回分页
    }
    /**
     * 获取最新数据
     *
     * @return 实例对象
     */
    @ApiOperation("获取最新数据")
    @PostMapping("/last")
    public AjaxResult getlastRecord(@RequestBody  String 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("A0",myMap.get(j.getString("leixing")));
        if (head == null) return AjaxResult.error("访问无数据");
        BianxkVo hanjiVo = new BianxkVo();
        hanjiVo.setHead(head);
 
        hanjiVo.setBainxkVoList(bianxkService.queryByHeadId(head.getId()));
        return AjaxResult.success(hanjiVo);
    }
 
 
 
}