¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.limslaboratory.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.limslaboratory.pojo.Instrument; |
| | | import com.yuanchu.limslaboratory.pojo.dto.UpdateInstrumentDto; |
| | | import com.yuanchu.limslaboratory.service.InstrumentService; |
| | | import com.yuanchu.limslaboratory.service.UserService; |
| | | import com.yuanchu.limslaboratory.utils.JackSonUtil; |
| | | import com.yuanchu.limslaboratory.utils.RedisUtil; |
| | | import com.yuanchu.limslaboratory.vo.Result; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | | * å端æ§å¶å¨ |
| | | * </p> |
| | | * |
| | | * @author æ±èéµ·éç½ç»ç§ææéå
¬å¸ |
| | | * @since 2023-07-20 |
| | | */ |
| | | @Api(tags = "å®éªå®¤-->1ã设å¤å°è´¦-->2ãä»ªå¨æ¨¡å") |
| | | @RestController |
| | | @RequestMapping("/instrument") |
| | | public class InstrumentController { |
| | | |
| | | @Autowired |
| | | private InstrumentService instrumentService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @ApiOperation("æ·»å 仪å¨è®¾å¤") |
| | | @PostMapping("/add") |
| | | public Result<?> addInstrumentInformation(@RequestHeader("X-Token") String token, @RequestBody Instrument instrument) throws Exception { |
| | | Object object = RedisUtil.get(token); |
| | | Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class); |
| | | instrument.setCreateUserId((Integer) unmarshal.get("id")); |
| | | Integer isInsertSuccess = instrumentService.addInstrumentInformation(instrument); |
| | | if (isInsertSuccess == 1){ |
| | | return Result.success("æ·»å ã" + instrument.getEquipmentName() + "ãæå!"); |
| | | } |
| | | return Result.fail("仪å¨è®¾å¤ç¼å·éå¤ï¼æ·»å ã" + instrument.getEquipmentName() + "ã失败! "); |
| | | } |
| | | |
| | | @ApiOperation("æ ¹æ®åç±»Idï¼å页å表å±ç¤º") |
| | | @GetMapping("/list") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "classifyId", value = "åç±»Id", dataTypeClass = Integer.class, required = true), |
| | | @ApiImplicitParam(name = "pageNo", value = "èµ·å§é¡µ", dataTypeClass = Integer.class, required = true), |
| | | @ApiImplicitParam(name = "pageSize", value = "æ¯ä¸é¡µæ°é", dataTypeClass = Integer.class, required = true), |
| | | @ApiImplicitParam(name = "conditions", value = "æ¥è¯¢ç¶æ:é»è®¤å
¨é¨", dataTypeClass = Integer.class), |
| | | @ApiImplicitParam(name = "whetherWhether", value = "æ¯å¦å·²è¿æ", dataTypeClass = Boolean.class), |
| | | @ApiImplicitParam(name = "numberOrNameOrSpecifications", value = "ç¼å·/设å¤åç§°/è§æ ¼åå·", dataTypeClass = String.class) |
| | | }) |
| | | public Result<?> getListInstrumentInformation(Integer pageNo, |
| | | Integer pageSize, |
| | | Integer conditions, |
| | | Integer classifyId, |
| | | Boolean whetherWhether, |
| | | String numberOrNameOrSpecifications) { |
| | | IPage<Map<String, Object>> pageList = instrumentService.getListInstrumentInformation(conditions, whetherWhether, numberOrNameOrSpecifications, |
| | | classifyId, new Page<Objects>(pageNo, pageSize)); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("row", pageList.getRecords()); |
| | | map.put("total", pageList.getTotal()); |
| | | return Result.success(map); |
| | | } |
| | | |
| | | @ApiOperation("å é¤ä»ªå¨æ°æ®") |
| | | @DeleteMapping("/delete") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "instrumentId", value = "仪å¨Id", dataTypeClass = String.class, required = true) |
| | | }) |
| | | public Result<?> deleteInstrumentInformation(String instrumentId) { |
| | | Boolean isDeleteSuccess = instrumentService.deleteInstrumentInformation(instrumentId); |
| | | if (isDeleteSuccess){ |
| | | return Result.success("å é¤ä»ªå¨æåï¼"); |
| | | } |
| | | return Result.fail("å é¤ä»ªå¨å¤±è´¥ï¼"); |
| | | } |
| | | |
| | | @ApiOperation("æ·»å ä»ªå¨æ¶ä¿ç®¡äººä¸ææ¡æ°æ®") |
| | | @GetMapping("/get_user") |
| | | public Result<?> getMapUserInformation() { |
| | | return Result.success(userService.getUserNameAndId()); |
| | | } |
| | | |
| | | @ApiOperation("æ ¹æ®ä»ªå¨Idè·åä¿¡æ¯ç¨äºç¼è¾") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "InstrumentId", value = "åç±»Id", dataTypeClass = Integer.class, required = true) |
| | | }) |
| | | @GetMapping("/get_instrument") |
| | | public Result<?> getIdInstrumentInformation(Integer InstrumentId) { |
| | | Instrument idInstrumentInformation = instrumentService.getIdInstrumentInformation(InstrumentId); |
| | | return Result.success(idInstrumentInformation); |
| | | } |
| | | |
| | | @ApiOperation("æ ¹æ®ä»ªå¨Idæ´æ°æ°æ®") |
| | | @PutMapping("/update") |
| | | public Result<?> updateEquipmentPointInformation(@RequestBody UpdateInstrumentDto updateInstrumentDto) throws Exception { |
| | | Instrument instrument = JackSonUtil.unmarshal(JackSonUtil.marshal(updateInstrumentDto), Instrument.class); |
| | | Integer isUpdateSuccess = instrumentService.updateEquipmentPointInformation(instrument); |
| | | if (isUpdateSuccess == 1){ |
| | | return Result.success("æ´æ°ã" + instrument.getEquipmentName() + "ãæå!"); |
| | | } |
| | | return Result.fail("仪å¨è®¾å¤ç¼å·éå¤ï¼æ´æ°ã" + instrument.getEquipmentName() + "ã失败! "); |
| | | } |
| | | } |