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> { public TaxAgentDeleteCmd(Map params, User user) { this.user = user; this.params = params; } @Override public BizLogContext getLogContext() { return null; } @Override public Map execute(CommandContext commandContext) { Map apidatas = new HashMap(16); Collection idList = (Collection)params.get("ids"); if (CollectionUtils.isEmpty(idList)) { throw new SalaryRunTimeException("参数错误"); } SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); try { TaxAgentMapper taxAgentMapper = sqlSession.getMapper(TaxAgentMapper.class); // String sql = MyBatisFactory.sqlSessionFactory.getConfiguration().getMappedStatement("com.engine.salary.mapper.TaxAgentMapper.delete").getBoundSql(TaxAgent.builder().id(1l).build()).getSql(); List taxAgents = taxAgentMapper.listBySome(TaxAgentQueryParam.builder().ids(idList).build()); if (CollectionUtils.isEmpty(taxAgents)) { throw new SalaryRunTimeException("要删除的个税扣缴义务人在不存在或已删除"); } // todo 正在使用的记录不允许删除 // WeaResult 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 List castList(Object obj, Class clazz) { List result = new ArrayList(); 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; } }