package com.terra.system.controller.sys; import com.terra.system.annotation.SysLog; import com.terra.system.controller.all.BaseController; import com.terra.system.entity.all.ResponseMsg; import com.terra.system.entity.sys.DepEntity; import com.terra.system.entity.sys.UserEntity; import com.terra.system.helper.StringHelper; import com.terra.system.service.sys.DepService; import com.terra.system.service.sys.TokenService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import javax.annotation.Resource; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * 组织机构 * @author sws * @date 2022-09-23 */ @Tag(name = "运维管理\\单位管理") @RestController @RequestMapping("/dep") public class DepController extends BaseController { @Resource DepService depService; @Resource TokenService tokenService; @SysLog() @Operation(summary = "插入一条") @Parameters({ @Parameter(name = "entity", description = "实体类", example = "") }) @PostMapping(value = "/insertDep", produces = "application/json; charset=UTF-8") public ResponseMsg insertDep(@RequestBody DepEntity entity, HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue != null) { entity.setCreateUser(ue.getId()); } int count = depService.insertDep(entity); return success(count); } catch (Exception ex) { return fail(ex, -1); } } @SysLog() @Operation(summary = "插入多条") @Parameters({ @Parameter(name = "list", description = "实体类集合", example = "") }) @PostMapping(value = "/insertDes", produces = "application/json; charset=UTF-8") public ResponseMsg insertDes(@RequestBody List list, HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue != null) { for (DepEntity entity : list) { entity.setCreateUser(ue.getId()); } } int count = depService.insertDeps(list); return success(count); } catch (Exception ex) { return fail(ex, -1); } } @SysLog() @Operation(summary = "删除一条") @Parameters({ @Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1") }) @GetMapping(value = "/deleteDep") public ResponseMsg deleteDep(int id) { try { int count = depService.deleteDep(id); return success(count); } catch (Exception ex) { return fail(ex, -1); } } @SysLog() @Operation(summary = "删除多条") @Parameters({ @Parameter(name = "ids", description = "ID数组", in = ParameterIn.QUERY, example = "1") }) @GetMapping(value = "/deleteDeps") public ResponseMsg deleteDeps(@RequestParam List ids) { try { if (ids == null || ids.isEmpty()) { return fail("id数组不能为空", -1); } int count = depService.deleteDeps(ids); return success(count); } catch (Exception ex) { return fail(ex, -1); } } @SysLog() @Operation(summary = "更新一条") @Parameters({ @Parameter(name = "entity", description = "实体类", example = "") }) @ResponseBody @PostMapping(value = "/updateDep", produces = "application/json; charset=UTF-8") public ResponseMsg updateDep(@RequestBody DepEntity entity, HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue != null) { entity.setUpdateUser(ue.getId()); } int count = depService.updateDep(entity); return success(count); } catch (Exception ex) { return fail(ex, -1); } } @SysLog() @Operation(summary = "更新多条") @Parameters({ @Parameter(name = "list", description = "实体类集合") }) @ResponseBody @PostMapping(value = "/updateDeps", produces = "application/json; charset=UTF-8") public ResponseMsg updateDeps(@RequestBody List list, HttpServletRequest req) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue != null) { for (DepEntity entity : list) { entity.setUpdateUser(ue.getId()); } } int count = depService.updateDeps(list); return success(count); } catch (Exception ex) { return fail(ex, -1); } } @SysLog() @Operation(summary = "根据ID查询") @Parameters({ @Parameter(name = "id", description = "ID", in = ParameterIn.QUERY, example = "1") }) @GetMapping(value = "/selectDep") public ResponseMsg selectDep(int id) { try { DepEntity de = depService.selectDep(id); return success(de); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @Operation(summary = "查询所有数据") @GetMapping(value = "/selectDepAll") public ResponseMsg> selectDepAll() { try { List list = depService.selectDepAll(); return success(list); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @Operation(summary = "递归查询") @Parameters({ @Parameter(name = "name", description = "单位名称", in = ParameterIn.QUERY, required = false, example = "中国xxx工程有限公司") }) @GetMapping(value = "/selectDepRecursive") public ResponseMsg> selectDepRecursive(String name) { try { if (StringHelper.isEmpty(name)) { name = "中国xxx工程有限公司"; } List list = depService.selectDepRecursive(name); return success(list); } catch (Exception ex) { return fail(ex, null); } } }