Browse Source

Merge branch 'master' of gitee.com:ccsens_s/ccsenscloud

master
zhangye 5 years ago
parent
commit
282f04e9c1
  1. 3
      health/src/main/java/com/ccsens/health/api/HealthController.java
  2. 18
      health/src/main/java/com/ccsens/health/api/JourneyController.java
  3. 32
      health/src/main/java/com/ccsens/health/api/StudentController.java
  4. 15
      health/src/main/java/com/ccsens/health/bean/dto/JourneyDto.java
  5. 2
      health/src/main/java/com/ccsens/health/bean/dto/MemberDto.java
  6. 22
      health/src/main/java/com/ccsens/health/bean/vo/JourneyVo.java
  7. 8
      health/src/main/java/com/ccsens/health/bean/vo/MemberVo.java
  8. 7
      health/src/main/java/com/ccsens/health/bean/vo/UserVo.java
  9. 14
      health/src/main/java/com/ccsens/health/persist/dao/JourneyDao.java
  10. 15
      health/src/main/java/com/ccsens/health/persist/dao/MemberDao.java
  11. 8
      health/src/main/java/com/ccsens/health/persist/dao/RealNameAuthDao.java
  12. 32
      health/src/main/java/com/ccsens/health/service/AsyncService.java
  13. 20
      health/src/main/java/com/ccsens/health/service/IAsyncService.java
  14. 26
      health/src/main/java/com/ccsens/health/service/IJourneyService.java
  15. 29
      health/src/main/java/com/ccsens/health/service/IStudentService.java
  16. 54
      health/src/main/java/com/ccsens/health/service/JourneyService.java
  17. 141
      health/src/main/java/com/ccsens/health/service/StudentService.java
  18. 110
      health/src/main/java/com/ccsens/health/service/UserService.java
  19. 20
      health/src/main/java/com/ccsens/health/service/WeiXinService.java
  20. 32
      health/src/main/java/com/ccsens/health/util/HealthConstant.java
  21. 4
      health/src/main/resources/application-dev.yml
  22. 6
      health/src/main/resources/application-test.yml
  23. 22
      health/src/main/resources/mapper_dao/JourneyDao.xml
  24. 20
      health/src/main/resources/mapper_dao/MemberDao.xml
  25. 12
      health/src/main/resources/mapper_raw/MemberMapper.xml
  26. 4
      ht/src/main/resources/application.yml
  27. 2
      ht/src/main/resources/druid-prod.yml
  28. 2
      tall/src/main/resources/druid-prod.yml
  29. 3
      util/src/main/java/com/ccsens/util/CodeEnum.java
  30. 21
      util/src/main/java/com/ccsens/util/TransactionUtil.java

3
health/src/main/java/com/ccsens/health/api/HealthController.java

@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@ -27,7 +28,7 @@ import java.util.List;
@RequestMapping("/health")
public class HealthController {
@Autowired
@Resource
private IHealthService healthService;
@MustLogin

18
health/src/main/java/com/ccsens/health/api/JourneyController.java

@ -7,6 +7,7 @@ import com.ccsens.health.bean.vo.UserVo;
import com.ccsens.health.service.IJourneyService;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.bean.dto.QueryDto;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -83,4 +84,21 @@ public class JourneyController {
journeyService.deleteAbnormalJourney(params);
return JsonResponse.newInstance().ok();
}
@MustLogin
@ApiOperation(value = "全校返校行程统计", notes = "")
@RequestMapping(value = "backSchoolStatistics", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<JourneyVo.BackSchoolStatistics> backSchoolStatistics(){
log.info("统计全校返校行程");
JourneyVo.BackSchoolStatistics statistics = journeyService.backSchoolStatistics();
return JsonResponse.newInstance().ok(statistics);
}
@MustLogin
@ApiOperation(value = "班级复课情况", notes = "")
@RequestMapping(value = "classBackStatistics", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<PageInfo<JourneyVo.ClassBack>> backSchoolStatistics(@RequestBody QueryDto<JourneyDto.BackClass> params){
log.info("统计全校返校行程");
PageInfo<JourneyVo.ClassBack> pageInfo = journeyService.classBackStatistics(params.getParam());
return JsonResponse.newInstance().ok(pageInfo);
}
}

32
health/src/main/java/com/ccsens/health/api/StudentController.java

@ -5,6 +5,9 @@ import com.ccsens.health.bean.dto.MemberDto;
import com.ccsens.health.bean.vo.MemberVo;
import com.ccsens.health.service.IStudentService;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.PropUtil;
import com.ccsens.util.UploadFileUtil_Servlet3;
import com.ccsens.util.WebConstant;
import com.ccsens.util.bean.dto.QueryDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -12,11 +15,10 @@ import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Part;
import java.io.File;
import java.util.List;
@Slf4j
@ -44,4 +46,26 @@ public class StudentController {
MemberVo.ContactPatientVo contactPatientVo = studentService.getContactPatient(params);
return JsonResponse.newInstance().ok(contactPatientVo);
}
// @MustLogin
@PostMapping("import")
@ApiOperation(value = "导入成员", notes = "")
public JsonResponse importMembers(@RequestParam(required = true) Part file) {
try {
long time1 = System.currentTimeMillis();
//1.上传文件
String allowedExts = "xls,xlsx";
String dir = PropUtil.path ;
String path = UploadFileUtil_Servlet3.uploadFile(file, allowedExts, dir);
File execlFile = new File(dir+path);
long time2 = System.currentTimeMillis();
log.info("解析文件耗时:{}", (time2 - time1));
studentService.importMember(execlFile, 0, 1, 2);
} catch (Exception e) {
e.printStackTrace();
}
log.info("导入前3个sheet完成");
return JsonResponse.newInstance().ok();
}
}

15
health/src/main/java/com/ccsens/health/bean/dto/JourneyDto.java

@ -198,4 +198,19 @@ public class JourneyDto {
@ApiModelProperty("id")
private Long id;
}
@Data
@ApiModel("复课查询")
public static class BackClass{
@ApiModelProperty("查询时间 默认当前时间")
private Long endTime = System.currentTimeMillis();
@ApiModelProperty("第几页")
@Min(value = 1)
private int pageNum = 1;
@ApiModelProperty("每页多少条")
@Min(value = 1)
@Max(value=100)
private int pageSize = 10;
}
}

