package com.gkhy.safePlatform.equipment.controller; import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq; import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery; import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto; import com.gkhy.safePlatform.equipment.service.MaterialClassifyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/equipment/classify") public class MaterialClassifyController { @Autowired private MaterialClassifyService materialClassifyService; /** * 列表 * @return */ @PostMapping(value = "/list") public ResultVO> list(Authentication authentication){ ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); return new ResultVO<>(ResultCodes.OK,materialClassifyService.list()); } /** * 新增 * @return */ @PostMapping(value = "save") public ResultVO save(Authentication authentication, @Validated @RequestBody SafeMaterialClassifyAddReq req){ ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); return materialClassifyService.save(currentUser,req); } /** * 更新 * @return */ @PostMapping(value = "update") public ResultVO update(Authentication authentication, @Validated @RequestBody SafeMaterialClassifyModReq req){ ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); return materialClassifyService.update(currentUser,req); } /** * 逻辑删除 单条 * @return */ @PostMapping(value = "delete") public ResultVO delete(Authentication authentication, @RequestBody JSONObject jsonObject){ ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); Long id = jsonObject.getLong("id"); return materialClassifyService.delete(id); } /** * 查询单条数据 */ @PostMapping(value = "queryById") public ResultVO queryById(Authentication authentication, @RequestBody JSONObject jsonObject){ Long id = jsonObject.getLong("id"); return new ResultVO<>(ResultCodes.OK,materialClassifyService.queryById(id)); } }