You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.esms.utils;
import com.esms.dao.MonthlyAttendanceMapper;
import com.esms.dao.SalaryMapper;
import com.esms.po.MonthlyAttendance;
import com.esms.po.Salary;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class JXLUtilsTest {
@Autowired
private SalaryMapper salaryMapper;
@Autowired
private MonthlyAttendanceMapper monthlyAttendanceMapper;
@Before
public void before() {
}
@Test
public void readMonthlyAttendanceTest() throws Exception{
File file = new File("D://ESMSexcel/Monthly_attendance_table/考勤表_2018-7.xls");
List<MonthlyAttendance> monthlyAttendanceList = JXLUtils.readMonthlyAttendanceTable(file);
for (MonthlyAttendance monthlyAttendance:monthlyAttendanceList){
monthlyAttendanceMapper.insert(monthlyAttendance);
}
}
@Test
public void readRessiueTest(){
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
File file = new File("D://ESMSexcel/monthly_reissue_table/补发金额表_2018-7.xls");
List<Salary> salaryList = JXLUtils.readReissueTable(file);
for(Salary salary:salaryList){
Salary temp = salaryMapper.selectByEidAndTime(salary.getEmployee().geteId(),dateFormat.format(salary.getsTime()));
//如果数据库表salay不存在此记录直接插入
if(temp == null ){
salaryMapper.insertSelective(salary);
}else {
//如果数据库表salay已存在此记录修改补发金额数据
salary.setsId(temp.getsId());
salaryMapper.updateByPrimaryKeySelective(salary);
}
}
}
}