个税扣缴义务人相关接口(6)

This commit is contained in:
钱涛 2022-02-28 17:19:07 +08:00
parent a35259c1ef
commit f591c09dc9
12 changed files with 352 additions and 64 deletions

View File

@ -0,0 +1,98 @@
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 com.google.common.collect.Collections2;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.BeanUtils;
import weaver.conn.mybatis.MyBatisFactory;
import weaver.general.Util;
import weaver.hrm.User;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
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);
List<String> ids = castList(params.get("ids"), String.class);
if (CollectionUtils.isEmpty(ids)) {
throw new SalaryRunTimeException("参数错误");
}
List<Long> idList = ids.stream().map(Long::valueOf).collect(Collectors.toList());
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;
}
}

View File

@ -8,6 +8,7 @@ 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 org.springframework.transaction.annotation.Transactional;
import weaver.conn.mybatis.MyBatisFactory;
import weaver.general.Util;
import weaver.hrm.User;
@ -38,7 +39,6 @@ public class TaxAgentSaveCmd extends AbstractCommonCommand<Map<String, Object>>
List<TaxAgent> list = mapper.listByName(Util.null2String(this.params.get("name")));
if (CollectionUtils.isNotEmpty(list)) {
throw new SalaryRunTimeException("名称不允许重复");
// apidatas.put("status",false);
}
TaxAgent taxAgent = TaxAgent.convertToPO(params, (long) user.getUID());

View File

@ -0,0 +1,63 @@
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.commons.compress.utils.Lists;
import org.apache.ibatis.session.SqlSession;
import weaver.conn.mybatis.MyBatisFactory;
import weaver.hrm.User;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class TaxAgentSelectListCmd extends AbstractCommonCommand<Map<String, Object>> {
public TaxAgentSelectListCmd(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);
List<Map<String, String>> list = Lists.newArrayList();
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
TaxAgentMapper taxAgentMapper = sqlSession.getMapper(TaxAgentMapper.class);
List<TaxAgent> taxAgents = taxAgentMapper.listAll();
taxAgents.forEach(m -> {
Map<String, String> map = new HashMap<>(2);
map.put("id", String.valueOf(m.getId()));
map.put("content", m.getName());
list.add(map);
});
apidatas.put("list", list);
sqlSession.commit();
} finally {
sqlSession.close();
}
return apidatas;
}
}

View File

@ -34,30 +34,32 @@ public class TaxAgentUpdateCmd extends AbstractCommonCommand<Map<String, Object>
if (StringUtils.isBlank(name)) {
throw new SalaryRunTimeException("名称必填");
}
Long id = Long.valueOf((Util.null2String(params.get("id"))));
if (params.get("id") == null) {
throw new SalaryRunTimeException("参数错误");
}
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
TaxAgentMapper taxAgentMapper = sqlSession.getMapper(TaxAgentMapper.class);
try {
TaxAgentMapper taxAgentMapper = sqlSession.getMapper(TaxAgentMapper.class);
TaxAgent taxAgent = taxAgentMapper.getById((Long) params.get("id"));
if (taxAgent == null) {
throw new SalaryRunTimeException("个税扣缴义务人不存在");
}
List<TaxAgent> individualTaxWithholdingAgents = taxAgentMapper.listByName(name);
boolean nameExist = individualTaxWithholdingAgents.stream().anyMatch(e -> !Objects.equals(e.getId(), (Long)params.get("id")));
if (nameExist) {
throw new SalaryRunTimeException("名称不允许重复");
}
TaxAgent taxAgent = taxAgentMapper.getById(id);
if (taxAgent == null) {
throw new SalaryRunTimeException("个税扣缴义务人不存在");
}
List<TaxAgent> individualTaxWithholdingAgents = taxAgentMapper.listByName(name);
boolean nameExist = individualTaxWithholdingAgents.stream().anyMatch(e -> !Objects.equals(e.getId(), id));
if (nameExist) {
throw new SalaryRunTimeException("名称不允许重复");
}
TaxAgent taxAgentNew = new TaxAgent();
BeanUtils.copyProperties(taxAgent, taxAgentNew);
taxAgentNew.setName(name);
taxAgentNew.setDescription(Util.null2String(params.get("description")));
taxAgentNew.setUpdateTime(new Date());
TaxAgent taxAgentNew = new TaxAgent();
BeanUtils.copyProperties(taxAgent, taxAgentNew);
taxAgentNew.setName(name);
taxAgentNew.setDescription(Util.null2String(params.get("description")));
taxAgentNew.setUpdateTime(new Date());
taxAgentMapper.updateIgnoreNull(taxAgentNew);
taxAgentMapper.updateIgnoreNull(taxAgentNew);
// taxAgentMapper.updateById(taxAgentNew);
// // 记录日志
@ -69,6 +71,10 @@ public class TaxAgentUpdateCmd extends AbstractCommonCommand<Map<String, Object>
// taxAgent,
// taxAgentNew);
sqlSession.commit();
} finally {
sqlSession.close();
}
return apidatas;
}

