UserClockServiceImpl.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package cn.com.lzt.userclock.service.impl;
  2. import cn.com.lzt.common.util.StringUtil;
  3. import cn.com.lzt.overtimerecord.entity.OvertimeRecordEntity;
  4. import cn.com.lzt.overtimerecord.service.OvertimeRecordServiceI;
  5. import cn.com.lzt.userclock.service.UserClockService;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.core.metadata.IPage;
  8. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  9. import com.daju.common.util.DataPage;
  10. import com.daju.mix.dao.entity.TBUserClock;
  11. import com.daju.mix.dao.mapper.TBUserClockMapper;
  12. import com.daju.mix.dao.service.impl.BaseServiceImpl;
  13. import com.daju.mix.dto.TBUserClockDto;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.util.List;
  17. import java.util.Map;
  18. /**
  19. * @author :sahib.kio.m
  20. * @date :Created in 2021/8/9 下午1:52
  21. */
  22. @Service
  23. public class UserClockServiceImpl extends BaseServiceImpl<TBUserClockMapper, TBUserClock> implements UserClockService {
  24. // 上班
  25. private static final String WORKING = "1";
  26. // 下班
  27. private static final String STOP_WORKING = "2";
  28. // 加班
  29. private static final String OVER_WORKING = "1";
  30. @Resource
  31. private OvertimeRecordServiceI overtimeRecordServiceI;
  32. public DataPage clockList(Map<String, String> param) {
  33. DataPage result = new DataPage();
  34. int page = 1;
  35. if (param.containsKey("page")) {
  36. page = Integer.valueOf(param.get("page"));
  37. }
  38. int rows = 50;
  39. if (param.containsKey("rows")) {
  40. rows = Integer.valueOf(param.get("rows"));
  41. }
  42. String code = param.get("code");
  43. String userNum = param.get("userNum");
  44. String userId = param.get("user.id");
  45. String userName = param.get("user.id.str");
  46. String depart = param.get("depart");
  47. String post = param.get("post");
  48. String start = param.get("clock_time_begin1");
  49. String end = param.get("clock_time_end2");
  50. QueryWrapper<?> queryWrapper = new QueryWrapper<>();
  51. String selectSql = " SELECT TBUC.*, TSBU.REALNAME AS NAME, tbup.in_postid as post, tsbu.departid as depart,TSU.USERNUM as userNum\n" +
  52. "FROM T_B_USER_CLOCK TBUC\n" +
  53. " left join t_bus_user_personnel tbup on TBUC.user_id = tbup.userid\n" +
  54. " left join t_bus_post tbp on tbup.in_postid = tbp.id\n" +
  55. " LEFT JOIN T_S_BASE_USER TSBU ON TBUC.USER_ID = TSBU.ID\n" +
  56. " LEFT JOIN T_S_USER TSU ON TBUC.USER_ID = TSU.ID " +
  57. "WHERE 1 = 1 ";
  58. if (!StringUtil.isEmpty(code)) {
  59. selectSql += "AND TBUC.code like '%" + code + "%' ";
  60. }
  61. if (!StringUtil.isEmpty(userNum)) {
  62. selectSql += "AND TSU.USERNUM like '%" + userNum + "%' ";
  63. }
  64. if (!StringUtil.isEmpty(userName)) {
  65. selectSql += "and TBUC.user_id in (select id from t_s_base_user where realname like '%"+userName+"%') ";
  66. }
  67. if (!StringUtil.isEmpty(userId)) {
  68. selectSql += "and TBUC.user_id = '" + userId + "' ";
  69. }
  70. if (!StringUtil.isEmpty(depart)) {
  71. selectSql += "and tsbu.departid = '" + depart + "' ";
  72. }
  73. if (!StringUtil.isEmpty(post)) {
  74. selectSql += "and tbup.in_postid = '" + post + "' ";
  75. }
  76. if (!StringUtil.isEmpty(start)) {
  77. selectSql += "and TBUC.clock_time >= '" + start + "' ";
  78. }
  79. if (!StringUtil.isEmpty(end)) {
  80. selectSql += "and TBUC.clock_time <= '" + end + "' ";
  81. }
  82. IPage<Map<String, Object>> mapPage = getBaseMapper().queryMapPageBySql(new Page<>(page, rows), queryWrapper, selectSql);
  83. result.setList(mapPage.getRecords());
  84. result.setTotalCount((int) mapPage.getTotal());
  85. return result;
  86. }
  87. @Override
  88. public List<TBUserClockDto> listOrderByUserIdAndTime(String YearAndMonth, String userId) throws Exception {
  89. List<TBUserClockDto> tbUserClockDtos = baseMapper.listOrderByUserIdAndTime(YearAndMonth, userId);
  90. List<OvertimeRecordEntity> overtimeRecordEntities = overtimeRecordServiceI.getOvertimeRecordEntities(userId,YearAndMonth);
  91. tbUserClockDtos.forEach(tbUserClockDto -> {
  92. if (OVER_WORKING.equals(tbUserClockDto.getWorkType())) {
  93. // 加班
  94. if (WORKING.equals(tbUserClockDto.getClockType())) {
  95. tbUserClockDto.setOverTime(tbUserClockDto.getClockTime());
  96. }
  97. if (STOP_WORKING.equals(tbUserClockDto.getClockType())) {
  98. tbUserClockDto.setStopOvertime(tbUserClockDto.getClockTime());
  99. }
  100. } else {
  101. if (WORKING.equals(tbUserClockDto.getClockType())) {
  102. tbUserClockDto.setWorkingTime(tbUserClockDto.getClockTime());
  103. }
  104. if (STOP_WORKING.equals(tbUserClockDto.getClockType())) {
  105. tbUserClockDto.setStopWorkingTime(tbUserClockDto.getClockTime());
  106. }
  107. }
  108. });
  109. return tbUserClockDtos;
  110. }
  111. }