From 7214ae59e03b79372a923eae8206082efc3fab85 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Thu, 07 Dec 2017 17:08:28 +0800 Subject: [PATCH] app 接口 --- src/main/java/com/moral/entity/Organization.java | 81 ++++++- src/main/java/com/moral/service/OrganizationService.java | 5 src/main/java/com/moral/controller/MobileController.java | 25 + src/main/java/com/moral/service/OperateUserService.java | 4 src/main/resources/mapper/AccountMapper.xml | 13 - src/main/java/com/moral/service/impl/OperateUserServiceImpl.java | 22 - src/main/java/com/moral/service/impl/DeviceServiceImpl.java | 34 +- src/main/java/com/moral/mapper/MonitorPointMapper.java | 11 + src/main/java/com/moral/config/MessageSourceConfig.java | 22 ++ src/main/java/com/moral/mapper/AccountMapper.java | 1 src/main/java/com/moral/service/DeviceService.java | 2 src/main/java/com/moral/entity/OperateUser.java | 3 src/main/java/com/moral/service/MonitorPointService.java | 11 + src/main/resources/mapper/HistoryMapper.xml | 16 src/main/java/com/moral/controller/ScreenController.java | 4 src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java | 23 ++ src/main/java/com/moral/service/AccountService.java | 5 src/main/resources/mapper/OrganizationMapper.xml | 32 +- src/main/java/com/moral/service/impl/AccountServiceImpl.java | 29 - src/main/java/com/moral/config/InjectionConfig.java | 22 ++ src/main/java/com/moral/entity/MonitorPoint.java | 97 ++++++++ src/main/resources/mapper/DeviceMapper.xml | 20 - src/main/java/com/moral/entity/Account.java | 45 ++++ src/main/java/com/moral/entity/Device.java | 3 /dev/null | 23 -- src/main/java/com/moral/entity/OrganizationRelation.java | 3 src/main/resources/mapper/MonitorPointMapper.xml | 14 + src/main/java/com/moral/service/impl/OrganizationServiceImpl.java | 14 src/main/java/com/moral/mapper/OrganizationMapper.java | 4 src/main/resources/application.yml | 6 src/main/resources/i18n/exceptions_zh_CN.properties | 8 31 files changed, 432 insertions(+), 170 deletions(-) diff --git a/src/main/java/com/moral/config/InjectionConfig.java b/src/main/java/com/moral/config/InjectionConfig.java new file mode 100644 index 0000000..4948846 --- /dev/null +++ b/src/main/java/com/moral/config/InjectionConfig.java @@ -0,0 +1,22 @@ +package com.moral.config; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; + +import org.springframework.context.MessageSource; +import org.springframework.stereotype.Component; + +import com.moral.common.util.ValidateUtil; + + +@Component +public class InjectionConfig { + + @Resource + MessageSource resources; + + @PostConstruct + private void init() { + ValidateUtil.setResources(resources); + } +} \ No newline at end of file diff --git a/src/main/java/com/moral/config/MessageSourceConfig.java b/src/main/java/com/moral/config/MessageSourceConfig.java new file mode 100644 index 0000000..e4dfcc6 --- /dev/null +++ b/src/main/java/com/moral/config/MessageSourceConfig.java @@ -0,0 +1,22 @@ +package com.moral.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.i18n.SessionLocaleResolver; + +@Configuration +public class MessageSourceConfig { + @Bean(name="localeResolver") + public LocaleResolver localeResolverBean() { + return new SessionLocaleResolver(); + } + + @Bean(name="messageSource") + public ResourceBundleMessageSource resourceBundleMessageSource(){ + ResourceBundleMessageSource source=new ResourceBundleMessageSource(); + source.setBasename("i18n/exceptions"); + return source; + } +} \ No newline at end of file diff --git a/src/main/java/com/moral/controller/MobileController.java b/src/main/java/com/moral/controller/MobileController.java index d178bc7..8fcf666 100644 --- a/src/main/java/com/moral/controller/MobileController.java +++ b/src/main/java/com/moral/controller/MobileController.java @@ -9,13 +9,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.github.pagehelper.PageHelper; -import com.moral.common.bean.PageBean; import com.moral.common.bean.ResultBean; import com.moral.entity.Device; +import com.moral.entity.MonitorPoint; import com.moral.entity.OperateUser; +import com.moral.entity.Organization; import com.moral.service.DeviceService; +import com.moral.service.MonitorPointService; import com.moral.service.OperateUserService; +import com.moral.service.OrganizationService; @RestController @RequestMapping(value = "mobile") @@ -27,6 +29,12 @@ @Resource private DeviceService deviceService; + + @Resource + private OrganizationService organizationService; + + @Resource + private MonitorPointService monitorPointService; // 1������ @GetMapping(value = "accountlogin") @@ -57,15 +65,20 @@ } @GetMapping(value = "getEquInfoByMac") - public void getEquInfoByMac(String mac) { + public ResultBean<Device> getDeviceByMac(String mac) { + Device device = deviceService.getDeviceByMac(mac); + return new ResultBean<Device>(device); } @GetMapping(value = "getMpointsByAreaName") - public void getMpointsByAreaName(String areaName) { + public ResultBean<List<MonitorPoint>> getMonitorPointsByAreaName(String areaName) { + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByAreaName(areaName); + return new ResultBean<List<MonitorPoint>>(monitorPoints); } @GetMapping(value = "getOrgsByAreaName") - public void getOrgsByAreaName(String areaName) { - + public ResultBean<List<Organization>> getOrganizationsByAreaName(String areaName) { + List<Organization> organizations = organizationService.getOrganizationsByAreaName(areaName); + return new ResultBean<List<Organization>>(organizations); } } diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java index 0da945c..54c309f 100644 --- a/src/main/java/com/moral/controller/ScreenController.java +++ b/src/main/java/com/moral/controller/ScreenController.java @@ -4,7 +4,6 @@ import static com.moral.common.util.RedisUtil.hasKey; import static com.moral.common.util.ResourceUtil.getValue; import static com.moral.common.util.WebUtils.getParametersStartingWith; -import static org.springframework.util.ObjectUtils.isEmpty; import java.io.IOException; import java.io.InputStreamReader; @@ -26,7 +25,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONReader; import com.alibaba.fastjson.TypeReference; -import com.moral.common.exception.BusinessException; import com.moral.common.util.ValidateUtil; import com.moral.service.AccountService; import com.moral.service.DeviceService; @@ -138,8 +136,8 @@ */ @GetMapping("sensor-standard") public Map<String, Object> getStandardBySensor(@RequestParam("macKey") String macKey) { + ValidateUtil.notEmpty(macKey, "param.is.null"); Map<String, Object> result = new HashMap<String, Object>(); - ValidateUtil.notEmpty(macKey, "���������������������"); result.put("standard", getValue(macKey + "-standard")); return result; } diff --git a/src/main/java/com/moral/entity/Account.java b/src/main/java/com/moral/entity/Account.java index c94b61e..935a924 100644 --- a/src/main/java/com/moral/entity/Account.java +++ b/src/main/java/com/moral/entity/Account.java @@ -2,28 +2,71 @@ import java.util.Date; +import javax.persistence.Id; + import lombok.Data; @Data public class Account { - private Integer id; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.id + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ + @Id + private Integer id; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.account_name + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private String accountName; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.password + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private String password; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.organization_id + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private Integer organizationId; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.email + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private String email; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.mobile + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private String mobile; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.weixin + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private String weixin; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.is_delete + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private String isDelete; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.create_time + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private Date createTime; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column account.expire_time + * @mbggenerated Thu Dec 07 16:17:21 CST 2017 + */ private Date expireTime; } \ No newline at end of file diff --git a/src/main/java/com/moral/entity/Device.java b/src/main/java/com/moral/entity/Device.java index ca4ebc2..7c2670f 100644 --- a/src/main/java/com/moral/entity/Device.java +++ b/src/main/java/com/moral/entity/Device.java @@ -2,6 +2,8 @@ import java.util.Date; +import javax.persistence.Id; + import lombok.Data; @@ -13,6 +15,7 @@ * This field was generated by MyBatis Generator. This field corresponds to the database column device.id * @mbggenerated Wed Nov 29 16:17:59 CST 2017 */ + @Id private Integer id; /** * This field was generated by MyBatis Generator. This field corresponds to the database column device.name diff --git a/src/main/java/com/moral/entity/MonitorPoint.java b/src/main/java/com/moral/entity/MonitorPoint.java new file mode 100644 index 0000000..305bee2 --- /dev/null +++ b/src/main/java/com/moral/entity/MonitorPoint.java @@ -0,0 +1,97 @@ +package com.moral.entity; + +import javax.persistence.Id; + +import lombok.Data; + +@Data +public class MonitorPoint { + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.id + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + @Id + private Integer id; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.name + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private String name; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.longitude + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private Float longitude; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.latitude + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private Float latitude; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.province_code + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private Integer provinceCode; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.city_code + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private Integer cityCode; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.area_code + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private Integer areaCode; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.organization_id + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private Integer organizationId; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.address + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private String address; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.is_delete + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private String isDelete; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database column monitor_point.description + * + * @mbggenerated Thu Dec 07 16:40:22 CST 2017 + */ + private String description; +} \ No newline at end of file diff --git a/src/main/java/com/moral/entity/OperateUser.java b/src/main/java/com/moral/entity/OperateUser.java index 405d8db..4f79eba 100644 --- a/src/main/java/com/moral/entity/OperateUser.java +++ b/src/main/java/com/moral/entity/OperateUser.java @@ -2,10 +2,13 @@ import java.util.Date; +import javax.persistence.Id; + import lombok.Data; @Data public class OperateUser { + @Id private Integer id; private String jobNumber; diff --git a/src/main/java/com/moral/entity/Organization.java b/src/main/java/com/moral/entity/Organization.java index c615e27..2449152 100644 --- a/src/main/java/com/moral/entity/Organization.java +++ b/src/main/java/com/moral/entity/Organization.java @@ -2,34 +2,89 @@ import java.util.Date; +import javax.persistence.Id; + import lombok.Data; @Data public class Organization { - private Integer id; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.id + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + @Id + private Integer id; - private String name; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.name + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private String name; - private Integer rank; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.rank + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private Integer rank; - private Integer provinceCode; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.province_code + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private Integer provinceCode; - private Integer cityCode; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.city_code + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private Integer cityCode; - private Integer areaCode; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.area_code + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private Integer areaCode; - private String address; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.address + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private String address; - private String telephone; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.telephone + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private String telephone; - private String email; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.email + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private String email; - private String isDelete; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.is_delete + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private String isDelete; - private Date createTime; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.create_time + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private Date createTime; - private Date expireTime; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.expire_time + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private Date expireTime; - private String description; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column organization.description + * @mbggenerated Thu Dec 07 15:18:16 CST 2017 + */ + private String description; } \ No newline at end of file diff --git a/src/main/java/com/moral/entity/OrganizationRelation.java b/src/main/java/com/moral/entity/OrganizationRelation.java index 008fa4f..7a48c3f 100644 --- a/src/main/java/com/moral/entity/OrganizationRelation.java +++ b/src/main/java/com/moral/entity/OrganizationRelation.java @@ -1,9 +1,12 @@ package com.moral.entity; +import javax.persistence.Id; + import lombok.Data; @Data public class OrganizationRelation { + @Id private Integer id; private Integer parentId; diff --git a/src/main/java/com/moral/mapper/AccountMapper.java b/src/main/java/com/moral/mapper/AccountMapper.java index 22aaf08..3c54a7f 100644 --- a/src/main/java/com/moral/mapper/AccountMapper.java +++ b/src/main/java/com/moral/mapper/AccountMapper.java @@ -7,6 +7,5 @@ import com.moral.entity.Account; public interface AccountMapper extends BaseMapper<Account> { - List<Map<String, Object>> getRoleNameByAccountId(Integer accountId); } \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/MonitorPointMapper.java b/src/main/java/com/moral/mapper/MonitorPointMapper.java new file mode 100644 index 0000000..d05e398 --- /dev/null +++ b/src/main/java/com/moral/mapper/MonitorPointMapper.java @@ -0,0 +1,11 @@ +package com.moral.mapper; + +import java.util.List; + +import com.moral.common.mapper.BaseMapper; +import com.moral.entity.MonitorPoint; + +public interface MonitorPointMapper extends BaseMapper<MonitorPoint>{ + + List<MonitorPoint> getMonitorPointsByAreaName(String areaName); +} \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/OrganizationMapper.java b/src/main/java/com/moral/mapper/OrganizationMapper.java index f0ce07d..7998d97 100644 --- a/src/main/java/com/moral/mapper/OrganizationMapper.java +++ b/src/main/java/com/moral/mapper/OrganizationMapper.java @@ -1,7 +1,11 @@ package com.moral.mapper; +import java.util.List; + import com.moral.common.mapper.BaseMapper; import com.moral.entity.Organization; public interface OrganizationMapper extends BaseMapper<Organization> { + + List<Organization> getOrganizationsByAreaName(String areaName); } \ No newline at end of file diff --git a/src/main/java/com/moral/service/AccountService.java b/src/main/java/com/moral/service/AccountService.java index da45443..69c2880 100644 --- a/src/main/java/com/moral/service/AccountService.java +++ b/src/main/java/com/moral/service/AccountService.java @@ -1,6 +1,5 @@ package com.moral.service; -import java.util.List; import java.util.Map; import com.moral.entity.Account; @@ -9,9 +8,7 @@ Map<String, Object> screenLogin(Map<String, Object> parameters); - List<Account> getAccountLists(String account, String password); - - List<Account> getAccountList(String account); + Account getAccountByAccountName(String account); void setOrgIdsByAccount(Map<String, Object> parameters); diff --git a/src/main/java/com/moral/service/DeviceService.java b/src/main/java/com/moral/service/DeviceService.java index b0f9d49..7c27be8 100644 --- a/src/main/java/com/moral/service/DeviceService.java +++ b/src/main/java/com/moral/service/DeviceService.java @@ -14,4 +14,6 @@ void saveOrUpdateDevice(Device device); List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize); + + Device getDeviceByMac(String mac); } diff --git a/src/main/java/com/moral/service/MonitorPointService.java b/src/main/java/com/moral/service/MonitorPointService.java new file mode 100644 index 0000000..c5f8508 --- /dev/null +++ b/src/main/java/com/moral/service/MonitorPointService.java @@ -0,0 +1,11 @@ +package com.moral.service; + +import java.util.List; + +import com.moral.entity.MonitorPoint; + +public interface MonitorPointService { + + List<MonitorPoint> getMonitorPointsByAreaName(String areaName); + +} diff --git a/src/main/java/com/moral/service/OperateUserService.java b/src/main/java/com/moral/service/OperateUserService.java index 8c24053..e53567e 100644 --- a/src/main/java/com/moral/service/OperateUserService.java +++ b/src/main/java/com/moral/service/OperateUserService.java @@ -1,12 +1,10 @@ package com.moral.service; -import java.util.List; - import com.moral.entity.OperateUser; public interface OperateUserService { - List<OperateUser> getUserList(String mobile); + OperateUser getOperateUserByMobile(String mobile); OperateUser mobileLogin(String mobile, String password); diff --git a/src/main/java/com/moral/service/OrganizationService.java b/src/main/java/com/moral/service/OrganizationService.java index a835f01..fc20a17 100644 --- a/src/main/java/com/moral/service/OrganizationService.java +++ b/src/main/java/com/moral/service/OrganizationService.java @@ -1,9 +1,14 @@ package com.moral.service; +import java.util.List; import java.util.Set; + +import com.moral.entity.Organization; public interface OrganizationService { Set<Integer> getChildOrganizationIds(Integer orgId); + List<Organization> getOrganizationsByAreaName(String areaName); + } diff --git a/src/main/java/com/moral/service/impl/AccountServiceImpl.java b/src/main/java/com/moral/service/impl/AccountServiceImpl.java index 4993b3c..9c7eba0 100644 --- a/src/main/java/com/moral/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/moral/service/impl/AccountServiceImpl.java @@ -8,7 +8,6 @@ import static org.springframework.util.ObjectUtils.isEmpty; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; @@ -22,8 +21,6 @@ import com.moral.service.AccountService; import com.moral.service.OrganizationService; -import tk.mybatis.mapper.entity.Example; - @Service public class AccountServiceImpl implements AccountService { @@ -36,14 +33,13 @@ @Override public Map<String, Object> screenLogin(Map<String, Object> parameters) { Map<String, Object> result = new HashMap<String, Object>(); - Example example = new Example(Account.class); - String password = md5((String) parameters.get("account")); - example.or().andEqualTo("accountName",parameters.get("account")).andEqualTo("password",password); - List<Account> accounts = accountMapper.selectByExample(example); - if (isEmpty(accounts) || accounts.size() != 1) { + Account account = new Account(); + account.setAccountName((String) parameters.get("account")); + account.setPassword(md5((String) parameters.get("password"))); + account = accountMapper.selectOne(account); + if (isEmpty(account)) { result.put("msg", "���������������������������������"); } else { - Account account = accounts.get(0); if (IS_DELETE_FALSE.equals(account.getIsDelete())) { result.put("msg", "���������������"); result.put("accountId", account.getId()); @@ -56,17 +52,10 @@ } @Override - public List<Account> getAccountLists(String accountName, String password) { - Example example = new Example(Account.class); - example.or().andEqualTo("accountName",accountName).andEqualTo("password",password); - return accountMapper.selectByExample(example); - } - - @Override - public List<Account> getAccountList(String accountName) { - Example example = new Example(Account.class); - example.or().andEqualTo("accountName",accountName); - return accountMapper.selectByExample(example); + public Account getAccountByAccountName(String accountName) { + Account account = new Account(); + account.setAccountName(accountName); + return accountMapper.selectOne(account); } @Override diff --git a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java index b21b0af..d286c8f 100644 --- a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java @@ -11,14 +11,11 @@ import org.springframework.util.ObjectUtils; import com.github.pagehelper.PageHelper; -import com.moral.common.exception.BusinessException; import com.moral.common.util.ValidateUtil; import com.moral.entity.Device; import com.moral.mapper.DeviceMapper; import com.moral.service.AccountService; import com.moral.service.DeviceService; - -import tk.mybatis.mapper.entity.Example; @Service public class DeviceServiceImpl implements DeviceService { @@ -63,32 +60,39 @@ @Override public void saveOrUpdateDevice(Device device) { - ValidateUtil.notNull(device, "������������������"); - ValidateUtil.notEmpty(device.getMac(), "������������������"); - Example example = new Example(Device.class); - example.or().andEqualTo("mac",device.getMac()); - List<Device> devices = deviceMapper.selectByExample(example); + 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(devices)) { + if (ObjectUtils.isEmpty(queryDevice)) { device.setCreateTime(operateDate); device.setState("4"); deviceMapper.insertSelective(device); - }else if (devices.size() > 1) { - throw new BusinessException("���������������������������������������"); }else { - device.setId(devices.get(0).getId()); + device.setId(queryDevice.getId()); deviceMapper.updateByPrimaryKeySelective(device); } } @Override public List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize) { - Example example = new Example(Device.class); - example.or().andEqualTo("operateUserId",uid); + Device device = new Device(); + device.setOperateUserId(uid); PageHelper.startPage(pageIndex, pageSize); - List<Device> devices = deviceMapper.selectByExample(example); + List<Device> devices = deviceMapper.select(device); return devices; } + @Override + public Device getDeviceByMac(String mac) { + ValidateUtil.notEmpty(mac, "param.is.null"); + Device device = new Device(); + device.setMac(mac); + device = deviceMapper.selectOne(device); + return device; + } + } diff --git a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java new file mode 100644 index 0000000..5f07384 --- /dev/null +++ b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java @@ -0,0 +1,23 @@ +package com.moral.service.impl; + +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.moral.entity.MonitorPoint; +import com.moral.mapper.MonitorPointMapper; +import com.moral.service.MonitorPointService; + +@Service +public class MonitorPointServiceImpl implements MonitorPointService { + @Resource + private MonitorPointMapper monitorPointMapper; + + @Override + public List<MonitorPoint> getMonitorPointsByAreaName(String areaName) { + return monitorPointMapper.getMonitorPointsByAreaName(areaName); + } + +} diff --git a/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java b/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java index f574667..30c9889 100644 --- a/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java +++ b/src/main/java/com/moral/service/impl/OperateUserServiceImpl.java @@ -1,7 +1,5 @@ package com.moral.service.impl; -import java.util.List; - import javax.annotation.Resource; import org.springframework.stereotype.Service; @@ -13,8 +11,6 @@ import com.moral.mapper.OperateUserMapper; import com.moral.service.OperateUserService; -import tk.mybatis.mapper.entity.Example; - @Service public class OperateUserServiceImpl implements OperateUserService { @@ -22,21 +18,21 @@ private OperateUserMapper operateUserMapper; @Override - public List<OperateUser> getUserList(String mobile) { - Example example = new Example(OperateUser.class); - example.or().andEqualTo("mobile", mobile); - return operateUserMapper.selectByExample(example); + public OperateUser getOperateUserByMobile(String mobile) { + OperateUser operateUser = new OperateUser(); + operateUser.setMobile(mobile); + return operateUserMapper.selectOne(operateUser); } @Override public OperateUser mobileLogin(String mobile, String password) { - Example example = new Example(OperateUser.class); - example.or().andEqualTo("mobile", mobile).andEqualTo("password", Crypto.md5(password)); - List<OperateUser> operateUsers = operateUserMapper.selectByExample(example); - if (ObjectUtils.isEmpty(operateUsers) || operateUsers.size() > 1) { + OperateUser operateUser = new OperateUser(); + operateUser.setMobile(mobile); + operateUser.setPassword(Crypto.md5(password)); + operateUser = operateUserMapper.selectOne(operateUser); + if (ObjectUtils.isEmpty(operateUser)) { throw new BusinessException("������������������������,���������������"); }else { - OperateUser operateUser = operateUsers.get(0); operateUser.setPassword(password); return operateUser; } diff --git a/src/main/java/com/moral/service/impl/OrganizationServiceImpl.java b/src/main/java/com/moral/service/impl/OrganizationServiceImpl.java index a262729..8b20b1d 100644 --- a/src/main/java/com/moral/service/impl/OrganizationServiceImpl.java +++ b/src/main/java/com/moral/service/impl/OrganizationServiceImpl.java @@ -16,8 +16,6 @@ import com.moral.mapper.OrganizationRelationMapper; import com.moral.service.OrganizationService; -import tk.mybatis.mapper.entity.Example; - @Service public class OrganizationServiceImpl implements OrganizationService { @@ -31,11 +29,11 @@ public Set<Integer> getChildOrganizationIds(Integer orgId){ Set<Integer> orgIds = new HashSet<Integer>(); orgIds.add(orgId); - Example example = new Example(OrganizationRelation.class); - example.or().andEqualTo("parentId",orgId); + OrganizationRelation relation = new OrganizationRelation(); + relation.setParentId(orgId); Organization organization = organizationMapper.selectByPrimaryKey(orgId); if (IS_DELETE_FALSE.equals(organization.getIsDelete())) { - List<OrganizationRelation> organizationRelations = organizationRelationMapper.selectByExample(example); + List<OrganizationRelation> organizationRelations = organizationRelationMapper.select(relation); for (OrganizationRelation organizationRelation : organizationRelations) { Set<Integer> organizationIds = getChildOrganizationIds(organizationRelation.getParentId()); orgIds.addAll(organizationIds); @@ -44,4 +42,10 @@ return orgIds; } + @Override + public List<Organization> getOrganizationsByAreaName(String areaName) { + List<Organization> organizations = organizationMapper.getOrganizationsByAreaName(areaName); + return organizations; + } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index aa91078..39a5b8b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -61,6 +61,6 @@ mongodb: uri: mongodb://47.96.171.62:27017/monitor -#mybatis: -# mapper-locations: classpath*:/mapper/*Mapper.xml -# type-aliases-package: com.moral.entity \ No newline at end of file +mybatis: + mapper-locations: classpath*:/mapper/*Mapper.xml + type-aliases-package: com.moral.entity \ No newline at end of file diff --git a/src/main/resources/i18n/exceptions_zh_CN.properties b/src/main/resources/i18n/exceptions_zh_CN.properties new file mode 100644 index 0000000..b6e3bf3 --- /dev/null +++ b/src/main/resources/i18n/exceptions_zh_CN.properties @@ -0,0 +1,8 @@ +param.is.null=\u53C2\u6570\u4E3A\u7A7A +name.is.null=\u540D\u79F0\u4E3A\u7A7A +value.is.null=\u53D6\u503C\u4E3A\u7A7A +id.error=\u975E\u6CD5\u7684id\uFF1A{0} + +name.repeat=\u540D\u79F0\u5DF2\u7ECF\u5B58\u5728 + +no.permission=\u6CA1\u6709\u6743\u9650 \ No newline at end of file diff --git a/src/main/resources/mapper/AccountMapper.xml b/src/main/resources/mapper/AccountMapper.xml index 8545989..71dcf36 100644 --- a/src/main/resources/mapper/AccountMapper.xml +++ b/src/main/resources/mapper/AccountMapper.xml @@ -1,19 +1,6 @@ <?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.AccountMapper"> - <resultMap id="BaseResultMap" type="com.moral.entity.Account"> - <id column="id" jdbcType="INTEGER" property="id" /> - <result column="account_name" jdbcType="VARCHAR" property="accountName" /> - <result column="password" jdbcType="VARCHAR" property="password" /> - <result column="organization_id" jdbcType="INTEGER" property="organizationId" /> - <result column="email" jdbcType="VARCHAR" property="email" /> - <result column="mobile" jdbcType="VARCHAR" property="mobile" /> - <result column="weixin" jdbcType="VARCHAR" property="weixin" /> - <result column="is_delete" jdbcType="CHAR" property="isDelete" /> - <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> - <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> - </resultMap> - <select id="getRoleNameByAccountId" resultType="map"> SELECT r.role_name diff --git a/src/main/resources/mapper/DeviceMapper.xml b/src/main/resources/mapper/DeviceMapper.xml index 9f49de0..03f9da8 100644 --- a/src/main/resources/mapper/DeviceMapper.xml +++ b/src/main/resources/mapper/DeviceMapper.xml @@ -1,25 +1,6 @@ <?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.DeviceMapper"> - <resultMap id="BaseResultMap" type="com.moral.entity.Device"> - <!-- - WARNING - @mbggenerated - This element is automatically generated by MyBatis Generator, do not modify. - This element was generated on Wed Nov 29 16:17:59 CST 2017. - --> - <id column="id" jdbcType="INTEGER" property="id" /> - <result column="name" jdbcType="VARCHAR" property="name" /> - <result column="address" jdbcType="VARCHAR" property="address" /> - <result column="longitude" jdbcType="REAL" property="longitude" /> - <result column="latitude" jdbcType="REAL" property="latitude" /> - <result column="mac" jdbcType="VARCHAR" property="mac" /> - <result column="operate_user_id" jdbcType="INTEGER" property="operateUserId" /> - <result column="state" jdbcType="CHAR" property="state" /> - <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> - <result column="install_time" jdbcType="TIMESTAMP" property="installTime" /> - <result column="monitor_point_id" jdbcType="INTEGER" property="monitorPointId" /> - <result column="device_version_id" jdbcType="INTEGER" property="deviceVersionId" /> - </resultMap> <select id="getDeviceStatesByAccount" resultType="map"> SELECT COUNT( d.state ) count, @@ -37,6 +18,7 @@ </if> GROUP BY d.state </select> + <select id="getSensorsByDevice" resultType="map"> SELECT s.`key`, diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml index 580a1f2..0f1a427 100644 --- a/src/main/resources/mapper/HistoryMapper.xml +++ b/src/main/resources/mapper/HistoryMapper.xml @@ -1,8 +1,7 @@ <?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.HistoryMapper"> - - <select id="getDayAQIByDevice" resultType="map"> + <select id="getDayAQIByDevice" resultType="map"> SELECT AVG(value -> '$.e1') e1, AVG(value -> '$.e2') e2, @@ -14,9 +13,9 @@ history WHERE mac = #{mac} - AND time > #{start} + AND time >= #{start} AND time < #{end} - </select> + </select> <select id="getAllSensorAverageByDevice" resultType="java.util.LinkedHashMap"> SELECT @@ -28,13 +27,13 @@ <if test="orgIds != null and orgIds.size > 0"> LEFT JOIN monitor_point_organization mpo ON mpo.monitor_point_id = mp.id AND mpo.organization_id IN - <foreach close=")" collection="orgIds" item="listItem" open="(" separator=","> + <foreach collection="orgIds" open="(" separator="," close=")" item="listItem"> #{listItem} </foreach> </if> WHERE mp.area_code = #{areaCode} - AND h.time > #{start} + AND h.time >= #{start} AND h.time < #{end} AND h.mac = d.mac AND d.monitor_point_id = mp.id @@ -55,11 +54,11 @@ monitor_point mp WHERE mp.area_code = #{areaCode} - AND h.time > #{start} + AND h.time >= #{start} AND h.time < #{end} <if test="orgIds != null and orgIds.size > 0"> AND mp.organization_id IN - <foreach collection="orgIds" open="(" separator="," close=")" item="listItem" > + <foreach collection="orgIds" open="(" separator="," close=")" item="listItem"> #{listItem} </foreach> </if> @@ -86,5 +85,4 @@ ORDER BY time </select> - </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/MonitorPointMapper.xml b/src/main/resources/mapper/MonitorPointMapper.xml new file mode 100644 index 0000000..33258a0 --- /dev/null +++ b/src/main/resources/mapper/MonitorPointMapper.xml @@ -0,0 +1,14 @@ +<?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.MonitorPointMapper" > + <select id="getMonitorPointsByAreaName" resultType="com.moral.entity.MonitorPoint"> + SELECT + mp.* + FROM + monitor_point mp, + area a + WHERE + mp.area_code = a.area_code + AND a.area_name = #{areaName} + </select> +</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/OperateUserMapper.xml b/src/main/resources/mapper/OperateUserMapper.xml deleted file mode 100644 index 37a87c8..0000000 --- a/src/main/resources/mapper/OperateUserMapper.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?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.OperateUserMapper" > - <resultMap id="BaseResultMap" type="com.moral.entity.OperateUser" > - <id column="id" property="id" jdbcType="INTEGER" /> - <result column="job_number" property="jobNumber" jdbcType="VARCHAR" /> - <result column="name" property="name" jdbcType="VARCHAR" /> - <result column="password" property="password" jdbcType="VARCHAR" /> - <result column="organization_id" property="organizationId" jdbcType="INTEGER" /> - <result column="mobile" property="mobile" jdbcType="VARCHAR" /> - <result column="email" property="email" jdbcType="VARCHAR" /> - <result column="weixin" property="weixin" jdbcType="VARCHAR" /> - <result column="is_delete" property="isDelete" jdbcType="CHAR" /> - <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> - <result column="expire_time" property="expireTime" jdbcType="TIMESTAMP" /> - </resultMap> -</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/OrganizationMapper.xml b/src/main/resources/mapper/OrganizationMapper.xml index bb995d4..cfbdada 100644 --- a/src/main/resources/mapper/OrganizationMapper.xml +++ b/src/main/resources/mapper/OrganizationMapper.xml @@ -1,20 +1,14 @@ -<?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.OrganizationMapper" > - <resultMap id="BaseResultMap" type="com.moral.entity.Organization" > - <id column="id" property="id" jdbcType="INTEGER" /> - <result column="name" property="name" jdbcType="VARCHAR" /> - <result column="rank" property="rank" jdbcType="INTEGER" /> - <result column="province_code" property="provinceCode" jdbcType="INTEGER" /> - <result column="city_code" property="cityCode" jdbcType="INTEGER" /> - <result column="area_code" property="areaCode" jdbcType="INTEGER" /> - <result column="address" property="address" jdbcType="VARCHAR" /> - <result column="telephone" property="telephone" jdbcType="VARCHAR" /> - <result column="email" property="email" jdbcType="VARCHAR" /> - <result column="is_delete" property="isDelete" jdbcType="CHAR" /> - <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> - <result column="expire_time" property="expireTime" jdbcType="TIMESTAMP" /> - <result column="description" property="description" jdbcType="VARCHAR" /> - </resultMap> - +<?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.OrganizationMapper"> + <select id="getOrganizationsByAreaName" resultType="com.moral.entity.Organization"> + SELECT + o.* + FROM + organization o, + area a + WHERE + o.area_code = a.area_code + AND a.area_name = #{areaName} + </select> </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/OrganizationRelationMapper.xml b/src/main/resources/mapper/OrganizationRelationMapper.xml deleted file mode 100644 index 7794fba..0000000 --- a/src/main/resources/mapper/OrganizationRelationMapper.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?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.OrganizationRelationMapper" > - <resultMap id="BaseResultMap" type="com.moral.entity.OrganizationRelation" > - <id column="id" property="id" jdbcType="INTEGER" /> - <result column="parent_id" property="parentId" jdbcType="INTEGER" /> - <result column="child_id" property="childId" jdbcType="INTEGER" /> - </resultMap> -</mapper> \ No newline at end of file diff --git a/src/test/java/com/moral/MybatisConfig.java b/src/test/java/com/moral/MybatisConfig.java deleted file mode 100644 index 0ebce67..0000000 --- a/src/test/java/com/moral/MybatisConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.moral; - -import java.util.Properties; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.github.pagehelper.PageHelper; - -@Configuration -public class MybatisConfig { - @Bean - public PageHelper pageHelper(){ - PageHelper pageHelper = new PageHelper(); - Properties properties = new Properties(); - properties.setProperty("offsetAsPageNum","true"); - properties.setProperty("rowBoundsWithCount","true"); - properties.setProperty("reasonable","true"); - properties.setProperty("dialect","mysql"); //������mysql������������������ - pageHelper.setProperties(properties); - return pageHelper; - } -} \ No newline at end of file -- Gitblit v1.8.0