yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
package com.qianwen.smartman.modules.cps.controller;
 
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
 
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.scanner.modular.annotation.DeleteResource;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.scanner.modular.annotation.PutResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.api.ResultCode;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.ShiftConvert;
import com.qianwen.smartman.modules.cps.entity.ShiftModel;
import com.qianwen.smartman.modules.cps.service.IShiftModelService;
import com.qianwen.smartman.modules.cps.vo.ShiftIndexNameVO;
import com.qianwen.smartman.modules.cps.vo.ShiftModelSearchVO;
import com.qianwen.smartman.modules.cps.vo.ShiftModelVO;
import com.qianwen.smartman.modules.cps.vo.ShiftSaveVO;
import com.qianwen.smartman.modules.cps.vo.ShiftSimpleVO;
import com.qianwen.smartman.modules.cps.vo.ShiftUpdateBasicVO;
import com.qianwen.smartman.modules.cps.vo.ShiftUpdateVO;
import com.qianwen.smartman.modules.cps.vo.ShiftVO;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
 
@ApiResource({"smis/shift"})
@Api(value = "班次", tags = {"班次"})
@RestController
public class ShiftController extends BladeController {
    private final IShiftModelService shiftModelService;
 
 
    public ShiftController(IShiftModelService shiftModelService) {
        this.shiftModelService = shiftModelService;
    }
 
    @PreAuth
    @PostResource
    @ApiOperation("新建班次模型")
    public R<ShiftModelVO> saveShift(@Validated @RequestBody ShiftSaveVO shiftSaveVO) {
        return R.data(ShiftConvert.INSTANCE.convert(this.shiftModelService.saveShift(shiftSaveVO)));
    }
 
    @PreAuth
    @PutResource
    @ApiOperation("编辑班次模型")
    public R<ShiftModelVO> updateShift(@Validated @RequestBody ShiftUpdateVO shiftUpdateVO) {
        return R.data(ShiftConvert.INSTANCE.convert(this.shiftModelService.update(shiftUpdateVO)));
    }
 
    @PreAuth
    @PutResource({"/updateBasic"})
    @ApiOperation("编辑班次模型基础信息")
    public R<ShiftModelVO> updateShiftBasic(@RequestBody ShiftUpdateBasicVO shiftUpdateBasicVO) {
        return R.data(ShiftConvert.INSTANCE.convert(this.shiftModelService.updateShiftBasic(shiftUpdateBasicVO)));
    }
 
    @PreAuth
    @DeleteResource({"/{id}"})
    @ApiOperation("删除班次模型")
    public R<Void> deleteShift(@PathVariable String id) {
        this.shiftModelService.deleteShift(id);
        return R.success(ResultCode.SUCCESS);
    }
 
    @PreAuth
    @PostResource({"/page"})
    @ApiOperation(value = "分页查询班次模型", notes = "传入分页条件")
    public R<IPage<ShiftSimpleVO>> getPageShift(Query query, @Validated @RequestBody ShiftModelSearchVO shiftModelSearchVO) {
        //return 
        return Optional.<IPage<ShiftModel>>ofNullable(this.shiftModelService.page(Condition.getPage(query), Wrappers.<ShiftModel>query().lambda()
                  .in(ShiftModel::getStatus, shiftModelSearchVO.getStatusList())
                  .eq(ShiftModel::getTenantId, AuthUtil.getTenantId())
                  .like(Func.isNotEmpty(shiftModelSearchVO.getCode()), ShiftModel::getCode, shiftModelSearchVO.getCode())
                  .like(Func.isNotEmpty(shiftModelSearchVO.getName()), ShiftModel::getName, shiftModelSearchVO.getName())
                  .orderByDesc(ShiftModel::getCreateTime)))
              .map(iPage -> {
                  List<ShiftSimpleVO> list = iPage.getRecords().stream().map(ShiftConvert.INSTANCE::convertSimple).collect(Collectors.toList());
                  IPage<ShiftSimpleVO> page = new Page<>();
                  BeanUtils.copyProperties(iPage, page);
                  page.setRecords(list);
                  return R.data(page);
                }).orElse(R.data(new Page<>()));
        /*
        return (R) Optional.ofNullable(this.shiftModelService.page(Condition.getPage(query), (Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().in((v0) -> {
            return v0.getStatus();
        }, shiftModelSearchVO.getStatusList())).eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId())).like(Func.isNotEmpty(shiftModelSearchVO.getCode()), (v0) -> {
            return v0.getCode();
        }, shiftModelSearchVO.getCode()).like(Func.isNotEmpty(shiftModelSearchVO.getName()), (v0) -> {
            return v0.getName();
        }, shiftModelSearchVO.getName()).orderByDesc((v0) -> {
            return v0.getCreateTime();
        }))).map(iPage -> {
            Stream stream = iPage.getRecords().stream();
            ShiftConvert shiftConvert = ShiftConvert.INSTANCE;
            shiftConvert.getClass();
            List<ShiftSimpleVO> list = (List) stream.map(this::convertSimple).collect(Collectors.toList());
            Page page = new Page();
            BeanUtils.copyProperties(iPage, page);
            page.setRecords(list);
            return R.data(page);
        }).orElse(R.data(new Page()));
        */
    }
 
    @PreAuth
    @PostResource({"/list"})
    @ApiOperation(value = "班次模型列表", notes = "班次模型列表")
    public R<List<ShiftSimpleVO>> getShiftList(@Validated @RequestBody ShiftModelSearchVO shiftModelSearchVO) {
        return R.data(this.shiftModelService.list(new QueryWrapper<ShiftModel>().lambda()
                  .in(ShiftModel::getStatus, shiftModelSearchVO.getStatusList())
                  .eq(ShiftModel::getTenantId, AuthUtil.getTenantId()))
                .stream()
                .map(ShiftConvert.INSTANCE::convertSimple)
                .collect(Collectors.toList()));
        /*
        Stream stream = this.shiftModelService.list((Wrapper) ((LambdaQueryWrapper) new QueryWrapper().lambda().in((v0) -> {
            return v0.getStatus();
        }, shiftModelSearchVO.getStatusList())).eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId())).stream();
        ShiftConvert shiftConvert = ShiftConvert.INSTANCE;
        shiftConvert.getClass();
        return R.data(stream.map(this::convertSimple).collect(Collectors.toList()));
        */
    }
 
    @PreAuth
    @GetResource({"/{id}"})
    @ApiOperation(value = "查询班次详情", notes = "传入id")
    public R<ShiftVO> getShiftDetail(@PathVariable String id) {
        return R.data(this.shiftModelService.getShiftDetail(Long.valueOf(id)));
    }
 
    @GetResource({"/shiftIndex/{id}"})
    @ApiOperation(value = "查询班次index详情", notes = "传入id")
    public R<List<Integer>> getShiftIndex(@PathVariable String id) {
        return R.data(this.shiftModelService.getShiftIndex(Long.valueOf(id)));
    }
 
    @GetResource({"/indexNames"})
    @ApiOperation(value = "查询租户下所有班次模型对应名称", notes = "查询租户下所有班次模型对应名称")
    public R<ShiftIndexNameVO> getShiftIndexName() {
        return R.data(this.shiftModelService.getShiftIndexName());
    }
}