src/main/java/com/moral/controller/AccountRoleController.java
New file @@ -0,0 +1,69 @@ package com.moral.controller; import javax.annotation.Resource; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.moral.common.bean.PageBean; import com.moral.common.bean.ResultBean; import com.moral.entity.AccountRole; import com.moral.service.AccountRoleService; import com.moral.service.AccountService; import com.moral.service.RoleService; @RestController @RequestMapping("account-role") @CrossOrigin(origins = "*", maxAge = 3600) public class AccountRoleController { @Resource AccountService accountService; @Resource RoleService roleService; @Resource AccountRoleService accountRoleService; @GetMapping("account-list") public ResultBean getAccountList(String accountName) { ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); resultBean.setData(accountService.getAccountList(accountName)); return resultBean; } @GetMapping("role-list") public ResultBean getRoleList(String roleName) { ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); resultBean.setData(roleService.getRoleList(roleName)); return resultBean; } @PostMapping("add-or-modify") public ResultBean saveOrUpdate(@RequestBody AccountRole accountRole) { accountRoleService.addOrModify(accountRole); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } @GetMapping("count-by-example") public ResultBean<Integer> countByExample(PageBean pageBean) { return new ResultBean<Integer>(accountRoleService.countByExample(pageBean)); } @GetMapping("accountRole-list") public PageBean getAccountRoleList(PageBean pageBean) { return accountRoleService.getAccountRoleList(pageBean); } @PostMapping("delete-by-ids") public ResultBean deleteByIds(@RequestBody Integer [] ids){ accountRoleService.deleteByIds(ids); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } } src/main/java/com/moral/controller/MenuController.java
New file @@ -0,0 +1,64 @@ package com.moral.controller; import javax.annotation.Resource; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.moral.common.bean.PageBean; import com.moral.common.bean.ResultBean; import com.moral.entity.Menu; import com.moral.service.MenuService; @RestController @RequestMapping("menu") @CrossOrigin(origins = "*", maxAge = 3600) public class MenuController { @Resource MenuService menuService; @GetMapping("count-by-example") public ResultBean<Integer> countByExample(PageBean pageBean) { return new ResultBean<Integer>(menuService.countByExample(pageBean)); } @PostMapping("add-or-modify") public ResultBean saveOrUpdate(@RequestBody Menu menu) { menuService.addOrModify(menu); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } @GetMapping("page-list") public PageBean pageList(PageBean pageBean) { return menuService.queryByPageBean(pageBean); } @GetMapping("page-allList") public PageBean pageAllList(PageBean pageBean) { return menuService.queryByAllPageBean(pageBean); } @GetMapping("menu-list") public PageBean getMenuList(PageBean pageBean) { return menuService.getMenuList(pageBean); } @GetMapping("menuParent-list") public ResultBean getMenuParentList(String menuName) { ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); resultBean.setData(menuService.getMenuParentList(menuName)); return resultBean; } @PostMapping("delete-by-ids") public ResultBean deleteByIds(@RequestBody Integer [] ids){ menuService.deleteByIds(ids); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } } src/main/java/com/moral/controller/RoleController.java
New file @@ -0,0 +1,49 @@ package com.moral.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.moral.common.bean.PageBean; import com.moral.common.bean.ResultBean; import com.moral.entity.Role; import com.moral.service.RoleService; @RestController @RequestMapping("role") @CrossOrigin(origins = "*", maxAge = 3600) public class RoleController { @Autowired RoleService roleService; @GetMapping("count-by-example") public ResultBean<Integer> countByExample(PageBean pageBean){ return new ResultBean<Integer>(roleService.countByExample(pageBean)); } @GetMapping("page-list") public PageBean pageList(PageBean pageBean) { return roleService.queryByPageBean(pageBean); } @PostMapping("add-or-modify") public ResultBean addOrModify(@RequestBody Role role) { roleService.addOrModify(role); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } @PostMapping("delete-by-ids") public ResultBean deleteByIds(@RequestBody List<Integer> ids){ roleService.deleteByIds(ids); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } } src/main/java/com/moral/controller/RoleMenuController.java
New file @@ -0,0 +1,70 @@ package com.moral.controller; import javax.annotation.Resource; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.moral.common.bean.PageBean; import com.moral.common.bean.ResultBean; import com.moral.entity.RoleMenu; import com.moral.service.MenuService; import com.moral.service.RoleMenuService; import com.moral.service.RoleService; @RestController @RequestMapping("role-menu") @CrossOrigin(origins = "*", maxAge = 3600) public class RoleMenuController { @Resource RoleService roleService; @Resource MenuService menuService; @Resource RoleMenuService roleMenuService; @GetMapping("role-list") public ResultBean getRoleList(String roleName) { ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); resultBean.setData(roleService.getRoleList(roleName)); return resultBean; } @GetMapping("menu-list") public ResultBean getMenuList(String menuName) { ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); resultBean.setData(menuService.getMenuListByName(menuName)); return resultBean; } @PostMapping("add-or-modify") public ResultBean saveOrUpdate(@RequestBody RoleMenu roleMenu) { roleMenuService.addOrModify(roleMenu); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } @GetMapping("count-by-example") public ResultBean<Integer> countByExample(PageBean pageBean) { return new ResultBean<Integer>(roleMenuService.countByExample(pageBean)); } @GetMapping("roleMenu-list") public PageBean getRoleMenuList(PageBean pageBean) { return roleMenuService.getRoleMenuList(pageBean); } @PostMapping("delete-by-ids") public ResultBean deleteByIds(@RequestBody Integer [] ids){ roleMenuService.deleteByIds(ids); ResultBean resultBean = new ResultBean(ResultBean.SUCCESS); return resultBean; } } src/main/java/com/moral/entity/Account.java
@@ -80,7 +80,7 @@ // TODO 临时角色 public List<Role> getRoles(){ Role role = new Role(); role.setName("temp"); role.setRoleName("temp"); return Arrays.asList(role); } @Transient src/main/java/com/moral/entity/AccountRole.java
New file @@ -0,0 +1,21 @@ package com.moral.entity; import javax.persistence.Transient; import lombok.Data; @Data public class AccountRole { private Integer id; private Integer accountId; private Integer roleId; @Transient private Account account; @Transient private Role role; } src/main/java/com/moral/entity/Menu.java
New file @@ -0,0 +1,38 @@ package com.moral.entity; import java.util.Date; import javax.persistence.Id; import lombok.Data; @Data public class Menu { @Id private Integer id; private String menuCode; private String menuName; private String menuIcon; private String menuUrl; private Integer menuOrder; private Integer menuParentId; private String menuRemark; private String isDelete; private Date createTime; private String createUser; private Date updateTime; private String updateUser; } src/main/java/com/moral/entity/Role.java
@@ -1,8 +1,30 @@ package com.moral.entity; import java.util.Date; import javax.persistence.Id; import lombok.Data; @Data public class Role { private String name; @Id private Integer id; private String roleCode; private String roleName; private String isDelete; private String roleRemark; private Date createTime; private String createUser; private Date updateTime; private String updateUser; } src/main/java/com/moral/entity/RoleMenu.java
New file @@ -0,0 +1,21 @@ package com.moral.entity; import javax.persistence.Transient; import lombok.Data; @Data public class RoleMenu { private Integer id; private Integer roleId; private Integer menuId; @Transient private Role role; @Transient private Menu menu; } src/main/java/com/moral/mapper/AccountMapper.java
@@ -3,11 +3,19 @@ import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Param; import com.moral.common.mapper.BaseMapper; import com.moral.entity.Account; public interface AccountMapper extends BaseMapper<Account> { List<Map<String, Object>> getRoleNameByAccountId(Integer accountId); Account getByAccountName(String name); Map<String, Object> getOrganizationIdByAccountId(Integer accountId); List<Account> getAccountList(@Param("accountName") String accountName); } src/main/java/com/moral/mapper/AccountRoleMapper.java
New file @@ -0,0 +1,18 @@ package com.moral.mapper; import java.util.List; import com.moral.common.mapper.BaseMapper; import com.moral.entity.AccountRole; import tk.mybatis.mapper.entity.Example; public interface AccountRoleMapper extends BaseMapper<AccountRole> { List<AccountRole> getAccountRoleList(Example example); int updateByPrimaryKey(AccountRole accountRole); int deleteByPrimaryKeyOwn(Integer id); } src/main/java/com/moral/mapper/MenuMapper.java
New file @@ -0,0 +1,23 @@ package com.moral.mapper; import java.util.List; import org.apache.ibatis.annotations.Param; import com.moral.common.mapper.BaseMapper; import com.moral.entity.Menu; import tk.mybatis.mapper.entity.Example; public interface MenuMapper extends BaseMapper<Menu> { List<Menu> selectWithMenuNameByExample(Example example); List<Menu> getMenuList(Example example); List<Menu> getParentMenuList(@Param("menuName") String menuName); List<Menu> getMenuListByName(@Param("menuName") String menuName); } src/main/java/com/moral/mapper/RoleMapper.java
New file @@ -0,0 +1,17 @@ package com.moral.mapper; import java.util.List; import org.apache.ibatis.annotations.Param; import com.moral.common.mapper.BaseMapper; import com.moral.entity.Role; public interface RoleMapper extends BaseMapper<Role> { int insertSelective(Role role); int updateByPrimaryKeySelective(Role role); List<Role> getRoleList(@Param("roleName") String roleName); } src/main/java/com/moral/mapper/RoleMenuMapper.java
New file @@ -0,0 +1,18 @@ package com.moral.mapper; import java.util.List; import com.moral.common.mapper.BaseMapper; import com.moral.entity.RoleMenu; import tk.mybatis.mapper.entity.Example; public interface RoleMenuMapper extends BaseMapper<RoleMenu> { List<RoleMenu> getRoleMenuList(Example example); int deleteByPrimaryKeyOwn(Integer id); int updateByPrimaryKey(RoleMenu roleMenu); } src/main/java/com/moral/security/auth/login/LoginAuthenticationProvider.java
@@ -70,7 +70,7 @@ throw new InsufficientAuthenticationException("User has no roles assigned"); } List<GrantedAuthority> authorities = account.getRoles().stream() .map(authority -> new SimpleGrantedAuthority(authority.getName())) .map(authority -> new SimpleGrantedAuthority(authority.getRoleName())) .collect(Collectors.toList()); UserContext userContext = UserContext.create(account.getAccountName(),mode,account.getOrganizationId(),authorities); src/main/java/com/moral/security/endpoint/RefreshTokenEndpoint.java
@@ -72,7 +72,7 @@ if (account.getRoles() == null) throw new InsufficientAuthenticationException("User has no roles assigned"); List<GrantedAuthority> authorities = account.getRoles().stream() .map(authority -> new SimpleGrantedAuthority(authority.getName())) .map(authority -> new SimpleGrantedAuthority(authority.getRoleName())) .collect(Collectors.toList()); UserContext userContext = UserContext.create(account.getAccountName(),mode,account.getOrganizationId(),authorities); src/main/java/com/moral/service/AccountRoleService.java
New file @@ -0,0 +1,15 @@ package com.moral.service; import com.moral.common.bean.PageBean; import com.moral.entity.AccountRole; public interface AccountRoleService { void addOrModify(AccountRole accountRole); int countByExample(PageBean pageBean); PageBean getAccountRoleList(PageBean pageBean); void deleteByIds(Integer... ids); } src/main/java/com/moral/service/AccountService.java
@@ -30,4 +30,6 @@ Account companyLogin(Map<String, Object> parameters); Map<String, Object> getOrganizationIdByAccountId(String id); List<Account> getAccountList(String accountName); } src/main/java/com/moral/service/MenuService.java
New file @@ -0,0 +1,24 @@ package com.moral.service; import java.util.List; import com.moral.common.bean.PageBean; import com.moral.entity.Menu; public interface MenuService { void addOrModify(Menu menu); PageBean queryByPageBean(PageBean pageBean); PageBean queryByAllPageBean(PageBean pageBean); int countByExample(PageBean pageBean); PageBean getMenuList(PageBean pageBean); List<Menu> getMenuParentList(String menuName); void deleteByIds(Integer[] ids); List<Menu> getMenuListByName(String menuName); } src/main/java/com/moral/service/RoleMenuService.java
New file @@ -0,0 +1,15 @@ package com.moral.service; import com.moral.common.bean.PageBean; import com.moral.entity.RoleMenu; public interface RoleMenuService { void addOrModify(RoleMenu roleMenu); int countByExample(PageBean pageBean); PageBean getRoleMenuList(PageBean pageBean); void deleteByIds(Integer... ids); } src/main/java/com/moral/service/RoleService.java
New file @@ -0,0 +1,19 @@ package com.moral.service; import java.util.List; import com.moral.common.bean.PageBean; import com.moral.entity.Role; public interface RoleService { PageBean<Role> queryByPageBean(PageBean pageBean); void addOrModify(Role role); int deleteByIds(List<Integer> ids); int countByExample(PageBean pageBean); List<Role> getRoleList(String roleName); } src/main/java/com/moral/service/impl/AccountRoleServiceImpl.java
New file @@ -0,0 +1,76 @@ package com.moral.service.impl; import java.util.Arrays; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.github.pagehelper.PageHelper; import com.moral.common.bean.PageBean; import com.moral.common.util.ExampleUtil; import com.moral.entity.AccountRole; import com.moral.mapper.AccountRoleMapper; import com.moral.service.AccountRoleService; import tk.mybatis.mapper.entity.Example; @Service public class AccountRoleServiceImpl implements AccountRoleService { private static Class ENTITY_CLASS = AccountRole.class; @Resource private AccountRoleMapper accountRoleMapper; @Override public void addOrModify(AccountRole accountRole) { try { if (accountRole.getId() != null) { accountRoleMapper.updateByPrimaryKey(accountRole); } else { AccountRole accountRoleQuery = new AccountRole(); accountRoleQuery.setAccountId(accountRole.getAccountId()); accountRoleQuery.setRoleId(accountRole.getRoleId()); AccountRole accountRoleResult = accountRoleMapper.selectOne(accountRoleQuery); if (accountRoleResult == null) { accountRoleMapper.insertSelective(accountRole); } } } catch (Exception ex) { throw ex; } } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); return accountRoleMapper.selectCountByExample(example); } @Override public PageBean getAccountRoleList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List<AccountRole> accountRoleList = accountRoleMapper.getAccountRoleList(example); return new PageBean(accountRoleList); } @Override public void deleteByIds(Integer... ids) { if (ids != null && ids.length > 0) { if (ids.length == 1) { accountRoleMapper.deleteByPrimaryKeyOwn(ids[0]); } else { Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); accountRoleMapper.deleteByExample(example); } } } } src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -206,4 +206,10 @@ Map<String, Object> map = accountMapper.getOrganizationIdByAccountId(accountId); return map; } @Override public List<Account> getAccountList(String accountName) { List<Account> accountList = accountMapper.getAccountList(accountName); return accountList; } } src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -20,6 +20,8 @@ import com.moral.mapper.OrganizationMapper; import com.moral.service.AccountService; import com.moral.service.DeviceService; import com.moral.util.TkMybatisUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -27,10 +29,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import tk.mybatis.mapper.entity.Example; import javax.annotation.Resource; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -41,137 +45,142 @@ @Service public class DeviceServiceImpl implements DeviceService { private static Logger log = Logger.getLogger(DeviceServiceImpl.class); //-----------------------redis key前缀-开始--------------------------------- private static String AlARM = "alarm";//警报阀值储存key前缀 private static String ADJUST="adjust";//校准值存储key前缀 private static String DEVICE = "device";//设备信息数据key前缀 private static String STATE = "state";//设备实时状态key前缀 private static String DATA = "data";//设备实时数据key前缀 //-----------------------redis key前缀-结束--------------------------------- private String keysConnect(String... keys) { StringBuilder key = new StringBuilder(keys[0]); for(int i=1;i<keys.length;i++) { key.append("_"); key.append(keys[i]); } return key.toString().toLowerCase(); } @Resource private DeviceMapper deviceMapper; private static Logger log = Logger.getLogger(DeviceServiceImpl.class); //-----------------------redis key前缀-开始--------------------------------- private static String AlARM = "alarm";//警报阀值储存key前缀 private static String ADJUST = "adjust";//校准值存储key前缀 private static String DEVICE = "device";//设备信息数据key前缀 private static String STATE = "state";//设备实时状态key前缀 private static String DATA = "data";//设备实时数据key前缀 //-----------------------redis key前缀-结束--------------------------------- private String keysConnect(String... keys) { StringBuilder key = new StringBuilder(keys[0]); for (int i = 1; i < keys.length; i++) { key.append("_"); key.append(keys[i]); } return key.toString().toLowerCase(); } @Resource private DeviceMapper deviceMapper; @Resource private MonitorPointMapper monitorPointMapper; @Resource private AccountService accountService; @Resource private AccountService accountService; private Class ENTITY_CLASS = Device.class; @Resource OrganizationMapper orgMapper; OrganizationMapper orgMapper; @Resource DeviceVersionMapper deviceVersionMapper; @Resource RedisUtils redisUtils; @Resource OrganizationMapper organizationMapper; @Resource DictionaryDataMapper dictionaryDataMapper; @Override public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("accountId"), "param.is.null"); Map<String, Object> result = new HashMap<String, Object>(); accountService.setOrgIdsByAccount(parameters); List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(parameters); Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L; for (Map<String, Object> map : list) { Long count = (Long) map.get("count"); all += count; switch (Integer.valueOf((String) map.get("state"))) { case 0: normal = count; break; case 4: stop = count; break; default: abnormal += count; } } result.put("all", all); result.put("normal", normal); result.put("abnormal", abnormal); result.put("stop", stop); return result; } @Override @Transactional public void saveOrUpdateDevice(Device device) { ValidateUtil.notNull(device, "param.is.null"); ValidateUtil.notEmpty(device.getMac(), "param.is.null"); Device queryDevice = new Device(); queryDevice.setMac(device.getMac()); queryDevice = deviceMapper.selectOne(queryDevice); Date operateDate = new Date(); device.setInstallTime(operateDate); if (ObjectUtils.isEmpty(queryDevice)) { device.setCreateTime(operateDate); device.setState("4"); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); }else { device.setId(queryDevice.getId()); deviceMapper.updateByPrimaryKeySelective(device); } //刷新redis里的信息 refreshDeviceInRedis(device.getMac()); } DeviceVersionMapper deviceVersionMapper; @Resource RedisUtils redisUtils; @Resource OrganizationMapper organizationMapper; @Resource DictionaryDataMapper dictionaryDataMapper; @Override public List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize) { ValidateUtil.notNull(uid, "param.is.null"); Device device = new Device(); device.setOperateUserId(uid); PageHelper.startPage(pageIndex, pageSize,false); List<Device> devices = deviceMapper.select(device); return devices; } /** * * @param mac * @param fromCache * @return 包含组织数组 */ @Override public Device getDeviceByMac (String mac ,boolean fromCache){ if(fromCache){ public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("accountId"), "param.is.null"); Map<String, Object> result = new HashMap<String, Object>(); accountService.setOrgIdsByAccount(parameters); List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(parameters); Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L; for (Map<String, Object> map : list) { Long count = (Long) map.get("count"); all += count; switch (Integer.valueOf((String) map.get("state"))) { case 0: normal = count; break; case 4: stop = count; break; default: abnormal += count; } } result.put("all", all); result.put("normal", normal); result.put("abnormal", abnormal); result.put("stop", stop); return result; } @Override @Transactional public void saveOrUpdateDevice(Device device) { ValidateUtil.notNull(device, "param.is.null"); ValidateUtil.notEmpty(device.getMac(), "param.is.null"); Device queryDevice = new Device(); queryDevice.setMac(device.getMac()); queryDevice = deviceMapper.selectOne(queryDevice); Date operateDate = new Date(); device.setInstallTime(operateDate); if (ObjectUtils.isEmpty(queryDevice)) { device.setCreateTime(operateDate); device.setState("4"); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); } else { device.setId(queryDevice.getId()); deviceMapper.updateByPrimaryKeySelective(device); } //刷新redis里的信息 refreshDeviceInRedis(device.getMac()); } @Override public List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize) { ValidateUtil.notNull(uid, "param.is.null"); Device device = new Device(); device.setOperateUserId(uid); PageHelper.startPage(pageIndex, pageSize, false); List<Device> devices = deviceMapper.select(device); return devices; } /** * @param mac * @param fromCache * @return 包含组织数组 */ @Override public Device getDeviceByMac(String mac, boolean fromCache) { if (fromCache) { Device device = getDeviceFromRedis(mac); if(device==null) { if (device == null) { device = deviceMapper.selectWithOrgIdsByMac(mac); } return device; }else { return deviceMapper.selectWithOrgIdsByMac(mac); return device; } else { return deviceMapper.selectWithOrgIdsByMac(mac); } } /** * 默认会从缓存取 * * @param mac * @return */ @Override public Device getDeviceByMac(String mac) { @Override public Device getDeviceByMac(String mac) { return getDeviceByMac(mac,true); } /* * 获取报警阀值在redis里的key */ private String getDeviceKey(String mac) { return keysConnect(DEVICE,mac); } // /* return getDeviceByMac(mac, true); } /* * 获取报警阀值在redis里的key */ private String getDeviceKey(String mac) { return keysConnect(DEVICE, mac); } // /* // * 将校正值存入redis方法组 开始 // */ // private void setDeviceToRedis(String mac,Device device){ @@ -187,438 +196,439 @@ // simpleDevice.setDeviceVersion(device.getDeviceVersion()); // redisUtils.set(key,simpleDevice); // } private Device getDeviceFromRedis(String mac) { String key = getDeviceKey(mac); return redisUtils.get(key,Device.class); } private Device getDeviceFromRedis(String mac) { String key = getDeviceKey(mac); return redisUtils.get(key, Device.class); } /** * * @param params * map里 包括 组织id和4个坐标点 * @return 返回未删除结果集 */ @Override public List<Device> query(Map<String, Object> params) { Object orgIdObj = params.get("orgId"); List<Device> deviceList = null; if(orgIdObj != null) { Integer orgId = Integer.parseInt(orgIdObj.toString()); List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); params.put("orgIds", orgIds); deviceList = deviceMapper.selectByMap(params); loadDeviceState(deviceList); } return deviceList; } /** * 根据组织id和设备名称 分页查询设备 * @param orgId * @param deviceName * @param pageSize * @param pageNo * @return 返回未删除结果 */ @Override public PageResult query(Integer orgId, String deviceName, Integer pageSize, Integer pageNo) { List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); if(!ObjectUtils.isEmpty(pageSize)&&!ObjectUtils.isEmpty(pageNo)){ PageHelper.startPage(pageNo,pageSize); } String state = null; switch (deviceName){ case "正常": state = "0"; deviceName = null;break; case "轻度": state = "1"; deviceName = null;break; case "中度": state = "2"; deviceName = null;break; case "重度": state = "3"; deviceName = null;break; case "维保": state = "4"; deviceName = null;break; } List<Device> list = deviceMapper.selectByOrgIdAndDevName(orgId,orgIds,state,deviceName); //从redis里取状态 loadDeviceState(list); if(list instanceof Page){ return new PageResult(((Page) list).getTotal(),list); } return new PageResult(null,list); } /** * @param params map里 包括 组织id和4个坐标点 * @return 返回未删除结果集 */ @Override public List<Device> query(Map<String, Object> params) { Object orgIdObj = params.get("orgId"); List<Device> deviceList = null; if (orgIdObj != null) { Integer orgId = Integer.parseInt(orgIdObj.toString()); List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); params.put("orgIds", orgIds); deviceList = deviceMapper.selectByMap(params); loadDeviceState(deviceList); } return deviceList; } /** * 根据组织id和监控点id 分页查询设备 * @param orgId * @param mpId * @param pageSize * @param pageNo * @return 返回未删除结果 */ @Override public PageResult query(Integer orgId, Integer mpId, Integer pageSize, Integer pageNo) { List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); if(!ObjectUtils.isEmpty(pageSize)&&!ObjectUtils.isEmpty(pageNo)){ PageHelper.startPage(pageNo,pageSize); } List<Device> list = deviceMapper.selectByOrgIdAndMpId(orgId,orgIds,mpId); //从redis里取状态 loadDeviceState(list); if(list instanceof Page){ return new PageResult(((Page) list).getTotal(),list); } return new PageResult(null,list); } private void loadDeviceState(List<Device> list){ //从redis里取状态 list.stream().map( device -> { String mac = device.getMac(); if(!StringUtils.isBlank(mac)){ String state = getSateFromRedis(device.getMonitorPointId(),mac.toLowerCase()); device.setState(state); }else{ device.setState(Constants.DEVICE_STATE_OFFLINE); } return device; }).count(); } private String getSateFromRedis(Integer mpId,String mac){ /** * 根据组织id和设备名称 分页查询设备 * * @param orgId * @param deviceName * @param pageSize * @param pageNo * @return 返回未删除结果 */ @Override public PageResult query(Integer orgId, String deviceName, Integer pageSize, Integer pageNo) { List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); if (!ObjectUtils.isEmpty(pageSize) && !ObjectUtils.isEmpty(pageNo)) { PageHelper.startPage(pageNo, pageSize); } String state = null; switch (deviceName) { case "正常": state = "0"; deviceName = null; break; case "轻度": state = "1"; deviceName = null; break; case "中度": state = "2"; deviceName = null; break; case "重度": state = "3"; deviceName = null; break; case "维保": state = "4"; deviceName = null; break; } List<Device> list = deviceMapper.selectByOrgIdAndDevName(orgId, orgIds, state, deviceName); //从redis里取状态 loadDeviceState(list); if (list instanceof Page) { return new PageResult(((Page) list).getTotal(), list); } return new PageResult(null, list); } Map<String,String> stateMap = getStateMapFromRedis(mpId,mac); String state = null; if(stateMap != null){ state = stateMap.get("state"); } state = state == null ?Constants.DEVICE_STATE_OFFLINE:state; return state; } public Map<String,String> getStateMapFromRedis(Integer mpId,String mac){ StringBuilder key = new StringBuilder(); //拼凑key key.append("state_").append(mpId).append("_").append(mac); return redisUtils.get(key.toString(),new TypeReference<Map<String,String>>(){}); } private Device getDeviceWithOrgIdsByMac(String mac) { String key = "device_"+mac; Device device = redisUtils.get(key,Device.class); if(device==null) { device = deviceMapper.selectWithOrgIdsByMac(mac); if(device!=null){ redisUtils.set(key,device); } } return device; } /** * 根据组织id和监控点id 分页查询设备 * * @param orgId * @param mpId * @param pageSize * @param pageNo * @return 返回未删除结果 */ @Override public PageResult query(Integer orgId, Integer mpId, Integer pageSize, Integer pageNo) { List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); if (!ObjectUtils.isEmpty(pageSize) && !ObjectUtils.isEmpty(pageNo)) { PageHelper.startPage(pageNo, pageSize); } List<Device> list = deviceMapper.selectByOrgIdAndMpId(orgId, orgIds, mpId); //从redis里取状态 loadDeviceState(list); if (list instanceof Page) { return new PageResult(((Page) list).getTotal(), list); } return new PageResult(null, list); } /** * 要在数据库更改后刷新 * 刷新 redis 设备的信息,注意此处指删除不做更新。更新由task完成 * @param mac */ private void refreshDeviceInRedis(String mac){ if(!StringUtils.isBlank(mac)){ String key = getDeviceKey(mac); redisUtils.remove(key); }else { log.warn("param mac is null in method [refreshDeviceInRedis]"); } } @Override public int countByExample(PageBean pageBean){ Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean); addDeletesToExample(example); private void loadDeviceState(List<Device> list) { //从redis里取状态 list.stream().map(device -> { String mac = device.getMac(); if (!StringUtils.isBlank(mac)) { String state = getSateFromRedis(device.getMonitorPointId(), mac.toLowerCase()); device.setState(state); } else { device.setState(Constants.DEVICE_STATE_OFFLINE); } return device; }).count(); } private String getSateFromRedis(Integer mpId, String mac) { Map<String, String> stateMap = getStateMapFromRedis(mpId, mac); String state = null; if (stateMap != null) { state = stateMap.get("state"); } state = state == null ? Constants.DEVICE_STATE_OFFLINE : state; return state; } public Map<String, String> getStateMapFromRedis(Integer mpId, String mac) { StringBuilder key = new StringBuilder(); //拼凑key key.append("state_").append(mpId).append("_").append(mac); return redisUtils.get(key.toString(), new TypeReference<Map<String, String>>() { }); } private Device getDeviceWithOrgIdsByMac(String mac) { String key = "device_" + mac; Device device = redisUtils.get(key, Device.class); if (device == null) { device = deviceMapper.selectWithOrgIdsByMac(mac); if (device != null) { redisUtils.set(key, device); } } return device; } /** * 要在数据库更改后刷新 * 刷新 redis 设备的信息,注意此处指删除不做更新。更新由task完成 * * @param mac */ private void refreshDeviceInRedis(String mac) { if (!StringUtils.isBlank(mac)) { String key = getDeviceKey(mac); redisUtils.remove(key); } else { log.warn("param mac is null in method [refreshDeviceInRedis]"); } } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); TkMybatisUtils.addDeletesToExample(example); return deviceMapper.selectCountByExample(example); } } /** * 增加删除条件过滤 * @param example */ private void addDeletesToExample(Example example){ List<Example.Criteria> criteriaList = example.getOredCriteria(); if(criteriaList!=null&&criteriaList.size()>0){ for(Example.Criteria cri : criteriaList){ cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE); } }else { example.or().andNotEqualTo("isDelete",Constants.IS_DELETE_TRUE); } } @Override public PageBean queryByPageBean(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean); @Override public PageBean queryByPageBean(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); // addDeletesToExample(example); if(pageBean.getPageSize()>0){ PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize()); } List<Device> deviceList = deviceMapper.selectWithRelationData(example); return new PageBean(deviceList); } if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List<Device> deviceList = deviceMapper.selectWithRelationData(example); return new PageBean(deviceList); } @Override public void deleteByIds(Integer[] ids) { Device device = new Device(); device.setIsDelete(Constants.IS_DELETE_TRUE); if(ids!=null&&ids.length>0){ Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); if(ids.length==1){ device.setId(ids[0]); deviceMapper.updateByPrimaryKeySelective(device); }else{ deviceMapper.updateByExampleSelective(device,example); } List<Device> deviceList = deviceMapper.selectByExample(example); List<String> adjustAndDeviceKeys = deviceList.stream().collect( ArrayList<String>::new, (list,dev) -> { if(!StringUtils.isBlank(dev.getMac())){ list.add("device_"+dev.getMac()); list.add("adjust_"+dev.getMac()); } }, (oList,nList)-> { oList.addAll(nList); } ); redisUtils.remove(adjustAndDeviceKeys.toArray(new String [adjustAndDeviceKeys.size()])); } } @Override public void deleteByIds(Integer[] ids) { Device device = new Device(); device.setIsDelete(Constants.IS_DELETE_TRUE); if (ids != null && ids.length > 0) { Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); if (ids.length == 1) { device.setId(ids[0]); deviceMapper.updateByPrimaryKeySelective(device); } else { deviceMapper.updateByExampleSelective(device, example); } List<Device> deviceList = deviceMapper.selectByExample(example); List<String> adjustAndDeviceKeys = deviceList.stream().collect( ArrayList<String>::new, (list, dev) -> { if (!StringUtils.isBlank(dev.getMac())) { list.add("device_" + dev.getMac()); list.add("adjust_" + dev.getMac()); } }, (oList, nList) -> { oList.addAll(nList); } ); redisUtils.remove(adjustAndDeviceKeys.toArray(new String[adjustAndDeviceKeys.size()])); } } @Override @Transactional public void addOrModify(Device device){ try{ //mac 转小写 if(!StringUtils.isBlank(device.getMac())){ device.setMac(device.getMac().toLowerCase()); } if(device.getId()!=null){ deviceMapper.updateByPrimaryKeySelective(device); }else{ Device deviceQuery = new Device(); deviceQuery.setMac(device.getMac()); Device deviceResult = deviceMapper.selectOne(deviceQuery); if(deviceResult !=null){ device.setId(deviceResult.getId()); deviceMapper.updateByPrimaryKeySelective(device); }else { device.setState(Constants.DEVICE_STATE_OFFLINE); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); } } //刷新redis里设备信息 refreshDeviceInRedis(device.getMac()); } catch (Exception ex){ throw ex; } } @Override public List<Map> countByTimes(Date start,Date end,String format){ if(start==null||end==null||StringUtils.isBlank(format)){ log.error("some params is null"); throw new BusinessException("some params is null"); } return deviceMapper.countByTimes(start, end, format); } @Override public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { Device device = new Device(); device.setMonitorPointId(monitorPointId); device.setIsDelete(Constants.IS_DELETE_FALSE); List<Device> devices = deviceMapper.select(device); for (Device device2 : devices) { DeviceProperty deviceProperty = devicePropertyMapper.selectByPrimaryKey(device2.getId()); device2.setDeviceProperty(deviceProperty); } return devices; } @Override @Transactional public void addOrModify(Device device) { try { //mac 转小写 if (!StringUtils.isBlank(device.getMac())) { device.setMac(device.getMac().toLowerCase()); } if (device.getId() != null) { deviceMapper.updateByPrimaryKeySelective(device); } else { Device deviceQuery = new Device(); deviceQuery.setMac(device.getMac()); Device deviceResult = deviceMapper.selectOne(deviceQuery); if (deviceResult != null) { device.setId(deviceResult.getId()); deviceMapper.updateByPrimaryKeySelective(device); } else { device.setState(Constants.DEVICE_STATE_OFFLINE); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); } } //刷新redis里设备信息 refreshDeviceInRedis(device.getMac()); } catch (Exception ex) { throw ex; } } /** * 返回map{mac:,state:} * @param macList * @return */ @Override public List<Map<String,String>> queryDevicesState(List<String> macList,Boolean withData) { List<Map<String,String>> list = macList.stream().map(mac->{ Map<String,String> resultMap = new HashMap<>(); if(!StringUtils.isBlank(mac)){ mac = mac.toLowerCase(); Device device = getDeviceWithOrgIdsByMac(mac); Map<String,String> stateMap = getStateMapFromRedis(device.getMonitorPointId(),mac); if(!MapUtils.isEmpty(stateMap)){ resultMap.putAll(stateMap); }else{ resultMap.put("state",Constants.DEVICE_STATE_OFFLINE); resultMap.put("mac",mac); } //添加data if(BooleanUtils.isTrue(withData)){ String dataKey = "data_"+mac; Map<String,String> dataMap = redisUtils.get(dataKey,new TypeReference<Map<String,String>>(){}); if(!MapUtils.isEmpty(dataMap)){ resultMap.putAll(dataMap); } } } return resultMap; }).collect(Collectors.toList()); return list; } @Override public List<Map> countByTimes(Date start, Date end, String format) { if (start == null || end == null || StringUtils.isBlank(format)) { log.error("some params is null"); throw new BusinessException("some params is null"); } return deviceMapper.countByTimes(start, end, format); } @Override public Device queryById(Integer id) { return deviceMapper.selectByPrimaryKey(id); } @Override public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { Device device = new Device(); device.setMonitorPointId(monitorPointId); device.setIsDelete(Constants.IS_DELETE_FALSE); List<Device> devices = deviceMapper.select(device); for (Device device2 : devices) { DeviceProperty deviceProperty = devicePropertyMapper.selectByPrimaryKey(device2.getId()); device2.setDeviceProperty(deviceProperty); } return devices; } @Override public List<Device> getDevicesByProfessionId(Map<String, Object> parameters) { return deviceMapper.getDevicesByProfession(parameters); } /** * 返回map{mac:,state:} * * @param macList * @return */ @Override public List<Map<String, String>> queryDevicesState(List<String> macList, Boolean withData) { List<Map<String, String>> list = macList.stream().map(mac -> { Map<String, String> resultMap = new HashMap<>(); if (!StringUtils.isBlank(mac)) { mac = mac.toLowerCase(); Device device = getDeviceWithOrgIdsByMac(mac); Map<String, String> stateMap = getStateMapFromRedis(device.getMonitorPointId(), mac); if (!MapUtils.isEmpty(stateMap)) { resultMap.putAll(stateMap); } else { resultMap.put("state", Constants.DEVICE_STATE_OFFLINE); resultMap.put("mac", mac); } //添加data if (BooleanUtils.isTrue(withData)) { String dataKey = "data_" + mac; Map<String, String> dataMap = redisUtils.get(dataKey, new TypeReference<Map<String, String>>() { }); if (!MapUtils.isEmpty(dataMap)) { resultMap.putAll(dataMap); } } } return resultMap; }).collect(Collectors.toList()); return list; } @Override public List<Device> getDevicesByOrganizationId(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("organizationId"), "param.is.null"); return deviceMapper.getDevicesByOrganizationId(parameters); } @Override public Map<String,Long> queryDeviceStateSummary(@NotNull Integer orgId){ Map<String,Object> params = new HashMap<>(); if(!dictionaryDataMapper.isSupperOrgId(orgId)){ List<Integer> orgIds = organizationMapper.selectLowerOrgIds(orgId); params.put("orgIds",orgIds); } List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(params); Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L; for (Map<String, Object> map : list) { Long count = (Long) map.get("count"); all += count; switch (Integer.valueOf((String) map.get("state"))) { case 0: normal = count; break; case 4: stop = count; break; default: abnormal += count; } } Map<String,Long> result = new HashMap<>(); result.put("all", all); result.put("normal", normal); result.put("abnormal", abnormal); result.put("stop", stop); return result; } @Override public Device queryById(Integer id) { return deviceMapper.selectByPrimaryKey(id); } @Resource private DevicePropertyMapper devicePropertyMapper; @Override @Transactional public void saveOrUpdate(Device device, DeviceProperty deviceProperty) { device.setMac(device.getMac().toLowerCase()); if (ObjectUtils.isEmpty(device.getId())) { device.setState(Constants.DEVICE_STATE_OFFLINE); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); deviceProperty.setId(device.getId()); } else { deviceMapper.updateByPrimaryKeySelective(device); devicePropertyMapper.deleteByPrimaryKey(deviceProperty); } devicePropertyMapper.insertSelective(deviceProperty); refreshDeviceInRedis(device.getMac()); @Override public List<Device> getDevicesByProfessionId(Map<String, Object> parameters) { } @Override public PageBean getDeviceList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean); if(pageBean.getPageSize()>0){ PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize()); } List<Device> deviceList = deviceMapper.getDeviceList(example); return new PageBean(deviceList); } return deviceMapper.getDevicesByProfession(parameters); } @Override public void offLinToMaintenance(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("id"), "param.is.null"); ValidateUtil.notNull(parameters.get("old_state"), "param.is.null"); ValidateUtil.notNull(parameters.get("new_state"), "param.is.null"); int count = 0; if (Constants.DEVICE_STATE_OFFLINE.equals(parameters.get("old_state")) && Constants.DEVICE_STATE_MAINTENANCE.equals(parameters.get("new_state"))) { Device device = new Device(); Example example = new Example(ENTITY_CLASS); example.and().andEqualTo("id", new Integer(parameters.get("id").toString())).andEqualTo("state", Constants.DEVICE_STATE_OFFLINE); device.setState(Constants.DEVICE_STATE_MAINTENANCE); count = deviceMapper.updateByExampleSelective(device, example); } if (count == 0) { throw new BusinessException("参数不合法!"); } } @Override public List<Device> getDevicesByOrganizationId(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("organizationId"), "param.is.null"); return deviceMapper.getDevicesByOrganizationId(parameters); } @Override public void saveOrUpdate4Mobile(Device device, DeviceProperty deviceProperty) { device.setMac(device.getMac().toLowerCase()); Device selectDevice = new Device(); selectDevice.setMac(device.getMac()); selectDevice = deviceMapper.selectOne(selectDevice); if (ObjectUtils.isEmpty(selectDevice)) { device.setState(Constants.DEVICE_STATE_OFFLINE); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); deviceProperty.setId(device.getId()); devicePropertyMapper.insertSelective(deviceProperty); } else { device.setId(selectDevice.getId()); deviceMapper.updateByPrimaryKeySelective(device); deviceProperty.setId(selectDevice.getId()); devicePropertyMapper.selectByPrimaryKey(selectDevice.getId()); if (ObjectUtils.isEmpty(devicePropertyMapper.selectByPrimaryKey(deviceProperty.getId()))) { devicePropertyMapper.insertSelective(deviceProperty); } else { devicePropertyMapper.updateByPrimaryKeySelective(deviceProperty); } } refreshDeviceInRedis(device.getMac()); @Override public Map<String, Long> queryDeviceStateSummary(@NotNull Integer orgId) { Map<String, Object> params = new HashMap<>(); if (!dictionaryDataMapper.isSupperOrgId(orgId)) { List<Integer> orgIds = organizationMapper.selectLowerOrgIds(orgId); params.put("orgIds", orgIds); } List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(params); Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L; for (Map<String, Object> map : list) { Long count = (Long) map.get("count"); all += count; switch (Integer.valueOf((String) map.get("state"))) { case 0: normal = count; break; case 4: stop = count; break; default: abnormal += count; } } Map<String, Long> result = new HashMap<>(); result.put("all", all); result.put("normal", normal); result.put("abnormal", abnormal); result.put("stop", stop); return result; } } @Resource private DevicePropertyMapper devicePropertyMapper; @Override public String getLimitDataByDevice(Map<String, Object> parameters) { // TODO Auto-generated method stub return deviceMapper.getLimitDataByDevice(parameters); } @Override @Transactional public void saveOrUpdate(Device device, DeviceProperty deviceProperty) { device.setMac(device.getMac().toLowerCase()); if (ObjectUtils.isEmpty(device.getId())) { device.setState(Constants.DEVICE_STATE_OFFLINE); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); deviceProperty.setId(device.getId()); } else { deviceMapper.updateByPrimaryKeySelective(device); devicePropertyMapper.deleteByPrimaryKey(deviceProperty); } devicePropertyMapper.insertSelective(deviceProperty); refreshDeviceInRedis(device.getMac()); //按经度升序排序,通过mac地址找到相邻经度的第二个点位置 @Override public Device getDeviceByLongitudeAsc(String mac) { Example example = new Example(Device.class); example.setOrderByClause("longitude ASC"); List<Device> deviceList=deviceMapper.selectByExample(example); for(int i=0;i<deviceList.size();i++){ if(mac.equals(deviceList.get(i).getMac())){ Device deviceSecond=deviceList.get(i+1); return deviceSecond; } } return null; } } @Override public PageBean getDeviceList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List<Device> deviceList = deviceMapper.getDeviceList(example); return new PageBean(deviceList); } @Override public void offLinToMaintenance(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("id"), "param.is.null"); ValidateUtil.notNull(parameters.get("old_state"), "param.is.null"); ValidateUtil.notNull(parameters.get("new_state"), "param.is.null"); int count = 0; if (Constants.DEVICE_STATE_OFFLINE.equals(parameters.get("old_state")) && Constants.DEVICE_STATE_MAINTENANCE.equals(parameters.get("new_state"))) { Device device = new Device(); Example example = new Example(ENTITY_CLASS); example.and().andEqualTo("id", new Integer(parameters.get("id").toString())).andEqualTo("state", Constants.DEVICE_STATE_OFFLINE); device.setState(Constants.DEVICE_STATE_MAINTENANCE); count = deviceMapper.updateByExampleSelective(device, example); } if (count == 0) { throw new BusinessException("参数不合法!"); } } @Override public void saveOrUpdate4Mobile(Device device, DeviceProperty deviceProperty) { device.setMac(device.getMac().toLowerCase()); Device selectDevice = new Device(); selectDevice.setMac(device.getMac()); selectDevice = deviceMapper.selectOne(selectDevice); if (ObjectUtils.isEmpty(selectDevice)) { device.setState(Constants.DEVICE_STATE_OFFLINE); device.setIsDelete(Constants.IS_DELETE_FALSE); deviceMapper.insertSelective(device); deviceProperty.setId(device.getId()); devicePropertyMapper.insertSelective(deviceProperty); } else { device.setId(selectDevice.getId()); deviceMapper.updateByPrimaryKeySelective(device); deviceProperty.setId(selectDevice.getId()); devicePropertyMapper.selectByPrimaryKey(selectDevice.getId()); if (ObjectUtils.isEmpty(devicePropertyMapper.selectByPrimaryKey(deviceProperty.getId()))) { devicePropertyMapper.insertSelective(deviceProperty); } else { devicePropertyMapper.updateByPrimaryKeySelective(deviceProperty); } } refreshDeviceInRedis(device.getMac()); } @Override public String getLimitDataByDevice(Map<String, Object> parameters) { // TODO Auto-generated method stub return deviceMapper.getLimitDataByDevice(parameters); } //按经度升序排序,通过mac地址找到相邻经度的第二个点位置 @Override public Device getDeviceByLongitudeAsc(String mac) { Example example = new Example(Device.class); example.setOrderByClause("longitude ASC"); List<Device> deviceList = deviceMapper.selectByExample(example); for (int i = 0; i < deviceList.size(); i++) { if (mac.equals(deviceList.get(i).getMac())) { Device deviceSecond = deviceList.get(i + 1); return deviceSecond; } } return null; } } src/main/java/com/moral/service/impl/MenuServiceImpl.java
New file @@ -0,0 +1,139 @@ package com.moral.service.impl; import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.github.pagehelper.PageHelper; import com.moral.common.bean.Constants; import com.moral.common.bean.PageBean; import com.moral.common.util.ExampleUtil; import com.moral.entity.Menu; import com.moral.mapper.MenuMapper; import com.moral.service.MenuService; import com.moral.util.TkMybatisUtils; import tk.mybatis.mapper.entity.Example; @Service public class MenuServiceImpl implements MenuService { private static Class ENTITY_CLASS = Menu.class; @Resource private MenuMapper menuMapper; @Override public void addOrModify(Menu menu) { try { menu.setUpdateTime(new Date()); menu.setUpdateUser(menu.getUpdateUser()); if (menu.getId() != null) { menuMapper.updateByPrimaryKeySelective(menu); } else { Menu menuQuery = new Menu(); menuQuery.setMenuCode(menu.getMenuCode()); menuQuery.setIsDelete(Constants.IS_DELETE_FALSE); Menu menuResult = menuMapper.selectOne(menuQuery); if (menuResult != null) { menu.setId(menuResult.getId()); menuMapper.updateByPrimaryKeySelective(menu); } else { menu.setIsDelete(Constants.IS_DELETE_FALSE); menu.setCreateTime(new Date()); menu.setCreateUser(menu.getCreateUser()); menuMapper.insertSelective(menu); } } } catch (Exception ex) { throw ex; } } @Override public PageBean queryByPageBean(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); List<Example.Criteria> criteriaList = example.getOredCriteria(); if (criteriaList != null && criteriaList.size() > 0) { for (Example.Criteria cri : criteriaList) { cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE); } } else { example.or().andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE); } if (example.getOrderByClause() == null || example.getOrderByClause().isEmpty()) { example.setOrderByClause("menu_name asc"); } List<Menu> menuList = menuMapper.selectWithMenuNameByExample(example); Iterator<Menu> iterator = menuList.iterator(); while (iterator.hasNext()) { Menu menu = iterator.next(); if (menu.getMenuParentId() == null) { iterator.remove(); } } return new PageBean(menuList); } @Override public PageBean queryByAllPageBean(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); List<Example.Criteria> criteriaList = example.getOredCriteria(); if (criteriaList != null && criteriaList.size() > 0) { for (Example.Criteria cri : criteriaList) { cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE); } } else { example.or().andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE); } if (example.getOrderByClause() == null || example.getOrderByClause().isEmpty()) { example.setOrderByClause("menu_name asc"); } List<Menu> menuList = menuMapper.selectWithMenuNameByExample(example); Iterator<Menu> iterator = menuList.iterator(); return new PageBean(menuList); } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); TkMybatisUtils.addDeletesToExample(example); return menuMapper.selectCountByExample(example); } @Override public PageBean getMenuList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List<Menu> menuList = menuMapper.getMenuList(example); return new PageBean(menuList); } @Override public List<Menu> getMenuParentList(String menuName) { List<Menu> menuParentList = menuMapper.getParentMenuList(menuName); return menuParentList; } @Override public void deleteByIds(Integer[] ids) { Menu menu = new Menu(); menu.setIsDelete(Constants.IS_DELETE_TRUE); Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); menuMapper.updateByExampleSelective(menu, example); } @Override public List<Menu> getMenuListByName(String menuName) { List<Menu> menuList = menuMapper.getMenuListByName(menuName); return menuList; } } src/main/java/com/moral/service/impl/RoleMenuServiceImpl.java
New file @@ -0,0 +1,76 @@ package com.moral.service.impl; import java.util.Arrays; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.github.pagehelper.PageHelper; import com.moral.common.bean.PageBean; import com.moral.common.util.ExampleUtil; import com.moral.entity.RoleMenu; import com.moral.mapper.RoleMenuMapper; import com.moral.service.RoleMenuService; import tk.mybatis.mapper.entity.Example; @Service public class RoleMenuServiceImpl implements RoleMenuService { private static Class ENTITY_CLASS = RoleMenu.class; @Resource private RoleMenuMapper roleMenuMapper; @Override public void addOrModify(RoleMenu roleMenu) { try { if (roleMenu.getId() != null) { roleMenuMapper.updateByPrimaryKey(roleMenu); } else { RoleMenu roleMenuQuery = new RoleMenu(); roleMenuQuery.setRoleId(roleMenu.getRoleId()); roleMenuQuery.setMenuId(roleMenu.getMenuId()); RoleMenu roleMenuResult = roleMenuMapper.selectOne(roleMenuQuery); if (roleMenuResult == null) { roleMenuMapper.insertSelective(roleMenu); } } } catch (Exception ex) { throw ex; } } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); return roleMenuMapper.selectCountByExample(example); } @Override public PageBean getRoleMenuList(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); if (pageBean.getPageSize() > 0) { PageHelper.startPage(pageBean.getPageIndex(), pageBean.getPageSize()); } List<RoleMenu> roleMenuList = roleMenuMapper.getRoleMenuList(example); return new PageBean(roleMenuList); } @Override public void deleteByIds(Integer... ids) { if (ids != null && ids.length > 0) { if (ids.length == 1) { roleMenuMapper.deleteByPrimaryKeyOwn(ids[0]); } else { Example example = new Example(ENTITY_CLASS); example.or().andIn("id", Arrays.asList(ids)); roleMenuMapper.deleteByExample(example); } } } } src/main/java/com/moral/service/impl/RoleServiceImpl.java
New file @@ -0,0 +1,86 @@ package com.moral.service.impl; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.moral.common.bean.Constants; import com.moral.common.bean.PageBean; import com.moral.common.util.ExampleUtil; import com.moral.common.util.MyBatisBaseMapUtil; import com.moral.entity.Role; import com.moral.mapper.RoleMapper; import com.moral.service.RoleService; import com.moral.util.TkMybatisUtils; import tk.mybatis.mapper.entity.Example; @Service public class RoleServiceImpl implements RoleService { private static Class ENTITY_CLASS = Role.class; @Resource RoleMapper roleMapper; @Override public PageBean<Role> queryByPageBean(PageBean pageBean) { return MyBatisBaseMapUtil.queryPage(roleMapper, pageBean, ENTITY_CLASS); } @Override @Transactional public void addOrModify(Role role) { try { role.setUpdateTime(new Date()); role.setUpdateUser(role.getUpdateUser()); if (role.getId() != null) { roleMapper.updateByPrimaryKeySelective(role); } else { Role roleQuery = new Role(); roleQuery.setRoleCode(role.getRoleCode()); roleQuery.setIsDelete(Constants.IS_DELETE_FALSE); Role roleResult = roleMapper.selectOne(roleQuery); if (roleResult != null) { role.setId(roleResult.getId()); roleMapper.updateByPrimaryKeySelective(role); } else { role.setIsDelete(Constants.IS_DELETE_FALSE); role.setCreateTime(new Date()); role.setCreateUser(role.getCreateUser()); roleMapper.insertSelective(role); } } } catch (Exception ex) { throw ex; } } @Override @Transactional public int deleteByIds(List<Integer> ids) { Role role = new Role(); role.setIsDelete(Constants.IS_DELETE_TRUE); Example example = new Example(ENTITY_CLASS); example.or().andIn("id", ids); return roleMapper.updateByExampleSelective(role, example); } @Override public int countByExample(PageBean pageBean) { Example example = ExampleUtil.generateExample(ENTITY_CLASS, pageBean); TkMybatisUtils.addDeletesToExample(example); return roleMapper.selectCountByExample(example); } @Override public List<Role> getRoleList(String roleName) { List<Role> roleList = roleMapper.getRoleList(roleName); return roleList; } } src/main/java/com/moral/util/TkMybatisUtils.java
New file @@ -0,0 +1,25 @@ package com.moral.util; import java.util.List; import com.moral.common.bean.Constants; import tk.mybatis.mapper.entity.Example; public class TkMybatisUtils { /** * 增加删除条件过滤 * @param example */ public static void addDeletesToExample(Example example){ List<Example.Criteria> criteriaList = example.getOredCriteria(); if(criteriaList!=null&&criteriaList.size()>0){ for(Example.Criteria cri : criteriaList){ cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE); } }else { example.or().andNotEqualTo("isDelete",Constants.IS_DELETE_TRUE); } } } src/main/resources/mapper/AccountMapper.xml
@@ -45,4 +45,14 @@ FROM account WHERE id=#{id} </select> <select id="getAccountList" resultMap="BaseResultMap"> select <include refid="Base_Column_List"/> from account where is_delete=0 and expire_time > now() <if test="accountName != 'null'"> and account_name like concat('%',#{accountName},'%') </if> </select> </mapper> src/main/resources/mapper/AccountRoleMapper.xml
New file @@ -0,0 +1,80 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.moral.mapper.AccountRoleMapper"> <resultMap id="ResultMap" type="com.moral.entity.AccountRole" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="account_id" property="accountId" jdbcType="INTEGER" /> <result column="role_id" property="roleId" jdbcType="INTEGER" /> </resultMap> <resultMap id="BaseResultMap" type="com.moral.entity.AccountRole" extends="ResultMap"> <association property="account" javaType="com.moral.entity.Account"> <result column="account_id" jdbcType="INTEGER" property="id" /> <result column="account_name" jdbcType="VARCHAR" property="accountName" /> </association> <association property="role" javaType="com.moral.entity.Role"> <result column="role_id" property="id" jdbcType="INTEGER" /> <result column="role_name" property="roleName" jdbcType="VARCHAR" /> </association> </resultMap> <sql id="Example_Where_Clause" > <where > <foreach collection="oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <select id="getAccountRoleList" resultMap="BaseResultMap"> select ar.*, a.account_name, r.role_name from account_role ar left join account a on ar.account_id = a.id left join role r on ar.role_id = r.id <if test="_parameter != null"> <include refid="Example_Where_Clause"/> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> </select> <update id="updateByPrimaryKey" parameterType="com.moral.entity.AccountRole" > update account_role set account_id = #{accountId,jdbcType=INTEGER}, role_id = #{roleId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> <delete id="deleteByPrimaryKeyOwn" parameterType="java.lang.Integer" > delete from account_role where id = #{id,jdbcType=INTEGER} </delete> </mapper> src/main/resources/mapper/MenuMapper.xml
New file @@ -0,0 +1,108 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.moral.mapper.MenuMapper"> <resultMap id="BaseResultMap" type="com.moral.entity.Menu"> <id column="id" property="id" jdbcType="INTEGER"/> <result column="menu_code" property="menuCode" jdbcType="VARCHAR"/> <result column="menu_name" property="menuName" jdbcType="VARCHAR"/> <result column="menu_icon" property="menuIcon" jdbcType="VARCHAR"/> <result column="menu_url" property="menuUrl" jdbcType="VARCHAR"/> <result column="menu_order" property="menuOrder" jdbcType="INTEGER"/> <result column="menu_parent_id" property="menuParentId" jdbcType="INTEGER"/> <result column="menu_remark" property="menuRemark" jdbcType="VARCHAR"/> <result column="is_delete" property="isDelete" jdbcType="CHAR"/> <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="create_user" property="createUser" jdbcType="VARCHAR"/> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/> <result column="update_user" property="updateUser" jdbcType="VARCHAR"/> </resultMap> <sql id="Example_Where_Clause"> <where> <foreach collection="oredCriteria" item="criteria" separator="or"> <if test="criteria.valid"> <trim prefix="(" suffix=")" prefixOverrides="and"> <foreach collection="criteria.criteria" item="criterion"> <choose> <when test="criterion.noValue"> and ${criterion.condition} </when> <when test="criterion.singleValue"> and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue"> and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue"> and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator=","> #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <select id="selectWithMenuNameByExample" parameterType="tk.mybatis.mapper.entity.Example" resultMap="BaseResultMap"> select <if test="distinct"> distinct </if> <include refid="Base_Column_List"/> from menu <if test="_parameter != null"> <include refid="Example_Where_Clause"/> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> </select> <select id="getMenuList" resultMap="BaseResultMap" parameterType="tk.mybatis.mapper.entity.Example"> select <if test="distinct"> distinct </if> <include refid="Base_Column_List"/> from menu <if test="_parameter != null"> <include refid="Example_Where_Clause"/> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> </select> <sql id="Base_Column_List"> id, menu_code, menu_name, menu_icon, menu_url, menu_order, menu_parent_id, menu_remark, is_delete, create_time, create_user, update_time, update_user </sql> <select id="getParentMenuList" resultMap="BaseResultMap"> select distinct <include refid="Base_Column_List"/> from menu where id IN (select distinct(menu_parent_Id) from menu where menu_parent_Id is not null) <if test="menuName != 'null'"> and menu_name like concat('%',#{menuName},'%') </if> </select> <select id="getMenuListByName" resultMap="BaseResultMap"> select <include refid="Base_Column_List"/> from menu where is_delete=0 <if test="menuName != 'null'"> and menu_name like concat('%',#{menuName},'%') </if> </select> </mapper> src/main/resources/mapper/RoleMapper.xml
New file @@ -0,0 +1,115 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.moral.mapper.RoleMapper"> <resultMap id="BaseResultMap" type="com.moral.entity.Role"> <id column="id" property="id" jdbcType="INTEGER"/> <result column="role_code" property="roleCode" jdbcType="VARCHAR"/> <result column="role_name" property="roleName" jdbcType="VARCHAR"/> <result column="is_delete" property="isDelete" jdbcType="CHAR"/> <result column="role_remark" property="roleRemark" jdbcType="VARCHAR"/> <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="create_user" property="createUser" jdbcType="VARCHAR"/> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/> <result column="update_user" property="updateUser" jdbcType="VARCHAR"/> </resultMap> <sql id="Base_Column_List"> id, role_code, role_name, is_delete, role_remark, create_time, create_user, update_time, update_user </sql> <insert id="insertSelective" parameterType="com.moral.entity.Role"> insert into role <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="roleCode != null"> role_code, </if> <if test="roleName != null"> role_name, </if> <if test="isDelete != null"> is_delete, </if> <if test="roleRemark != null"> role_remark, </if> <if test="createTime != null"> create_time, </if> <if test="createUser != null"> create_user, </if> <if test="updateTime != null"> update_time, </if> <if test="updateUser != null"> update_user, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=INTEGER}, </if> <if test="roleCode != null"> #{roleCode,jdbcType=VARCHAR}, </if> <if test="roleName != null"> #{roleName,jdbcType=VARCHAR}, </if> <if test="isDelete != null"> #{isDelete,jdbcType=CHAR}, </if> <if test="roleRemark != null"> #{roleRemark,jdbcType=VARCHAR}, </if> <if test="createTime != null"> #{createTime,jdbcType=TIMESTAMP}, </if> <if test="createUser != null"> #{createUser,jdbcType=VARCHAR}, </if> <if test="updateTime != null"> #{updateTime,jdbcType=TIMESTAMP}, </if> <if test="updateUser != null"> #{updateUser,jdbcType=VARCHAR}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.moral.entity.Role"> update role <set> <if test="roleName != null"> role_name=#{roleName,jdbcType=VARCHAR}, </if> <if test="roleCode != null"> role_code=#{roleCode,jdbcType=VARCHAR}, </if> <if test="roleRemark != null"> role_remark=#{roleRemark,jdbcType=VARCHAR}, </if> <if test="updateTime != null"> update_time=#{updateTime,jdbcType=TIMESTAMP}, </if> <if test="updateUser != null"> update_user=#{updateUser,jdbcType=VARCHAR}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <select id="getRoleList" resultMap="BaseResultMap"> select <include refid="Base_Column_List"/> from role where is_delete=0 <if test="roleName != 'null'"> and role_name like concat('%',#{roleName},'%') </if> </select> </mapper> src/main/resources/mapper/RoleMenuMapper.xml
New file @@ -0,0 +1,80 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.moral.mapper.RoleMenuMapper"> <resultMap id="ResultMap" type="com.moral.entity.RoleMenu" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="role_id" property="roleId" jdbcType="INTEGER" /> <result column="menu_id" property="menuId" jdbcType="INTEGER" /> </resultMap> <resultMap id="BaseResultMap" type="com.moral.entity.RoleMenu" extends="ResultMap"> <association property="role" javaType="com.moral.entity.Role"> <result column="role_id" property="id" jdbcType="INTEGER" /> <result column="role_name" property="roleName" jdbcType="VARCHAR" /> </association> <association property="menu" javaType="com.moral.entity.Menu"> <result column="menu_id" property="id" jdbcType="INTEGER"/> <result column="menu_name" property="menuName" jdbcType="VARCHAR"/> </association> </resultMap> <sql id="Example_Where_Clause" > <where > <foreach collection="oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <select id="getRoleMenuList" resultMap="BaseResultMap"> select rm.*, r.role_name, m.menu_name from role_menu rm left join role r on rm.role_id = r.id left join menu m on rm.menu_id = m.id <if test="_parameter != null"> <include refid="Example_Where_Clause"/> </if> <if test="orderByClause != null"> order by ${orderByClause} </if> </select> <update id="updateByPrimaryKey" parameterType="com.moral.entity.RoleMenu" > update role_menu set role_id = #{roleId,jdbcType=INTEGER}, menu_id = #{menuId,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} </update> <delete id="deleteByPrimaryKeyOwn" parameterType="java.lang.Integer" > delete from role_menu where id = #{id,jdbcType=INTEGER} </delete> </mapper>