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
package com.qianwen.smartman.modules.cps.controller;
 
import java.util.List;
import java.util.Optional;
 
import org.springframework.transaction.annotation.Transactional;
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.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.smartman.modules.cps.convert.ProductionCalendarConvert;
import com.qianwen.smartman.modules.cps.entity.ProductionCalendar;
import com.qianwen.smartman.modules.cps.service.ICalendarService;
import com.qianwen.smartman.modules.cps.vo.CalendarAssociateWorkstationVO;
import com.qianwen.smartman.modules.cps.vo.CalendarCopyVO;
import com.qianwen.smartman.modules.cps.vo.CalendarSaveVO;
import com.qianwen.smartman.modules.cps.vo.CalendarSearchVO;
import com.qianwen.smartman.modules.cps.vo.CalendarSimpleVO;
import com.qianwen.smartman.modules.cps.vo.CalendarUpdateVO;
import com.qianwen.smartman.modules.cps.vo.CalendarVO;
import com.qianwen.smartman.modules.cps.vo.ProductionCalendarVO;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
 
@ApiResource({"smis/calendar"})
@Api(value = "生产日历", tags = {"生产日历"})
@RestController
public class CalendarController extends BladeController {
    private final ICalendarService calendarService;
 
 
    public CalendarController(ICalendarService calendarService) {
        this.calendarService = calendarService;
    }
 
    @PreAuth
    @PostResource
    @ApiOperation("新建生产日历")
    public R<ProductionCalendarVO> saveCalendar(@Validated @RequestBody CalendarSaveVO calendarSaveVO) {
        return R.data(ProductionCalendarConvert.INSTANCE.convert(this.calendarService.saveCalendar(calendarSaveVO)));
    }
 
    @PostResource({"/sync"})
    @ApiOperation("新建全年的生产日历")
    @Transactional(rollbackFor = {Exception.class})
    @PreAuth
    public ProductionCalendarVO syncCalendar(@Validated @RequestBody CalendarSaveVO calendarSaveVO) {
        return ProductionCalendarConvert.INSTANCE.convert(this.calendarService.saveYearCalendar(calendarSaveVO));
    }
 
    @PutResource
    @ApiOperation("编辑生产日历日期")
    @Transactional(rollbackFor = {Exception.class})
    @PreAuth
    public R<ProductionCalendarVO> updateCalendar(@Validated @RequestBody CalendarUpdateVO calendarUpdateVO) {
        return R.data(ProductionCalendarConvert.INSTANCE.convert(this.calendarService.updateCalendar(calendarUpdateVO)));
    }
 
    @PostResource({"/copy"})
    @ApiOperation("复制生产日历")
    public R<ProductionCalendarVO> copyCalendar(@Validated @RequestBody CalendarCopyVO calendarCopyVO) {
        return R.data(ProductionCalendarConvert.INSTANCE.convert(this.calendarService.copyCalendar(calendarCopyVO)));
    }
 
    @PreAuth
    @PutResource({"/rename"})
    @ApiOperation("生产日历重命名")
    public R<ProductionCalendarVO> rename(String name, String id, Integer status) {
        ProductionCalendar productionCalendar = new ProductionCalendar();
        productionCalendar.setId(Long.valueOf(id));
        productionCalendar.setName(name);
        this.calendarService.updateById(productionCalendar);
        return R.data(ProductionCalendarConvert.INSTANCE.convert(productionCalendar));
    }
 
    @PreAuth
    @PostResource({"/page"})
    @ApiOperation(value = "分页查询生产日历", notes = "传入分页条件")
    public R<IPage<CalendarSimpleVO>> getPageCalendar(Query query, @Validated @RequestBody CalendarSearchVO calendarSearchVO) {
        
        return Optional.<IPage<ProductionCalendar>>ofNullable(this.calendarService.page(Condition.getPage(query), Wrappers.<ProductionCalendar>query().lambda()
                  .eq(ProductionCalendar::getTenantId, AuthUtil.getTenantId())
                  .in(ProductionCalendar::getStatus, calendarSearchVO.getStatusList())
                  .orderByDesc(ProductionCalendar::getCreateTime)))
                
              .map(calendar -> {
                  
                  IPage<CalendarSimpleVO> page = new Page<>(calendar.getCurrent(), calendar.getSize(), calendar.getTotal());
                  page.setRecords(ProductionCalendarConvert.INSTANCE.convert(calendar.getRecords()));
                  return R.data(page);
                }).orElse(R.data(new Page<>()));
        /*
        return (R) Optional.ofNullable(this.calendarService.page(Condition.getPage(query), (Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId())).in((v0) -> {
            return v0.getStatus();
        }, calendarSearchVO.getStatusList())).orderByDesc((v0) -> {
            return v0.getCreateTime();
        }))).map(calendar -> {
            Page page = new Page(calendar.getCurrent(), calendar.getSize(), calendar.getTotal());
            page.setRecords(ProductionCalendarConvert.INSTANCE.convert(calendar.getRecords()));
            return R.data(page);
        }).orElse(R.data(new Page()));*/
    }
 
    @GetResource({"/list"})
    @ApiOperation(value = "生产日历列表", notes = "生产日历列表")
    public R<List<CalendarSimpleVO>> listCalendars() {
        return R.data(ProductionCalendarConvert.INSTANCE.convert(this.calendarService
                  .list(Wrappers.<ProductionCalendar>query().lambda().eq(ProductionCalendar::getTenantId, AuthUtil.getTenantId())
                    .eq(ProductionCalendar::getStatus, 1).orderByDesc(ProductionCalendar::getCreateTime))));
        
    }
 
    @PreAuth
    @GetResource({"/{id}"})
    @ApiOperation(value = "查询生产日历详情", notes = "传入id")
    public R<CalendarVO> getCalendarDetail(@PathVariable String id) {
        return R.data(this.calendarService.getCalendar(Long.valueOf(id)));
    }
 
    @PreAuth
    @DeleteResource({"/{id}"})
    @ApiOperation(value = "删除生产日历", notes = "传入id")
    public R<Boolean> deleteCalendar(@PathVariable String id) {
        return R.data(this.calendarService.deleteCalendar(Long.valueOf(id)));
    }
 
    @GetResource({"/expire/info"})
    @ApiOperation(value = "查询快过期生产日历提示", notes = "查询快过期生产日历提示")
    public R<String> expireCalendarInfo() {
        return R.data(this.calendarService.expireCalendarInfo());
    }
 
    @PostResource({"/associate-workstation"})
    @ApiOperation(value = "生产日历关联工位", notes = "生产日历关联工位")
    public R<Boolean> associateWorkstation(@RequestBody CalendarAssociateWorkstationVO calendarAssociateWorkstationVO) {
        return R.data(this.calendarService.associateWorkstation(calendarAssociateWorkstationVO));
    }
}