package com.skyline.electricity.controller; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.*; import com.skyline.electricity.service.*; import org.springframework.beans.factory.annotation.*; import org.apache.commons.lang3.*; import com.alibaba.fastjson.*; import io.swagger.annotations.*; import org.springframework.web.bind.annotation.*; import com.skyline.electricity.pojo.*; import java.util.*; import com.skyline.electricity.utils.*; import com.skyline.electricity.entity.*; @RequestMapping({ "/infosynch" }) @Controller @CrossOrigin public class InfoSynchController { @Autowired private InfoSynchService infoSynchService; @RequestMapping(value = { "/saveOrUpdateOrg" }, method = { RequestMethod.POST }) @ApiOperation("保存或更新组织结构相关信息") @ResponseBody public Object saveOrUpdateOrg(final String saveOrUpdateOrg) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)saveOrUpdateOrg)) { rtn.put("code", "-1"); rtn.put("msg", "参数为空"); return rtn; } final String orgInfo = saveOrUpdateOrg.replace("[", "").replaceAll("]", ""); final JSONObject jsonObject = JSONObject.parseObject(orgInfo); final SysOrg sysOrg = (SysOrg)jsonObject.toJavaObject((Class)SysOrg.class); final SysOrg sog = this.infoSynchService.selectOrgInfoById(sysOrg.getId()); if (sog == null) { final int flag = this.infoSynchService.insertOrgInfo(sysOrg); if (flag > 0) { rtn.put("msg", "插入数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "插入数据失败"); rtn.put("code", "-1"); return rtn; } else { final int flag = this.infoSynchService.updateOrgInfo(sysOrg); if (flag > 0) { rtn.put("msg", "更新数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "更新数据失败"); rtn.put("code", "-1"); return rtn; } } @RequestMapping(value = { "/deleteOrgs" }, method = { RequestMethod.POST }) @ApiOperation("删除组织机构相关信息") @ResponseBody public Object deleteOrgs(final String deleteOrgs) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)deleteOrgs)) { rtn.put("code", "-1"); rtn.put("msg", "输入的数据不能为空"); return rtn; } final String[] orgs = deleteOrgs.split(","); rtn.put("code", "0"); rtn.put("msg", "删除成功"); if (orgs.length > 0) { for (final String id : orgs) { try { this.infoSynchService.deleteOrgs(Integer.parseInt(id)); } catch (Exception e) { rtn.put("code", "-1"); rtn.put("msg", "删除失败"); e.printStackTrace(); } } return rtn; } rtn.put("msg", "输入的数据不能为空"); rtn.put("code", "-1"); return rtn; } @RequestMapping(value = { "/saveOrUpdatePos" }, method = { RequestMethod.POST }) @ApiOperation("保存或更新岗位相关信息") @ResponseBody public Object saveOrUpdatePos(final String saveOrUpdatePos) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)saveOrUpdatePos)) { rtn.put("code", "-1"); rtn.put("msg", "参数为空"); return rtn; } final String posInfo = saveOrUpdatePos.replace("[", "").replaceAll("]", ""); final JSONObject jsonObject = JSONObject.parseObject(posInfo); final PgPos pgPos = (PgPos)jsonObject.toJavaObject((Class)PgPos.class); final PgPos position = this.infoSynchService.selectPosInfoById(pgPos.getId()); if (position == null) { final int flag = this.infoSynchService.insertPosInfo(pgPos); if (flag > 0) { rtn.put("msg", "插入数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "插入数据失败"); rtn.put("code", "-1"); return rtn; } else { final int flag = this.infoSynchService.updatePosInfo(pgPos); if (flag > 0) { rtn.put("msg", "更新数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "更新数据失败"); rtn.put("code", "-1"); return rtn; } } @RequestMapping(value = { "/deletePoss" }, method = { RequestMethod.POST }) @ApiOperation("删除岗位相关信息") @ResponseBody public Object deletePoss(final String deletePoss) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)deletePoss)) { rtn.put("code", "-1"); rtn.put("msg", "输入的数据不能为空"); return rtn; } final String[] poss = deletePoss.split(","); rtn.put("code", "0"); rtn.put("msg", "删除成功"); if (poss.length > 0) { for (final String id : poss) { try { this.infoSynchService.deletePoss(id); } catch (Exception e) { rtn.put("code", "-1"); rtn.put("msg", "删除失败"); e.printStackTrace(); } } return rtn; } rtn.put("msg", "输入的数据不能为空"); rtn.put("code", "-1"); return rtn; } @RequestMapping(value = { "/saveOrUpdateSpec" }, method = { RequestMethod.POST }) @ApiOperation("保存或更新专业相关信息") @ResponseBody public Object saveOrUpdateSpec(final String saveOrUpdateSpec) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)saveOrUpdateSpec)) { rtn.put("code", "-1"); rtn.put("msg", "参数为空"); return rtn; } final String specInfo = saveOrUpdateSpec.replace("[", "").replaceAll("]", ""); final JSONObject jsonObject = JSONObject.parseObject(specInfo); final PgSpec pgSpec = (PgSpec)jsonObject.toJavaObject((Class)PgSpec.class); final PgSpec spec = this.infoSynchService.selectSpecInfoById(pgSpec.getId()); if (spec == null) { final int flag = this.infoSynchService.insertSpecInfo(pgSpec); if (flag > 0) { rtn.put("msg", "插入数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "插入数据失败"); rtn.put("code", "-1"); return rtn; } else { final int flag = this.infoSynchService.updateSpecInfo(pgSpec); if (flag > 0) { rtn.put("msg", "更新数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "更新数据失败"); rtn.put("code", "-1"); return rtn; } } @RequestMapping(value = { "/deleteSpec" }, method = { RequestMethod.POST }) @ApiOperation("删除专业相关信息") @ResponseBody public Object deleteSpecs(final String deleteSpecs) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)deleteSpecs)) { rtn.put("code", "-1"); rtn.put("msg", "输入的数据不能为空"); return rtn; } final String[] specs = deleteSpecs.split(","); rtn.put("code", "0"); rtn.put("msg", "删除成功"); if (specs.length > 0) { for (final String id : specs) { try { this.infoSynchService.deleteSpec(Integer.parseInt(id)); } catch (Exception e) { rtn.put("code", "-1"); rtn.put("msg", "删除失败"); e.printStackTrace(); } } return rtn; } rtn.put("msg", "输入的数据不能为空"); rtn.put("code", "-1"); return rtn; } @RequestMapping(value = { "/saveOrUpdateUser" }, method = { RequestMethod.POST }) @ApiOperation("保存或更新用户相关信息") @ResponseBody public Object saveOrUpdateUser(final String saveOrUpdateUser) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)saveOrUpdateUser)) { rtn.put("code", "-1"); rtn.put("msg", "参数为空"); return rtn; } final String userInfo = saveOrUpdateUser.replace("[", "").replaceAll("]", ""); final JSONObject jsonObject = JSONObject.parseObject(userInfo); final SysUser sysUser = (SysUser)jsonObject.toJavaObject((Class)SysUser.class); final SysUser user = this.infoSynchService.selectUserInfoById(sysUser.getId()); if (user == null) { final int flag = this.infoSynchService.insertUserInfo(sysUser); if (flag > 0) { rtn.put("msg", "插入数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "插入数据失败"); rtn.put("code", "-1"); return rtn; } else { final int flag = this.infoSynchService.updateUserInfo(sysUser); if (flag > 0) { rtn.put("msg", "更新数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "更新数据失败"); rtn.put("code", "-1"); return rtn; } } @RequestMapping(value = { "/deleteUser" }, method = { RequestMethod.POST }) @ApiOperation("删除用户相关相关信息") @ResponseBody public Object deleteUsers(final String deleteUsers) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)deleteUsers)) { rtn.put("code", "-1"); rtn.put("msg", "输入的数据不能为空"); return rtn; } final String[] users = deleteUsers.split(","); rtn.put("code", "0"); rtn.put("msg", "删除成功"); if (users.length > 0) { for (final String id : users) { try { this.infoSynchService.deleteUser(id); } catch (Exception e) { rtn.put("code", "-1"); rtn.put("msg", "删除失败"); e.printStackTrace(); } } return rtn; } rtn.put("msg", "输入的数据不能为空"); rtn.put("code", "-1"); return rtn; } @RequestMapping(value = { "/saveOrUpdateDict" }, method = { RequestMethod.POST }) @ApiOperation("保存或更新字典管理信息") @ResponseBody public Object saveOrUpdateDict(final String saveOrUpdateDict) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)saveOrUpdateDict)) { rtn.put("code", "-1"); rtn.put("msg", "参数为空"); return rtn; } final String dictInfo = saveOrUpdateDict.replace("[", "").replaceAll("]", ""); final JSONObject jsonObject = JSONObject.parseObject(dictInfo); final SysDicts sysDicts = (SysDicts)jsonObject.toJavaObject((Class)SysDicts.class); final SysDicts dicts = this.infoSynchService.selectDictInfoById(sysDicts.getId()); if (dicts == null) { final int flag = this.infoSynchService.insertDictInfo(sysDicts); if (flag > 0) { rtn.put("msg", "插入数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "插入数据失败"); rtn.put("code", "-1"); return rtn; } else { final int flag = this.infoSynchService.updateDictInfo(sysDicts); if (flag > 0) { rtn.put("msg", "更新数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "更新数据失败"); rtn.put("code", "-1"); return rtn; } } @RequestMapping(value = { "/deleteDicts" }, method = { RequestMethod.POST }) @ApiOperation("删除字典管理相关信息") @ResponseBody public Object deleteDicts(final String deleteDicts) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)deleteDicts)) { rtn.put("code", "-1"); rtn.put("msg", "输入的数据不能为空"); return rtn; } final String[] dicts = deleteDicts.split(","); rtn.put("code", "0"); rtn.put("msg", "删除成功"); if (dicts.length > 0) { for (final String id : dicts) { try { this.infoSynchService.deleteDicts(id); } catch (Exception e) { rtn.put("code", "-1"); rtn.put("msg", "删除失败"); e.printStackTrace(); } } return rtn; } rtn.put("msg", "输入的数据不能为空"); rtn.put("code", "-1"); return rtn; } @RequestMapping(value = { "/saveOrUpdateUserPos" }, method = { RequestMethod.POST }) @ApiOperation("保存或更新用户和岗位关联信息") @ResponseBody public Object saveOrUpdateUserPos(final String saveOrUpdateUserPos) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)saveOrUpdateUserPos)) { rtn.put("code", "-1"); rtn.put("msg", "参数为空"); return rtn; } final String userPosInfo = saveOrUpdateUserPos.replace("[", "").replaceAll("]", ""); final JSONObject jsonObject = JSONObject.parseObject(userPosInfo); final UserPos userPos = (UserPos)jsonObject.toJavaObject((Class)UserPos.class); final UserPos up = this.infoSynchService.selectUserPosInfoById(userPos.getId()); if (up == null) { final int flag = this.infoSynchService.insertUserPosInfo(userPos); if (flag > 0) { rtn.put("msg", "插入数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "插入数据失败"); rtn.put("code", "-1"); return rtn; } else { final int flag = this.infoSynchService.updateUserPosInfo(userPos); if (flag > 0) { rtn.put("msg", "更新数据成功"); rtn.put("code", "0"); return rtn; } rtn.put("msg", "更新数据失败"); rtn.put("code", "-1"); return rtn; } } @RequestMapping(value = { "/deleteUserPoss" }, method = { RequestMethod.POST }) @ApiOperation("删除用户和岗位关联信息") @ResponseBody public Object deleteUserPoss(final String deleteUserPoss) { final Map rtn = new HashMap(); if (StringUtils.isEmpty((CharSequence)deleteUserPoss)) { rtn.put("code", "-1"); rtn.put("msg", "输入的数据不能为空"); return rtn; } final String[] userPoss = deleteUserPoss.split(","); rtn.put("code", "0"); rtn.put("msg", "删除成功"); if (userPoss.length > 0) { for (final String id : userPoss) { try { this.infoSynchService.deleteUserPoss(id); } catch (Exception e) { rtn.put("code", "-1"); rtn.put("msg", "删除失败"); e.printStackTrace(); } } return rtn; } rtn.put("msg", "输入的数据不能为空"); rtn.put("code", "-1"); return rtn; } @RequestMapping(value = { "/addUserToFence" }, method = { RequestMethod.POST }) @ApiOperation("添加许可人员到固定围栏") @ResponseBody public Object addUserToFence(final String username, final String org_name, final String mobile, final String workId) { final String userId = this.infoSynchService.selectIdByName(username); if (StringUtils.isEmpty((CharSequence)userId)) { return "人员姓名不存在 请输入正确的员工姓名"; } final Fence_User fu = new Fence_User(); final Fence_User fence_user = this.infoSynchService.selectUser(username, workId); if (fence_user == null) { fu.setUsername(username); fu.setWorkId(workId); fu.setMobile(mobile); fu.setOrg_name(org_name); fu.setUserId(userId); this.infoSynchService.insertFenceUser(fu); } final SysUser sysUser = this.infoSynchService.getUserInfoById(userId); final Map map = new HashMap(); map.put("userInfo", sysUser); return map; } @RequestMapping(value = { "/deleteUserFromFence" }, method = { RequestMethod.POST }) @ApiOperation("删除固定围栏中的人员") @ResponseBody public Object deleteUserFromFence(@Param("username") String username, @Param("workId") String workId) { String msg = null; try { this.infoSynchService.deleteFenceUser(username, workId); msg = "删除成功"; } catch (Exception e) { msg = "删除失败"; e.printStackTrace(); } return msg; } @RequestMapping(value = { "/getUsersInFence" }, method = { RequestMethod.GET }) @ApiOperation("获取固定围栏许可的人员") @ResponseBody public Object getUsersInFence(final String workId) { final List list = (List)this.infoSynchService.selectUserInFence(workId); final WhiteList whiteList = new WhiteList(); whiteList.setMsg("查询成功"); whiteList.setCode(0); whiteList.setCount(this.infoSynchService.selectWhiteListCount()); final List fenceUserList = new ArrayList(); for (final Fence_User fenceUser : list) { final FenceUserDto dto = new FenceUserDto(); dto.setMobile(fenceUser.getMobile()); dto.setOrg_name(fenceUser.getOrg_name()); dto.setUsername(fenceUser.getUsername()); fenceUserList.add(dto); } whiteList.setData(fenceUserList); return whiteList; } @RequestMapping(value = { "/getNameById" }, method = { RequestMethod.POST }) @ApiOperation("通过人员ID获取人员姓名") @ResponseBody public Object getNameById(final String userId) { final String username = this.infoSynchService.selectNameById(userId); return username; } @RequestMapping(value = { "/getUserInfoById" }, method = { RequestMethod.POST }) @ApiOperation("通过人员ID获取人员信息") @ResponseBody public Object getUserInfoById(final String userId) { final SysUser sysUser = this.infoSynchService.selectUserInfoById(userId); return sysUser; } @RequestMapping(value = { "/getAllUserName" }, method = { RequestMethod.POST }) @ApiOperation("获取所有人员姓名") @ResponseBody public Object getAllUserName() { final List nameList = (List)this.infoSynchService.getAllUserName(); final Map map = new HashMap(); map.put("nameList", nameList); return map; } @RequestMapping(value = { "/addRecipients" }, method = { RequestMethod.POST }) @ApiOperation("添加预警信息接受人员") @ResponseBody public Object addRecipients(final String username, final String org_name, final String mobile) { final String userId = this.infoSynchService.selectIdByName(username); final List idList = (List)this.infoSynchService.selectAllRecipientsId(); final Recipients recipients = new Recipients(); final RecipientsDTO recipientsDTO = new RecipientsDTO(); final Map map = new HashMap(); if (StringUtils.isEmpty((CharSequence)userId)) { map.put("msg", "人员姓名不存在 请输入正确的员工姓名"); return map; } if (idList.contains(userId)) { map.put("msg", "该员工已被添加过 请勿重复添加"); } else { recipients.setUser_id(userId); recipients.setUsername(username); recipients.setOrg_name(org_name); recipients.setMobile(mobile); this.infoSynchService.setRecipients(recipients); recipientsDTO.setOrg_name(org_name); recipientsDTO.setMobile(mobile); recipientsDTO.setUsername(username); map.put("recipient", recipientsDTO); map.put("msg", "添加成功"); } return map; } @RequestMapping(value = { "/getRecipients" }, method = { RequestMethod.GET }) @ApiOperation("获取预警信息接受人员名单") @ResponseBody public Object getRecipients() { RecipientsList recipientsList = null; try { final List list = (List)this.infoSynchService.getRecipientsDTO(); recipientsList = new RecipientsList(); recipientsList.setCode(Integer.valueOf(0)); final Integer count = this.infoSynchService.selectRecipientsCount(); recipientsList.setCount(count); recipientsList.setData((List)list); recipientsList.setMsg("查询成功"); } catch (Exception e) { recipientsList = new RecipientsList(); recipientsList.setCode(Integer.valueOf(-1)); recipientsList.setCount(Integer.valueOf(0)); recipientsList.setData((List)null); recipientsList.setMsg("查询失败"); } return recipientsList; } @RequestMapping(value = { "/deleteRecipients" }, method = { RequestMethod.POST }) @ApiOperation("删除预警信息接受人员") @ResponseBody public Object deleteRecipients(final String username) { String msg = null; try { this.infoSynchService.deleteRecipients(username); msg = "删除成功"; } catch (Exception e) { msg = "删除失败"; e.printStackTrace(); } return msg; } @RequestMapping(value = { "/addPermissions" }, method = { RequestMethod.POST }) @ApiOperation("添加权限人员信息") @ResponseBody public Object addPermissions(final String username, final String org_name, final String mobile) { final String userId = this.infoSynchService.selectIdByName(username); final List idList = (List)this.infoSynchService.selectAllPermissionsId(); final Permissions permissions = new Permissions(); final PermissionsDTO permissionsDTO = new PermissionsDTO(); final Map map = new HashMap(); if (StringUtils.isEmpty((CharSequence)userId)) { map.put("msg", "人员姓名不存在 请输入正确的员工姓名"); return map; } if (idList.contains(userId)) { map.put("msg", "该员工已被添加过 请勿重复添加"); } else { permissions.setUser_id(userId); permissions.setUsername(username); permissions.setOrg_name(org_name); permissions.setMobile(mobile); this.infoSynchService.setPermissions(permissions); permissionsDTO.setOrg_name(org_name); permissionsDTO.setMobile(mobile); permissionsDTO.setUsername(username); map.put("permissions", permissionsDTO); map.put("msg", "添加成功"); } return map; } @RequestMapping(value = { "/getPermissions" }, method = { RequestMethod.GET }) @ApiOperation("获取权限人员名单信息") @ResponseBody public Object getPermissions() { PermissionsList permissionsList = null; try { final List list = (List)this.infoSynchService.getPermissionsDTO(); for (final PermissionsDTO permissionsDTO : list) { if (permissionsDTO.getPos_name() == null || permissionsDTO.getPos_name().equals("")) { permissionsDTO.setPos_name("暂无数据"); } } permissionsList = new PermissionsList(); permissionsList.setCode(0); final Integer count = this.infoSynchService.selectPermissionsCount(); permissionsList.setCount(count); permissionsList.setData(list); permissionsList.setMsg("查询成功"); } catch (Exception e) { permissionsList = new PermissionsList(); permissionsList.setCode(-1); permissionsList.setCount(0); permissionsList.setData(null); permissionsList.setMsg("查询失败"); } return permissionsList; } @RequestMapping(value = { "/deletePermissions" }, method = { RequestMethod.POST }) @ApiOperation("删除权限人员名单信息") @ResponseBody public Object deletePermissions(final String username) { String msg = null; try { this.infoSynchService.deletePermissions(username); msg = "删除成功"; } catch (Exception e) { msg = "删除失败"; e.printStackTrace(); } return msg; } @RequestMapping(value = { "/initializePermissions" }, method = { RequestMethod.POST }) @ApiOperation("初始化权限人员名单信息") @ResponseBody public void initializePermissions() { final String posIdList = PropertiesUtil.getProperty("posIdList"); final String[] idList = posIdList.split(","); final List totalList = new ArrayList(); final Permissions permissions = new Permissions(); for (final String id : idList) { List posInfoList = new ArrayList(); posInfoList = (List)this.infoSynchService.selectPositionInfoById(id); for (final PosInfo posInfo : posInfoList) { totalList.add(posInfo); } } for (final PosInfo posInfo2 : totalList) { permissions.setUser_id(posInfo2.getUser_id()); permissions.setUsername(posInfo2.getUsername()); permissions.setPos_name(posInfo2.getPos_name()); final String mobile = this.infoSynchService.getMobileById(posInfo2.getUser_id()); permissions.setMobile(mobile); final String org_name = this.infoSynchService.getOrgNameById(posInfo2.getUser_id()); permissions.setOrg_name(org_name); this.infoSynchService.setPermissions(permissions); } } }