| package com.xzx.gc.user.controller;  | 
|   | 
|   | 
| import cn.hutool.core.convert.Convert;  | 
| import com.github.pagehelper.PageInfo;  | 
| import com.xzx.gc.common.constant.CommonEnum;  | 
| import com.xzx.gc.common.constant.Constants;  | 
| import com.xzx.gc.common.dto.log.OperationAppLog;  | 
| import com.xzx.gc.common.request.BaseController;  | 
| import com.xzx.gc.common.utils.MqUtil;  | 
| import com.xzx.gc.common.utils.RedisUtil;  | 
| import com.xzx.gc.entity.UserRole;  | 
| import com.xzx.gc.model.JsonResult;  | 
| import com.xzx.gc.model.admin.AppRoleModel;  | 
| import com.xzx.gc.model.admin.PunchChannelModel;  | 
| import com.xzx.gc.model.dto.FunctionNodeView;  | 
| import com.xzx.gc.model.query.XzxUserRoleInfoQuery;  | 
| import com.xzx.gc.user.service.UserAuthService;  | 
| import com.xzx.gc.user.service.UserRoleService;  | 
| import com.xzx.gc.user.service.UserService;  | 
| import com.xzx.gc.util.ConvertUtil;  | 
| import com.xzx.gc.util.PageQuery;  | 
| import io.swagger.annotations.Api;  | 
| 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 javax.servlet.http.HttpServletRequest;  | 
| import java.text.SimpleDateFormat;  | 
| import java.util.Calendar;  | 
| import java.util.List;  | 
|   | 
| /**  | 
|  * 用户管理  | 
|  */  | 
| //@Controller  | 
| @RestController  | 
| @Api(tags = "APP角色管理")  | 
| public class AppManagementController extends BaseController {  | 
|   | 
|     private static final String MODEL = "/admin/front/app";  | 
|   | 
|     @Autowired  | 
|     private UserService userService;  | 
|   | 
|     @Autowired  | 
|     private MqUtil mqUtil;  | 
|     @Autowired  | 
|     RedisUtil redisService;  | 
|     @Autowired  | 
|     private UserRoleService userRoleService;  | 
|     @Autowired  | 
|     private UserAuthService userAuthService;  | 
|     static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  | 
|   | 
|     @PostMapping( "/admin/front/app/appRoleList.do")  | 
|     @ApiOperation(value="APP管理-角色管理", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),  | 
|             @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int")  | 
|     })  | 
|     public JsonResult<List<UserRole>> appRoleList(@RequestBody XzxUserRoleInfoQuery condtion)  | 
|     {  | 
|         PageQuery page = condtion.getPageQuery();  | 
|         PageInfo<UserRole> pageInfo = userRoleService.queryByCondition(page);  | 
|         return JsonResult.successx(pageInfo.getList(),Convert.toStr(pageInfo.getTotal()));  | 
|     }  | 
|   | 
|     @PostMapping( "/admin/front/app/tree.json")  | 
|     @ApiOperation(value="APP管理-角色管理(构造树型结构列表)", notes="test: 仅0有正确返回")  | 
|     public JsonResult<List<FunctionNodeView>> getFunctionTree() {  | 
|         List<FunctionNodeView> tree =userAuthService.buildViewList();  | 
|         return JsonResult.success(tree);  | 
|     }  | 
|   | 
|     @PostMapping( "/admin/front/app/add.json")  | 
|     @ApiOperation(value="APP管理-角色管理(添加角色)", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "authIds", value = "权限ID集合", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "roleName", value = "角色名称", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult add(@RequestBody UserRole xzxUserRoleInfo, HttpServletRequest request)  | 
|     {  | 
|         Calendar calendar = Calendar.getInstance();  | 
|         calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY)-1);  | 
|         String dataNow = sdf3.format(calendar.getTime());  | 
|         xzxUserRoleInfo.setDelFlag("0");  | 
|         xzxUserRoleInfo.setCreateTime(dataNow);  | 
|         String[] strs = xzxUserRoleInfo.getAuthIds().split(",");  | 
|         StringBuffer buf = new StringBuffer();  | 
|         for (String str:strs) {  | 
|             if(Integer.parseInt(str)<10000){  | 
|                 buf.append(str).append(",");  | 
|             }  | 
|         }  | 
|         if(null!=buf.toString()&&!"".equals(buf.toString())){  | 
|             String bufStr = buf.toString().substring(0,buf.toString().length()-1);  | 
|             xzxUserRoleInfo.setAuthIds(bufStr);  | 
|   | 
|         }  | 
|         UserRole roleInfo = userRoleService.queryMaxAppRole();  | 
|         String userType = roleInfo.getRoleCode();  | 
|         xzxUserRoleInfo.setRoleCode((Integer.parseInt(userType)+1)+"");  | 
|         userRoleService.save(xzxUserRoleInfo);  | 
|   | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                 .methodName(Constants.USER_MODUL_NAME).operateAction("添加角色-"+xzxUserRoleInfo.getId()).build();  | 
|         mqUtil.sendApp(build);  | 
|   | 
|         return new JsonResult().success();  | 
|     }  | 
|   | 
|     @PostMapping( "/admin/front/app/edit.json")  | 
|     @ApiOperation(value="APP管理-角色管理(修改角色)", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "角色表Id", required = true, dataType = "Long"),  | 
|             @ApiImplicitParam(paramType="query", name = "authIds", value = "权限ID集合", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "roleName", value = "角色名称", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult<String> update(@RequestBody UserRole xzxUserRoleInfo,HttpServletRequest request) {  | 
|         UserRole roleInfo = userRoleService.queryById(xzxUserRoleInfo.getId());  | 
|         Calendar calendar = Calendar.getInstance();  | 
|          if(roleInfo==null){  | 
|              return JsonResult.failMessage("保存失败");  | 
|          }  | 
|         if(null!=xzxUserRoleInfo.getAuthIds()){  | 
|             String[] strs = xzxUserRoleInfo.getAuthIds().split(",");  | 
|             StringBuffer buf = new StringBuffer();  | 
|             for (String str:strs) {  | 
|                 if(Integer.parseInt(str)<10000){  | 
|                     buf.append(str).append(",");  | 
|                 }  | 
|             }  | 
|             if(null!=buf.toString()&&!"".equals(buf.toString())){  | 
|                 String bufStr = buf.toString().substring(0,buf.toString().length()-1);  | 
|                 roleInfo.setAuthIds(bufStr);  | 
|             }  | 
|             String dataNow = sdf3.format(calendar.getTime());  | 
|             roleInfo.setDelFlag("0");  | 
|             roleInfo.setUpdateTime(dataNow);  | 
|         }  | 
|         boolean success = userRoleService.update(roleInfo);  | 
|         if (success) {  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.USER_MODUL_NAME).operateAction("修改角色-"+xzxUserRoleInfo.getId()).build();  | 
|             mqUtil.sendApp(build);  | 
|             return new JsonResult().success();  | 
|         } else {  | 
|             return JsonResult.failMessage("保存失败");  | 
|         }  | 
|     }  | 
|   | 
|     @PostMapping(MODEL + "/delete.json")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="APP管理-角色管理(删除角色)", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "ids", value = "角色表Id集合(多个角色用逗号隔开)", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult delete(@RequestBody AppRoleModel model,HttpServletRequest request) {  | 
|         String ids = model.getIds();  | 
|         if (ids.endsWith(",")) {  | 
|             ids = StringUtils.substringBeforeLast(ids, ",");  | 
|         }  | 
|         List<Long> idList = ConvertUtil.str2longs(ids);  | 
|         userRoleService.batchDelXzxUserRoleInfo(idList);  | 
|   | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                 .methodName(Constants.USER_MODUL_NAME).operateAction("删除角色-"+model.getIds()).build();  | 
|         mqUtil.sendApp(build);  | 
|   | 
|   | 
|         return new JsonResult().success();  | 
|     }  | 
|   | 
|     @GetMapping(MODEL + "/view.json")  | 
|     @ResponseBody  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "角色表Id", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult<UserRole> queryInfo(@RequestBody AppRoleModel model) {  | 
|         Long id = model.getId();  | 
|         UserRole xzxUserRoleInfo = userRoleService.queryById(id);  | 
|         return  JsonResult.success(xzxUserRoleInfo);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping(MODEL + "/queryPunchChannel.do")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="APP管理-打卡通道", notes="test: 仅0有正确返回")  | 
|     public JsonResult<String> queryPunchChannel() {  | 
|         String value = userRoleService.queryPunchChannel();  | 
|         return JsonResult.success(value);  | 
|     }  | 
|   | 
|     @PostMapping(MODEL + "/updatePunchChannel.json")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="APP管理-打卡通道(保存)", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "status", value = "打卡通道状态(0:打开,1:关闭)", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult updatePunchChannel (@RequestBody PunchChannelModel model,HttpServletRequest request) {  | 
|         userRoleService.updatePunchChannel(model);  | 
|   | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                 .methodName(Constants.USER_MODUL_NAME).operateAction("修改配置打卡通道-CODE_SCAN_RK").build();  | 
|         mqUtil.sendApp(build);  | 
|   | 
|         return new JsonResult().success();  | 
|     }  | 
|   | 
|   | 
| }  |