yangys
2024-02-02 b82c71a3e3a97a78bd18ff598d27f3062600d22a
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
package com.qianwen.mdc.controller.machine;
 
import java.util.List;
 
import javax.validation.groups.Default;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.qianwen.mdc.common.OpResult;
import com.qianwen.mdc.dto.IdsDTO;
import com.qianwen.mdc.dto.MachineProtocolDTO;
import com.qianwen.mdc.dto.machine.MachineDTO;
import com.qianwen.mdc.dto.workshop.WorkshopDTO;
import com.qianwen.mdc.service.machine.MachineEditService;
import com.qianwen.mdc.service.workshop.WorkshopService;
 
/**
 * @author y_ys79
 * 机床设备修改控制器
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/machine")
public class MachineEditController {
    @Autowired
    private MachineEditService editService;
    @Autowired
    private WorkshopService workshopService;
    
    public static final Logger logger = LoggerFactory.getLogger(MachineEditController.class);
    
    @PostMapping(value = "/modify")
    public OpResult<Void> modify(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @Validated(value = {Default.class}) @RequestBody MachineDTO machineDTO) {
        
        try {
            editService.modify(machineDTO);
        }catch(Exception ex) {
            logger.error("新增机床失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
        return OpResult.success();
    }
    
 
    /**
     * 查询所有车间的列表,含内部工段
     * @param token
     * @param machineDTO
     * @param request
     * @return
     */
    @GetMapping(value = "/workshopList")
    public OpResult<List<WorkshopDTO>> workshopList(@RequestHeader(value = "mdc-token", defaultValue = "") String token) {
        
        try {
            return OpResult.success(workshopService.listWithSections());
        }catch(Exception ex) {
            logger.error("获取车间和工段数据失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
    }
    
    
    @GetMapping(value = "/protocolList")
    public OpResult<List<MachineProtocolDTO>> protocolList(@RequestHeader(value = "mdc-token", defaultValue = "") String token) {
        
        try {
            return OpResult.success(editService.machineProtocolList());
        }catch(Exception ex) {
            logger.error("获取采集协议数据失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
    }
    
    /**
     * 删除设备,应该不需要了
     * @param token
     * @param id
     * @param request
     * @return
     */
    //@PostMapping(value = "/delete")
    public OpResult<Void> delete(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @RequestBody IdsDTO dto) {
        
        try {
            //editService.delete(dto.getIds());
        }catch(Exception ex) {
            logger.error("删除机床失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
        return OpResult.success();
    }
   
    /**
     * 给机床设置关注标记
     * @param token
     * @param dto 包含id,concern参数
     * @return
     */
    @PostMapping(value = "/concern")
    public OpResult<Void> switchConcern(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @RequestBody MachineDTO dto) {
       //Integer id,int concern
        try {
            editService.switchConcern(dto.getId(),dto.getConcern());
        }catch(Exception ex) {
            logger.error("机床设置关注失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
        return OpResult.success();
    }
 
}