2
health/src/main/java/com/ccsens/health/bean/dto/MemberDto.java

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class MemberDto {

22
health/src/main/java/com/ccsens/health/bean/vo/JourneyVo.java

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class JourneyVo {
@ -44,4 +46,24 @@ public class JourneyVo {
@ApiModelProperty("备注")
private String description;
}
@Data
@ApiModel("返校统计")
public static class BackSchoolStatistics{
@ApiModelProperty("总人数")
private long totalMembersNum;
@ApiModelProperty("到校")
private long backSchoolNum;
@ApiModelProperty("未到")
private long notReportNum;
}
@Data
@ApiModel("班级复课情况")
public static class ClassBack{
private String className;
private int totalNum;
private int backNum;
private int noBackNum;
}
}

8
health/src/main/java/com/ccsens/health/bean/vo/MemberVo.java

@ -117,4 +117,12 @@ public class MemberVo {
@ApiModelProperty("同行人员")
private String together;
}
@Data
@ApiModel("用户是否为学校成员")
public static class MemberJudge{
@ApiModelProperty("学校成员 1:是 0:否")
private byte schoolMember;
@ApiModelProperty("是否实名认证 1:是 0:否")
private byte realName;
}
}

7
health/src/main/java/com/ccsens/health/bean/vo/UserVo.java

