yangys
2024-02-02 d8ee16afd15fcf8a40b220b5b94e3be8ecbda0fc
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
package com.qianwen.mdc.controller.workshop;
 
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.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.workshop.WorkshopDTO;
import com.qianwen.mdc.service.workshop.WorkshopEditService;
import com.qianwen.mdc.service.workshop.WorkshopService;
 
/**
 * @author y_ys79
 * 车间修改控制器
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/workshop")
public class WorkshopEditController {
    @Autowired
    private WorkshopEditService editService;
    @Autowired
    private WorkshopService workshopService;
    
    public static final Logger logger = LoggerFactory.getLogger(WorkshopEditController.class);
    
    @PostMapping(value = "/create")
    public OpResult<Void> create(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @Validated(value = {Default.class}) @RequestBody WorkshopDTO workshopDTO) {
        
        try {
            editService.save(workshopDTO);
        }catch(Exception ex) {
            logger.error("新增车间失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
        return OpResult.success();
    }
    
    @PostMapping(value = "/update")
    public OpResult<Void> update(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @Validated(value = {Default.class}) @RequestBody WorkshopDTO workshopDTO) {
        
        try {
            editService.modify(workshopDTO);
        }catch(Exception ex) {
            logger.error("新增车间失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
        return OpResult.success();
    }
    
    @PostMapping(value = "/delete")
    public OpResult<Void> delete(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @Validated @RequestBody IdsDTO idsDTO) {
        
        try {
            editService.delete(idsDTO);
        }catch(Exception ex) {
            logger.error("新增车间失败",ex);
            return OpResult.fail(ex.getMessage());
        }
 
        return OpResult.success();
    }
    
}