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();
|
}
|
|
}
|