LiGuang 3 سال پیش
والد
کامیت
22009224b1

+ 7 - 0
jeecg-boot-module-demo/src/main/java/org/jeecg/modules/geke/userShift/mapper/UserShiftMapper.java

@@ -33,6 +33,13 @@ public interface UserShiftMapper extends BaseMapper<UserShift> {
      */
     List<Map<String,Object>> getOneUserShift(@Param("userid")String userid, @Param("date")String date,@Param("shiftid")String shiftid);
 
+
+    /**
+     * 根据用户id和时间查询用户当月是否排班
+     * @param userid
+     * @return
+     */
+    List<Map<String,Object>> getMothsUserShift(@Param("userid")String userid, @Param("date")String date);
     /**
      * 根据用户id和时间查询用户当月排班次数
      * @param userid

+ 12 - 0
jeecg-boot-module-demo/src/main/java/org/jeecg/modules/geke/userShift/mapper/xml/UserShiftMapper.xml

@@ -201,4 +201,16 @@ order by a.shift_date desc
             </foreach>
         </if>
     </select>
+    <select id="getMothsUserShift" resultType="java.util.Map">
+        select a.shift_id as 'id', a.user_id as 'userid',b.shift_type as 'type', ifnull(b.name,'休息') as 'name',date_format(b.start_date,'%H:%i:%s') as 'startDate',date_format(b.end_date,'%H:%i:%s') as 'endDate',date_format(b.start2_date,'%H:%i:%s') as 'start2Date',date_format(b.end2_date,'%H:%i:%s') as 'end2Date',DAYOFMONTH(a.shift_date) as 'shiftDate'
+        from geke_user_shift a left join geke_shift b on a.shift_id=b.id
+        where 1=1
+        <if test="userid!=null and ''!=userid">
+            and   a.user_id=#{userid}
+        </if>
+        <if test="date!=null and ''!=date">
+            and  date_format(a.shift_date,'%Y-%m')=date_format(#{date},'%Y-%m')
+        </if>
+        order by date_format(b.start_date,'%H:%i:%s') asc
+    </select>
 </mapper>

+ 26 - 16
jeecg-boot-module-demo/src/main/java/org/jeecg/modules/geke/userShift/service/impl/UserShiftServiceImpl.java

@@ -156,22 +156,19 @@ public class UserShiftServiceImpl extends ServiceImpl<UserShiftMapper, UserShift
         int month = calendar.get(calendar.MONTH) + 1;//月份
         int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);//获取前端传过来的时间获取月份的总天数
         if (type.equals("2")) {
-            for (int i = 1; i <= actualMaximum; i++) {
                 for (Map user : users.getRecords()) {
                     if (!user.get("type").equals("1") && !user.get("type").equals("3")) {
-                        String shiftname = "";
-                        List<Map<String, Object>> id = userShiftMapper.getOneUserShift(user.get("id").toString(), year + "-" + month + "-" + i, "");
-                        if (id.size() > 0&&id!=null) {
-                            if (id.get(0).get("id").equals("0") || id.get(0).get("id") == "0") {
-                                shiftname = "休息";
-                            } else {
-                                if (oConvertUtils.isNotEmpty(id.get(0).get("name"))){
-                                    shiftname = id.get(0).get("name").toString();
-                                }
-                            }
-                        }
-                        user.put("a" + i, shiftname);
+                        List<Map<String, Object>> id = userShiftMapper.getMothsUserShift(user.get("id").toString(), date);
+                        for (int i = 1; i <= actualMaximum; i++) {
+                            user.put("a" + i, null);
+                            user.put("shiftid"+i,null);
                    }
+                   if (oConvertUtils.isNotEmpty(id)){
+                            id.forEach(i->{
+                                user.put("a"+i.get("shiftDate"),i.get("name"));
+                                user.put("shiftid"+i.get("shiftDate"),i.get("id"));
+                       });
+                  }
                 }
             }
         }else if (type.equals("4")){
@@ -215,12 +212,25 @@ public class UserShiftServiceImpl extends ServiceImpl<UserShiftMapper, UserShift
             }
         }else {
             if (userByids!=null){
-                for (int i = 1; i <= actualMaximum; i++) {
+                userByids.forEach(st->{
+                    for (int i = 1; i <= actualMaximum; i++) {
+                        st.put("a" + i, null);
+                        st.put("shiftid"+i,null);
+                    }
+                    List<Map<String, Object>> id = userShiftMapper.getMothsUserShift(st.get("id").toString(), date);
+                    if (oConvertUtils.isNotEmpty(id)){
+                        id.forEach(i->{
+                            st.put("a"+i.get("shiftDate"),i.get("name"));
+                            st.put("shiftid"+i.get("shiftDate"),i.get("id"));
+                        });
+                    }
+                });
+                /*for (int i = 1; i <= actualMaximum; i++) {
                     int ts=i;
                     userByids.forEach(st->{
                         String shiftname = "";
                         String sid = "";
-                        List<Map<String, Object>> id = userShiftMapper.getOneUserShift(st.get("id").toString(), year + "-" + month + "-" + ts, "");
+                        List<Map<String, Object>> id = userShiftMapper.getMothsUserShift(st.get("id").toString(), year + "-" + month);
                         if (id.size() > 0) {
                             if (id.get(0).get("id").equals("0") || id.get(0).get("id") == "0") {
                                 shiftname = "休息";
@@ -233,7 +243,7 @@ public class UserShiftServiceImpl extends ServiceImpl<UserShiftMapper, UserShift
                         st.put("a" + ts, shiftname);
                         st.put("shiftid"+ts,sid);
                     });
-                }
+                }*/
             }
         }