Browse Source

导入用户打卡数据开发第二版,导入数据库再做处理

anderx 1 year ago
parent
commit
d9e7503476

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java

@@ -288,6 +288,7 @@ public class SysUserController extends BaseController
     public AjaxResult importUserClock( @RequestParam("file") MultipartFile file) throws Exception{
         ExcelUtil<Map> util = new ExcelUtil<>(Map.class);
         List<Map<Integer, String>> maps = util.importMapExcel(file.getInputStream(), 0);
-        return success(userService.pushUserClock(maps));
+        userService.pushUserClock(maps);
+        return success();
     }
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/project/mapper/ProjectStaffMapper.java

@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.project.domain.ProjectStaff;
 import org.apache.ibatis.annotations.Param;
 
+import java.time.LocalDate;
 import java.util.List;
 
 public interface ProjectStaffMapper {
@@ -28,4 +29,5 @@ public interface ProjectStaffMapper {
     void updateNameByAid(SysUser user);
 
     List<ProjectStaff> selectByAid(Long userId);
+
 }

+ 4 - 1
ruoyi-system/src/main/java/com/ruoyi/project/mapper/ProjectStaffRecordMapper.java

@@ -7,6 +7,7 @@ import com.ruoyi.project.bo.ProjectStaffRecordOut;
 import com.ruoyi.project.domain.ProjectStaffRecord;
 import org.apache.ibatis.annotations.Param;
 
+import java.time.LocalDate;
 import java.util.List;
 
 public interface ProjectStaffRecordMapper {
@@ -39,5 +40,7 @@ public interface ProjectStaffRecordMapper {
 
     void updateSumDurationStaff(Long pid);
 
-    void selectByAidAndTime(@Param("uid") Long uid, @Param("startTime") String startTime, @Param("endTime") String endTime);
+    List<ProjectStaffRecord> selectByAidAndTime(@Param("uid") Long uid, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<ProjectStaffRecord> selectByDDUidAndTime(@Param("ddUserId") Long ddUserId, @Param("clockDate") LocalDate clockDate);
 }

+ 77 - 11
ruoyi-system/src/main/java/com/ruoyi/system/domain/UserRecord.java

@@ -19,6 +19,11 @@ public class UserRecord implements Serializable {
     private Long psrId;
 
     /**
+     * 打卡人名称
+     */
+    private String name;
+
+    /**
      * 状态
      */
     private Integer status;
@@ -44,9 +49,19 @@ public class UserRecord implements Serializable {
     private Date endTime;
 
     /**
-     * 时长
+     * 计算时长
+     */
+    private Double sumDuration;
+
+    /**
+     * 核对时长
+     */
+    private Double checkDuration;
+
+    /**
+     * 操作人编号
      */
-    private Double duration;
+    private Long createId;
 
     private static final long serialVersionUID = 1L;
 
@@ -79,6 +94,20 @@ public class UserRecord implements Serializable {
     }
 
     /**
+     * 打卡人名称
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 打卡人名称
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
      * 状态
      */
     public Integer getStatus() {
@@ -149,17 +178,45 @@ public class UserRecord implements Serializable {
     }
 
     /**
-     * 时长
+     * 计算时长
+     */
+    public Double getSumDuration() {
+        return sumDuration;
+    }
+
+    /**
+     * 计算时长
+     */
+    public void setSumDuration(Double sumDuration) {
+        this.sumDuration = sumDuration;
+    }
+
+    /**
+     * 核对时长
+     */
+    public Double getCheckDuration() {
+        return checkDuration;
+    }
+
+    /**
+     * 核对时长
+     */
+    public void setCheckDuration(Double checkDuration) {
+        this.checkDuration = checkDuration;
+    }
+
+    /**
+     * 操作人编号
      */
-    public Double getDuration() {
-        return duration;
+    public Long getCreateId() {
+        return createId;
     }
 
     /**
-     * 时长
+     * 操作人编号
      */
-    public void setDuration(Double duration) {
-        this.duration = duration;
+    public void setCreateId(Long createId) {
+        this.createId = createId;
     }
 
     @Override
@@ -176,12 +233,15 @@ public class UserRecord implements Serializable {
         UserRecord other = (UserRecord) that;
         return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
             && (this.getPsrId() == null ? other.getPsrId() == null : this.getPsrId().equals(other.getPsrId()))
+            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
             && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
             && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()))
             && (this.getRecordTime() == null ? other.getRecordTime() == null : this.getRecordTime().equals(other.getRecordTime()))
             && (this.getStartTime() == null ? other.getStartTime() == null : this.getStartTime().equals(other.getStartTime()))
             && (this.getEndTime() == null ? other.getEndTime() == null : this.getEndTime().equals(other.getEndTime()))
-            && (this.getDuration() == null ? other.getDuration() == null : this.getDuration().equals(other.getDuration()));
+            && (this.getSumDuration() == null ? other.getSumDuration() == null : this.getSumDuration().equals(other.getSumDuration()))
+            && (this.getCheckDuration() == null ? other.getCheckDuration() == null : this.getCheckDuration().equals(other.getCheckDuration()))
+            && (this.getCreateId() == null ? other.getCreateId() == null : this.getCreateId().equals(other.getCreateId()));
     }
 
     @Override
@@ -190,12 +250,15 @@ public class UserRecord implements Serializable {
         int result = 1;
         result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
         result = prime * result + ((getPsrId() == null) ? 0 : getPsrId().hashCode());
+        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
         result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
         result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
         result = prime * result + ((getRecordTime() == null) ? 0 : getRecordTime().hashCode());
         result = prime * result + ((getStartTime() == null) ? 0 : getStartTime().hashCode());
         result = prime * result + ((getEndTime() == null) ? 0 : getEndTime().hashCode());
-        result = prime * result + ((getDuration() == null) ? 0 : getDuration().hashCode());
+        result = prime * result + ((getSumDuration() == null) ? 0 : getSumDuration().hashCode());
+        result = prime * result + ((getCheckDuration() == null) ? 0 : getCheckDuration().hashCode());
+        result = prime * result + ((getCreateId() == null) ? 0 : getCreateId().hashCode());
         return result;
     }
 
@@ -207,12 +270,15 @@ public class UserRecord implements Serializable {
         sb.append("Hash = ").append(hashCode());
         sb.append(", id=").append(id);
         sb.append(", psrId=").append(psrId);
+        sb.append(", name=").append(name);
         sb.append(", status=").append(status);
         sb.append(", content=").append(content);
         sb.append(", recordTime=").append(recordTime);
         sb.append(", startTime=").append(startTime);
         sb.append(", endTime=").append(endTime);
-        sb.append(", duration=").append(duration);
+        sb.append(", sumDuration=").append(sumDuration);
+        sb.append(", checkDuration=").append(checkDuration);
+        sb.append(", createId=").append(createId);
         sb.append(", serialVersionUID=").append(serialVersionUID);
         sb.append("]");
         return sb.toString();

+ 34 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/UserRecordOut.java

@@ -0,0 +1,34 @@
+package com.ruoyi.system.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.project.domain.ProjectStaffRecord;
+
+import java.util.Date;
+import java.util.List;
+
+public class UserRecordOut extends UserRecord{
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date recordTime;
+
+    /**
+     * 开始时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date endTime;
+
+    private List<ProjectStaffRecord> list;
+
+    public List<ProjectStaffRecord> getList() {
+        return list;
+    }
+
+    public void setList(List<ProjectStaffRecord> list) {
+        this.list = list;
+    }
+}

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java

@@ -143,5 +143,5 @@ public interface SysUserMapper
 
     int selectParticipateProjectSum(Long userId);
 
-    SysUser selectDDUserId(String ddUserId);
+    SysUser selectDDUserId(Long ddUserId);
 }

+ 5 - 1
ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserRecordMapper.java

@@ -1,11 +1,14 @@
 package com.ruoyi.system.mapper;
 
 import com.ruoyi.system.domain.UserRecord;
+import com.ruoyi.system.domain.UserRecordOut;
+
+import java.util.List;
 
 /**
 * @author Administrator
 * @description 针对表【user_record(用户考勤记录表)】的数据库操作Mapper
-* @createDate 2024-03-18 15:10:04
+* @createDate 2024-03-18 15:14:13
 * @Entity com.ruoyi.system.domain.UserRecord
 */
 public interface UserRecordMapper {
@@ -22,4 +25,5 @@ public interface UserRecordMapper {
 
     int updateByPrimaryKey(UserRecord record);
 
+
 }

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -5,6 +5,7 @@ import java.util.Map;
 
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.system.domain.UserClockDtails;
+import com.ruoyi.system.domain.UserRecord;
 
 /**
  * 用户 业务层
@@ -215,5 +216,5 @@ public interface ISysUserService
 
     boolean checkProject(Long[] userIds);
 
-    List<UserClockDtails> pushUserClock(List<Map<Integer, String>> maps);
+    void pushUserClock(List<Map<Integer, String>> maps);
 }

+ 43 - 28
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -5,6 +5,7 @@ import java.sql.SQLIntegrityConstraintViolationException;
 import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -18,7 +19,7 @@ import com.ruoyi.project.domain.ProjectTask;
 import com.ruoyi.project.mapper.ProjectStaffMapper;
 import com.ruoyi.project.mapper.ProjectStaffRecordMapper;
 import com.ruoyi.project.mapper.ProjectTaskMapper;
-import com.ruoyi.system.domain.UserClockDtails;
+import com.ruoyi.system.domain.*;
 import com.ruoyi.system.mapper.*;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.weChat.service.WeChatService;
@@ -37,9 +38,6 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanValidators;
 import com.ruoyi.common.utils.spring.SpringUtils;
-import com.ruoyi.system.domain.SysPost;
-import com.ruoyi.system.domain.SysUserPost;
-import com.ruoyi.system.domain.SysUserRole;
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysUserService;
 
@@ -82,6 +80,8 @@ public class SysUserServiceImpl implements ISysUserService
     private ProjectStaffRecordMapper projectStaffRecordMapper;
     @Autowired
     private ProjectTaskMapper projectTaskMapper;
+    @Autowired
+    private UserRecordMapper userRecordMapper;
 
 
     /**
@@ -708,10 +708,8 @@ public class SysUserServiceImpl implements ISysUserService
         else return deptId;
     }
     @Override
-    public  List<UserClockDtails> pushUserClock(List<Map<Integer, String>> maps) {
+    public  void pushUserClock(List<Map<Integer, String>> maps) {
         List<UserClockDtails> list=new ArrayList<>();
-        List<String> names=new ArrayList<>();
-        List<String> uids=new ArrayList<>();
         int month =0;
         int year =0;
         int days=0;
@@ -728,7 +726,6 @@ public class SysUserServiceImpl implements ISysUserService
                     int i2 = head.indexOf("至");
                      startClockTime = head.substring(i1, i2).trim();
                      endClockTime = head.substring(i2+1).trim();
-                    System.out.println(startClockTime+"~"+endClockTime);
                     LocalDate date = LocalDate.parse(startClockTime, DateTimeFormatter.ISO_DATE);
                     month=date.getMonthValue();
                     year = date.getYear();
@@ -778,10 +775,6 @@ public class SysUserServiceImpl implements ISysUserService
                               }else {
                                   newUserlock.setDuration(0.0);
                               }
-                            if (!names.contains(newUserlock.getName())){
-                                names.add(newUserlock.getName());
-                                uids.add(newUserlock.getUserId());
-                            }
                             list.add(newUserlock);
                           }
                         }
@@ -790,22 +783,44 @@ public class SysUserServiceImpl implements ISysUserService
                 }
             }
         }
-            //处理数据库
-//        List<String> errorNames = new ArrayList<>();
-//        List<Long> userList=new ArrayList<>();
-//        for (int i = 0; i < names.size(); i++) {
-//            SysUser sysUser = userMapper.selectDDUserId(uids.get(i));
-//            if (sysUser==null){
-//                errorNames.add(names.get(i));
-//            }else {
-//                userList.add(sysUser.getUserId());
-//            }
-//        }
-//        if (!errorNames.isEmpty())throw new ServiceException(String.format("用户%s不能匹配到账号",errorNames.toString()));
-//        for (Long uid : userList) {
-//            projectStaffRecordMapper.selectByAidAndTime(uid,startClockTime,endClockTime);
-//        }
-        return list;
+        List<UserRecordOut> userRecordList = new ArrayList<>();
+        for (UserClockDtails e:list){
+            Long ddUserId = Long.valueOf(e.getUserId());
+            List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByDDUidAndTime(ddUserId, e.getClockTime());
+            if (!projectStaffRecords.isEmpty()){
+                UserRecordOut ur=new UserRecordOut();
+                ur.setName(e.getName());
+                ur.setCheckDuration(e.getDuration());
+                ur.setSumDuration(e.getDuration());
+                ur.setContent(e.getClockDate());
+                ur.setStartTime(Date.from(e.getStartTime().atZone(ZoneId.systemDefault()).toInstant()));
+                if (e.getEndTime() != null){
+                    ur.setEndTime(Date.from(e.getEndTime().atZone(ZoneId.systemDefault()).toInstant()));
+                    ur.setStatus(0);
+                }else {
+                    ur.setStatus(1);
+                }
+                ur.setRecordTime(Date.from(e.getClockTime().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
+                if (projectStaffRecords.size()==1){
+                    ur.setStatus(0);
+                    ur.setPsrId(projectStaffRecords.get(0).getId());
+                }else if (projectStaffRecords.size()>1){
+                    if (ur.getStatus()==1){
+                        ur.setStatus(3);
+                    }else{
+                        ur.setStatus(2);
+                    }
+                    ur.setList(projectStaffRecords);
+                }
+                ur.setCreateId(SecurityUtils.getUserId());
+                userRecordList.add(ur);
+            }
+        }
+        if (!userRecordList.isEmpty()){
+            for (UserRecordOut userRecordOut : userRecordList) {
+                userRecordMapper.insertSelective(userRecordOut);
+            }
+        }
     }
 
     private String  getTime(String s) {

+ 40 - 15
ruoyi-system/src/main/resources/mapper/UserRecordMapper.xml

@@ -7,18 +7,22 @@
     <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.UserRecord">
             <id property="id" column="id" jdbcType="BIGINT"/>
             <result property="psrId" column="psr_id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
             <result property="status" column="status" jdbcType="INTEGER"/>
             <result property="content" column="content" jdbcType="VARCHAR"/>
             <result property="recordTime" column="record_time" jdbcType="TIMESTAMP"/>
             <result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
             <result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
-            <result property="duration" column="duration" jdbcType="DOUBLE"/>
+            <result property="sumDuration" column="sum_duration" jdbcType="DOUBLE"/>
+            <result property="checkDuration" column="check_duration" jdbcType="DOUBLE"/>
+            <result property="createId" column="create_id" jdbcType="BIGINT"/>
     </resultMap>
 
     <sql id="Base_Column_List">
-        id,psr_id,status,
-        content,record_time,start_time,
-        end_time,duration
+        id,psr_id,name,
+        status,content,record_time,
+        start_time,end_time,sum_duration,
+        check_duration,create_id
     </sql>
 
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
@@ -34,42 +38,54 @@
     </delete>
     <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.system.domain.UserRecord" useGeneratedKeys="true">
         insert into user_record
-        ( id,psr_id,status
-        ,content,record_time,start_time
-        ,end_time,duration)
-        values (#{id,jdbcType=BIGINT},#{psrId,jdbcType=BIGINT},#{status,jdbcType=INTEGER}
-        ,#{content,jdbcType=VARCHAR},#{recordTime,jdbcType=TIMESTAMP},#{startTime,jdbcType=TIMESTAMP}
-        ,#{endTime,jdbcType=TIMESTAMP},#{duration,jdbcType=DOUBLE})
+        ( id,psr_id,name
+        ,status,content,record_time
+        ,start_time,end_time,sum_duration
+        ,check_duration,create_id)
+        values (#{id,jdbcType=BIGINT},#{psrId,jdbcType=BIGINT},#{name,jdbcType=VARCHAR}
+        ,#{status,jdbcType=INTEGER},#{content,jdbcType=VARCHAR},#{recordTime,jdbcType=TIMESTAMP}
+        ,#{startTime,jdbcType=TIMESTAMP},#{endTime,jdbcType=TIMESTAMP},#{sumDuration,jdbcType=DOUBLE}
+        ,#{checkDuration,jdbcType=DOUBLE},#{createId,jdbcType=BIGINT})
     </insert>
     <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.system.domain.UserRecord" useGeneratedKeys="true">
         insert into user_record
         <trim prefix="(" suffix=")" suffixOverrides=",">
                 <if test="id != null">id,</if>
                 <if test="psrId != null">psr_id,</if>
+                <if test="name != null">name,</if>
                 <if test="status != null">status,</if>
                 <if test="content != null">content,</if>
                 <if test="recordTime != null">record_time,</if>
                 <if test="startTime != null">start_time,</if>
                 <if test="endTime != null">end_time,</if>
-                <if test="duration != null">duration,</if>
+                <if test="sumDuration != null">sum_duration,</if>
+                <if test="checkDuration != null">check_duration,</if>
+                <if test="createId != null">create_id,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
                 <if test="id != null">#{id,jdbcType=BIGINT},</if>
                 <if test="psrId != null">#{psrId,jdbcType=BIGINT},</if>
+                <if test="name != null">#{name,jdbcType=VARCHAR},</if>
                 <if test="status != null">#{status,jdbcType=INTEGER},</if>
                 <if test="content != null">#{content,jdbcType=VARCHAR},</if>
                 <if test="recordTime != null">#{recordTime,jdbcType=TIMESTAMP},</if>
                 <if test="startTime != null">#{startTime,jdbcType=TIMESTAMP},</if>
                 <if test="endTime != null">#{endTime,jdbcType=TIMESTAMP},</if>
-                <if test="duration != null">#{duration,jdbcType=DOUBLE},</if>
+                <if test="sumDuration != null">#{sumDuration,jdbcType=DOUBLE},</if>
+                <if test="checkDuration != null">#{checkDuration,jdbcType=DOUBLE},</if>
+                <if test="createId != null">#{createId,jdbcType=BIGINT},</if>
         </trim>
     </insert>
+
     <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.system.domain.UserRecord">
         update user_record
         <set>
                 <if test="psrId != null">
                     psr_id = #{psrId,jdbcType=BIGINT},
                 </if>
+                <if test="name != null">
+                    name = #{name,jdbcType=VARCHAR},
+                </if>
                 <if test="status != null">
                     status = #{status,jdbcType=INTEGER},
                 </if>
@@ -85,8 +101,14 @@
                 <if test="endTime != null">
                     end_time = #{endTime,jdbcType=TIMESTAMP},
                 </if>
-                <if test="duration != null">
-                    duration = #{duration,jdbcType=DOUBLE},
+                <if test="sumDuration != null">
+                    sum_duration = #{sumDuration,jdbcType=DOUBLE},
+                </if>
+                <if test="checkDuration != null">
+                    check_duration = #{checkDuration,jdbcType=DOUBLE},
+                </if>
+                <if test="createId != null">
+                    create_id = #{createId,jdbcType=BIGINT},
                 </if>
         </set>
         where   id = #{id,jdbcType=BIGINT} 
@@ -95,12 +117,15 @@
         update user_record
         set 
             psr_id =  #{psrId,jdbcType=BIGINT},
+            name =  #{name,jdbcType=VARCHAR},
             status =  #{status,jdbcType=INTEGER},
             content =  #{content,jdbcType=VARCHAR},
             record_time =  #{recordTime,jdbcType=TIMESTAMP},
             start_time =  #{startTime,jdbcType=TIMESTAMP},
             end_time =  #{endTime,jdbcType=TIMESTAMP},
-            duration =  #{duration,jdbcType=DOUBLE}
+            sum_duration =  #{sumDuration,jdbcType=DOUBLE},
+            check_duration =  #{checkDuration,jdbcType=DOUBLE},
+            create_id =  #{createId,jdbcType=BIGINT}
         where   id = #{id,jdbcType=BIGINT} 
     </update>
 </mapper>

+ 12 - 1
ruoyi-system/src/main/resources/mapper/project/ProjectStaffRecordMapper.xml

@@ -281,12 +281,14 @@
     select
     <include refid="Base_Column_List" />
     from project_staff_record
-    where 1=1 and aid = #{uid}
+    where  aid = #{uid}
     and record_time between #{startTime} and #{endTime}
 
 
   </select>
 
+
+
   <update id="updateNameByAid" parameterType="com.ruoyi.common.core.domain.entity.SysUser">
     update project_staff_record
     set name= #{nickName}
@@ -304,5 +306,14 @@
     set x.duration=y.duration
     where x.user_id =y.aid
   </update>
+  <select id="selectByDDUidAndTime" resultType="com.ruoyi.project.domain.ProjectStaffRecord">
+    select
+    b.id,b.duration,b.aid,b.pid,
+    date_format(b.record_time,'%Y-%m-%d')recordTime
+    from sys_user a left join  project_staff_record b on a.user_id=b.aid
+    where a.dd_user_id= #{ddUserId}
+    and b.record_time = #{clockDate}
+  </select>
+
 
 </mapper>