View File

@ -0,0 +1,25 @@
package com.engine.salary.entity.taxrate.param;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TaxAgentQueryParam {
private Collection<Long> ids;
private String name;
}

View File

@ -0,0 +1,2 @@
--
alter table hrsa_tax_agent modify id bigint auto_increment;

View File

@ -1,71 +1,94 @@
package com.engine.salary.mapper;
import java.util.Collection;
import java.util.List;
import com.engine.salary.entity.taxrate.TaxAgent;
import com.engine.salary.entity.taxrate.param.TaxAgentQueryParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface TaxAgentMapper {
/**
/**
* 查询所有记录
*
* @return 返回集合没有返回空List
*/
List<TaxAgent> listAll();
List<TaxAgent> listAll();
/**
/**
* 根据主键查询
*
* @param id 主键
* @return 返回记录没有返回null
*/
TaxAgent getById(Long id);
/**
TaxAgent getById(Long id);
/**
* 新增插入所有字段
*
* @param taxAgent 新增的记录
* @return 返回影响行数
*/
int insert(TaxAgent taxAgent);
/**
int insert(TaxAgent taxAgent);
/**
* 新增忽略null字段
*
* @param taxAgent 新增的记录
* @return 返回影响行数
*/
int insertIgnoreNull(TaxAgent taxAgent);
/**
int insertIgnoreNull(TaxAgent taxAgent);
/**
* 修改修改所有字段
*
* @param taxAgent 修改的记录
* @return 返回影响行数
*/
int update(TaxAgent taxAgent);
/**
int update(TaxAgent taxAgent);
/**
* 修改忽略null字段
*
* @param taxAgent 修改的记录
* @return 返回影响行数
*/
int updateIgnoreNull(TaxAgent taxAgent);
/**
int updateIgnoreNull(TaxAgent taxAgent);
/**
* 删除记录
*
* @param taxAgent 待删除的记录
* @return 返回影响行数
*/
int delete(TaxAgent taxAgent);
@Select("SELECT * FROM hrsa_tax_agent WHERE delete_type = 0 and name = #{name}")
List<TaxAgent> listByName(String name);
int delete(TaxAgent taxAgent);
/**
* 条件查询
* @param taxAgent
* @return
*/
List<TaxAgent> listBySome(@Param("param") TaxAgentQueryParam taxAgent);
/**
* 根据名称查询
* @param name
* @return
*/
@Select("SELECT * FROM hrsa_tax_agent WHERE delete_type = 0 and name = #{name}")
List<TaxAgent> listByName(String name);
/**
* 批量删除个税扣缴义务人
*
* @param ids
*/
void deleteByIds(@Param("ids") Collection<Long> ids);
}

View File