@ -1,5 +1,6 @@
package com.ccsens.health.bean.vo;
import com.ccsens.health.util.HealthConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -12,6 +13,12 @@ public class UserVo {
@Data
@ApiModel("查询个人信息")
public static class UserInfo{
// @ApiModelProperty("学校成员 1:是 0:否")
// private byte schoolMember = HealthConstant.SCHOOL_MEMBER_NO;
// @ApiModelProperty("是否实名认证 1:是 0:否")
// private byte realName = HealthConstant.REAL_NAME_NO;
@ApiModelProperty("用户身份")
private MemberVo.MemberJudge judge;
@ApiModelProperty("成员id")
private Long id;
@ApiModelProperty("姓名")

14
health/src/main/java/com/ccsens/health/persist/dao/JourneyDao.java

@ -11,4 +11,18 @@ import java.util.List;
@Repository
public interface JourneyDao extends JourneyMapper {
List<JourneyVo.JourneyInfo> selectJourneyByDate(@Param("employeeId")Long employeeId, @Param("startTime")Long startTime, @Param("endTime")Long endTime);
/**
* 根据类型查询总人数
* @param journeyType
* @return
*/
long countByType(@Param("journeyType") Byte journeyType);
/**
* 根据时间查询复课情况
* @param endTime
* @return
*/
List<JourneyVo.ClassBack> classBackStatistics(@Param("endTime") Long endTime);
}

15
health/src/main/java/com/ccsens/health/persist/dao/MemberDao.java

@ -0,0 +1,15 @@
package com.ccsens.health.persist.dao;
import com.ccsens.health.bean.po.Member;
import com.ccsens.health.persist.mapper.MemberMapper;
import java.util.List;
public interface MemberDao extends MemberMapper {
/**
* 批量插入用户信息
* @param memberList
*/
void insertBatch(List<Member> memberList);
}

8
health/src/main/java/com/ccsens/health/persist/dao/RealNameAuthDao.java

@ -1,8 +1,16 @@
package com.ccsens.health.persist.dao;
import com.ccsens.health.persist.mapper.RealNameAuthMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface RealNameAuthDao extends RealNameAuthMapper {
/**
* 更新userid
* @param sourceUserId
* @param targetUserId
*/
void updateUserId(@Param("sourceUserId")Long sourceUserId, @Param("targetUserId") Long targetUserId);
}

32
health/src/main/java/com/ccsens/health/service/AsyncService.java

@ -0,0 +1,32 @@
package com.ccsens.health.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Slf4j
@Async
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class AsyncService implements IAsyncService {
@Resource
private IStudentService studentService;
@Resource
private IJourneyService journeyService;
@Override
public long updateBackNum() {
return journeyService.updateBackNum();
}
@Override
public void updateStudentNum() {
studentService.updateStudentNum();
}
}

20
health/src/main/java/com/ccsens/health/service/IAsyncService.java

@ -0,0 +1,20 @@
package com.ccsens.health.service;
import com.ccsens.util.CodeEnum;
/**
* 异步方法
*/
public interface IAsyncService {
/**
* 更新山大总人数
*/
void updateStudentNum();
/**
* 更新返校行程总人数
* @return
*/
long updateBackNum();
}

26
health/src/main/java/com/ccsens/health/service/IJourneyService.java

@ -4,6 +4,7 @@ import com.ccsens.health.bean.dto.JourneyDto;
import com.ccsens.health.bean.vo.JourneyVo;
import com.ccsens.health.bean.vo.UserVo;
import com.ccsens.util.bean.dto.QueryDto;
import com.github.pagehelper.PageInfo;
import java.util.List;
@ -19,4 +20,29 @@ public interface IJourneyService {
void updateAbnormalJourney(QueryDto<JourneyDto.UpdateAbnormalJourney> params);
void deleteAbnormalJourney(QueryDto<JourneyDto.DeleteAbnormalJourney> params);
/**
* 查询填写返校行程的总用户数
* @return
*/
long countBackNum();
/**
* 更新返校行程总人数
* @return
*/
long updateBackNum();
/**
* 统计全校成员返校情况
* @return
*/
JourneyVo.BackSchoolStatistics backSchoolStatistics();
/**
* 分页查询班级复课情况
* @param backClass
* @return
*/
PageInfo<JourneyVo.ClassBack> classBackStatistics(JourneyDto.BackClass backClass);
}

29
health/src/main/java/com/ccsens/health/service/IStudentService.java

@ -2,12 +2,41 @@ package com.ccsens.health.service;
import com.ccsens.health.bean.dto.MemberDto;
import com.ccsens.health.bean.vo.MemberVo;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.bean.dto.QueryDto;
import java.io.File;
import java.util.List;
public interface IStudentService {
List<MemberVo.StudentHealthVo> getStudentHealthList(QueryDto<MemberDto.StudentHealth> params);
MemberVo.ContactPatientVo getContactPatient(QueryDto<MemberDto.ContactPatientDto> params);
/**
* 导入成员信息
* @param file
* @param sheetIndex
* @return
* @throws Exception
*/
JsonResponse importMember(File file, int... sheetIndex) throws Exception;
/**
* 更新总人数
* @return
*/
long updateStudentNum();
/**
* 获取成员总数
* @return
*/
long getTotalMember();
/**
* 判断学生是否为学校成员是否实名认证
* @param userId
* @return
*/
MemberVo.MemberJudge pageMember(long userId);
}

54
health/src/main/java/com/ccsens/health/service/JourneyService.java

@ -16,16 +16,21 @@ import com.ccsens.health.bean.vo.UserVo;
import com.ccsens.health.persist.dao.EmployeeDao;
import com.ccsens.health.persist.dao.JourneyAbnormalDao;
import com.ccsens.health.persist.dao.JourneyDao;
import com.ccsens.health.util.HealthConstant;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.DateUtil;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.util.exception.BaseException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Slf4j
@ -39,9 +44,56 @@ public class JourneyService implements IJourneyService{
private JourneyDao journeyDao;
@Autowired
private TallFeignClient tallFeignClient;
@Resource
private RedisUtil redisUtil;
@Resource
private IStudentService studentService;
@Resource
private IAsyncService asyncService;
@Autowired
private JourneyAbnormalDao journeyAbnormalDao;
@Override
public JourneyVo.BackSchoolStatistics backSchoolStatistics() {
long totalMember = studentService.getTotalMember();
log.info("总人数:{}", totalMember);
long backNum = countBackNum();
log.info("返校人数:{}", backNum);
JourneyVo.BackSchoolStatistics statistics = new JourneyVo.BackSchoolStatistics();
statistics.setTotalMembersNum(totalMember);
statistics.setBackSchoolNum(backNum);
statistics.setNotReportNum(backNum > totalMember ? 0 : totalMember - backNum);
log.info("全校人数汇总统计:{}", statistics);
return statistics;
}
@Override
public PageInfo<JourneyVo.ClassBack> classBackStatistics(JourneyDto.BackClass backClass) {
PageHelper.startPage(backClass.getPageNum(), backClass.getPageSize());
List<JourneyVo.ClassBack> vos = journeyDao.classBackStatistics(backClass.getEndTime());
return new PageInfo<>(vos);
}
@Override
public long countBackNum() {
Object o = redisUtil.get(HealthConstant.BACK_SCHOOL_TOTAL_REDIS);
log.info("查询返校总人数:{}", o);
if (o == null) {
return updateBackNum();
}
return (Integer)o;
}
@Override
public long updateBackNum() {
long total = journeyDao.countByType(HealthConstant.JOURNEY_BACK_SCHOOL);
redisUtil.set(HealthConstant.BACK_SCHOOL_TOTAL_REDIS, total);
log.info("填写返校行程的总人数:{}", total);
return total;
}
/**
* 上报行程
* @param params
@ -64,6 +116,8 @@ public class JourneyService implements IJourneyService{
JourneyVo.JourneyInfo journeyInfoVo = new JourneyVo.JourneyInfo();
BeanUtil.copyProperties(journey,journeyInfoVo);
//更新返校总人数
asyncService.updateBackNum();
return journeyInfoVo;
}

141
health/src/main/java/com/ccsens/health/service/StudentService.java

@ -1,19 +1,52 @@
package com.ccsens.health.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.StrUtil;
import com.ccsens.health.bean.dto.MemberDto;
import com.ccsens.health.bean.po.EmployeeExample;
import com.ccsens.health.bean.po.Member;
import com.ccsens.health.bean.po.MemberExample;
import com.ccsens.health.bean.po.RealNameAuthExample;
import com.ccsens.health.bean.vo.MemberVo;
import com.ccsens.health.persist.dao.EmployeeDao;
import com.ccsens.health.persist.dao.MemberDao;
import com.ccsens.health.persist.dao.RealNameAuthDao;
import com.ccsens.health.util.HealthConstant;
import com.ccsens.util.*;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.util.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class StudentService implements IStudentService{
@Resource
private Snowflake snowflake;
@Resource
private PlatformTransactionManager transactionManager;
@Resource
private RedisUtil redisUtil;
@Resource
private MemberDao memberDao;
@Resource
private EmployeeDao employeeDao;
@Resource
private RealNameAuthDao realNameAuthDao;
@Resource
private IAsyncService asyncService;
/**
* 查询学生健康信息列表
* @param params
@ -24,6 +57,114 @@ public class StudentService implements IStudentService{
return null;
}
@Override
public JsonResponse importMember(File file, int... sheetIndex) throws Exception {
log.info("导入成员信息:{}, {}", file, sheetIndex);
if (sheetIndex == null || sheetIndex.length == 0) {
throw new BaseException(CodeEnum.PARAM_ERROR);
}
List<Member> memberList = new ArrayList<>();
for (int index: sheetIndex) {
StringBuilder builder = new StringBuilder();
List<Object[]> members = PoiUtil.readExce(file, index, null,1, false);
log.info("导入员工,读取数据:{}", members);
List<Member> member = initMembers(members);
memberList.addAll(member);
}
if (CollectionUtil.isEmpty(memberList)) {
log.info("没有有效的导入学生信息");
throw new BaseException(CodeEnum.NO_IMPORT_DATA);
}
int size = memberList.size();
log.info("封装参数结束, 导入成员数:{}", size);
int count = 100;
for (int i = 0; i < size; i+=count) {
int end = i + count > size ? size : i+count;
// 手动提交事务
TransactionStatus transactionStatus = TransactionUtil.getTransactionStatus(transactionManager);
memberDao.insertBatch(memberList.subList(i, end));
transactionManager.commit(transactionStatus);
}
// 更新redis
asyncService.updateStudentNum();
log.info("导入员工信息完成,{}", Thread.currentThread().getId());
return JsonResponse.newInstance().ok();
}
@Override
public long updateStudentNum() {
MemberExample example = new MemberExample();
long total = memberDao.countByExample(example);
redisUtil.set(HealthConstant.MEMBER_TOTAL_REDIS, total);
log.info("更新成员总数redis结束:{}", total);
return total;
}
@Override
public long getTotalMember() {
Object obj = redisUtil.get(HealthConstant.MEMBER_TOTAL_REDIS);
log.info("获取总人数:{}", obj);
if (obj != null) {
return (Integer)obj;
}
long memberTotalNum = updateStudentNum();
return memberTotalNum;
}
@Override
public MemberVo.MemberJudge pageMember(long userId) {
log.info("判断{}是否为学校学生,及是否实名认证");
MemberVo.MemberJudge judge = new MemberVo.MemberJudge();
//判断是否关联企业帐号
EmployeeExample employeeExample = new EmployeeExample();
employeeExample.createCriteria().andTallUserIdEqualTo(userId);
long empCount = employeeDao.countByExample(employeeExample);
judge.setSchoolMember((byte)(empCount > 0 ? 1 : 0));
// 判断是否实名认证
RealNameAuthExample authExample = new RealNameAuthExample();
authExample.createCriteria().andUserIdEqualTo(userId);
long authCount = realNameAuthDao.countByExample(authExample);
judge.setRealName((byte)(authCount > 0 ? 1 : 0));
return judge;
}
/**
* 将表格转换为members
* @param members
* @return
*/
private List<Member> initMembers(List<Object[]> members) {
List<Member> memberList = new ArrayList<>();
if (CollectionUtil.isEmpty(members)) {
log.info("没有有效的数据");
return memberList;
}
members.forEach(obj -> {
boolean isBlank = obj[0]==null || obj[1] == null || obj[2] == null;
if (isBlank) {
log.info("{},{},{}有参数为空,跳过下一行", obj[0], obj[1], obj[2]);
return;
}
Member member = new Member();
member.setId(snowflake.nextId());
member.setWkno((String)obj[0]);
member.setName((String)obj[1]);
member.setDepartment((String)obj[2]);
member.setProvince(obj[3] == null ? StrUtil.EMPTY : (String)obj[3]);
member.setCity(obj[4] == null ? StrUtil.EMPTY : (String)obj[4]);
member.setCounty(obj[5] == null ? StrUtil.EMPTY : (String)obj[5]);
member.setSite(obj[6] == null ? StrUtil.EMPTY : (String)obj[6]);
member.setType(obj[7] == null ? 0 : Byte.valueOf((String)obj[7]));
memberList.add(member);
});
return memberList;
}
/**
* 查询接触病患的学生列表
* @param params

110
health/src/main/java/com/ccsens/health/service/UserService.java

@ -9,11 +9,10 @@ import com.ccsens.cloudutil.feign.TallFeignClient;
import com.ccsens.health.bean.dto.JourneyDto;
import com.ccsens.health.bean.dto.UserDto;
import com.ccsens.health.bean.po.*;
import com.ccsens.health.bean.vo.MemberVo;
import com.ccsens.health.bean.vo.UserVo;
import com.ccsens.health.persist.dao.EmployeeDao;
import com.ccsens.health.persist.dao.HealthRecordsDao;
import com.ccsens.health.persist.dao.RealNameAuthDao;
import com.ccsens.health.persist.mapper.HealthQRCodeMapper;
import com.ccsens.health.persist.dao.*;
import com.ccsens.health.util.HealthConstant;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.DateUtil;
import com.ccsens.util.bean.dto.QueryDto;
@ -24,7 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@ -42,6 +41,10 @@ public class UserService implements IUserService{
private TallFeignClient tallFeignClient;
@Autowired
private HealthRecordsDao healthRecordsDao;
@Resource
private MemberDao memberDao;
@Resource
private JourneyDao journeyDao;
/**
* 查询个人信息
@ -75,7 +78,16 @@ public class UserService implements IUserService{
if(CollectionUtil.isNotEmpty(realNameAuthList)){
userInfoVo = new UserVo.UserInfo();
BeanUtil.copyProperties(realNameAuthList.get(0),userInfoVo);
// userInfoVo.setRealName(HealthConstant.REAL_NAME_YES);
}
// //判断是否为学校成员
// EmployeeExample newExample = new EmployeeExample();
// newExample.createCriteria().andTallUserIdEqualTo(userId);
// long newCount = employeeDao.countByExample(newExample);
// log.info("绑定企业微信帐号数:{}", newCount);
// if (newCount > 0) {
// userInfoVo.setSchoolMember(HealthConstant.SCHOOL_MEMBER_YES);
// }
//查询健康码
List<UserVo.HealthCode> healthCodeList = healthRecordsDao.getHealthQrCodeByEmployeeId(userId,startTime,endTime);
@ -95,15 +107,57 @@ public class UserService implements IUserService{
//获取个人信息和tall的userId
UserDto.UserInfo userInfo = params.getParam();
Long userId = params.getUserId();
//判断是否绑定企业微信
EmployeeExample newExample = new EmployeeExample();
newExample.createCriteria().andTallUserIdEqualTo(userId);
long bindQyCount = employeeDao.countByExample(newExample);
//检查是否认证过
RealNameAuthExample realNameAuthExample = new RealNameAuthExample();
realNameAuthExample.createCriteria().andUserIdEqualTo(userId);
List<RealNameAuth> realNameAuthList = realNameAuthDao.selectByExample(realNameAuthExample);
if(CollectionUtil.isNotEmpty(realNameAuthList)){
//如果不为空代表已经认证过,直接返回认证信息
throw new BaseException(CodeEnum.ALREADY_REAL_AUTH);
//判断是否为同一个user_id
RealNameAuth auth = realNameAuthList.get(0);
if (auth.getUserId().longValue() == userId.longValue()) {
//如果不为空代表已经认证过,直接返回认证信息
throw new BaseException(CodeEnum.ALREADY_REAL_AUTH);
} else {
// 判断哪个userid和企业微信绑定
EmployeeExample oldExample = new EmployeeExample();
oldExample.createCriteria().andTallUserIdEqualTo(auth.getUserId());
long authCount = employeeDao.countByExample(oldExample);
boolean hasBind = bindQyCount > 0 && authCount <= 0 || bindQyCount <= 0 && authCount > 0;
if (!hasBind) {
throw new BaseException(CodeEnum.ALREADY_REAL_AUTH);
} else {
//更新返校行程,健康打卡,
if (bindQyCount > 0) {
bindUser(auth.getUserId(), userId);
} else {
bindUser(userId, auth.getUserId());
}
throw new BaseException(CodeEnum.ACCOUNT_BIND);
}
}
}
//实名认证,检查是否属于该学校的学生
MemberExample memberExample = new MemberExample();
memberExample.createCriteria().andWknoEqualTo(userInfo.getNo()).andNameEqualTo(userInfo.getName());
List<Member> memberList = memberDao.selectByExample(memberExample);
log.info("校验身份信息:{}", memberList);
if (CollectionUtil.isEmpty(memberList)) {
throw new BaseException(CodeEnum.FILL_ERROR);
}
//TODO 实名认证,检查是否属于该学校的学生
Member member = memberList.get(0);
//如果是 1, 2 是学生
boolean isStu = member.getType() == null
|| member.getType().byteValue() == HealthConstant.MEMBER_UNDERGRADUATE
|| member.getType().byteValue() == HealthConstant.MEMBER_GRADUATE;
userInfo.setPost(isStu ? HealthConstant.REAL_NAME_STUDENG : userInfo.getPost());
//保存信息
RealNameAuth realNameAuth = new RealNameAuth();
realNameAuth.setId(snowflake.nextId());
@ -117,9 +171,49 @@ public class UserService implements IUserService{
//返回
UserVo.UserInfo userInfoVo = new UserVo.UserInfo();
BeanUtil.copyProperties(realNameAuth,userInfoVo);
// userInfoVo.setRealName(HealthConstant.REAL_NAME_YES);
// userInfoVo.setSchoolMember(bindQyCount > 0 ? HealthConstant.SCHOOL_MEMBER_YES : HealthConstant.SCHOOL_MEMBER_NO);
return userInfoVo;
}
/**
* 绑定帐号
* @param sourceUserId 源userId
* @param targetUserId 替换的userId()
* @return
*/
private void bindUser(Long sourceUserId, Long targetUserId) {
//TODO 帐号绑定
// 绑定实名认证
RealNameAuth auth = new RealNameAuth();
auth.setUserId(targetUserId);
RealNameAuthExample authExample = new RealNameAuthExample();
authExample.createCriteria().andUserIdEqualTo(sourceUserId);
realNameAuthDao.updateByExampleSelective(auth, authExample);
log.info("实名认证更新");
// 绑定健康打卡
HealthRecords healthRecords = new HealthRecords();
healthRecords.setUserId(targetUserId);
HealthRecordsExample recordsExample = new HealthRecordsExample();
recordsExample.createCriteria().andUserIdEqualTo(sourceUserId);
healthRecordsDao.updateByExampleSelective(healthRecords, recordsExample);
log.info("绑定健康上报");
// 绑定行程上报
Journey journey = new Journey();
journey.setUserId(targetUserId);
JourneyExample journeyExample = new JourneyExample();
journeyExample.createCriteria().andUserIdEqualTo(sourceUserId);
journeyDao.updateByExampleSelective(journey, journeyExample);
log.info("绑定行程上报");
// 绑定校园打卡
SiteClockIn clockIn = new SiteClockIn();
clockIn.setUserId(targetUserId);
SiteClockInExample clockInExample = new SiteClockInExample();
clockInExample.createCriteria().andUserIdEqualTo(sourceUserId);
log.info("绑定校园打卡");
}
/**
* 查询个人轨迹
* @param params

20
health/src/main/java/com/ccsens/health/service/WeiXinService.java

@ -15,6 +15,7 @@ import com.ccsens.health.persist.mapper.HealthAuthMapper;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.RestTemplateUtil;
import com.ccsens.util.TransactionUtil;
import com.ccsens.util.enterprisewx.WeiXinConstant;
import com.ccsens.util.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
@ -239,7 +240,7 @@ public class WeiXinService implements IWeiXinService {
int once = 100;
for (int i = 0; i < empSize; i+=once) {
int end = i+once > empSize ? empSize : i+once;
TransactionStatus status = getTransactionStatus();
TransactionStatus status = TransactionUtil.getTransactionStatus(transactionManager);
try {
employeeDao.insertBatch(employees.subList(i, end));
//提交事务
@ -252,7 +253,7 @@ public class WeiXinService implements IWeiXinService {
}
for (int i = 0; i < deSize; i+=once) {
int end = i+once > deSize ? deSize : i+once;
TransactionStatus status = getTransactionStatus();
TransactionStatus status = TransactionUtil.getTransactionStatus(transactionManager);
try {
departmentEmployeeDao.insertBatch(des.subList(i, end));
//提交事务
@ -270,7 +271,7 @@ public class WeiXinService implements IWeiXinService {
* @param departments
*/
private void insertBatchDepartment(List<Department> departments) {
TransactionStatus status = getTransactionStatus();
TransactionStatus status = TransactionUtil.getTransactionStatus(transactionManager);
int size = departments.size();
int once = 100;
for (int i = 0; i < size; i+=once) {
@ -287,18 +288,7 @@ public class WeiXinService implements IWeiXinService {
}
}
/**
* 手动开启事务获取事务状态
* @return
*/
private TransactionStatus getTransactionStatus() {
//开启手动事务
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// 事务隔离级别,开启新事务
def.setPropagationBehavior( TransactionDefinition.PROPAGATION_REQUIRES_NEW );
//获取事务状态,并开启事务,相当于transation.begin();
return transactionManager.getTransaction( def );
}
/**
* 初始化永久授权信息

32
health/src/main/java/com/ccsens/health/util/HealthConstant.java

@ -0,0 +1,32 @@
package com.ccsens.health.util;
/**
* 健康码项目常量类
* @author whj
*/
public class HealthConstant {
/*** redis key: 总人数*/
public static final String MEMBER_TOTAL_REDIS = "health_member_total_redis";
/** redis key: 返校行程总人数*/
public static final String BACK_SCHOOL_TOTAL_REDIS = "health_back_school_total_redis";
/**成员表 本科生*/
public static final byte MEMBER_UNDERGRADUATE = 0;
/**成员表 研究生*/
public static final byte MEMBER_GRADUATE = 1;
/**实名认证 学生*/
public static final byte REAL_NAME_STUDENG = 0;
/**已实名认证*/
public static final byte REAL_NAME_YES = 1;
/**未实名认证*/
public static final byte REAL_NAME_NO = 0;
/**是学校成员*/
public static final byte SCHOOL_MEMBER_YES = 1;
/**不是学校成员*/
public static final byte SCHOOL_MEMBER_NO = 0;
/**行程类型: 返校行程*/
public static final byte JOURNEY_BACK_SCHOOL = 1;
/**行程类型: 日常外出*/
public static final byte JOURNEY_OUT_SCHOOL = 1;
}

4
health/src/main/resources/application-dev.yml

@ -27,3 +27,7 @@ spring:
swagger:
enable: true
file:
path: /home/cloud/health/uploads/
domain: http://localhost:7080/
imgDomain: http://localhost:7080/uploads

6
health/src/main/resources/application-test.yml

@ -28,4 +28,8 @@ swagger:
enable: true
eureka:
instance:
ip-address: 119.28.76.62
ip-address: 119.28.76.62
file:
path: /home/cloud/health/uploads/
domain: https://test.tall.wiki/gateway/health/
imgDomain: https://test.tall.wiki/gateway/health/uploads

22
health/src/main/resources/mapper_dao/JourneyDao.xml

@ -34,6 +34,28 @@
end_time &gt;= #{startTime}
ORDER By start_time DESC
</select>
<select id="countByType" resultType="java.lang.Long">
select count(DISTINCT user_id) from t_journey
<where>
<if test="journeyType != null">
and journey_type = 1
</if>
and rec_status = 0
</where>
</select>
<select id="classBackStatistics" resultType="com.ccsens.health.bean.vo.JourneyVo$ClassBack">
select t1.department as className, t1.totalNum, ifNull(t2.backNum,0) as backNum, t1.totalNum-IFNULL(t2.backNum,0) as noBackNum from
(select department, count(id) as totalNum from t_member where type in (0,1) group by department) t1
left join
(select m.department, count(DISTINCT j.user_id) as backNum from
t_journey j left join t_real_name_auth a on j.user_id = a.user_id
left join t_member m on a.no = m.wkno
where (a.id is null or a.post = 0)
and j.end_time &lt; #{endTime}
GROUP BY m.department) t2
on t1.department = t2.department
</select>
</mapper>

20
health/src/main/resources/mapper_dao/MemberDao.xml

@ -0,0 +1,20 @@
<?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.ccsens.health.persist.dao.MemberDao">
<insert id="insertBatch">
insert into t_member (id, wkno, `name`,
department, province, city,
county, site, `type`
)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=BIGINT}, #{item.wkno,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
#{item.department,jdbcType=VARCHAR}, #{item.province,jdbcType=VARCHAR}, #{item.city,jdbcType=VARCHAR},
#{item.county,jdbcType=VARCHAR}, #{item.site,jdbcType=VARCHAR}, #{item.type,jdbcType=TINYINT}
)
</foreach>
on duplicate key update wkno = values(wkno)
</insert>
</mapper>

12
health/src/main/resources/mapper_raw/MemberMapper.xml

@ -108,16 +108,18 @@
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.health.bean.po.Member">
insert into t_member (id, wkno, name,
replace into t_member (id, wkno, name,
department, province, city,
county, site, type,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{wkno,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{department,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR},
#{county,jdbcType=VARCHAR}, #{site,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=BIGINT}, #{item.wkno,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},
#{item.department,jdbcType=VARCHAR}, #{item.province,jdbcType=VARCHAR}, #{item.city,jdbcType=VARCHAR},
#{item.county,jdbcType=VARCHAR}, #{item.site,jdbcType=VARCHAR}, #{item.type,jdbcType=TINYINT},
)
</foreach>
</insert>
<insert id="insertSelective" parameterType="com.ccsens.health.bean.po.Member">
insert into t_member

4
ht/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: test
include: common, util-test
active: prod
include: common, util-prod

2
ht/src/main/resources/druid-prod.yml

@ -27,7 +27,7 @@ spring:
testOnReturn: false
testWhileIdle: true
timeBetweenEvictionRunsMillis: 60000
url: jdbc:mysql://127.0.0.1/pt_pro?useUnicode=true&characterEncoding=UTF-8
url: jdbc:mysql://127.0.0.1/ht?useUnicode=true&characterEncoding=UTF-8
username: root
validationQuery: SELECT 1 FROM DUAL
env: CCSENS_HT

2
tall/src/main/resources/druid-prod.yml

@ -27,7 +27,7 @@ spring:
testOnReturn: false
testWhileIdle: true
timeBetweenEvictionRunsMillis: 60000
url: jdbc:mysql://127.0.0.1/pt_pro?useUnicode=true&characterEncoding=UTF-8
url: jdbc:mysql://127.0.0.1/tall?useUnicode=true&characterEncoding=UTF-8
username: root
validationQuery: SELECT 1 FROM DUAL
env: CCSENS_TALL

3
util/src/main/java/com/ccsens/util/CodeEnum.java

@ -103,6 +103,9 @@ public enum CodeEnum {
SITE_EXCEED(86,"您所添加的场所数量已超出上限,请联系客服提高场所上限",true),
SITE_NAME_REPETITION(86,"场所名重复",true),
LOCATION_LONG(87,"对不起,您的距离太远了,请靠近目的地后重试。",true),
NO_IMPORT_DATA(88,"没有有效的数据,请检查您的导入文件。",true),
FILL_ERROR(89,"您的信息填写有误,请检查您的信息。",true),
ACCOUNT_BIND(90,"您的帐号已经绑定了,请关注。",true),
;
public CodeEnum addMsg(String msg){

21
util/src/main/java/com/ccsens/util/TransactionUtil.java

@ -0,0 +1,21 @@
package com.ccsens.util;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
public class TransactionUtil {
/**
* 手动开启事务获取事务状态
* @return
*/
public static TransactionStatus getTransactionStatus(PlatformTransactionManager transactionManager) {
//开启手动事务
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// 事务隔离级别,开启新事务
def.setPropagationBehavior( TransactionDefinition.PROPAGATION_REQUIRES_NEW );
// 获取事务状态,并开启事务,相当于 transaction begin;
return transactionManager.getTransaction( def );
}
}
Loading…
Cancel
Save