Explorar o código

食堂打卡测试用例

zhengqiang %!s(int64=4) %!d(string=hai) anos
pai
achega
a662bcf6e4

+ 62 - 0
web/src/main/java/com/jpsoft/shinestar/modules/base/controller/CanteenDiningRecordController.java

@@ -71,6 +71,9 @@ public class CanteenDiningRecordController {
     @Autowired
     private UserCompanyService userCompanyService;
 
+    @Autowired
+    private PersonDeviceLogService personDeviceLogService;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<CanteenDiningRecord> create(){
@@ -1025,4 +1028,63 @@ public class CanteenDiningRecordController {
 
         return messageResult;
     }
+    
+    @GetMapping("batchUpdate")
+    @ApiOperation(value="更新食堂就餐记录")
+    public MessageResult<Integer> batchUpdate(Long personId,String deviceNo,
+                                             @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") Date startTime,
+                                             @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") Date endTime){
+        MessageResult<Integer> messageResult = new MessageResult<>();
+        int affectCount = 0;
+
+        try {
+            Map<String,Object> searchParams = new HashMap<>();
+
+            if(personId!=null){
+                searchParams.put("personId",personId);
+            }
+
+            searchParams.put("deviceNo",deviceNo);
+            searchParams.put("beginTime", startTime);
+            searchParams.put("endTime", endTime);
+
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.create_time","asc"));
+
+            Page<PersonDeviceLog> page = personDeviceLogService.pageSearch(searchParams,1,100,true,sortList);
+            int pages = page.getPages();
+
+            for (int i=1;i<=pages;i++){
+                List<PersonDeviceLog> list;
+
+                if(i==1) {
+                    list = page.getResult();
+                }
+                else{
+                    page = personDeviceLogService.pageSearch(searchParams,i,100,true,sortList);
+                    list = page.getResult();
+                }
+
+                for (PersonDeviceLog personDeviceLog : list) {
+                    boolean result = canteenDiningRecordService.punchIn(personDeviceLog.getDeviceNo(),personDeviceLog.getPersonId(),personDeviceLog.getRecordTime());
+
+                    if (result){
+                        affectCount++;
+                    }
+                }
+            }
+
+            //todo 填写具体代码
+            messageResult.setData(affectCount);
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+    
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+    
+        return messageResult;
+    }
 }

+ 37 - 0
web/src/test/java/com/jpsoft/shinestar/CanteenDiningTest.java

@@ -0,0 +1,37 @@
+package com.jpsoft.shinestar;
+
+import com.jpsoft.shinestar.modules.base.service.CanteenDiningRecordService;
+import com.jpsoft.shinestar.modules.base.service.PersonDeviceLogService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class CanteenDiningTest {
+    @Autowired
+    private CanteenDiningRecordService canteenDiningRecordService;
+
+    @Autowired
+    private PersonDeviceLogService personDeviceLogService;
+
+    @Test
+    public void testPunchIn(){
+        try {
+            String deviceNo = "210235TN1L3212001989";
+            Long personId = 47619L;
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+            Date recordTime = sdf.parse("2021-06-01 12:05:01");
+
+            Boolean result = canteenDiningRecordService.punchIn(deviceNo, personId, recordTime);
+        }
+        catch (Exception ex){
+            ex.printStackTrace();
+        }
+    }
+}