From 026447959141110afd24d18b61da953c62aa2209 Mon Sep 17 00:00:00 2001
From: zhubaomin <470473919@qq.com>
Date: 星期三, 23 四月 2025 12:23:55 +0800
Subject: [PATCH] 各轮灌组开阀时间提前2分钟,第一组除外

---
 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