xufenglei
2017-12-04 b28a5002a58d8d0b37082da12e5b218f0951de47
更新
1 files added
9 files modified
149 ■■■■■ changed files
src/main/java/com/moral/config/RedisConfig.java 58 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ReportController.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java 15 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/AccountService.java 5 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/AccountServiceImpl.java 34 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/DeviceServiceImpl.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryServiceImpl.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OperateUserServiceImpl.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OrganizationServiceImpl.java 7 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryMapper.xml 2 ●●● patch | view | raw | blame | history
src/main/java/com/moral/config/RedisConfig.java
New file
@@ -0,0 +1,58 @@
package com.moral.config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.lang.reflect.Method;
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {
    @Bean
    public KeyGenerator keyGenerator() {
        return new KeyGenerator() {
            @Override
            public Object generate(Object target, Method method, Object... params) {
                StringBuilder sb = new StringBuilder();
                sb.append(target.getClass().getName());
                sb.append(method.getName());
                for (Object obj : params) {
                    sb.append(obj.toString());
                }
                return sb.toString();
            }
        };
    }
    @SuppressWarnings("rawtypes")
    @Bean
    public CacheManager cacheManager(RedisTemplate redisTemplate) {
        RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
        //设置缓存过期时间
        //rcm.setDefaultExpiration(60);//秒
        return rcm;
    }
    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
        StringRedisTemplate template = new StringRedisTemplate(factory);
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        template.setDefaultSerializer(stringRedisSerializer);
        template.setKeySerializer(stringRedisSerializer);
        template.setValueSerializer(stringRedisSerializer);
        template.setHashKeySerializer(stringRedisSerializer);
        template.setHashValueSerializer(stringRedisSerializer);
        return template;
    }
}
src/main/java/com/moral/controller/ReportController.java
@@ -2,17 +2,17 @@
import static com.moral.common.util.ExportExcelUtils.exportData;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
import static org.springframework.util.ObjectUtils.isEmpty;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import static org.springframework.util.ObjectUtils.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -27,10 +27,10 @@
@CrossOrigin(origins = "*", maxAge = 3600)
public class ReportController {
    @Autowired
    @Resource
    private HistoryService historyService;
    
    @Autowired
    @Resource
    private DeviceService deviceService;
    @GetMapping("sensors-average")
src/main/java/com/moral/controller/ScreenController.java
@@ -12,11 +12,10 @@
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@@ -43,24 +42,24 @@
public class ScreenController {
    /** The screen service. */
    @Autowired
    @Resource
    private HistoryService historyService;
    /** The account service. */
    @Autowired
    @Resource
    private AccountService accountService;
    /** The device service. */
    @Autowired
    @Resource
    private DeviceService deviceService;
    /** The resource. */
    @Value(value = "classpath:system/alarmLevels.json")
    private Resource resource;
    private org.springframework.core.io.Resource resource;
    /** The redis template. */
    @javax.annotation.Resource
    RedisTemplate<String, String> redisTemplate;
    @Resource
    private RedisTemplate<String, String> redisTemplate;
    /** The level key. */
    private String levelKey = "alarm_level_config";
src/main/java/com/moral/service/AccountService.java
@@ -3,7 +3,6 @@
import java.util.List;
import java.util.Map;
import com.moral.common.bean.ResultBean;
import com.moral.entity.Account;
public interface AccountService {
@@ -11,11 +10,9 @@
    Map<String, Object> screenLogin(Map<String, Object> parameters);
    List<Account> getAccountLists(String account, String password);
    List<Account> getAccountList(String account);
    void setOrgIdsByAccount(Map<String, Object> parameters);
    ResultBean<Account> screenLogin1(Map<String, Object> parameters);
}
src/main/java/com/moral/service/impl/AccountServiceImpl.java
@@ -12,12 +12,11 @@
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.moral.common.bean.ResultBean;
import com.moral.common.exception.BusinessException;
import com.moral.common.util.Crypto;
import com.moral.entity.Account;
import com.moral.entity.AccountExample;
import com.moral.mapper.AccountMapper;
@@ -26,10 +25,11 @@
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    @Resource
    private AccountMapper accountMapper;
    @Autowired
    @Resource
    private OrganizationService organizationService;
    @Override
@@ -46,35 +46,13 @@
            if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
                result.put("msg", "登录成功!");
                result.put("accountId", account.getId());
                result.put("orgId", account.getOrganizationId());
            } else {
                result.put("msg","您的账号已禁用,请联系管理员!");
            }
        }
        return result;
    }
    @Override
    public ResultBean<Account> screenLogin1(Map<String, Object> parameters) {
        ResultBean<Account> resultBean = new ResultBean<Account>();
        AccountExample example = new AccountExample();
        String password = Crypto.md5((String) parameters.get("password"));
        example.or().andAccountNameEqualTo((String) parameters.get("account")).andPasswordEqualTo(password);
        List<Account> accounts = accountMapper.selectByExample(example);
        if (isEmpty(accounts) || accounts.size() != 1) {
            resultBean.setMsg("用户名及密码输入错误!");
            resultBean.setCode(ResultBean.FAIL);
        } else {
            Account account = accounts.get(0);
            if (IS_DELETE_FALSE.equals(account.getIsDelete())) {
                resultBean.setData(account);
            } else {
                resultBean.setCode(ResultBean.NO_PERMISSION);
                resultBean.setMsg("您的账号已禁用,请联系管理员!");
            }
        }
        return resultBean;
    }
    
    @Override
    public List<Account> getAccountLists(String accountName, String password) {
src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -4,7 +4,8 @@
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.moral.mapper.DeviceMapper;
@@ -14,10 +15,10 @@
@Service
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    @Resource
    private DeviceMapper deviceMapper;
    @Autowired
    @Resource
    private AccountService accountService;
    @Override
src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -20,6 +20,8 @@
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
@@ -38,13 +40,13 @@
@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    @Resource
    private AccountService accountService;
    @Autowired
    @Resource
    private HistoryMapper historyMapper;
    @Autowired
    @Resource
    private MongoTemplate mongoTemplate;
    @Override
src/main/java/com/moral/service/impl/OperateUserServiceImpl.java
@@ -2,7 +2,8 @@
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.moral.entity.OperateUser;
@@ -13,7 +14,7 @@
@Service
public class OperateUserServiceImpl implements OperateUserService {
    @Autowired
    @Resource
    private OperateUserMapper operateUserMapper;
    @Override
src/main/java/com/moral/service/impl/OrganizationServiceImpl.java
@@ -6,7 +6,8 @@
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.moral.entity.Organization;
@@ -19,10 +20,10 @@
@Service
public class OrganizationServiceImpl implements OrganizationService {
    @Autowired
    @Resource
    private OrganizationMapper organizationMapper;
    @Autowired
    @Resource
    private OrganizationRelationMapper organizationRelationMapper;
    @Override
src/main/resources/mapper/HistoryMapper.xml
@@ -59,7 +59,7 @@
            AND h.time &lt; #{end}
        <if test="orgIds != null and orgIds.size &gt; 0">
            AND mp.organization_id IN
            <foreach close=")" collection="orgIds" item="listItem" open="(" separator=",">
            <foreach  collection="orgIds" open="(" separator="," close=")" item="listItem" >
                #{listItem}
            </foreach>
        </if>