weaver-hrm-salary/src/com/engine/salary/cmd/TaxAgent/TaxAgentDeleteCmd.java

93 lines
3.2 KiB
Java
Raw Normal View History

package com.engine.salary.cmd.TaxAgent;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.salary.entity.taxrate.TaxAgent;
import com.engine.salary.entity.taxrate.param.TaxAgentQueryParam;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.TaxAgentMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.session.SqlSession;
import weaver.conn.mybatis.MyBatisFactory;
import weaver.hrm.User;
import java.lang.reflect.Array;
import java.util.*;
public class TaxAgentDeleteCmd extends AbstractCommonCommand<Map<String, Object>> {
public TaxAgentDeleteCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> apidatas = new HashMap<String, Object>(16);
2022-03-01 18:49:22 +08:00
Collection<Long> idList = (Collection<Long>)params.get("ids");
if (CollectionUtils.isEmpty(idList)) {
throw new SalaryRunTimeException("参数错误");
}
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
TaxAgentMapper taxAgentMapper = sqlSession.getMapper(TaxAgentMapper.class);
List<TaxAgent> taxAgents = taxAgentMapper.listBySome(TaxAgentQueryParam.builder().ids(idList).build());
if (CollectionUtils.isEmpty(taxAgents)) {
throw new SalaryRunTimeException("要删除的个税扣缴义务人在不存在或已删除");
}
// todo 正在使用的记录不允许删除
// WeaResult<String> checkUsed = checkUsed(ids, tenantKey);
// if (checkUsed.getCode() == WeaResultCodeEnum.ERROR.getCode()) {
// return checkUsed;
// }
taxAgentMapper.deleteByIds(idList);
sqlSession.commit();
} finally {
sqlSession.close();
}
return apidatas;
}
//
// taxAgentMapper.deleteByIds(ids, tenantKey);
// // 记录日志
// taxAgents.forEach(e -> SalaryLoggerUtil.recordDeleteSingleLog(taxAgentLoggerTemplate,
// e.getId(),
// e.getName(),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100546, "删除个税扣缴义务人"),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100546, "删除个税扣缴义务人") + "" + e.getName(),
// e));
public static <T> List<T> castList(Object obj, Class<T> clazz) {
List<T> result = new ArrayList<T>();
if (obj.getClass().isArray()) {
int len = Array.getLength(obj);
for (int i = 0; i < len; i++) {
Object o = Array.get(obj, i);
result.add(clazz.cast(o));
}
} else if (obj instanceof List<?>) {
for (Object o : (List<?>) obj) {
result.add(clazz.cast(o));
}
}
return result;
}
}