@ -24,12 +24,35 @@
, t.update_time
</sql>
<sql id="paramSql">
<if test="param.ids != null and param.ids.size()>0">
AND id IN
<foreach collection="param.ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.name != null and param.name != ''">
AND name like CONCAT('%',#{param.name},'%')
</if>
</sql>
<!-- 查询 -->
<select id="listBySome" resultMap="BaseResultMap">
SELECT
<include refid="baseColumns"/>
FROM hrsa_tax_agent t
WHERE delete_type = 0
<include refid="paramSql"/>
ORDER BY id DESC
</select>
<!-- 查询全部 -->
<select id="listAll" resultMap="BaseResultMap">
SELECT
<include refid="baseColumns"/>
FROM hrsa_tax_agent t
WHERE delete_type = 0
ORDER BY id DESC
</select>
<!-- 根据主键获取单条记录 -->
@ -178,8 +201,18 @@
UPDATE hrsa_tax_agent
SET delete_type=1
WHERE id = #{id}
AND delete_type = 0AND delete_type = 0
AND delete_type = 0
</delete>
<update id="deleteByIds">
UPDATE hrsa_tax_agent
SET delete_type = 1
WHERE delete_type = 0
AND id IN
<foreach collection="ids" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>

View File

@ -15,4 +15,7 @@ public interface TaxAgentService {
Map<String, Object> update(Map<String, Object> params);
Map<String, Object> delete(Map<String, Object> params);
Map<String, Object> selectList(Map<String, Object> params);
}

View File

@ -3,10 +3,7 @@ package com.engine.salary.service.impl;
import com.cloudstore.eccom.pc.table.WeaTable;
import com.engine.core.impl.Service;
import com.engine.portrait.cmd.individual.GetIndividualItemDataCmd;
import com.engine.salary.cmd.TaxAgent.TaxAgentGetFromCmd;
import com.engine.salary.cmd.TaxAgent.TaxAgentListCmd;
import com.engine.salary.cmd.TaxAgent.TaxAgentSaveCmd;
import com.engine.salary.cmd.TaxAgent.TaxAgentUpdateCmd;
import com.engine.salary.cmd.TaxAgent.*;
import com.engine.salary.service.TaxAgentService;
import weaver.hrm.User;
@ -33,4 +30,14 @@ public class TaxAgentServiceImpl extends Service implements TaxAgentService {
public Map<String, Object> update(Map<String, Object> params) {
return commandExecutor.execute(new TaxAgentUpdateCmd(params,user));
}
@Override
public Map<String, Object> delete(Map<String, Object> params) {
return commandExecutor.execute(new TaxAgentDeleteCmd(params,user));
}
@Override
public Map<String, Object> selectList(Map<String, Object> params) {
return commandExecutor.execute(new TaxAgentSelectListCmd(params,user));
}
}

View File

@ -0,0 +1,20 @@
package com.engine.salary.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
public class BaseController {
@SuppressWarnings("unchecked")
protected Map<String,Object> getRequestParams(HttpServletRequest request, HttpServletResponse response){
Map<String, Object> params = new HashMap<String, Object>();
Enumeration<String> em = request.getParameterNames();
while(em.hasMoreElements()){
String paramname = em.nextElement();
params.put(paramname, request.getParameter(paramname));
}
return params;
}
}

View File

@ -13,17 +13,15 @@ import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TaxAgentController {
public class TaxAgentController extends BaseController {
private BaseBean logger = new BaseBean();
@ -34,7 +32,7 @@ public class TaxAgentController {
//个税扣缴义务人列表
@GET
@Path("/list")
@Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public String list(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return ResponseResult.run(getService(user)::list, ParamUtil.request2Map(request));
@ -43,7 +41,7 @@ public class TaxAgentController {
//获取个税扣缴义务人表单
@GET
@Path("/getForm")
@Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return ResponseResult.run(getService(user)::getForm, ParamUtil.request2Map(request));
@ -52,10 +50,10 @@ public class TaxAgentController {
//新建个税扣缴义务人
@POST
@Path("/save")
@Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public String getFrom(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return ResponseResult.run(getService(user)::save, getRequestParams(request,response));
return ResponseResult.run(getService(user)::save, ParamUtil.request2Map(request));
}
/**
@ -63,22 +61,32 @@ public class TaxAgentController {
*/
@POST
@Path("/update")
@Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public String update(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return ResponseResult.run(getService(user)::update, ParamUtil.request2Map(request));
}
protected Map<String,Object> getRequestParams(HttpServletRequest request, HttpServletResponse response){
Map<String, Object> params = new HashMap<String, Object>();
Enumeration<String> em = request.getParameterNames();
while(em.hasMoreElements()){
String paramname = em.nextElement();
params.put(paramname, request.getParameter(paramname));
}
params.put("param_ip", request.getRemoteAddr());//加入ip
return params;
/**
* 编辑个税扣缴义务人
*/
@POST
@Path("/delete")
@Produces(MediaType.APPLICATION_JSON)
public String delete(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return ResponseResult.run(getService(user)::delete, ParamUtil.request2Map(request));
}
/**
* 个税扣缴义务人下拉列表
*/
@GET
@Path("/selectList")
@Produces(MediaType.APPLICATION_JSON)
public String selectList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return ResponseResult.run(getService(user)::selectList, ParamUtil.request2Map(request));
}
}