From b181d08b9c8c4f3f4d8c475a60506ba4d93c8382 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期三, 09 四月 2025 11:38:23 +0800
Subject: [PATCH] 灌溉计划详情页,包含计划信息、轮灌组信息、取水口命令发布员结果信息
---
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java | 189 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 189 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
new file mode 100644
index 0000000..c5c3917
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
@@ -0,0 +1,189 @@
+package com.dy.pipIrrBase.role;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.dy.common.aop.SsoAop;
+import com.dy.common.mybatis.envm.Deleted;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.common.webUtil.QueryResultVo;
+import com.dy.common.webUtil.ResultCodeMsg;
+import com.dy.pipIrrBase.result.SystemResultCode;
+import com.dy.pipIrrGlobal.pojoBa.BaRole;
+import com.dy.pipIrrGlobal.pojoBa.BaRolePermissions;
+import com.dy.pipIrrGlobal.voBa.VoRole;
+import com.dy.pipIrrGlobal.voSe.VoActiveCard;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.MediaType;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.*;
+
+@Slf4j
+@Tag(name = "瑙掕壊绠$悊", description = "瑙掕壊澧炲垹鏀规煡绛夋搷浣�")
+@RestController
+@RequestMapping(path="role")
+@RequiredArgsConstructor
+@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked")
+public class RoleCtrl {
+
+ private final RoleSv roleSv;
+
+ /**
+ * 鏍规嵁鎸囧畾鏉′欢锛堣鑹茬紪鍙枫�佽鑹插悕绉帮級鑾峰彇瑙掕壊鍒楄〃
+ * 褰撹幏鍙栦竴鏉¤褰曟椂锛屼紶鍏oleId鍗冲彲
+ * @param vo
+ * @return
+ */
+ @Operation(summary = "鑾峰緱涓�椤佃鑹茶褰�", description = "杩斿洖涓�椤佃鑹叉暟鎹�")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "杩斿洖涓�椤垫帶鍒跺櫒鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = VoActiveCard.class))}
+ )
+ })
+ @GetMapping(path = "/roles")
+ @SsoAop()
+ public BaseResponse<QueryResultVo<List<VoRole>>> getRoles(QueryVo vo){
+ try {
+ //BaRolePermissions baRolePermissions = roleSv.getRolePermissionsById(2023122018334500002L);
+ //return BaseResponseUtils.buildSuccess(baRolePermissions);
+
+ QueryResultVo<List<VoRole>> res = roleSv.getRoles(vo);
+ if(res.itemTotal != null && res.itemTotal > 0) {
+ return BaseResponseUtils.buildSuccess(res);
+ }else {
+ return BaseResponseUtils.buildSuccess(SystemResultCode.NO_ROLES.getMessage());
+ }
+
+ } catch (Exception e) {
+ log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e);
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+
+ /**
+ * 瑙掕壊鎺堟潈
+ * 1. 濡傛灉roleid鍜宺oleName閮界┖锛氭彁绀洪敊璇俊鎭�
+ * 2. 濡傛灉roleid涓虹┖锛氭柊寤鸿鑹蹭笖鎺堟潈
+ * 1. 娣诲姞瑙掕壊璁板綍
+ * 2. 娣诲姞瑙掕壊銆佹潈闄愬叧鑱旇褰�
+ * 3. 濡傛灉roleid涓嶄负绌猴細淇敼瑙掕壊鍙婃巿鏉�
+ * 1. 鍒犻櫎瑙掕壊銆佹潈闄愯褰�
+ * 2. 淇敼瑙掕壊淇℃伅
+ * 3. 娣诲姞瑙掕壊銆佹潈闄愯褰�
+ * @param po
+ * @param bindingResult
+ * @return
+ */
+ @Operation(summary = "鎺堟潈", description = "鎺堟潈")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Boolean.class))}
+ )
+ })
+ @PostMapping(path = "addPermissions", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @Transactional(rollbackFor = Exception.class)
+ @SsoAop()
+ public BaseResponse<Boolean> permission(@RequestBody @Valid DtoRole po, BindingResult bindingResult){
+ if(bindingResult != null && bindingResult.hasErrors()){
+ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+
+ Long roleId = Optional.ofNullable(po.getRoleId()).orElse(0L);
+ String roleName = Optional.ofNullable(po.getRoleName()).orElse("");
+ JSONArray permissions = Optional.ofNullable(JSONArray.parseArray(po.getPermissions())).orElse(JSONArray.parseArray("[]"));
+ Long operator = Optional.ofNullable(po.getOperator()).orElse(0L);
+
+ if(roleId == 0 && roleName.length() == 0)
+ return BaseResponseUtils.buildFail(SystemResultCode.PERMISSION_ERROR.getMessage());
+
+ // 鏂板缓瑙掕壊涓旀巿鏉�
+ if(roleId == 0) {
+ BaRole baRole = new BaRole();
+ baRole.setName(roleName);
+ baRole.setOperator(operator);
+ Date operateTime = new Date();
+ baRole.setOperateDt(operateTime);
+ baRole.setDeleted(Deleted.NO.getCode());
+ roleId = Optional.ofNullable(roleSv.addRole(baRole)).orElse(0L);
+
+ BaRolePermissions baRolePermissions = new BaRolePermissions();
+ baRolePermissions.setRoleid(roleId);
+ baRolePermissions.setPermissions(permissions);
+ roleSv.addPermissions(baRolePermissions);
+ return BaseResponseUtils.buildSuccess(true) ;
+ }
+
+ // 淇敼瑙掕壊淇℃伅
+ BaRole baRole = new BaRole();
+ baRole.setId(roleId);
+ baRole.setName(roleName);
+ baRole.setOperator(operator);
+ Date operateTime = new Date();
+ baRole.setOperateDt(operateTime);
+ roleSv.updateRole(baRole);
+
+ // 淇敼瑙掕壊鎺堟潈
+ BaRolePermissions baRolePermissions = new BaRolePermissions();
+ baRolePermissions.setRoleid(roleId);
+ baRolePermissions.setPermissions(permissions);
+ roleSv.delPermissionsByRoleId(roleId);
+ roleSv.addPermissions(baRolePermissions);
+
+ return BaseResponseUtils.buildSuccess(true) ;
+ }
+
+ /**
+ * 鍒犻櫎瑙掕壊
+ * 閫昏緫鍒犻櫎瑙掕壊璁板綍锛岀墿鐞嗗垹闄よ鑹叉巿鏉冭褰�
+ * @param map
+ * @return 鏄惁鎴愬姛
+ */
+ @Operation(summary = "鍒犻櫎瑙掕壊", description = "鎻愪氦瑙掕壊ID锛岃繘琛岄�昏緫鍒犻櫎")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Boolean.class))}
+ )
+ })
+ //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE)
+ @PostMapping(path = "delete", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @Transactional(rollbackFor = Exception.class)
+ @SsoAop()
+ public BaseResponse<Boolean> delete(@RequestBody Map map){
+ Long id = Optional.ofNullable(Long.parseLong(map.get("id").toString())).orElse(0L);
+
+ if(id == 0)
+ return BaseResponseUtils.buildException(SystemResultCode.PLEASE_INPUT_ROLE_ID.getMessage());
+
+ try {
+ // 閫昏緫鍒犻櫎瑙掕壊璁板綍锛岀墿鐞嗗垹闄よ鑹叉巿鏉冭褰�
+ Integer res_role = Optional.ofNullable(roleSv.deleteRoleById(id)).orElse(0);
+ Integer res_per = Optional.ofNullable(roleSv.delPermissionsByRoleId(id)).orElse(0);
+ if(res_role == 0 || res_per == 0)
+ return BaseResponseUtils.buildFail(SystemResultCode.DELETE_ROLE_FAIL.getMessage());
+
+ return BaseResponseUtils.buildSuccess(true);
+ } catch (Exception e) {
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+
+}
--
Gitblit v1.8.0