package com.qianwen.mdc.controller.workshop;
|
|
import java.util.List;
|
|
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.SectionDTO;
|
import com.qianwen.mdc.service.section.SectionService;
|
import com.qianwen.mdc.vallidate.AddGroup;
|
import com.qianwen.mdc.vallidate.UpdateGroup;
|
|
/**
|
* @author y_ys79
|
* 工段数据维护控制器
|
*/
|
@RestController
|
@CrossOrigin
|
@RequestMapping(value = "/section")
|
public class SectionController {
|
@Autowired
|
private SectionService sectionService;
|
|
public static final Logger logger = LoggerFactory.getLogger(SectionController.class);
|
|
@PostMapping(value = "/create")
|
public OpResult<Void> create(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
|
@Validated(value = {AddGroup.class}) @RequestBody SectionDTO sectionDTO) {
|
|
try {
|
sectionService.save(sectionDTO);
|
}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 = {UpdateGroup.class}) @RequestBody SectionDTO sectionDTO) {
|
|
try {
|
sectionService.modify(sectionDTO);
|
}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 {
|
sectionService.delete(idsDTO);
|
}catch(Exception ex) {
|
logger.error("新增车间失败",ex);
|
return OpResult.fail(ex.getMessage());
|
}
|
|
return OpResult.success();
|
}
|
|
@GetMapping(value = "/listByWorkshop")
|
public OpResult<List<SectionDTO>> listByWorkshop(@RequestHeader(value = "mdc-token", defaultValue = "") String token,
|
Long workshopId) {
|
|
try {
|
return OpResult.success(sectionService.listByWorkshopId(workshopId));
|
}catch(Exception ex) {
|
logger.error("查询车间下属工段失败",ex);
|
return OpResult.fail(ex.getMessage());
|
}
|
}
|
}
|