wjli
2023-05-25 13c9e4032de40598787a453de77ba0db94666664
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
package cn.exrick.xboot.your.controller;
 
import cn.exrick.xboot.core.common.utils.PageUtil;
import cn.exrick.xboot.core.common.utils.ResultUtil;
import cn.exrick.xboot.core.common.vo.PageVo;
import cn.exrick.xboot.core.common.vo.Result;
import cn.exrick.xboot.your.entity.Area;
import cn.exrick.xboot.your.entity.Car;
import cn.exrick.xboot.your.service.IAreaService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author zhangzeli
 */
@Slf4j
@RestController
@Api(tags = "配送片区管理接口")
@RequestMapping("/xboot/area")
@Transactional
public class AreaController {
 
    @Autowired
    private IAreaService iAreaService;
 
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<Area> get(@PathVariable String id) {
 
        Area area = iAreaService.getById(id);
        return new ResultUtil<Area>().setData(area);
    }
 
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ApiOperation(value = "获取全部数据")
    public Result<List<Area>> getAll() {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("name");
        List<Area> list = iAreaService.list();
        return new ResultUtil<List<Area>>().setData(list);
    }
    @RequestMapping(value = "/getAllAreas", method = RequestMethod.GET)
    @ApiOperation(value = "获取所有区域数据")
    public Result<List<String>> getAllAreas(){
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("name");
        List<String> names = new ArrayList<>();
        List<Area> list = iAreaService.list();
        for (Area area:list ) {
           String name = area.getName();
          /* int wz = name.indexOf("0");
           if(wz>0){
               name = name.substring(0,wz);
           }*/
 
            name = name
                   .replace("01车","")
                   .replace("02车","")
                   .replace("03车","")
                   .replace("04车","")
                   .replace("05车","")
                   .replace("06车","")
                    .replace("07车","")
                    .replace("08车","")
                    .replace("09车","")
                    .replace("10车","")
                    .replace("11车","")
                    .replace("12车","")
                    .replace("13车","")
                    .replace("14车","")
                    .replace("15车","");
            name = name
                    .replace("01","")
                    .replace("02","")
                    .replace("03","")
                    .replace("04","")
                    .replace("05","")
                    .replace("06","")
                    .replace("07","")
                    .replace("08","")
                    .replace("09","")
                    .replace("10","")
                    .replace("11","")
                    .replace("12","")
                    .replace("13","")
                    .replace("14","")
                    .replace("15","");
           if(!names.contains(name)){
               names.add(name);
           }
        }
        return new ResultUtil<List<String>>().setData(names);
    }
 
    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<Area>> getByPage(String name,PageVo page) {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        if (!StrUtil.isEmpty(name))
            wrapper.like("a.name",name);
        IPage<Area> data = iAreaService.page2(PageUtil.initMpPage(page),wrapper);
        return new ResultUtil<IPage<Area>>().setData(data);
    }
 
    @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "编辑或更新数据")
    public Result<Area> saveOrUpdate(Area area) {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(area.getCarId())){
            wrapper.eq("car_id",area.getCarId());
            Area area1 = iAreaService.getOne(wrapper);
            if (area1 != null && !area.getId().equals(area1.getId())){
                return new ResultUtil<Area>().setErrorMsg("该车辆已被其它片区绑定,请先解绑");
            }
        }
 
        if (iAreaService.saveOrUpdate(area)) {
            return new ResultUtil<Area>().setData(area);
        }
        return new ResultUtil<Area>().setErrorMsg("操作失败");
    }
 
    @RequestMapping(value = "/delByIds", method = RequestMethod.POST)
    @ApiOperation(value = "批量通过id删除")
    public Result<Object> delAllByIds(@RequestParam String[] ids) {
 
        for (String id : ids) {
            iAreaService.removeById(id);
        }
        return ResultUtil.success("批量通过id删除数据成功");
    }
}