y_ys79
2024-01-05 e5840972b6b17ec03bfc1069a9cacfe0cef189c6
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.qianwen.mdc.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianwen.mdc.domain.maintain.*;
import com.qianwen.mdc.dto.MachineMaintainDTO;
import com.qianwen.mdc.dto.MachineMaintainFullDTO;
import com.qianwen.mdc.dto.MachineMaintainQueryDTO;
import com.qianwen.mdc.common.OpResult;
import com.qianwen.mdc.domain.*;
import com.qianwen.mdc.mapper.*;
import com.qianwen.mdc.service.impl.MdcTokenServiceImpl;
import com.qianwen.mdc.service.maintain.MachineMaintainAddService;
import com.qianwen.mdc.service.maintain.MachineMaintainEditService;
import com.qianwen.mdc.service.maintain.MachineMaintainQueryService;
import com.qianwen.mdc.service.sysaccount.AccountTokenService;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.List;
 
/**
 * 设备保养控制器
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/maintain", method = RequestMethod.POST)
public class MachineMaintainController {
    @Autowired
    private AccountTokenMapper mdcTokenMapper;
    @Autowired
    private SysAccountMapper mdcUserMapper;
    @Autowired
    private MachineMapper mdcMachineMapper;
    @Autowired
    private MdcMachineAccountMapper mdcMachineAccountMapper;
    @Autowired
    private MachineMaintainMapper mdcMachineMaintainMapper;
    
    @Autowired
    private MachineMaintainAddService addService;
    @Autowired
    private MachineMaintainEditService editService;
    @Autowired
    private MachineMaintainQueryService queryService;
    @Autowired
    private AccountTokenService accountTokenService;
 
    public static final Logger logger = LoggerFactory.getLogger(MachineMaintainController.class);
    
    /**
     * 新增设备保养
     * @param token
     * @param request
     * @return
     */
    @PostMapping(value = "/save")
    public OpResult<Void> save(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            MachineMaintainDTO dto,HttpServletRequest request) {
        /*
        AccountToken mdcTokenObj = new AccountToken();
        mdcTokenObj.setToken(token);
        AccountToken mdcToken = mdcTokenMapper.selectOne(mdcTokenObj);
        JSONObject tokenResult = MdcTokenServiceImpl.genTokenErrMsg(mdcToken);
        if (tokenResult != null) {
            return tokenResult;
        }
 
        mdcToken.setExpireTime(MdcTokenServiceImpl.genExpiredTime());
        mdcTokenMapper.updateByPrimaryKeySelective(mdcToken);
    */
        //JSONObject jsonResult = new JSONObject();
        //jsonResult.put("result", "SUCCESS");
        /*
        String style = request.getParameter("style");
        String machineName = request.getParameter("machineName");
        String userName = request.getParameter("userName");
        String uuid = request.getParameter("uuid");
        String type = request.getParameter("type");
        String startDateFrom = request.getParameter("startDateFrom");
        String startDateTo = request.getParameter("startDateTo");
        String completeDateFrom = request.getParameter("completeDateFrom");
        String completeDateTo = request.getParameter("completeDateTo");
        String isQualified = request.getParameter("isQualified");
        String state = request.getParameter("state");
        String detail = request.getParameter("detail");
        */
        /*
        MachineMaintain mdcMachineMaintainObj = new MachineMaintain();
 
        Machine mdcMachineObj = new Machine();
        mdcMachineObj.setName(machineName);
        Machine mdcMachine = mdcMachineMapper.selectOne(mdcMachineObj);
        if (mdcMachine != null) {
            mdcMachineMaintainObj.setMachineId(mdcMachine.getId());
        }
 
        if ((style != null) && (!style.equals(""))) {
            MdcUser mdcUserObj = new MdcUser();
            mdcUserObj.setName(userName);
            MdcUser mdcUser = mdcUserMapper.selectOne(mdcUserObj);
            if (mdcUser != null) {
                mdcMachineMaintainObj.setUserId(mdcUser.getId());
            }
        }
 
        if ((style != null) && (!style.equals(""))) {
            mdcMachineMaintainObj.setStyle(Integer.parseInt(style));
        }
 
        mdcMachineMaintainObj.setUuid(uuid);
        mdcMachineMaintainObj.setType(type);
 
        if ((isQualified != null) && (!isQualified.equals(""))) {
            if (!isQualified.equals("0")) {
                mdcMachineMaintainObj.setIsQualified(true);
            } else {
                mdcMachineMaintainObj.setIsQualified(false);
            }
        }
 
        mdcMachineMaintainObj.setState(state);
        mdcMachineMaintainObj.setDetail(detail);
 
        */
        try {
            accountTokenService.checkToken(token);
            
            addService.save(dto);
        }catch(DomainException ex) {
            return OpResult.fail(ex.getMessage());
        }catch(Exception ex) {
            return OpResult.fail(ex.getMessage());
        }
        return OpResult.success();
    }
 
    @PostMapping(value = "/pageQuery")
    public OpResult<Page<MachineMaintainFullDTO>> pageQuery(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            MachineMaintainQueryDTO dto) {
        try {
            return OpResult.success(queryService.pageQuery(dto));
        }catch(Exception e) {
            logger.error("维护分页查询异常",e);
            return OpResult.fail(e.getMessage());
        }
    }
    
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public OpResult<Void> modify(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            MachineMaintainDTO dto,HttpServletRequest request) {
        accountTokenService.checkToken(token);
        
        //TODO
        //mdcMachineMaintainMapper.updateByPrimaryKeySelective(mdcMachineMaintainObj);
        try {
            editService.modify(dto);
            return OpResult.success();
        }catch(Exception e) {
            return OpResult.fail(e.getMessage());
        }
    }
 
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public OpResult<Void> delete(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
            @RequestParam List<Integer> ids, HttpServletRequest request) {
        accountTokenService.checkToken(token);
 
        JSONObject jsonResult = new JSONObject();
        jsonResult.put("result", "SUCCESS");
 
        try {
            editService.delete(ids);
            return OpResult.success();
        }catch(Exception e) {
            return OpResult.fail(e.getMessage());
        }
    }
 
    
}