weaver-hrm-salary/src/com/engine/salary/service/impl/AttendQuoteFieldServiceImpl...

387 lines
21 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.engine.salary.service.impl;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.core.impl.Service;
import com.engine.salary.component.SalaryWeaTable;
import com.engine.salary.entity.datacollection.dto.AttendQuoteFieldListDTO;
import com.engine.salary.entity.datacollection.param.AttendQuoteFieldQueryParam;
import com.engine.salary.service.AttendQuoteFieldService;
import java.util.Map;
/**
* 数据采集-考勤引用字段
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
public class AttendQuoteFieldServiceImpl extends Service implements AttendQuoteFieldService {
//
// @Resource
// private AttendQuoteFieldMapper mapper;
// @RpcReference
// private RemoteAttendInitVacationService remoteAttendInitVacationService;
// @Autowired
// private LoggerTemplate attendQuoteFieldLoggerTemplate;
@Override
public Map<String, Object> list(AttendQuoteFieldQueryParam queryParam) {
int uid = user.getUID();
// todo 同步字段
// syncAttendFields(employeeId, tenantKey);
String fields = " t1.id\n" +
" ,\n" +
" t1.field_name,\n" +
" t1.source_type,\n" +
" t1.field_type,\n" +
" t1.enable_status,\n" +
" t1.description";
String fromSql = " FROM" +
" hrsa_add_up_deduction t1" +
" LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id" +
" LEFT JOIN hrmresource e ON t1.employee_id = e.id" +
" LEFT JOIN hrmdepartment d ON e.departmentid = d.id";
SalaryWeaTable<AttendQuoteFieldListDTO> table = new SalaryWeaTable<AttendQuoteFieldListDTO>(user, AttendQuoteFieldListDTO.class);
table.setBackfields(fields);
table.setSqlform(fromSql);
// table.setSqlwhere(makeSqlWhere());
table.setSqlorderby("t1.id DESC");
table.setSqlprimarykey("t1.id");
table.setSqlisdistinct("false");
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
return result.getResultMap();
// Page<AttendQuoteFieldListDTO> page = new Page<>(queryParam.getCurrent(), queryParam.getPageSize(), true);
// mapper.list(page, queryParam, tenantKey);
//
// List<AttendQuoteFieldListDTO> list = page.getRecords();
// list.forEach(m->{
// Integer sourceType = Integer.valueOf(m.getSourceType());
// m.setSourceType(AttendQuoteFieldSourceTypeEnum.getDefaultLabelByValue(sourceType, employeeId, tenantKey));
// m.setSourceTypeValue(AttendQuoteFieldSourceTypeEnum.getNameByValue(sourceType));
// m.setFieldType(AttendQuoteFieldTypeEnum.getDefaultLabelByValue(Integer.valueOf(m.getFieldType()), employeeId, tenantKey));
// });
//
// WeaTable<AttendQuoteFieldListDTO> weaTable = FormatManager.<AttendQuoteFieldListDTO>getInstance()
// .genTable(AttendQuoteFieldListDTO.class, page);
//
// EditableTable<Map<String, Object>> editableTable = new EditableTable<>(weaTable);
// editableTable.setColumns(AttendQuoteFieldBO.buildRecordTableColumns(employeeId, tenantKey));
// editableTable.setComProps(AttendQuoteFieldBO.buildEditableTableItemMap());
// editableTable.setPageSize(page.getSize());
// editableTable.setModule("hrmsalary");
// return editableTable;
}
// @Override
// public WeaForm getFrom(Long id, Long employeeId, String tenantKey) {
// AttendQuoteFieldFormDTO formDTO = new AttendQuoteFieldFormDTO();
// if (id != null) {
// AttendQuoteFieldPO po = mapper.getById(id, tenantKey);
// if (po == null) {
// throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100370, "字段不存在")+"[id:%s]", id));
// }
// BeanUtils.copyProperties(po, formDTO);
// } else {
// formDTO.setEnableStatus(0);
// }
// WeaForm weaForm = FormatManager.<AttendQuoteFieldFormDTO>getInstance().genForm(AttendQuoteFieldFormDTO.class, formDTO);
// weaForm.setData(JsonUtil.parseMap(formDTO, Object.class));
// return weaForm;
// }
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public WeaResult<String> save(AttendQuoteFieldSaveParam saveParam, Long employeeId, String tenantKey) {
// WeaResult<String> checkResult = AttendQuoteFieldSaveParam.checkParam(saveParam, employeeId, tenantKey);
// if (checkResult.getCode() == WeaResultCodeEnum.ERROR.getCode()) {
// return checkResult;
// }
// List<AttendQuoteFieldPO> attendQuoteFields = new LambdaQueryChainWrapper<>(mapper)
// .eq(AttendQuoteFieldPO::getDeleteType, 0)
// .eq(AttendQuoteFieldPO::getTenantKey, tenantKey)
// .eq(AttendQuoteFieldPO::getFieldName, saveParam.getFieldName()).list();
// if (CollectionUtils.isNotEmpty(attendQuoteFields)) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100371, "字段名称不允许重复"));
// }
//
// AttendQuoteFieldPO attendQuoteField = AttendQuoteFieldPO.builder()
// .id(IdGenerator.generate())
// .fieldName(saveParam.getFieldName())
// .sourceType(AttendQuoteFieldSourceTypeEnum.DEFAULT.getValue())
// .fieldType(saveParam.getFieldType().getValue())
// .enableStatus(saveParam.getEnableStatus()?1:0)
// .description(saveParam.getDescription())
// .createTime(LocalDateTime.now())
// .updateTime(LocalDateTime.now())
// .creator(employeeId)
// .tenantKey(tenantKey)
// .build();
// // 保存
// mapper.insert(attendQuoteField);
// // 记录日志
// SalaryLoggerUtil.recordAddSingleLog(attendQuoteFieldLoggerTemplate,
// attendQuoteField.getId(),
// attendQuoteField.getFieldName(),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100374, "新增字段"),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100374, "新增字段"),
// attendQuoteField);
//
// return WeaResult.success(StringUtils.EMPTY);
// }
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public WeaResult<String> update(AttendQuoteFieldSaveParam saveParam, Long employeeId, String tenantKey) {
// WeaResult<String> checkResult = AttendQuoteFieldSaveParam.checkParam(saveParam, employeeId, tenantKey);
// if (checkResult.getCode() == WeaResultCodeEnum.ERROR.getCode()) {
// return checkResult;
// }
// // 校验是否可以编辑
// if (saveParam.getId() == null) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 84026, "参数错误"));
// }
// AttendQuoteFieldPO attendQuoteField = mapper.getById(saveParam.getId(), tenantKey);
// if (attendQuoteField == null) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100375, "该字段不存在"));
// }
// if (!attendQuoteField.getSourceType().equals(AttendQuoteFieldSourceTypeEnum.DEFAULT.getValue())) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100376, "来源只能为自定义"));
// }
// List<AttendQuoteFieldPO> attendQuoteFields = new LambdaQueryChainWrapper<>(mapper)
// .eq(AttendQuoteFieldPO::getDeleteType, 0)
// .eq(AttendQuoteFieldPO::getTenantKey, tenantKey)
// .eq(AttendQuoteFieldPO::getFieldName, saveParam.getFieldName()).list();
// boolean fieldNameExist = CollectionUtils.emptyIfNull(attendQuoteFields).stream().anyMatch(e -> !Objects.equals(e.getId(), saveParam.getId()));
// if (fieldNameExist) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100371, "字段名称不允许重复"));
// }
//
// AttendQuoteFieldPO newAttendQuoteField = new AttendQuoteFieldPO();
// BeanUtils.copyProperties(attendQuoteField, newAttendQuoteField);
// newAttendQuoteField.setFieldName(saveParam.getFieldName());
// newAttendQuoteField.setFieldType(saveParam.getFieldType().getValue());
// newAttendQuoteField.setEnableStatus(saveParam.getEnableStatus()?1:0);
// newAttendQuoteField.setDescription(saveParam.getDescription());
// newAttendQuoteField.setUpdateTime(LocalDateTime.now());
// // 更新
// mapper.updateById(newAttendQuoteField);
//
// // 记录日志
// SalaryLoggerUtil.recordUpdateSingleLog(attendQuoteFieldLoggerTemplate,
// attendQuoteField.getId(),
// newAttendQuoteField.getFieldName(),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100378, "修改字段"),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100378, "修改字段"),
// attendQuoteField,
// newAttendQuoteField);
//
// return WeaResult.success(StringUtils.EMPTY);
// }
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public WeaResult<String> delete(Collection<Long> ids, Long employeeId, String tenantKey) {
// if (CollectionUtils.isEmpty(ids)) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 84026, "参数错误"));
// }
// List<AttendQuoteFieldListDTO> attendQuoteFields = mapper.list(AttendQuoteFieldQueryParam.builder().ids(ids).build(), tenantKey);
// if (CollectionUtils.isEmpty(attendQuoteFields)) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 87637, "要删除的数据在不存在或已删除"));
// }
//
// List<AttendQuoteFieldListDTO> attendQuoteAttendFields = attendQuoteFields.stream().filter(e-> e.getSourceType().equals(String.valueOf(AttendQuoteFieldSourceTypeEnum.ATTEND.getValue()))).collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(attendQuoteAttendFields)) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 87652, "考勤模块的字段不能删除"));
// }
//
// // TODO 正在使用的记录不允许删除
// mapper.deleteByIds(ids, tenantKey);
//
// // 记录日志
// attendQuoteFields.forEach(e -> {
// SalaryLoggerUtil.recordDeleteSingleLog(attendQuoteFieldLoggerTemplate,
// e.getId(),
// e.getFieldName(),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100380, "删除字段"),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100380, "删除字段"),
// e);
// });
// return WeaResult.success(StringUtils.EMPTY);
// }
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public WeaResult<String> updateEnableStatus(Long id, Boolean enableStatus, Long currentEmployeeId, String currentTenantKey) {
// // 校验是否可以编辑
// if (id == null || enableStatus == null) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 84026, "参数错误"));
// }
// AttendQuoteFieldPO attendQuoteField = mapper.getById(id, currentTenantKey);
// if (attendQuoteField == null) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100375, "该字段不存在"));
// }
// if (!attendQuoteField.getSourceType().equals(AttendQuoteFieldSourceTypeEnum.DEFAULT.getValue())) {
// return WeaResult.fail(SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100376, "来源只能为自定义"));
// }
//
// AttendQuoteFieldPO newAttendQuoteField = new AttendQuoteFieldPO();
// BeanUtils.copyProperties(attendQuoteField, newAttendQuoteField);
// newAttendQuoteField.setEnableStatus(enableStatus?1:0);
// newAttendQuoteField.setUpdateTime(LocalDateTime.now());
// // 更新
// mapper.updateById(newAttendQuoteField);
// String action = enableStatus?SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 87070, "启用"):SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100386, "停用");
// // 记录日志
// SalaryLoggerUtil.recordUpdateSingleLog(attendQuoteFieldLoggerTemplate,
// attendQuoteField.getId(),
// newAttendQuoteField.getFieldName(),
// action+SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100387, "字段"),
// action+SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100387, "字段"),
// attendQuoteField,
// newAttendQuoteField);
//
// return WeaResult.success(StringUtils.EMPTY);
// }
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public WeaResult<String> syncAttendFields(Long currentEmployeeId, String currentTenantKey) {
// // 所有字段管理的考勤模块引用字段
// List<AttendQuoteFieldPO> attendQuoteFields = new LambdaQueryChainWrapper<>(mapper)
// .eq(AttendQuoteFieldPO::getTenantKey, currentTenantKey)
// .eq(AttendQuoteFieldPO::getDeleteType, 0)
// .eq(AttendQuoteFieldPO::getSourceType, AttendQuoteFieldSourceTypeEnum.ATTEND.getValue())
// .orderByDesc(AttendQuoteFieldPO::getId).list();
// // 1.本地字段
// List<String> localFieldCodes = CollectionUtils.emptyIfNull(attendQuoteFields).stream().map(AttendQuoteFieldPO::getCode).collect(Collectors.toList());
//
// // 2.考勤模块字段
// // 请假类型
// List<AttendVacationType> attendVacationTypes;
// try {
// attendVacationTypes = remoteAttendInitVacationService.queryVacationTypes(Boolean.TRUE, currentTenantKey);
// } catch (Exception e) {
// log.error("同步考勤字段失败,请检查接口服务remoteAttendInitVacationService.queryVacationTypes:{}", e.getMessage());
// return WeaResult.success(StringUtils.EMPTY);
// }
// // 请假类型:按小时
// List<String> attendLeaveHourFieldCodes = CollectionUtils.emptyIfNull(attendVacationTypes).stream().map(m->m.getId()+"_leave_hour").collect(Collectors.toList());
// // 请假类型:按天
// List<String> attendLeaveDayFieldCodes = CollectionUtils.emptyIfNull(attendVacationTypes).stream().map(m->m.getId()+"_leave_day").collect(Collectors.toList());
// List<String> attendLeaveFieldCodes = Lists.newArrayList();
// attendLeaveFieldCodes.addAll(attendLeaveHourFieldCodes);
// attendLeaveFieldCodes.addAll(attendLeaveDayFieldCodes);
// // 所有考勤模块字段编码
// List<String> attendFieldCodes = Lists.newArrayList();
// attendFieldCodes.addAll(attendLeaveFieldCodes);
// // 考勤模块固定字段
// List<Map<String, String>> attendFixedFieldCodes = AttendQuoteFieldBO.buildAttendFixedFields();
// attendFieldCodes.addAll(attendFixedFieldCodes.stream().map(m->m.get("code")).collect(Collectors.toList()));
//
// // 本地已存在则更新【交集】
// List<String> updateCodes = localFieldCodes.stream().filter(item -> attendFieldCodes.contains(item)).collect(Collectors.toList());
// // 本地比attend多则删除【差集(local - attend)】
// List<String> deleteCodes = localFieldCodes.stream().filter(item -> !attendFieldCodes.contains(item)).collect(Collectors.toList());
// // attend比本地多则新增【差集(attend - local)】
// List<String> saveCodes = attendFieldCodes.stream().filter(item -> !localFieldCodes.contains(item)).collect(Collectors.toList());
// String hourI18n = SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100743, "小时");
// String dayI18n = SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmployeeId, 100744, "天");
// // 1.更新 == 目前除了请假类型其余都是固定,故只需更新请假类型部分
// List<AttendQuoteFieldPO> updates = Lists.newArrayList();
// CollectionUtils.emptyIfNull(updateCodes).forEach(e -> {
// Optional<AttendVacationType> optionalHour = CollectionUtils.emptyIfNull(attendVacationTypes).stream().filter(m->(m.getId()+"_leave_hour").equals(e)).findFirst();
// if (optionalHour.isPresent()) {
// AttendVacationType hour = optionalHour.get();
// updates.add(AttendQuoteFieldPO.builder()
// .code(e)
// .fieldName(hour.getName()+"("+hourI18n+")")
// .updateTime(LocalDateTime.now())
// .build());
// }
// Optional<AttendVacationType> optionalDay = CollectionUtils.emptyIfNull(attendVacationTypes).stream().filter(m->(m.getId()+"_leave_day").equals(e)).findFirst();
// if (optionalDay.isPresent()) {
// AttendVacationType day = optionalDay.get();
// updates.add(AttendQuoteFieldPO.builder()
// .code(e)
// .fieldName(day.getName()+"("+dayI18n+")")
// .updateTime(LocalDateTime.now())
// .build());
// }
// });
// if (CollectionUtils.isNotEmpty(updates)) {
// mapper.updateNameByCode(updates);
// }
// // 2.删除
// if (CollectionUtils.isNotEmpty(deleteCodes)) {
// new LambdaUpdateChainWrapper<>(mapper)
// .eq(AttendQuoteFieldPO::getDeleteType, 0)
// .eq(AttendQuoteFieldPO::getTenantKey, currentTenantKey)
// .eq(AttendQuoteFieldPO::getSourceType, AttendQuoteFieldSourceTypeEnum.ATTEND.getValue())
// .in(AttendQuoteFieldPO::getCode, deleteCodes)
// .set(AttendQuoteFieldPO::getDeleteType, 1).update();
// }
// // 3.新增
// List<AttendQuoteFieldPO> saves = new ArrayList<>();
// saves.addAll(CollectionUtils.emptyIfNull(attendFixedFieldCodes).stream().filter(e -> saveCodes.contains(e.get("code"))).map(m ->
// buildAttendQuoteField(m.get("code"), m.get("name"), currentEmployeeId, currentTenantKey)
// ).collect(Collectors.toList()));
// CollectionUtils.emptyIfNull(saveCodes).forEach(e -> {
// Optional<AttendVacationType> optionalHour = CollectionUtils.emptyIfNull(attendVacationTypes).stream().filter(m->(m.getId()+"_leave_hour").equals(e)).findFirst();
// if (optionalHour.isPresent()) {
// AttendVacationType hour = optionalHour.get();
// saves.add(buildAttendQuoteField(e, hour.getName()+"("+hourI18n+")", currentEmployeeId, currentTenantKey));
// }
// Optional<AttendVacationType> optionalDay = CollectionUtils.emptyIfNull(attendVacationTypes).stream().filter(m->(m.getId()+"_leave_day").equals(e)).findFirst();
// if (optionalDay.isPresent()) {
// AttendVacationType day = optionalDay.get();
// saves.add(buildAttendQuoteField(e, day.getName()+"("+dayI18n+")", currentEmployeeId, currentTenantKey));
// }
// });
//
// if (CollectionUtils.isNotEmpty(saves)) {
// mapper.saveBatch(saves);
// }
//
// return WeaResult.success(StringUtils.EMPTY);
// }
//
// /**
// * 构建考勤字段
// * @param code
// * @param name
// * @param currentEmployeeId
// * @param currentTenantKey
// * @return
// */
// private AttendQuoteFieldPO buildAttendQuoteField(String code, String name, Long currentEmployeeId, String currentTenantKey) {
// return AttendQuoteFieldPO.builder()
// .id(IdGenerator.generate())
// .code(code)
// .fieldName(name)
// .sourceType(AttendQuoteFieldSourceTypeEnum.ATTEND.getValue())
// .fieldType(AttendQuoteFieldTypeEnum.NUMBER.getValue())
// .enableStatus(1)
// .description("")
// .createTime(LocalDateTime.now())
// .updateTime(LocalDateTime.now())
// .creator(currentEmployeeId)
// .tenantKey(currentTenantKey)
// .build();
// }
//
// @Override
// public List<AttendQuoteFieldListDTO> listAll(String tenantKey) {
// return mapper.list(AttendQuoteFieldQueryParam.builder().build(), tenantKey);
// }
}