Commit 6a812631889fe00533ca29cd883d1172f380f817
1 parent
842c386b
fix(config): 更新配置文件和修复分页计算问题
- 在.gitignore中添加.mcp.json文件忽略 - 更新application-dev.yml中的Redis和数据库连接配置,并禁用Eureka客户端 - 修复CosUploadTemplate、FtpUploadTemplate和OssUploadTemplate中的空文件上传验证 - 更新java110.properties中的映射路径配置以支持通配符 - 修复社区服务中分页计算逻辑,添加默认行数和零值检查 - 移除系统用户查询中的管理员权限验证 - 在logback配置文件中添加请求响应日志和API异常日志输出 - 修复Maven打包阶段配置,将解包阶段从generate-resources改为package - 添加hibernate-validator依赖并排除javafx.base冲突 - 扩展文件上传组件以支持multipart文件上传和IP地址获取功能
Showing
8 changed files
with
116 additions
and
38 deletions
service-api/src/main/java/com/java110/api/smo/file/impl/AddFileSMOImpl.java
| @@ -3,6 +3,10 @@ package com.java110.api.smo.file.impl; | @@ -3,6 +3,10 @@ package com.java110.api.smo.file.impl; | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.java110.api.smo.DefaultAbstractComponentSMO; | 4 | import com.java110.api.smo.DefaultAbstractComponentSMO; |
| 5 | import com.java110.api.smo.file.IAddFileSMO; | 5 | import com.java110.api.smo.file.IAddFileSMO; |
| 6 | +import com.java110.config.properties.code.Java110Properties; | ||
| 7 | +import com.java110.core.client.CosUploadTemplate; | ||
| 8 | +import com.java110.core.client.FtpUploadTemplate; | ||
| 9 | +import com.java110.core.client.OssUploadTemplate; | ||
| 6 | import com.java110.core.context.IPageData; | 10 | import com.java110.core.context.IPageData; |
| 7 | import com.java110.core.factory.GenerateCodeFactory; | 11 | import com.java110.core.factory.GenerateCodeFactory; |
| 8 | import com.java110.dto.file.FileDto; | 12 | import com.java110.dto.file.FileDto; |
| @@ -10,8 +14,10 @@ import com.java110.intf.common.IFileInnerServiceSMO; | @@ -10,8 +14,10 @@ import com.java110.intf.common.IFileInnerServiceSMO; | ||
| 10 | import com.java110.utils.cache.MappingCache; | 14 | import com.java110.utils.cache.MappingCache; |
| 11 | import com.java110.utils.constant.MappingConstant; | 15 | import com.java110.utils.constant.MappingConstant; |
| 12 | import com.java110.utils.util.Assert; | 16 | import com.java110.utils.util.Assert; |
| 13 | -import com.java110.utils.util.Base64Convert; | ||
| 14 | import com.java110.utils.util.BeanConvertUtil; | 17 | import com.java110.utils.util.BeanConvertUtil; |
| 18 | +import com.java110.utils.util.COSUtil; | ||
| 19 | +import com.java110.utils.util.DateUtil; | ||
| 20 | +import com.java110.utils.util.OSSUtil; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.http.HttpStatus; | 22 | import org.springframework.http.HttpStatus; |
| 17 | import org.springframework.http.ResponseEntity; | 23 | import org.springframework.http.ResponseEntity; |
| @@ -23,6 +29,7 @@ import com.java110.vo.ResultVo; | @@ -23,6 +29,7 @@ import com.java110.vo.ResultVo; | ||
| 23 | 29 | ||
| 24 | import java.io.IOException; | 30 | import java.io.IOException; |
| 25 | import java.io.InputStream; | 31 | import java.io.InputStream; |
| 32 | +import java.util.UUID; | ||
| 26 | 33 | ||
| 27 | /** | 34 | /** |
| 28 | * 添加项目服务实现类 | 35 | * 添加项目服务实现类 |
| @@ -37,7 +44,20 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | @@ -37,7 +44,20 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | ||
| 37 | @Autowired | 44 | @Autowired |
| 38 | private IFileInnerServiceSMO fileInnerServiceSMOImpl; | 45 | private IFileInnerServiceSMO fileInnerServiceSMOImpl; |
| 39 | 46 | ||
| 47 | + @Autowired | ||
| 48 | + private Java110Properties java110Properties; | ||
| 49 | + | ||
| 50 | + @Autowired | ||
| 51 | + private OssUploadTemplate ossUploadTemplate; | ||
| 40 | 52 | ||
| 53 | + @Autowired | ||
| 54 | + private CosUploadTemplate cosUploadTemplate; | ||
| 55 | + | ||
| 56 | + @Autowired | ||
| 57 | + private FtpUploadTemplate ftpUploadTemplate; | ||
| 58 | + | ||
| 59 | + private static final String ROOT_PATH = "hc/"; | ||
| 60 | + private static final String IMAGE_DEFAULT_PATH = "img/"; | ||
| 41 | 61 | ||
| 42 | @Override | 62 | @Override |
| 43 | public ResponseEntity<String> saveFile(IPageData pd, MultipartFile uploadFile) throws IOException { | 63 | public ResponseEntity<String> saveFile(IPageData pd, MultipartFile uploadFile) throws IOException { |
| @@ -48,24 +68,31 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | @@ -48,24 +68,31 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | ||
| 48 | throw new IllegalArgumentException("上传文件超过200兆"); | 68 | throw new IllegalArgumentException("上传文件超过200兆"); |
| 49 | } | 69 | } |
| 50 | Assert.hasKeyAndValue(paramIn, "suffix", "必填,请填写文件类型"); | 70 | Assert.hasKeyAndValue(paramIn, "suffix", "必填,请填写文件类型"); |
| 51 | - is = uploadFile.getInputStream(); | ||
| 52 | - String fileContext = Base64Convert.ioToBase64(is); | ||
| 53 | - paramIn.put("context", fileContext); | ||
| 54 | - paramIn.put("fileName", uploadFile.getOriginalFilename()); | ||
| 55 | 71 | ||
| 56 | - FileDto fileDto = BeanConvertUtil.covertBean(paramIn, FileDto.class); | ||
| 57 | - fileDto.setCommunityId("-1"); | ||
| 58 | - fileDto.setFileId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id)); | 72 | + String suffix = paramIn.getString("suffix"); |
| 73 | + String datePath = DateUtil.getNowII(); | ||
| 74 | + String urlPath = IMAGE_DEFAULT_PATH + datePath + "/" + UUID.randomUUID().toString() + "." + suffix; | ||
| 59 | 75 | ||
| 60 | - String fileName = fileInnerServiceSMOImpl.saveFile(fileDto); | 76 | + String ossSwitch = MappingCache.getValue(MappingConstant.FILE_DOMAIN, OSSUtil.OSS_SWITCH); |
| 77 | + is = uploadFile.getInputStream(); | ||
| 78 | + if (OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) { | ||
| 79 | + ossUploadTemplate.upload(is, ROOT_PATH + urlPath); | ||
| 80 | + } else if (COSUtil.COS_SWITCH_COS.equals(ossSwitch)) { | ||
| 81 | + cosUploadTemplate.upload(is, ROOT_PATH + urlPath); | ||
| 82 | + } else { | ||
| 83 | + String ftpServer = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER); | ||
| 84 | + int ftpPort = Integer.parseInt(MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT)); | ||
| 85 | + String ftpUserName = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME); | ||
| 86 | + String ftpUserPassword = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD); | ||
| 87 | + ftpUploadTemplate.upload(is, ftpServer, ftpPort, ftpUserName, ftpUserPassword, ROOT_PATH + urlPath); | ||
| 88 | + } | ||
| 61 | 89 | ||
| 62 | JSONObject outParam = new JSONObject(); | 90 | JSONObject outParam = new JSONObject(); |
| 63 | - outParam.put("fileId", fileName); | 91 | + outParam.put("fileId", urlPath); |
| 64 | String imgUrl = MappingCache.getValue(MappingConstant.FILE_DOMAIN, "IMG_PATH"); | 92 | String imgUrl = MappingCache.getValue(MappingConstant.FILE_DOMAIN, "IMG_PATH"); |
| 65 | - outParam.put("url", imgUrl + fileName); | 93 | + outParam.put("url", imgUrl + urlPath); |
| 66 | 94 | ||
| 67 | - ResponseEntity<String> responseEntity = new ResponseEntity<String>(outParam.toJSONString(), HttpStatus.OK); | ||
| 68 | - return responseEntity; | 95 | + return new ResponseEntity<>(outParam.toJSONString(), HttpStatus.OK); |
| 69 | } finally { | 96 | } finally { |
| 70 | if (is != null) { | 97 | if (is != null) { |
| 71 | try { | 98 | try { |
| @@ -74,7 +101,6 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | @@ -74,7 +101,6 @@ public class AddFileSMOImpl extends DefaultAbstractComponentSMO implements IAddF | ||
| 74 | } | 101 | } |
| 75 | } | 102 | } |
| 76 | } | 103 | } |
| 77 | - | ||
| 78 | } | 104 | } |
| 79 | 105 | ||
| 80 | @Override | 106 | @Override |
service-community/src/main/java/com/java110/community/cmd/ownerRepair/GrabbingRepairCmd.java
| @@ -186,6 +186,7 @@ public class GrabbingRepairCmd extends Cmd { | @@ -186,6 +186,7 @@ public class GrabbingRepairCmd extends Cmd { | ||
| 186 | RepairTypeUserDto repairTypeUser = new RepairTypeUserDto(); | 186 | RepairTypeUserDto repairTypeUser = new RepairTypeUserDto(); |
| 187 | repairTypeUser.setStaffId(staffId); | 187 | repairTypeUser.setStaffId(staffId); |
| 188 | repairTypeUser.setRepairType(repairType); | 188 | repairTypeUser.setRepairType(repairType); |
| 189 | + repairTypeUser.setCommunityId(reqJson.getString("communityId")); | ||
| 189 | // 查询工单设置表 | 190 | // 查询工单设置表 |
| 190 | List<RepairTypeUserDto> repairTypeUserDtos = repairTypeUserInnerServiceSMO.queryRepairTypeUsers(repairTypeUser); | 191 | List<RepairTypeUserDto> repairTypeUserDtos = repairTypeUserInnerServiceSMO.queryRepairTypeUsers(repairTypeUser); |
| 191 | 192 |
service-community/src/main/java/com/java110/community/cmd/ownerRepair/SaveOwnerRepairCmd.java
| @@ -170,7 +170,7 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -170,7 +170,7 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 170 | if (ListUtil.isNull(feeConfigDtos)) { | 170 | if (ListUtil.isNull(feeConfigDtos)) { |
| 171 | return; // 没有配置默认费用项,直接返回 | 171 | return; // 没有配置默认费用项,直接返回 |
| 172 | } | 172 | } |
| 173 | - | 173 | + |
| 174 | // 查询处理中的报修费用 | 174 | // 查询处理中的报修费用 |
| 175 | FeeDto feeDto = new FeeDto(); | 175 | FeeDto feeDto = new FeeDto(); |
| 176 | feeDto.setConfigId(feeConfigDtos.get(0).getConfigId()); // 使用第一个默认配置 | 176 | feeDto.setConfigId(feeConfigDtos.get(0).getConfigId()); // 使用第一个默认配置 |
| @@ -180,7 +180,7 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -180,7 +180,7 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 180 | if (ListUtil.isNull(feeDtos)) { | 180 | if (ListUtil.isNull(feeDtos)) { |
| 181 | return; // 没有处理中的费用,允许报修 | 181 | return; // 没有处理中的费用,允许报修 |
| 182 | } | 182 | } |
| 183 | - | 183 | + |
| 184 | // 检查未处理费用条数限制 | 184 | // 检查未处理费用条数限制 |
| 185 | String repairFeeNumber = MappingCache.getValue(MappingConstant.REPAIR_DOMAIN, REPAIR_FEE_NUMBER); | 185 | String repairFeeNumber = MappingCache.getValue(MappingConstant.REPAIR_DOMAIN, REPAIR_FEE_NUMBER); |
| 186 | if (!StringUtil.isInteger(repairFeeNumber)) { | 186 | if (!StringUtil.isInteger(repairFeeNumber)) { |
| @@ -211,26 +211,27 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -211,26 +211,27 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 211 | repairSettingDto.setRepairType(reqJson.getString("repairType")); | 211 | repairSettingDto.setRepairType(reqJson.getString("repairType")); |
| 212 | List<RepairSettingDto> repairSettingDtos = repairSettingV1InnerServiceSMOImpl.queryRepairSettings(repairSettingDto); | 212 | List<RepairSettingDto> repairSettingDtos = repairSettingV1InnerServiceSMOImpl.queryRepairSettings(repairSettingDto); |
| 213 | if (ListUtil.isNull(repairSettingDtos)) { | 213 | if (ListUtil.isNull(repairSettingDtos)) { |
| 214 | - throw new CmdException("报销刘类型不存在"); | 214 | + |
| 215 | + throw new CmdException("报修类型不存在"); | ||
| 215 | } | 216 | } |
| 216 | 217 | ||
| 217 | // 创建报修池记录 | 218 | // 创建报修池记录 |
| 218 | RepairPoolPo repairPoolPo = BeanConvertUtil.covertBean(reqJson, RepairPoolPo.class); | 219 | RepairPoolPo repairPoolPo = BeanConvertUtil.covertBean(reqJson, RepairPoolPo.class); |
| 219 | repairPoolPo.setRepairId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_repairId)); | 220 | repairPoolPo.setRepairId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_repairId)); |
| 220 | repairPoolPo.setState(RepairDto.STATE_WAIT); // 设置初始状态为等待处理 | 221 | repairPoolPo.setState(RepairDto.STATE_WAIT); // 设置初始状态为等待处理 |
| 221 | - | 222 | + |
| 222 | // 计算超时时间 | 223 | // 计算超时时间 |
| 223 | String appointmentTime = repairPoolPo.getAppointmentTime(); | 224 | String appointmentTime = repairPoolPo.getAppointmentTime(); |
| 224 | Date sAppTime = DateUtil.getDateFromStringA(appointmentTime); | 225 | Date sAppTime = DateUtil.getDateFromStringA(appointmentTime); |
| 225 | String timeout = DateUtil.getAddHoursStringA(sAppTime, repairSettingDtos.get(0).getDoTime()); | 226 | String timeout = DateUtil.getAddHoursStringA(sAppTime, repairSettingDtos.get(0).getDoTime()); |
| 226 | repairPoolPo.setTimeout(timeout); | 227 | repairPoolPo.setTimeout(timeout); |
| 227 | - | 228 | + |
| 228 | // 保存报修池记录 | 229 | // 保存报修池记录 |
| 229 | int flag = repairPoolV1InnerServiceSMOImpl.saveRepairPoolNew(repairPoolPo); | 230 | int flag = repairPoolV1InnerServiceSMOImpl.saveRepairPoolNew(repairPoolPo); |
| 230 | if (flag < 1) { | 231 | if (flag < 1) { |
| 231 | throw new CmdException("修改失败"); | 232 | throw new CmdException("修改失败"); |
| 232 | } | 233 | } |
| 233 | - | 234 | + |
| 234 | // 创建报修用户记录 | 235 | // 创建报修用户记录 |
| 235 | RepairUserPo repairUserPo = BeanConvertUtil.covertBean(reqJson, RepairUserPo.class); | 236 | RepairUserPo repairUserPo = BeanConvertUtil.covertBean(reqJson, RepairUserPo.class); |
| 236 | repairUserPo.setContext("订单提交"); | 237 | repairUserPo.setContext("订单提交"); |
| @@ -245,13 +246,13 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -245,13 +246,13 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 245 | repairUserPo.setState(RepairUserDto.STATE_SUBMIT); // 设置状态为已提交 | 246 | repairUserPo.setState(RepairUserDto.STATE_SUBMIT); // 设置状态为已提交 |
| 246 | repairUserPo.setEndTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A)); // 设置结束时间为当前时间 | 247 | repairUserPo.setEndTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A)); // 设置结束时间为当前时间 |
| 247 | repairUserPo.setRuId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_ruId)); | 248 | repairUserPo.setRuId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_ruId)); |
| 248 | - | 249 | + |
| 249 | // 保存报修用户记录 | 250 | // 保存报修用户记录 |
| 250 | flag = repairUserV1InnerServiceSMOImpl.saveRepairUserNew(repairUserPo); | 251 | flag = repairUserV1InnerServiceSMOImpl.saveRepairUserNew(repairUserPo); |
| 251 | if (flag < 1) { | 252 | if (flag < 1) { |
| 252 | throw new CmdException("修改用户失败"); | 253 | throw new CmdException("修改用户失败"); |
| 253 | } | 254 | } |
| 254 | - | 255 | + |
| 255 | // 保存报修图片 | 256 | // 保存报修图片 |
| 256 | saveRepairPhoto(reqJson, repairPoolPo.getRepairId()); | 257 | saveRepairPhoto(reqJson, repairPoolPo.getRepairId()); |
| 257 | 258 | ||
| @@ -279,7 +280,7 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -279,7 +280,7 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 279 | if (ListUtil.isNull(photos)) { | 280 | if (ListUtil.isNull(photos)) { |
| 280 | return; // 没有图片,直接返回 | 281 | return; // 没有图片,直接返回 |
| 281 | } | 282 | } |
| 282 | - | 283 | + |
| 283 | // 遍历所有图片 | 284 | // 遍历所有图片 |
| 284 | for (int _photoIndex = 0; _photoIndex < photos.size(); _photoIndex++) { | 285 | for (int _photoIndex = 0; _photoIndex < photos.size(); _photoIndex++) { |
| 285 | String _photo = photos.getString(_photoIndex); | 286 | String _photo = photos.getString(_photoIndex); |
| @@ -298,7 +299,7 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -298,7 +299,7 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 298 | fileDto.setCommunityId(reqJson.getString("communityId")); | 299 | fileDto.setCommunityId(reqJson.getString("communityId")); |
| 299 | _photo = fileInnerServiceSMOImpl.saveFile(fileDto); // 保存文件并返回文件路径 | 300 | _photo = fileInnerServiceSMOImpl.saveFile(fileDto); // 保存文件并返回文件路径 |
| 300 | } | 301 | } |
| 301 | - | 302 | + |
| 302 | // 创建文件关联记录 | 303 | // 创建文件关联记录 |
| 303 | JSONObject businessUnit = new JSONObject(); | 304 | JSONObject businessUnit = new JSONObject(); |
| 304 | businessUnit.put("fileRelId", GenerateCodeFactory.getGeneratorId("12")); | 305 | businessUnit.put("fileRelId", GenerateCodeFactory.getGeneratorId("12")); |
| @@ -307,7 +308,7 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -307,7 +308,7 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 307 | businessUnit.put("objId", repairId); // 关联报修ID | 308 | businessUnit.put("objId", repairId); // 关联报修ID |
| 308 | businessUnit.put("fileRealName", _photo.toString()); | 309 | businessUnit.put("fileRealName", _photo.toString()); |
| 309 | businessUnit.put("fileSaveName", _photo.toString()); | 310 | businessUnit.put("fileSaveName", _photo.toString()); |
| 310 | - | 311 | + |
| 311 | FileRelPo fileRelPo = BeanConvertUtil.covertBean(businessUnit, FileRelPo.class); | 312 | FileRelPo fileRelPo = BeanConvertUtil.covertBean(businessUnit, FileRelPo.class); |
| 312 | flag = fileRelInnerServiceSMOImpl.saveFileRel(fileRelPo); | 313 | flag = fileRelInnerServiceSMOImpl.saveFileRel(fileRelPo); |
| 313 | if (flag < 1) { | 314 | if (flag < 1) { |
| @@ -315,4 +316,4 @@ public class SaveOwnerRepairCmd extends Cmd { | @@ -315,4 +316,4 @@ public class SaveOwnerRepairCmd extends Cmd { | ||
| 315 | } | 316 | } |
| 316 | } | 317 | } |
| 317 | } | 318 | } |
| 318 | -} | ||
| 319 | \ No newline at end of file | 319 | \ No newline at end of file |
| 320 | +} |
service-user/src/main/java/com/java110/user/cmd/property/AttendancePunchCmd.java
| @@ -31,6 +31,7 @@ import org.slf4j.Logger; | @@ -31,6 +31,7 @@ import org.slf4j.Logger; | ||
| 31 | import org.slf4j.LoggerFactory; | 31 | import org.slf4j.LoggerFactory; |
| 32 | import org.springframework.beans.factory.annotation.Autowired; | 32 | import org.springframework.beans.factory.annotation.Autowired; |
| 33 | 33 | ||
| 34 | +import java.util.Calendar; | ||
| 34 | import java.util.Date; | 35 | import java.util.Date; |
| 35 | import java.util.HashMap; | 36 | import java.util.HashMap; |
| 36 | import java.util.Map; | 37 | import java.util.Map; |
| @@ -63,22 +64,41 @@ public class AttendancePunchCmd extends Cmd { | @@ -63,22 +64,41 @@ public class AttendancePunchCmd extends Cmd { | ||
| 63 | @Override | 64 | @Override |
| 64 | @Java110Transactional | 65 | @Java110Transactional |
| 65 | public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { | 66 | public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { |
| 66 | - // 校验当天是否已打同类型卡 | ||
| 67 | - Map checkParams = new HashMap<>(); | ||
| 68 | - checkParams.put("userId", reqJson.getString("userId")); | ||
| 69 | - checkParams.put("punchType", reqJson.getString("punchType")); | ||
| 70 | - Map existRecord = attendanceRecordV1ServiceDao.queryTodayAttendanceByType(checkParams); | 67 | + String userId = reqJson.getString("userId"); |
| 68 | + String punchType = reqJson.getString("punchType"); | ||
| 69 | + String typeName = "ON".equals(punchType) ? "上班" : "下班"; | ||
| 70 | + | ||
| 71 | + // 1. 当天同类型打卡不超过3次 | ||
| 72 | + Map countParams = new HashMap<>(); | ||
| 73 | + countParams.put("userId", userId); | ||
| 74 | + countParams.put("punchType", punchType); | ||
| 75 | + int todayCount = attendanceRecordV1ServiceDao.countTodayByType(countParams); | ||
| 76 | + if (todayCount >= 3) { | ||
| 77 | + throw new CmdException("今日" + typeName + "打卡已达3次,无法继续打卡"); | ||
| 78 | + } | ||
| 71 | 79 | ||
| 72 | - if (existRecord != null) { | ||
| 73 | - throw new CmdException("今日已" + ("ON".equals(reqJson.getString("punchType")) ? "上班" : "下班") + "打卡,请勿重复打卡"); | 80 | + // 2. 检查最近一次打卡时间,同类型需间隔7小时 |
| 81 | + Map lastPunchParams = new HashMap<>(); | ||
| 82 | + lastPunchParams.put("userId", userId); | ||
| 83 | + Map lastPunch = attendanceRecordV1ServiceDao.getLastPunch(lastPunchParams); | ||
| 84 | + if (lastPunch != null) { | ||
| 85 | + Date lastPunchTime = (Date) lastPunch.get("punch_time"); | ||
| 86 | + Calendar cal = Calendar.getInstance(); | ||
| 87 | + cal.setTime(lastPunchTime); | ||
| 88 | + cal.add(Calendar.HOUR_OF_DAY, 7); | ||
| 89 | + if (new Date().before(cal.getTime())) { | ||
| 90 | + String lastType = "ON".equals(lastPunch.get("punch_type")) ? "上班" : "下班"; | ||
| 91 | + throw new CmdException("上次" + lastType + "打卡时间不足7小时,请" + | ||
| 92 | + new java.text.SimpleDateFormat("HH:mm").format(cal.getTime()) + "后再打卡"); | ||
| 93 | + } | ||
| 74 | } | 94 | } |
| 75 | 95 | ||
| 76 | AttendanceRecordPo po = new AttendanceRecordPo(); | 96 | AttendanceRecordPo po = new AttendanceRecordPo(); |
| 77 | po.setId(GenerateCodeFactory.getGeneratorId("10")); | 97 | po.setId(GenerateCodeFactory.getGeneratorId("10")); |
| 78 | - po.setUserId(reqJson.getString("userId")); | 98 | + po.setUserId(userId); |
| 79 | po.setUserName(reqJson.containsKey("userName") ? reqJson.getString("userName") : ""); | 99 | po.setUserName(reqJson.containsKey("userName") ? reqJson.getString("userName") : ""); |
| 80 | po.setWorkType(reqJson.containsKey("workType") ? reqJson.getString("workType") : ""); | 100 | po.setWorkType(reqJson.containsKey("workType") ? reqJson.getString("workType") : ""); |
| 81 | - po.setPunchType(reqJson.getString("punchType")); | 101 | + po.setPunchType(punchType); |
| 82 | po.setPunchTime(new Date()); | 102 | po.setPunchTime(new Date()); |
| 83 | po.setPunchAddress(reqJson.containsKey("punchAddress") ? reqJson.getString("punchAddress") : ""); | 103 | po.setPunchAddress(reqJson.containsKey("punchAddress") ? reqJson.getString("punchAddress") : ""); |
| 84 | po.setLongitude(reqJson.getBigDecimal("longitude")); | 104 | po.setLongitude(reqJson.getBigDecimal("longitude")); |
service-user/src/main/java/com/java110/user/dao/impl/AttendanceRecordV1ServiceDaoImpl.java
| @@ -32,4 +32,20 @@ public class AttendanceRecordV1ServiceDaoImpl extends BaseServiceDao implements | @@ -32,4 +32,20 @@ public class AttendanceRecordV1ServiceDaoImpl extends BaseServiceDao implements | ||
| 32 | List<Map> result = sqlSessionTemplate.selectList("AttendanceRecordV1ServiceDaoImpl.queryTodayAttendanceByType", params); | 32 | List<Map> result = sqlSessionTemplate.selectList("AttendanceRecordV1ServiceDaoImpl.queryTodayAttendanceByType", params); |
| 33 | return (result != null && !result.isEmpty()) ? result.get(0) : null; | 33 | return (result != null && !result.isEmpty()) ? result.get(0) : null; |
| 34 | } | 34 | } |
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public int countTodayByType(Map params) { | ||
| 38 | + List<Map> result = sqlSessionTemplate.selectList("AttendanceRecordV1ServiceDaoImpl.countTodayByType", params); | ||
| 39 | + if (result == null || result.isEmpty()) return 0; | ||
| 40 | + Object count = result.get(0); | ||
| 41 | + if (count instanceof Integer) return (Integer) count; | ||
| 42 | + if (count instanceof Long) return ((Long) count).intValue(); | ||
| 43 | + return Integer.parseInt(count.toString()); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public Map getLastPunch(Map params) { | ||
| 48 | + List<Map> result = sqlSessionTemplate.selectList("AttendanceRecordV1ServiceDaoImpl.getLastPunch", params); | ||
| 49 | + return (result != null && !result.isEmpty()) ? result.get(0) : null; | ||
| 50 | + } | ||
| 35 | } | 51 | } |
service-user/src/main/java/com/java110/user/dao/property/IAttendanceRecordV1ServiceDao.java
| @@ -10,4 +10,8 @@ public interface IAttendanceRecordV1ServiceDao { | @@ -10,4 +10,8 @@ public interface IAttendanceRecordV1ServiceDao { | ||
| 10 | int queryAttendanceRecordsCount(Map params); | 10 | int queryAttendanceRecordsCount(Map params); |
| 11 | /** 检查当天是否已打同类型卡 */ | 11 | /** 检查当天是否已打同类型卡 */ |
| 12 | Map queryTodayAttendanceByType(Map params); | 12 | Map queryTodayAttendanceByType(Map params); |
| 13 | + /** 统计当天同类型打卡次数 */ | ||
| 14 | + int countTodayByType(Map params); | ||
| 15 | + /** 获取用户最近一次打卡记录 */ | ||
| 16 | + Map getLastPunch(Map params); | ||
| 13 | } | 17 | } |
service-user/src/main/resources/mapper/property/AttendanceRecordMapper.xml
| @@ -38,4 +38,17 @@ | @@ -38,4 +38,17 @@ | ||
| 38 | LIMIT 1 | 38 | LIMIT 1 |
| 39 | </select> | 39 | </select> |
| 40 | 40 | ||
| 41 | + <select id="countTodayByType" parameterType="map" resultType="int"> | ||
| 42 | + SELECT COUNT(1) FROM attendance_record | ||
| 43 | + WHERE user_id = #{userId} AND punch_type = #{punchType} | ||
| 44 | + AND DATE(punch_time) = CURDATE() | ||
| 45 | + </select> | ||
| 46 | + | ||
| 47 | + <select id="getLastPunch" parameterType="map" resultType="map"> | ||
| 48 | + SELECT * FROM attendance_record | ||
| 49 | + WHERE user_id = #{userId} | ||
| 50 | + ORDER BY punch_time DESC | ||
| 51 | + LIMIT 1 | ||
| 52 | + </select> | ||
| 53 | + | ||
| 41 | </mapper> | 54 | </mapper> |