From f74ecba5f577a41ec3c8d678a18773c8d9748eb8 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Mon, 18 Dec 2017 08:44:52 +0800 Subject: [PATCH] 机器激活码 接口 --- src/main/resources/system/sysConfig.properties | 2 src/main/java/com/moral/common/bean/Constants.java | 4 + src/main/java/com/moral/controller/ReportController.java | 2 src/main/java/com/moral/controller/MobileController.java | 21 ++-- src/main/java/com/moral/entity/MachineActivate.java | 48 ++++++++++++ src/main/java/com/moral/controller/ScreenController.java | 28 +++++- src/main/java/com/moral/service/impl/MachineActivateServiceImpl.java | 75 ++++++++++++++++++ src/main/java/com/moral/mapper/MachineActivateMapper.java | 8 ++ src/main/java/com/moral/service/MachineActivateService.java | 11 ++ 9 files changed, 182 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/moral/common/bean/Constants.java b/src/main/java/com/moral/common/bean/Constants.java index 071f5c3..79474f6 100644 --- a/src/main/java/com/moral/common/bean/Constants.java +++ b/src/main/java/com/moral/common/bean/Constants.java @@ -13,5 +13,9 @@ /** The Constant NULL_VALUE. */ public static final String NULL_VALUE = "N/V"; + + public static final String IS_USED_FALSE = "0"; + + public static final String IS_USED_TRUE = "0"; } diff --git a/src/main/java/com/moral/controller/MobileController.java b/src/main/java/com/moral/controller/MobileController.java index ca4d05e..09b9c68 100644 --- a/src/main/java/com/moral/controller/MobileController.java +++ b/src/main/java/com/moral/controller/MobileController.java @@ -28,7 +28,7 @@ * The Class MobileController. */ @RestController -@RequestMapping(value = "mobile") +@RequestMapping("mobile") @CrossOrigin(origins = "*", maxAge = 3600) public class MobileController { @@ -55,7 +55,7 @@ * @param password the password * @return the result bean */ - @GetMapping(value = "accountlogin") + @GetMapping("accountlogin") public ResultBean<OperateUser> mobileLogin(String username, String password) { OperateUser operateUser = operateUserService.mobileLogin(username,password); return new ResultBean<OperateUser>(operateUser); @@ -69,7 +69,7 @@ * @param newpassword the newpassword * @return the result bean */ - @GetMapping(value = "upPassword") + @GetMapping("upPassword") public ResultBean<OperateUser> updatePassword(Integer uid, String password, String newpassword) { OperateUser operateUser = operateUserService.updatePassword(uid,password,newpassword); return new ResultBean<OperateUser>(operateUser); @@ -81,7 +81,7 @@ * @param device the device * @return the result bean */ - @GetMapping(value = "reportDevice") + @GetMapping("reportDevice") public ResultBean<String> installDevice(Device device) { deviceService.saveOrUpdateDevice(device); return new ResultBean<String>(""); @@ -95,9 +95,10 @@ * @param pageSize the page size * @return the install devices by operate user */ - @GetMapping(value = "myRelease") - public ResultBean<List<Device>> getInstallDevicesByOperateUser(@RequestParam(value="uid", required=true)Integer uid, @RequestParam(defaultValue="0")Integer pageIndex, @RequestParam(defaultValue="0")Integer pageSize) { - List<Device> devices = deviceService.getInstallDevicesByOperateUser(uid,pageIndex,pageSize); + @GetMapping("myRelease") + public ResultBean<List<Device>> getInstallDevicesByOperateUser(@RequestParam(value="uid", required=true)Integer uid, + @RequestParam(defaultValue="0")Integer pageIndex, @RequestParam(defaultValue="0")Integer pageSize) { + List<Device> devices = deviceService.getInstallDevicesByOperateUser(uid, pageIndex, pageSize); return new ResultBean<List<Device>>(devices); } @@ -107,7 +108,7 @@ * @param mac the mac * @return the device by mac */ - @GetMapping(value = "getEquInfoByMac") + @GetMapping("getEquInfoByMac") public ResultBean<Device> getDeviceByMac(@RequestParam(value="mac", required=true)String mac) { Device device = deviceService.getDeviceByMac(mac); return new ResultBean<Device>(device); @@ -119,7 +120,7 @@ * @param areaName the area name * @return the monitor points by area name */ - @GetMapping(value = "getMpointsByAreaName") + @GetMapping("getMpointsByAreaName") public ResultBean<List<MonitorPoint>> getMonitorPointsByAreaName(HttpServletRequest request) { Map<String, Object> parameters = getParametersStartingWith(request, null); List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByAreaName(parameters); @@ -132,7 +133,7 @@ * @param areaName the area name * @return the organizations by area name */ - @GetMapping(value = "getOrgsByAreaName") + @GetMapping("getOrgsByAreaName") public ResultBean<List<Organization>> getOrganizationsByAreaName(HttpServletRequest request) { Map<String, Object> parameters = getParametersStartingWith(request, null); List<Organization> organizations = organizationService.getOrganizationsByAreaName(parameters); diff --git a/src/main/java/com/moral/controller/ReportController.java b/src/main/java/com/moral/controller/ReportController.java index 866411a..d866077 100644 --- a/src/main/java/com/moral/controller/ReportController.java +++ b/src/main/java/com/moral/controller/ReportController.java @@ -24,7 +24,7 @@ import com.moral.service.HistoryService; @RestController -@RequestMapping(value = "report") +@RequestMapping("report") @CrossOrigin(origins = "*", maxAge = 3600) public class ReportController { diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java index a140d21..f101ce2 100644 --- a/src/main/java/com/moral/controller/ScreenController.java +++ b/src/main/java/com/moral/controller/ScreenController.java @@ -18,6 +18,7 @@ import org.springframework.data.redis.core.RedisTemplate; 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.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -29,12 +30,13 @@ import com.moral.service.AccountService; import com.moral.service.DeviceService; import com.moral.service.HistoryService; +import com.moral.service.MachineActivateService; /** * The Class ScreenController.������������ */ @RestController -@RequestMapping(value = "screen") +@RequestMapping("screen") @CrossOrigin(origins = "*", maxAge = 3600) public class ScreenController { @@ -49,6 +51,9 @@ /** The device service. */ @Resource private DeviceService deviceService; + + @Resource + private MachineActivateService machineActivateService; /** The resource. */ @Value(value = "classpath:system/alarmLevels.json") @@ -59,7 +64,7 @@ private RedisTemplate<String, String> redisTemplate; /** The level key. */ - private String levelKey = "alarm_level_config"; + private String levelKey = "alarm_"; /** * Screen login. ������������ @@ -104,16 +109,18 @@ */ @SuppressWarnings("resource") @GetMapping("alarm-levels") - public Map<String, Object> getAlarmLevels(HttpServletRequest request) { + public Map<String, Object> getAlarmLevels(HttpServletRequest request,String orgId) { Map<String, Object> result = new LinkedHashMap<String, Object>(); + String key = levelKey + orgId; try { - if (hasKey(redisTemplate, levelKey)) { - String levelConfigStr = get(redisTemplate, levelKey); + if (hasKey(redisTemplate, key)) { + String levelConfigStr = get(redisTemplate, key); result = JSON.parseObject(levelConfigStr, new TypeReference<Map<String, Object>>() {}); } else { InputStreamReader reader = new InputStreamReader(resource.getInputStream()); result = new JSONReader(reader).readObject(new TypeReference<LinkedHashMap<String, Object>>() {}); } + } catch (IOException e) { e.printStackTrace(); result.put("msg", "���������������������������������������������������" + e.getMessage()); @@ -188,4 +195,15 @@ return historyService.getMonthAverageBySensor(parameters); } + @GetMapping("check-activate") + public Map<String, Object> checkActivate(String macCpuCode) { + return machineActivateService.checkActivate(macCpuCode); + } + + @PostMapping("activate-machine") + public Map<String, Object> activateMachine(HttpServletRequest request) { + Map<String, Object> parameters = getParametersStartingWith(request, null); + return machineActivateService.activateMachine(parameters); + } + } diff --git a/src/main/java/com/moral/entity/MachineActivate.java b/src/main/java/com/moral/entity/MachineActivate.java new file mode 100644 index 0000000..bcf012f --- /dev/null +++ b/src/main/java/com/moral/entity/MachineActivate.java @@ -0,0 +1,48 @@ +package com.moral.entity; + +import java.util.Date; + +import javax.persistence.Id; + +import lombok.Data; + +@Data +public class MachineActivate { + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.id + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + @Id + private Integer id; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.mac_cpu_code + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + private String macCpuCode; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.activation_code + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + private String activationCode; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.organization_id + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + private Integer organizationId; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.is_used + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + private String isUsed; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.create_time + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + private Date createTime; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column machine_activate.expire_date + * @mbg.generated Fri Dec 15 09:47:31 CST 2017 + */ + private Date expireDate; + +} \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/MachineActivateMapper.java b/src/main/java/com/moral/mapper/MachineActivateMapper.java new file mode 100644 index 0000000..923598c --- /dev/null +++ b/src/main/java/com/moral/mapper/MachineActivateMapper.java @@ -0,0 +1,8 @@ +package com.moral.mapper; + +import com.moral.common.mapper.BaseMapper; +import com.moral.entity.MachineActivate; + +public interface MachineActivateMapper extends BaseMapper<MachineActivate>{ + +} \ No newline at end of file diff --git a/src/main/java/com/moral/service/MachineActivateService.java b/src/main/java/com/moral/service/MachineActivateService.java new file mode 100644 index 0000000..edfe810 --- /dev/null +++ b/src/main/java/com/moral/service/MachineActivateService.java @@ -0,0 +1,11 @@ +package com.moral.service; + +import java.util.Map; + +public interface MachineActivateService { + + Map<String, Object> checkActivate(String macCpuCode); + + Map<String, Object> activateMachine(Map<String, Object> parameters); + +} diff --git a/src/main/java/com/moral/service/impl/MachineActivateServiceImpl.java b/src/main/java/com/moral/service/impl/MachineActivateServiceImpl.java new file mode 100644 index 0000000..e49e743 --- /dev/null +++ b/src/main/java/com/moral/service/impl/MachineActivateServiceImpl.java @@ -0,0 +1,75 @@ +package com.moral.service.impl; + +import static org.apache.commons.lang3.time.DateUtils.truncate; + +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; + +import com.moral.common.bean.Constants; +import com.moral.common.exception.BusinessException; +import com.moral.common.util.ValidateUtil; +import com.moral.entity.MachineActivate; +import com.moral.mapper.MachineActivateMapper; +import com.moral.service.MachineActivateService; + +import tk.mybatis.mapper.entity.Example; +import tk.mybatis.mapper.entity.Example.Criteria; + +@Service +public class MachineActivateServiceImpl implements MachineActivateService { + + @Resource + private MachineActivateMapper machineActivateMapper; + + @Override + public Map<String, Object> checkActivate(String macCpuCode) { + ValidateUtil.notEmpty(macCpuCode, "param.is.null"); + + Map<String, Object> map = new HashMap<String, Object>(); + String result = "1"; + MachineActivate machineActivate = new MachineActivate(); + machineActivate.setMacCpuCode(macCpuCode); + machineActivate = machineActivateMapper.selectOne(machineActivate); + if (ObjectUtils.isEmpty(machineActivate)) { + result = "0"; + } + map.put("result", result); + + return map; + } + + @Override + @Transactional + public Map<String, Object> activateMachine(Map<String, Object> parameters) { + ValidateUtil.notNull(parameters.get("macCpuCode"), "param.is.null"); + ValidateUtil.notNull(parameters.get("activationCode"), "param.is.null"); + + Map<String, Object> map = new HashMap<String, Object>(); + + Example example = new Example(MachineActivate.class); + Criteria criteria = example.createCriteria(); + criteria.andEqualTo("activationCode", parameters.get("activationCode")); + criteria.andEqualTo("isUsed",Constants.IS_USED_FALSE); + criteria.andGreaterThanOrEqualTo("expireDate", truncate(new Date(), Calendar.DATE)); + List<MachineActivate> machineActivates = machineActivateMapper.selectByExample(example); + if (ObjectUtils.isEmpty(machineActivates)) { + throw new BusinessException("������������������������������������������"); + } + MachineActivate machineActivate = machineActivates.get(0); + machineActivate.setIsUsed(Constants.IS_DELETE_TRUE); + machineActivate.setMacCpuCode((String) parameters.get("macCpuCode")); + int updateCount = machineActivateMapper.updateByPrimaryKeySelective(machineActivate); + map.put("result", updateCount); + return map; + } + +} diff --git a/src/main/resources/system/sysConfig.properties b/src/main/resources/system/sysConfig.properties index 1e488b7..649686b 100644 --- a/src/main/resources/system/sysConfig.properties +++ b/src/main/resources/system/sysConfig.properties @@ -25,4 +25,4 @@ e17-standard=150 e18-standard=9 e19-standard=50 -orgId=5212b9dfb55448e699889e01fa0fa6a2 \ No newline at end of file +orgId=-1 \ No newline at end of file -- Gitblit v1.8.0