package com.philisense.www.controller.web;

import com.philisense.www.common.config.CommonConst;
import com.philisense.www.core.text.Convert;
import com.philisense.www.service.ProResAuthService;
import com.philisense.www.annotation.log.OperateLog;
import com.philisense.www.service.ProResourceActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.philisense.www.controller.BaseUtilController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(CommonConst.WEB_REST_SERVICE_PREFICX+"proresauth")
@Api(tags = "ProResAuthControllerForWeb|一个用来操作-{资源角色表}-业务模块的控制器")
public class ProResAuthControllerForWeb extends BaseUtilController{

        @Autowired
        private ProResAuthService proResAuthService;

        @Autowired
        private ProResourceActionService proResourceActionService;


        @GetMapping( "/delete")
        @ApiOperation(value="根据-{资源角色表}-主键删除记录", notes="成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
        @ApiImplicitParam(paramType="query", name = "recordid", value = "记录主键", required = true,  dataTypeClass = String.class)
        @OperateLog(name = "根据-{资源角色表}-主键删除记录",value = "delete",type = "PC")
        public Map<String, Object> deleteByPrimaryKeyForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestParam String recordid)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {
                int flag = proResAuthService.deleteByPrimaryKey(recordid);
                if(1<=flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);
                }else{
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG);
                }

                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @GetMapping( "/get")
        @ApiOperation(value="根据-{资源角色表}-主键查询记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"datarecord\":\"{}\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParam(paramType="query", name = "recordid", value = "记录主键", required = true,  dataTypeClass = String.class)
        @OperateLog(name = "根据-{资源角色表}-主键查询记录",value = "query",type = "PC")
        public Map<String, Object> selectByPrimaryKeyForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestParam String recordid)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATARECORD, proResAuthService.selectByPrimaryKey(recordid));
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/insert")
        @ApiOperation(value="根据-{资源角色表}-对象插入记录", notes="成功返回:{\"success\":true,\"message\",\"数据插入成功\"},失败返回:{\"success\":false,\"message\",\"数据插入失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象插入记录",value = "insert",type = "PC")
        public Map<String, Object>  insertForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {
                map.put("res_id", UUID.randomUUID().toString().replaceAll("-", ""));
                map.put("auth_id", UUID.randomUUID().toString().replaceAll("-", ""));

                proResAuthService.insert(map);
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, INSERT_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/update")
        @ApiOperation(value="根据-{资源角色表}-对象更新记录", notes="成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象更新记录",value = "update",type = "PC")
        public Map<String, Object>  updateForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {


                int flag = proResAuthService.update(map);
                if(1<=flag){
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
                }else{
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
                }

                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/deleteByMap")
        @ApiOperation(value="根据-{资源角色表}-对象Map删除记录", notes="成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map删除记录",value = "delete",type = "PC")
        public Map<String, Object>  deleteByMapForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {
                int flag = proResAuthService.deleteByMap(map);
                if(1<=flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);
                }else{
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG);
                }

                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/updateByMap")
        @ApiOperation(value="根据-{资源角色表}-对象Map更新记录", notes="成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map更新记录",value = "update",type = "PC")
        public Map<String, Object>  updateByMapForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {


                int flag = proResAuthService.updateByMap(map);
                if(1<=flag){
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
                }else{
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
                }

                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG+e.getMessage());
                }
                return result;
        }
        @PostMapping( "/getOne")
        @ApiOperation(value="根据-{资源角色表}-对象Map查询记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"datarecord\":\"{}\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map查询记录",value = "query",type = "PC")
        public Map<String, Object>  getOneForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATARECORD, proResAuthService.getOne(map));
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/getAll")
        @ApiOperation(value="根据-{资源角色表}-对象Map查询所有记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map查询所有记录",value = "query",type = "PC")
        public Map<String, Object>  getAllForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
                {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATALIST_VUE, proResAuthService.getAll(map));
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/queryPage")
        @ApiOperation(value="根据-{资源角色表}-对象Map分页记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
            @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map分页记录",value = "query",type = "PC")
        public Map<String, Object>  queryPageForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                int currentPage = map.get(DATACURRENT)!=null?Integer.parseInt(map.get(DATACURRENT)+"")-1:0;
                int pageSize = map.get(PAGESIZE)!=null?Integer.parseInt(map.get(PAGESIZE)+""):10;
                int pageStart = currentPage*pageSize ;


                map.put(PAGESIZE,pageSize);
                map.put(PAGESTART,pageStart);

                int total = proResAuthService.count(map);
                List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
                if(total>0){
                datalist = proResAuthService.queryPage(map);
                }
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATALIST,datalist);
                Map<String, Object> pagemode = new HashMap<String, Object>();
                pagemode.put(DATATOTAL,total);
                pagemode.put(PAGESIZE,map.get(PAGESIZE)!=null?map.get(PAGESIZE):10);
                pagemode.put(DATACURRENT,map.get(DATACURRENT)!=null?map.get(DATACURRENT):0);
                result.put(PAGINATION,pagemode);
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }


        @PostMapping( "/queryPageVue")
        @ApiOperation(value="根据-{资源角色表}-对象Map分页记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
            @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map分页记录",value = "query",type = "PC")
        public Map<String, Object>  queryPageVueForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                int currentPage = map.get(DATACURRENT_VUE)!=null?Integer.parseInt(map.get(DATACURRENT_VUE)+"")-1:0;
                int pageSize = map.get(PAGESIZE_VUE)!=null?Integer.parseInt(map.get(PAGESIZE_VUE)+""):10;
                int pageStart = currentPage*pageSize ;


                map.put(PAGESIZE_VUE,pageSize);
                map.put(PAGESTART,pageStart);

                int total = proResAuthService.count(map);
                List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
                if(total>0){
                datalist = proResAuthService.queryPage(map);
                }
                Map<String, Object> tempresult = new HashMap<String, Object>();
                tempresult.put(DATASUCCESS, SUCCESSFLAG);
                tempresult.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                tempresult.put(DATALIST_VUE,datalist);
                tempresult.put(DATATOTAL_VUE,total);
                tempresult.put(PAGESIZE_VUE,map.get(PAGESIZE_VUE)!=null?map.get(PAGESIZE_VUE):10);
                tempresult.put(DATACURRENT_VUE,map.get(DATACURRENT_VUE)!=null?map.get(DATACURRENT_VUE):0);
                result.put(DATARESULT, tempresult);
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }



        @PostMapping( "/queryPageOracle")
        @ApiOperation(value="根据-{资源角色表}-对象Map分页记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
            @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map分页记录",value = "query",type = "PC")
        public Map<String, Object>  queryPageOracleForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                int currentPage = map.get(DATACURRENT)!=null?Integer.parseInt(map.get(DATACURRENT)+""):1;
                int pageSize = map.get(PAGESIZE)!=null?Integer.parseInt(map.get(PAGESIZE)+""):10;
                int pageStart = currentPage*pageSize ;


                map.put(PAGESTART,(currentPage-1)*pageSize);
                map.put(PAGEEND,currentPage*pageSize);

                int total = proResAuthService.count(map);
                List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
                if(total>0){
                datalist = proResAuthService.queryPage(map);
                }
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATALIST,datalist);
                Map<String, Object> pagemode = new HashMap<String, Object>();
                pagemode.put(DATATOTAL,total);
                pagemode.put(PAGESIZE,map.get(PAGESIZE)!=null?map.get(PAGESIZE):10);
                pagemode.put(DATACURRENT,map.get(DATACURRENT)!=null?map.get(DATACURRENT):0);
                result.put(PAGINATION,pagemode);
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/count")
        @ApiOperation(value="根据-{资源角色表}-对象Map统计查询总数记录", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map统计查询总数记录",value = "query",type = "PC")
        public Map<String, Object>  countForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
                {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATATOTAL_VUE, proResAuthService.count(map));
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/insertBatch")
        @ApiOperation(value="根据-{资源角色表}-对象Map批量插入记录", notes="成功返回:{\"success\":true,\"message\",\"数据插入成功\"},失败返回:{\"success\":false,\"message\",\"数据插入失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map批量插入记录",value = "insert",type = "PC")
        public Map<String, Object>  insertBatchForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
                {
                Map<String, Object> result = new HashMap<String, Object>();
                try {
                        List<Map<String, Object>> list = (List) map.get("authids");
                        Map<String, Object> vars = new HashMap<>();
                        vars.put("list", list);
                        vars.put("systemid", map.get("systemid"));
                        if(null!=list && list.size()>0) {
                                proResAuthService.deleteBatchByAuthID(vars);//先把角色与资源删除
                        }
                        List<Map<String, Object>> list1 = (List)map.get("authids_resids");
                        if(null!=list1 && list1.size()>0) {
                                proResAuthService.insertBatch(list1);//再重新插入角色和资源
                        }
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, INSERT_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/deleteBatch")
        @ApiOperation(value="根据-{资源角色表}-对象Map批量删除记录", notes="成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map批量删除记录",value = "delete",type = "PC")
        public Map<String, Object>  deleteBatchForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody List<Map<String, Object>> list)
                {
                Map<String, Object> result = new HashMap<String, Object>();
                try {
                proResAuthService.deleteBatch(list);
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);

                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/updateBatch")
        @ApiOperation(value="根据-{资源角色表}-对象Map批量更新记录", notes="成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
        @ApiImplicitParams({
        @ApiImplicitParam(paramType="body", name = "res_id", value = "资源Id", required = true,  dataTypeClass = String.class),
        @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色Id", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据-{资源角色表}-对象Map批量更新记录",value = "update",type = "PC")
        public Map<String, Object>  updateBatchForProResAuthForWeb(HttpServletRequest request , HttpServletResponse response,@RequestBody List<Map<String, Object>> list)
                {
                Map<String, Object> result = new HashMap<String, Object>();
                try {


                proResAuthService.updateBatch(list);
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);

                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG+e.getMessage());
                }
                return result;
        }



        @PostMapping( "/getAllProResourceTreeByAuthID")
        @ApiOperation(value="根据角色ID查询所有被授权的资源树节点", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色ID", required = true,  dataTypeClass = String.class),
                @ApiImplicitParam(paramType="body", name = "systemid", value = "系统ID", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据角色ID查询所有被授权的资源树节点",value = "query",type = "PC")
        public Map<String, Object>  getAllProResourceTreeByAuthID(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                        Map<String, Object> mapauthids = new HashMap<String, Object>();
                        StringBuilder sb = new StringBuilder();
                        List<String> list = (List<String>) map.get("auth_id");
                        if(null!=list && list.size()>0){
                                for(String s:list){
                                        sb.append("'").append(s).append("'").append(",");
                                }
                                mapauthids.put("auth_id",sb.append("''").toString());
                        }
                        mapauthids.put("systemid", map.get("systemid"));
                        mapauthids.put("menuCheckStrictly", Convert.toBool(map.get("menuCheckStrictly"), true));

                        List<String> memuids = new ArrayList<String>();
                        List<Map<String,Object>> treedata = proResAuthService.getAllProResourceTreeByAuthID(mapauthids);
                        for(Map<String,Object> tree:treedata){
                                memuids.add(tree.get("id")+"");
                        }

                        result.put(DATASUCCESS, SUCCESSFLAG);
                        result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                        result.put(DATALIST, memuids );


                }catch(Exception e){
                        result.put(DATASUCCESS, ERRORFLAG);
                        result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }
        @PostMapping( "/getAllProResourceTreeByAuthIDVue")
        @ApiOperation(value="根据角色ID查询所有被授权的资源树节点", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType="body", name = "auth_id", value = "角色ID", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据角色ID查询所有被授权的资源树节点",value = "query",type = "PC")
        public Map<String, Object>  getAllProResourceTreeByAuthIDVue(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                        Map<String, Object> mapauthids = new HashMap<String, Object>();
                        StringBuilder sb = new StringBuilder();
                        List<String> list = (List<String>) map.get("auth_id");
                        if(null!=list && list.size()>0){
                                for(String s:list){
                                        sb.append("'").append(s).append("'").append(",");
                                }
                                mapauthids.put("auth_id",sb.append("''").toString());
                        }

                        List<String> memuids = new ArrayList<String>();
                        List<Map<String,Object>> treedata = proResAuthService.getAllProResourceTreeByAuthID(mapauthids);
                        for(Map<String,Object> tree:treedata){
                                memuids.add(tree.get("id")+"");
                        }

                        result.put(DATASUCCESS, SUCCESSFLAG);
                        result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                        result.put(DATALIST_VUE, memuids );


                }catch(Exception e){
                        result.put(DATASUCCESS, ERRORFLAG);
                        result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }
        @PostMapping( "/getPageAuthByProResourceTreeId")
        @ApiOperation(value="根据资源树节点ID查询拥有的角色列表", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType="body", name = "recordid", value = "资源ID", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据资源树节点ID查询拥有的角色列表",value = "query",type = "PC")
        public Map<String, Object>  getPageAuthByProResourceTreeId(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {

                int currentPage = map.get(DATACURRENT)!=null?Integer.parseInt(map.get(DATACURRENT)+"")-1:0;
                int pageSize = map.get(PAGESIZE)!=null?Integer.parseInt(map.get(PAGESIZE)+""):10;
                int pageStart = currentPage*pageSize ;


                map.put(PAGESIZE,pageSize);
                map.put(PAGESTART,pageStart);

                int total = proResAuthService.getCountAuthByProResourceTreeId(map);
                List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
                if(total>0){
                datalist = proResAuthService.getPageAuthByProResourceTreeId(map);
                }
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                result.put(DATALIST,datalist);
                Map<String, Object> pagemode = new HashMap<String, Object>();
                pagemode.put(DATATOTAL,total);
                pagemode.put(PAGESIZE,map.get(PAGESIZE)!=null?map.get(PAGESIZE):10);
                pagemode.put(DATACURRENT,map.get(DATACURRENT)!=null?map.get(DATACURRENT):0);
                result.put(PAGINATION,pagemode);
                }catch(Exception e){
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;


        }

        @PostMapping( "/getPageAuthByProResourceTreeIdVue")
        @ApiOperation(value="根据资源树节点ID查询拥有的角色列表", notes="成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType="body", name = "recordid", value = "资源ID", required = true,  dataTypeClass = String.class)
        })
        @OperateLog(name = "根据资源树节点ID查询拥有的角色列表",value = "query",type = "PC")
        public Map<String, Object>  getPageAuthByProResourceTreeIdVue(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {


                        int currentPage = map.get(DATACURRENT_VUE)!=null?Integer.parseInt(map.get(DATACURRENT_VUE)+"")-1:0;
                        int pageSize = map.get(PAGESIZE_VUE)!=null?Integer.parseInt(map.get(PAGESIZE_VUE)+""):10;
                        int pageStart = currentPage*pageSize ;

                        map.put(PAGESIZE_VUE,pageSize);
                        map.put(PAGESTART,pageStart);

                        int total = proResAuthService.getCountAuthByProResourceTreeId(map);
                        List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
                        if(total>0){
                                datalist = proResAuthService.getPageAuthByProResourceTreeId(map);
                        }
                        result.put(DATASUCCESS, SUCCESSFLAG);
                        result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
                        result.put(DATALIST_VUE,datalist);
                        Map<String, Object> pagemode = new HashMap<String, Object>();
                        pagemode.put(DATATOTAL_VUE,total);
                        pagemode.put(PAGESIZE_VUE,map.get(PAGESIZE_VUE)!=null?map.get(PAGESIZE_VUE):10);
                        pagemode.put(DATACURRENT_VUE,map.get(DATACURRENT_VUE)!=null?map.get(DATACURRENT_VUE):0);
                        result.put(PAGINATION,pagemode);

                }catch(Exception e){
                        result.put(DATASUCCESS, ERRORFLAG);
                        result.put(DATAMESSAGE, QUERY_FAIL_MSG+e.getMessage());
                }
                return result;
        }

        @PostMapping( "/updateChangeTargetNodeWithSourceNodeForProResource")
        @ApiOperation(value="根据-{来源节点与目标节点}-对象更新记录", notes="成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType="body", name = "source_id", value = "来源资源ID", required = true,  dataTypeClass = String.class),
                @ApiImplicitParam(paramType="body", name = "source_parentid", value = "来源资源父ID", required = true,  dataTypeClass = String.class),
                @ApiImplicitParam(paramType="body", name = "target_id", value = "目标资源ID", required = true,  dataTypeClass = String.class),
                @ApiImplicitParam(paramType="body", name = "levelcode", value = "修改后的层次码", required = true,  dataTypeClass = String.class),
        })
        @OperateLog(name = "根据-{来源节点与目标节点}-对象更新记录",value = "update",type = "PC")
        public Map<String, Object>  updateChangeTargetNodeWithSourceNodeForProResource(HttpServletRequest request , HttpServletResponse response,@RequestBody Map<String, Object> map)
        {
                Map<String, Object> result = new HashMap<String, Object>();
                try {


                        Map<String, Object> temp = new HashMap<String, Object>();

                        temp.put("id",map.get("source_id"));
                        temp.put("source_parentid",map.get("source_parentid"));
                        temp.put("parentid",map.get("target_id"));
                        temp.put("levelcode",map.get("levelcode"));

                        int flag =  proResAuthService.updateChangeTargetNodeWithSourceNodeForProResource(temp);
                        if(1<=flag){
                                result.put(DATASUCCESS, SUCCESSFLAG);
                                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
                                result.put(DATARECORD, proResourceActionService.selectByPrimaryKey(map.get("source_id")+""));
                        }else{
                                result.put(DATASUCCESS, ERRORFLAG);
                                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
                        }

                }catch(Exception e){
                        result.put(DATASUCCESS, ERRORFLAG);
                        result.put(DATAMESSAGE, UPDATE_FAIL_MSG+e.getMessage());
                }
                return result;
        }



}
