|
@@ -18,8 +18,10 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
-import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
@@ -118,6 +120,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
@Resource
|
|
|
private UserSalaryMapper userSalaryMapper;
|
|
|
@Resource
|
|
|
+ private UserSalaryService userSalaryService;
|
|
|
+ @Resource
|
|
|
private UserVcodeMapper userVcodeMapper;
|
|
|
@Resource
|
|
|
private ProjectBasecostSettingMapper projectBasecostSettingMapper;
|
|
@@ -259,6 +263,154 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importMonthCost(MultipartFile multipartFile, String yearMonth, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ //然后处理文件
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //然后解析表格
|
|
|
+ Workbook wb = WorkbookFactory.create(new FileInputStream(file));
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ //要插入的账号列表
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ //获取月成本列表
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
+ //需要更新成本的人员数据
|
|
|
+ List<User> updateUserList = new ArrayList<>();
|
|
|
+ String startStr = yearMonth + "-01";
|
|
|
+ String endStr = yearMonth + "-31";
|
|
|
+ BigDecimal monthTotalHours = timeType.getMonthDays().multiply(new BigDecimal(timeType.getAllday()));
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //工号 姓名 薪资
|
|
|
+ Cell jobNumberCell = row.getCell(0);
|
|
|
+
|
|
|
+ if (jobNumberCell != null) {
|
|
|
+ jobNumberCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+
|
|
|
+ Cell nameCell = row.getCell(1);
|
|
|
+ Cell salaryCell = row.getCell(2);
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
+
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ if (name.equals(MessageUtils.message("entry.name")) && rowIndex == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String cellJobNumber = jobNumberCell != null ?jobNumberCell.getStringCellValue().trim().replaceAll("\\u00a0", ""):null;
|
|
|
+ Optional<User> first = null;
|
|
|
+ if (!StringUtils.isEmpty(cellJobNumber)) {
|
|
|
+ //优先按照工号匹配
|
|
|
+ first = userList.stream().filter(u ->
|
|
|
+ u.getJobNumber() != null && u.getJobNumber().equals(cellJobNumber)).findFirst();
|
|
|
+ }
|
|
|
+ if (first == null || !first.isPresent()) {
|
|
|
+ //按照姓名匹配
|
|
|
+ first = userList.stream().filter(u ->
|
|
|
+ u.getName().equals(name)).findFirst();
|
|
|
+ }
|
|
|
+ if (first != null && first.isPresent()) {
|
|
|
+ if (salaryCell != null) {
|
|
|
+ salaryCell.setCellType(CellType.STRING);
|
|
|
+ String item = salaryCell.getStringCellValue();
|
|
|
+ BigDecimal monthSalary = item != null ? new BigDecimal(item.trim().replaceAll("\\u00a0", "")) : BigDecimal.valueOf(0);
|
|
|
+ User localUser = new User();
|
|
|
+ User findUser = first.get();
|
|
|
+ localUser.setId(findUser.getId());
|
|
|
+ localUser.setMonthCost(monthSalary);
|
|
|
+ localUser.setName(findUser.getName());
|
|
|
+ localUser.setSalaryType(findUser.getSalaryType());
|
|
|
+ //计算时薪
|
|
|
+ localUser.setCost(monthSalary.divide(monthTotalHours, 6, BigDecimal.ROUND_HALF_UP));
|
|
|
+ updateUserList.add(localUser);
|
|
|
+ } else {
|
|
|
+ //薪资为空的跳过
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msg.setError(MessageUtils.message("group.userNullById",name,cellJobNumber));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (updateUserList.size() > 0) {
|
|
|
+ //有人员薪资更新
|
|
|
+ updateBatchById(updateUserList);
|
|
|
+ //记录薪资变动
|
|
|
+ List<UserSalary> salaryChangeList = new ArrayList<>();
|
|
|
+ for (User u : updateUserList) {
|
|
|
+ UserSalary salary = UserSalary.copyFromUser(u);
|
|
|
+ salary.setYmonth(yearMonth);
|
|
|
+ salaryChangeList.add(salary);
|
|
|
+ }
|
|
|
+ userSalaryService.saveBatch(salaryChangeList);
|
|
|
+ }
|
|
|
+ //更新该月份的日报相关的成本
|
|
|
+ if (!StringUtils.isEmpty(yearMonth)) {
|
|
|
+ List<Report> reportList = reportMapper.selectSimpleTime(companyId, startStr, endStr);
|
|
|
+ if (reportList.size() > 0) {
|
|
|
+ List<Report> updateReportList = new ArrayList<>();
|
|
|
+ for (Report r : reportList) {
|
|
|
+ Optional<User> first = updateUserList.stream().filter(u -> u.getId().equals(r.getCreatorId())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ BigDecimal hourCost = first.get().getCost();
|
|
|
+ r.setCost(hourCost.multiply(new BigDecimal(r.getWorkingTime())));
|
|
|
+ r.setCreatorId(null);
|
|
|
+ r.setWorkingTime(null);
|
|
|
+ updateReportList.add(r);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批量更新日报的成本
|
|
|
+ if (updateReportList.size() > 0) {
|
|
|
+ reportService.updateBatchById(updateReportList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (IOException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件处理错误");
|
|
|
+ msg.setError(MessageUtils.message("file.error"));
|
|
|
+ }catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(file.delete());
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void setUserRoleMenu(UserVO user) {
|
|
|
Integer roleId = user.getRoleId();
|