xufenglei
2017-12-18 f74ecba5f577a41ec3c8d678a18773c8d9748eb8
机器激活码 接口
4 files added
5 files modified
197 ■■■■■ changed files
src/main/java/com/moral/common/bean/Constants.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/MobileController.java 19 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ReportController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java 28 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/entity/MachineActivate.java 48 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/MachineActivateMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/MachineActivateService.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/MachineActivateServiceImpl.java 75 ●●●●● patch | view | raw | blame | history
src/main/resources/system/sysConfig.properties 2 ●●● patch | view | raw | blame | history
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";
}
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,8 +95,9 @@
     * @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) {
    @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);
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 {
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 {
@@ -50,6 +52,9 @@
    @Resource
    private DeviceService deviceService;
    @Resource
    private MachineActivateService machineActivateService;
    /** The resource. */
    @Value(value = "classpath:system/alarmLevels.json")
    private org.springframework.core.io.Resource resource;
@@ -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);
    }
}
src/main/java/com/moral/entity/MachineActivate.java
New file
@@ -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;
}
src/main/java/com/moral/mapper/MachineActivateMapper.java
New file
@@ -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>{
}
src/main/java/com/moral/service/MachineActivateService.java
New file
@@ -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);
}
src/main/java/com/moral/service/impl/MachineActivateServiceImpl.java
New file
@@ -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;
    }
}
src/main/resources/system/sysConfig.properties
@@ -25,4 +25,4 @@
e17-standard=150
e18-standard=9
e19-standard=50
orgId=5212b9dfb55448e699889e01fa0fa6a2
orgId=-1