package com.steerinfo.ems.tcm0325.controller; import com.steerinfo.auth.utils.JwtUtil; import com.steerinfo.ems.tcm0310.model.TCm0310; import com.steerinfo.ems.tcm0325.mapper.TCm0325Mapper; import com.steerinfo.ems.tcm0325.model.TCm0325; import com.steerinfo.ems.tcm0325.service.ITCm0325Service; import com.steerinfo.framework.controller.BaseRESTfulController; import com.steerinfo.framework.controller.RESTfulResult; import com.steerinfo.framework.service.pagehelper.PageList; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Arrays; import java.util.HashMap; import java.util.Set; @RestController @RequestMapping("/${api.version}/tcm0325s") public class TCm0325Controller extends BaseRESTfulController { private static final Logger LOGGER = LoggerFactory.getLogger(TCm0325Controller.class); @Autowired ITCm0325Service tCm0325Service; @Autowired TCm0325Mapper tCm0325Mapper; @ApiOperation(value="获取列表", notes="分页查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) //@RequiresPermissions("trmunit:view") @GetMapping(value = "/") public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){ PageList list = tCm0325Service.queryForPage(parmas, pageNum, pageSize); return success(list); } @ApiOperation(value="获取列表", notes="分页模糊查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) //@RequiresPermissions("tpmcaseact:view") @GetMapping(value = "/like/") public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){ PageList list = tCm0325Service.queryLikeForPage(parmas, pageNum, pageSize); return success(list); } @ApiOperation(value="创建", notes="根据tCm0325对象创建") @ApiImplicitParam(name = "tCm0325", value = "详细实体tCm0325", required = true, dataType = "TCm0325") //@RequiresPermissions("trmunit:create") @PostMapping(value = "/") public RESTfulResult add(@ModelAttribute TCm0325 model){ if (null == model.getPowercode() || "".equals(model.getPowercode())) { Long maxid = tCm0325Service.getMaxId() == null ? 1 : Long.parseLong(tCm0325Service.getMaxId()) + 1; model.setPowercode("P" + String.format("%05d", maxid)); } model.setSort(tCm0325Service.getMaxSort()==null? 1 : tCm0325Service.getMaxSort() + 1); model.setPowername(model.getPowername()); TCm0325 tCm0325 = tCm0325Service.add(model); return success(tCm0325); } @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息") @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String") //@RequiresPermissions("trmunit:view") @GetMapping(value = "/{id}") public RESTfulResult get(@PathVariable String id){ TCm0325 tCm0325 = tCm0325Service.getById(id); return success(tCm0325); } @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的tCm0325信息来更新详细信息") @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"), @ApiImplicitParam(name = "tCm0325", value = "详细实体tCm0325", required = true, dataType = "TCm0325") }) //@RequiresPermissions("trmunit:update") @PutMapping(produces = "application/json;charset=UTF-8") public RESTfulResult update(@RequestBody TCm0325[] models){ for (TCm0325 model : models) { tCm0325Mapper.updateByPrimaryKeySelective(model); } return success(null,"修改成功"); } @ApiOperation(value="删除", notes="根据url的id来指定删除对象") @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String") //@RequiresPermissions("trmunit:delete") @DeleteMapping( produces = "application/json;charset=UTF-8")//String public RESTfulResult delete(@RequestBody TCm0325[] models){ for (TCm0325 model : models) { tCm0325Mapper.deleteByPrimaryKey(model.getPowercode()); } return success(); } @ApiOperation(value = "获取 code 和 Name",notes = "获取下拉框得值") @GetMapping(value = "/getCodeAndName") public RESTfulResult getCodeAndName(){ Set codeAndName = tCm0325Service.getCodeAndName(); return success(codeAndName); } }