Commit 6e758498 by zhangxiaoyan

Merge branch 'master' of git.minrow.com:reyun/manager

parents 1553050a 51fedc99
......@@ -3,12 +3,5 @@
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
package common.controller;
import common.model.User;
import common.repository.UserRepository;
import common.service.NoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import security.RedisLoginStatusManager;
import security.TokenManager;
import security.annotation.CurrentAccount;
import util.CipherUtil;
import util.Constant;
import util.ResultModel;
import util.ValidateUtil;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("notice")
public class NoticeController {
protected Logger logger = LoggerFactory.getLogger(NoticeController.class);
@Autowired
NoticeService noticeService;
@RequestMapping(value = "find", method = RequestMethod.GET)
@ResponseBody
public ResultModel find(@CurrentAccount User user) {
return ResultModel.OK(noticeService.findAll(user));
}
@RequestMapping(value = "read", method = RequestMethod.PUT)
@ResponseBody
public ResultModel loginCheck(@CurrentAccount User user) {
return ResultModel.OK(noticeService.read(user));
}
}
......@@ -2,12 +2,14 @@ package common.controller;
import common.model.Menu;
import common.model.User;
import common.repository.UserRepository;
import common.service.MenuService;
import common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import security.annotation.CurrentAccount;
import util.CipherUtil;
import util.ResultModel;
import javax.servlet.http.HttpServletResponse;
......@@ -17,11 +19,14 @@ import java.util.List;
* Created by mxq on 2017/12/21.
*/
@Controller
@RequestMapping("user")
@RequestMapping("system/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
UserRepository userRepository;
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
......@@ -51,20 +56,32 @@ public class UserController {
return ResultModel.OK();
}
@RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
@RequestMapping(value = "/update/name", method = RequestMethod.PUT)
@ResponseBody
public ResultModel updateName(@CurrentAccount User loginAccount, @RequestParam String name, @PathVariable Long id) {
userService.updateName(loginAccount, id, name);
return ResultModel.OK();
public ResultModel updateName(@CurrentAccount User loginAccount, @RequestParam String name) {
User login = userRepository.login(name);
if(null == login){
userService.updateName(loginAccount, name);
return ResultModel.OK(true);
}else{
return ResultModel.OK(false);
}
}
@RequestMapping(value = "/update/{id}/pwd", method = RequestMethod.PUT)
@RequestMapping(value = "/update/password", method = RequestMethod.PUT)
@ResponseBody
public ResultModel updatePwd(@CurrentAccount User loginAccount, @RequestParam String pwd, @PathVariable Long id) {
userService.updatePwd(loginAccount, id, pwd);
return ResultModel.OK();
public ResultModel updatePwd(@CurrentAccount User loginAccount, @RequestParam String pwd, @RequestParam String oldpwd) {
User login = userRepository.login(loginAccount.getEmail(), CipherUtil.generatePassword(oldpwd));
if(null != login){
userService.updatePwd(loginAccount, pwd);
return ResultModel.OK(true);
}else{
return ResultModel.OK(false);
}
}
//忘记密码时,修改密码
@RequestMapping(value = "/update/pwd", method = RequestMethod.PUT)
@ResponseBody
public ResultModel updatePwd(@RequestParam String email, @RequestParam String pwd) {
......@@ -72,17 +89,18 @@ public class UserController {
return ResultModel.OK(userService.updatePwd(email, pwd));
}
@RequestMapping(value = "forget/", method = RequestMethod.GET)
//忘记密码时,发送验证码
@RequestMapping(value = "/code", method = RequestMethod.GET)
@ResponseBody
public ResultModel sengCode(@RequestParam String email) {
return ResultModel.OK(userService.sendCode(email));
}
@RequestMapping(value = "valid/code", method = RequestMethod.GET)
//验证码验证
@RequestMapping(value = "/update/pwd", method = RequestMethod.GET)
@ResponseBody
public ResultModel validCode(@RequestParam String email, @RequestParam String code) {
userService.validCode(email, code);
return ResultModel.OK();
public ResultModel validCode(@RequestParam String email, @RequestParam String code, @RequestParam String pwd) {
return ResultModel.OK(userService.validCode(email, code, pwd));
}
}
......@@ -26,7 +26,7 @@ public class Account4Web {
private Boolean ioStatus;
private Boolean trackStatus;
private Boolean remStatus;
private Long bussinessMan;
@Id
@GeneratedValue
public Long getId() {
......@@ -181,6 +181,14 @@ public class Account4Web {
this.remStatus = remStatus;
}
public Long getBussinessMan() {
return bussinessMan;
}
public void setBussinessMan(Long bussinessMan) {
this.bussinessMan = bussinessMan;
}
@Override
public String toString() {
return "Account4Web{" +
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* Created by mxq on 2017/12/28.
*/
@Entity
public class Notice {
private Long id;
private Long user;
private String platform;
private String content;
private String ds;
private Boolean isNotRead;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDs() {
return ds;
}
public void setDs(String ds) {
this.ds = ds;
}
public Boolean getNotRead() {
return isNotRead;
}
public void setNotRead(Boolean notRead) {
isNotRead = notRead;
}
}
......@@ -15,4 +15,7 @@ public interface Account4WebRepository extends JpaRepository<Account4Web, Long>
@Query(value = "SELECT * from account4web where email in ?1", nativeQuery = true)
List<Account4Web> findByEmails(List<String> emails);
@Query(value = "SELECT * from account4web where past_date = ?1", nativeQuery = true)
List<Account4Web> findByPast(String yesterday);
}
package common.repository;
import common.model.Notice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public interface NoticeRepository extends JpaRepository<Notice, Long> {
@Query(value="select * from notice where user = ?1 and ds >= ?2",nativeQuery=true)
List<Notice> findall(Long user, String ds);
@Query(value="select * from notice where user = ?1",nativeQuery=true)
List<Notice> findall(Long user);
}
package common.service;
import common.model.Notice;
import common.model.User;
import java.util.List;
/**
* Created by mxq on 2017/12/28.
*/
public interface NoticeService {
List<Notice> findAll(User user);
Boolean read(User user);
}
......@@ -18,13 +18,13 @@ public interface UserService {
User delete(User login, Long id);
User updateName(User login, Long id, String name);
User updateName(User login, String name);
User updatePwd(User login, Long id, String pwd);
User updatePwd(User login, String pwd);
User updatePwd(String email, String pwd);
Boolean sendCode(String email);
String validCode(String email, String code);
String validCode(String email, String code, String pwd);
}
package common.service.impl;
import common.model.Notice;
import common.model.User;
import common.repository.NoticeRepository;
import common.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.DateUtil;
import util.ValidateUtil;
import java.util.ArrayList;
import java.util.List;
/**
* Created by mxq on 2017/12/28.
*/
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired
NoticeRepository noticeRepository;
@Override
public List<Notice> findAll(User user) {
List<Notice> noticeList = noticeRepository.findall(user.getId(), DateUtil.getBeforeDays(7));
return noticeList;
}
@Override
public Boolean read(User user) {
List<Notice> noticeList = noticeRepository.findall(user.getId());
if(ValidateUtil.isValid(noticeList)){
List<Notice> notices = new ArrayList<>();
for (Notice n : noticeList){
n.setNotRead(false);
notices.add(n);
}
noticeRepository.save(notices);
}
return true;
}
}
......@@ -94,8 +94,8 @@ public class UserServiceImpl implements UserService {
}
@Override
public User updateName(User login, Long id, String name) {
User one = userRepository.findOne(id);
public User updateName(User login, String name) {
User one = userRepository.findOne(login.getId());
one.setName(name);
one.setModifyTime(new Date());
one.setModifyAccount(login.getId());
......@@ -103,8 +103,8 @@ public class UserServiceImpl implements UserService {
}
@Override
public User updatePwd(User login, Long id, String pwd) {
User one = userRepository.findOne(id);
public User updatePwd(User login, String pwd) {
User one = userRepository.findOne(login.getId());
one.setPassword(CipherUtil.generatePassword(pwd));
one.setModifyTime(new Date());
one.setModifyAccount(login.getId());
......@@ -122,6 +122,10 @@ public class UserServiceImpl implements UserService {
@Override
public Boolean sendCode(String email) {
User user = userRepository.login(email);
if(null == user){
return false;
}
String code = CharacterUtils.getRandomString(4);
List<String> list = new ArrayList<>();
list.add(email);
......@@ -140,15 +144,20 @@ public class UserServiceImpl implements UserService {
}
@Override
public String validCode(String email, String code) {
Code valid = codeRepository.findValid(email, new Date());
public String validCode(String email, String code, String pwd) {
Calendar beforeTime = Calendar.getInstance();
beforeTime.add(Calendar.MINUTE, -5);// 5分钟之前的时间
Date beforeD = beforeTime.getTime();
Code valid = codeRepository.findValid(email, beforeD);
if(null != valid){
boolean b = valid.getCode().equals(code);
if(b){
updatePwd(email, pwd);
return "true";
}
return "false";
}
return "invalid";
return "false";
}
}
......@@ -39,7 +39,10 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
//放开登录
if (request.getRequestURL().indexOf("login/login") != -1){
if (request.getRequestURL().indexOf("login/login") != -1
|| request.getRequestURL().indexOf("update/pwd") != -1
|| request.getRequestURL().indexOf("user/forget") != -1
|| request.getRequestURL().indexOf("user/code") != -1){
return true;
}
//从header中得到token
......
......@@ -69,6 +69,7 @@ public class AccountTask {
}
account4Web.setUser(ac.getName());
account4Web.setTell(ac.getPhone());
account4Web.setBussinessMan(ac.getBussinessman());
list.add(account4Web);
}
}
......@@ -93,6 +94,7 @@ public class AccountTask {
account4Web.setTrackStatus(false);
account4Web.setUser(ac.getName());
account4Web.setTell(ac.getPhone());
account4Web.setBussinessMan(ac.getBussinessman());
list.add(account4Web);
}
}
......
package tkio.task;
import common.model.Account4Web;
import common.model.Notice;
import common.model.User;
import common.repository.Account4WebRepository;
import common.repository.NoticeRepository;
import common.repository.UserRepository;
import dic.RoleEnum;
import org.springframework.beans.factory.annotation.Autowired;
import tkio.model.SalesManLeader;
import tkio.repository.SalesManLeaderRepository;
import util.DateUtil;
import util.ValidateUtil;
import java.util.*;
/**
* Created by mxq on 2017/12/27.
*/
public class NoticeTask {
@Autowired
Account4WebRepository account4WebRepository;
@Autowired
UserRepository userRepository;
@Autowired
SalesManLeaderRepository salesManLeaderRepository;
@Autowired
NoticeRepository noticeRepository;
public void task(){
System.out.println("同步消息任务开始");
noticeRepository.findAll();
List<Account4Web> account4WebList = account4WebRepository.findByPast(DateUtil.getBeforeDays(1));
Map<Long, Integer> map = new HashMap<>();
Map<Long, Integer> mapTotle = new HashMap<>();
if(ValidateUtil.isValid(account4WebList)){
for(Account4Web aw : account4WebList){
if(mapTotle.containsKey(0L)){
mapTotle.put(0L, mapTotle.get(0L) + 1);
}else{
mapTotle.put(0L, 1);
}
if(null != aw.getBussinessMan()){
if(map.containsKey(aw.getBussinessMan())){
map.put(aw.getBussinessMan(), map.get(aw.getBussinessMan()) + 1);
}else{
map.put(aw.getBussinessMan(), 1);
}
}
}
List<SalesManLeader> salesManLeaders = salesManLeaderRepository.findAll();
Map<String, List<Long>> saleMap = new HashMap<>();
if(ValidateUtil.isValid(salesManLeaders)){
for(SalesManLeader sml : salesManLeaders){
List<Long> idList = new ArrayList<>();
if(sml.getId() == 0 || sml.getId() == sml.getLeader()){//不是主管
Long id = (long)sml.getId();
idList.add(id);
}else{//是主管
for(SalesManLeader sml2 : salesManLeaders){
if(sml.getId() == sml2.getLeader()){
Long id = (long)sml.getId();
idList.add(id);
}
}
}
saleMap.put(sml.getEmail(), idList);
}
}
Map<Long, Integer> resultMap = new HashMap<>();
List<User> userList = userRepository.findAll();
if(mapTotle.containsKey(0L)){
for(User user : userList){
if(user.getRole().equals(RoleEnum.MANAGER.getKey())){
resultMap.put(user.getId(), mapTotle.get(0L));
} else{
if(saleMap.containsKey(user.getId())){
List<Long> list = saleMap.get(user.getId());
for(Long id : list){
if(map.containsKey(id)){
if(resultMap.containsKey(user.getId())){
resultMap.put(user.getId(), map.get(user.getId()) + map.get(id));
}else{
resultMap.put(user.getId(), map.get(id));
}
}
}
}
}
}
List<Notice> list = new ArrayList<>();
String today = DateUtil.getBeforeDays(0);
Set<Long> keySet = resultMap.keySet();
for(Long id : keySet){
int num = resultMap.get(id);
Notice notice = new Notice();
notice.setUser(id);
notice.setPlatform("tkio");
notice.setContent("今日tkio有" + num + "个客户过期,请及时联系客户");
notice.setDs(today);
notice.setNotRead(true);
list.add(notice);
}
noticeRepository.save(list);
}
}
System.out.println("同步消息任务结束");
}
}
......@@ -10,11 +10,14 @@
<description>调度配置</description>
<bean id="tkioAccountTask" class="tkio.task.AccountTask"></bean>
<task:scheduled-tasks>
<!--//定时同步短链数据(每5分钟执行一次)-->
<task:scheduled ref="tkioAccountTask" method="task" cron="0 21 15 * * ?"/>
<task:scheduled ref="tkioAccountTask" method="task" cron="0 40 14 * * ?"/>
</task:scheduled-tasks>
<bean id="tkioNoticeTask" class="tkio.task.NoticeTask"></bean>
<task:scheduled-tasks>
<task:scheduled ref="tkioNoticeTask" method="task" cron="0 33 16 * * ?"/>
</task:scheduled-tasks>
<bean id="trackAccountTask" class="track.task.AccountTask"></bean>
......
......@@ -11,6 +11,7 @@ common\model\Auth.class
tkio\repository\AccountRepository.class
common\model\Menu.class
track\repository\TrackAppRepository.class
common\service\impl\NoticeServiceImpl.class
exception\GlobalExceptionAdvice.class
tkio\model\Campaign.class
security\RedisTokenManager.class
......@@ -37,6 +38,7 @@ util\DateUtil.class
common\model\AppCategory.class
tkio\repository\ChannelRepository.class
security\RedisLoginStatusManager.class
common\model\Notice.class
dic\RoleTypeEnum.class
common\repository\AppInfoRepository.class
tkio\model\Channel.class
......@@ -55,6 +57,7 @@ common\service\impl\AppServiceImpl$2.class
common\model\City.class
common\service\impl\AppServiceImpl.class
common\repository\ReminderRepository.class
common\controller\NoticeController.class
util\StringUtil.class
track\model\Channel.class
track\model\Campaign.class
......@@ -87,10 +90,13 @@ tkio\model\App.class
security\resolvers\LoginUserMethodArgumentsResolver.class
tkio\service\TkioAccountService.class
common\model\TrackAccount4Web.class
common\repository\NoticeRepository.class
common\service\NoticeService.class
common\model\RoleType.class
tkio\task\AccountTask.class
security\annotation\Authorization.class
util\IP$1.class
tkio\task\NoticeTask.class
common\repository\CodeRepository.class
tkio\model\SalesManLeader.class
common\controller\AppController.class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment