Merge remote-tracking branch 'remotes/origin/fix/DBType修改' into feature/230602-数据库适配-PG

This commit is contained in:
sy 2023-06-26 10:15:24 +08:00
commit f2cca4cfd7
9 changed files with 259 additions and 105 deletions

View File

@ -130,4 +130,14 @@ public class SalaryTemplateBiz {
sqlSession.close();
}
}
public List<SalaryTemplateListDTO> listDTO(SalaryTemplatePO param) {
SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession();
try {
SalaryTemplateMapper mapper = sqlSession.getMapper(SalaryTemplateMapper.class);
return mapper.listDTO(param);
} finally {
sqlSession.close();
}
}
}

View File

@ -3,6 +3,7 @@ package com.engine.salary.entity.salaryBill.dto;
import com.engine.salary.annotation.SalaryTable;
import com.engine.salary.annotation.SalaryTableColumn;
import com.engine.salary.annotation.SalaryTableOperate;
import com.engine.salary.annotation.TableTitle;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -25,26 +26,32 @@ public class SalaryTemplateListDTO {
//主键id
@SalaryTableColumn(column = "id", display = false)
@TableTitle(title = "id", dataIndex = "id", key = "id",display = false)
private Long id;
//工资单模板名称
@SalaryTableColumn(text = "工资单模板名称", width = "20%", column = "name")
@TableTitle(title = "工资单模板名称", dataIndex = "name", key = "name")
private String name;
//补发工资单模板名称
@SalaryTableColumn(text = "补发工资单模板名称", width = "20%", column = "replenishName")
@TableTitle(title = "补发工资单模板名称", dataIndex = "replenishName", key = "replenishName")
private String replenishName;
//所属薪资账套
@SalaryTableColumn(text = "所属薪资账套", width = "20%", column = "salarySob")
@TableTitle(title = "所属薪资账套", dataIndex = "salarySob", key = "salarySob")
private String salarySob;
//默认使用
@SalaryTableColumn(text = "默认使用", width = "20%", column = "useType")
@TableTitle(title = "默认使用", dataIndex = "useType", key = "useType")
private String useType;
// 备注
@SalaryTableColumn(text = "备注", width = "20%", column = "description")
@TableTitle(title = "备注", dataIndex = "description", key = "description")
private String description;
}

View File

@ -4,17 +4,12 @@ import com.engine.salary.common.BaseQueryParam;
import com.engine.salary.enums.SalaryOnOffEnum;
import com.engine.salary.enums.SalaryValueTypeEnum;
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
import com.engine.salary.util.db.DBType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import java.util.Collection;
import java.util.stream.Collectors;
/**
* 薪资项目查询参数
@ -69,38 +64,38 @@ public class SalaryItemSearchParam extends BaseQueryParam {
private Collection<Long> excludeIds;
public static String makeSqlWhere(SalaryItemSearchParam searchParam) {
String sqlWhere = " t.delete_type = 0 ";
DBType dbType = DBType.get(new RecordSet().getDBType());
String name = searchParam.getName();
if (StringUtils.isNotBlank(name)) {
sqlWhere += " AND t.name " + dbType.like(name);
}
String description = searchParam.getDescription();
if (StringUtils.isNotBlank(description)) {
sqlWhere += " AND t.description " + dbType.like(description);
}
Integer useInEmployeeSalary = searchParam.getUseInEmployeeSalary();
if (useInEmployeeSalary != null) {
sqlWhere += " AND t.use_in_employee_salary = " + useInEmployeeSalary;
}
Integer useDefault = searchParam.getUseDefault();
if (useDefault != null) {
sqlWhere += " AND t.use_default = " + useDefault;
}
Integer valueType = searchParam.getValueType();
if (valueType != null) {
sqlWhere += " AND t.value_type = " + valueType;
}
Collection<Long> excludeIds = searchParam.getExcludeIds();
if (CollectionUtils.isNotEmpty(excludeIds)) {
String idsStr = excludeIds.stream().map(String::valueOf).collect(Collectors.joining(","));
sqlWhere += " AND t.id NOT IN (" + idsStr + ")";
}
return sqlWhere;
}
// public static String makeSqlWhere(SalaryItemSearchParam searchParam) {
//
// String sqlWhere = " t.delete_type = 0 ";
//
// DBType dbType = DBType.get(new RecordSet().getDBType());
//
// String name = searchParam.getName();
// if (StringUtils.isNotBlank(name)) {
// sqlWhere += " AND t.name " + dbType.like(name);
// }
// String description = searchParam.getDescription();
// if (StringUtils.isNotBlank(description)) {
// sqlWhere += " AND t.description " + dbType.like(description);
// }
// Integer useInEmployeeSalary = searchParam.getUseInEmployeeSalary();
// if (useInEmployeeSalary != null) {
// sqlWhere += " AND t.use_in_employee_salary = " + useInEmployeeSalary;
// }
// Integer useDefault = searchParam.getUseDefault();
// if (useDefault != null) {
// sqlWhere += " AND t.use_default = " + useDefault;
// }
// Integer valueType = searchParam.getValueType();
// if (valueType != null) {
// sqlWhere += " AND t.value_type = " + valueType;
// }
// Collection<Long> excludeIds = searchParam.getExcludeIds();
// if (CollectionUtils.isNotEmpty(excludeIds)) {
// String idsStr = excludeIds.stream().map(String::valueOf).collect(Collectors.joining(","));
// sqlWhere += " AND t.id NOT IN (" + idsStr + ")";
// }
//
// return sqlWhere;
// }
}

View File

@ -3,7 +3,6 @@ package com.engine.salary.mapper.salarybill;
import com.engine.salary.entity.salaryBill.dto.SalaryTemplateListDTO;
import com.engine.salary.entity.salaryBill.param.SalaryTemplateQueryParam;
import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
@ -72,4 +71,6 @@ public interface SalaryTemplateMapper {
* @param po
*/
void updateUsetypeBySalarySobId(SalaryTemplatePO po);
List<SalaryTemplateListDTO> listDTO(SalaryTemplatePO param);
}

View File

@ -336,6 +336,102 @@
ORDER BY t.salary_sob_id,t.id DESC
</select>
<select id="listDTO" resultType="com.engine.salary.entity.salaryBill.dto.SalaryTemplateListDTO">
select
t.id,
t.name,
t.replenish_name as replenishName,
s.name as salarysob,
t.use_type as useType,
t.description
from
hrsa_salary_template t left join hrsa_salary_sob s on t.salary_sob_id = s.id
where t.delete_type = 0
<if test="id != null and id != ''">
AND t.id = #{id}
</if>
<if test="name != null and name != ''">
AND t.name like CONCAT('%',#{name},'%')
</if>
<if test="salarySobId != null and salarySobId != ''">
AND t.salary_sob_id = #{salarySobId}
</if>
<if test=" replenishName != null and replenishName != ''">
AND t.replenish_name = #{replenishName}
</if>
<if test="salarySobIds != null and salarySobIds.size() > 0">
AND t.salary_sob_id IN
<foreach collection="salarySobIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
ORDER BY id DESC
</select>
<select id="listDTO" resultType="com.engine.salary.entity.salaryBill.dto.SalaryTemplateListDTO" databaseId="oracle">
select
t.id,
t.name,
t.replenish_name as replenishName,
s.name as salarysob,
t.use_type as useType,
t.description
from
hrsa_salary_template t left join hrsa_salary_sob s on t.salary_sob_id = s.id
where t.delete_type = 0
<if test="id != null and id != ''">
AND t.id = #{id}
</if>
<if test="name != null and name != ''">
AND t.name like '%'||#{name}||'%'
</if>
<if test="salarySobId != null and salarySobId != ''">
AND t.salary_sob_id = #{salarySobId}
</if>
<if test=" replenishName != null and replenishName != ''">
AND t.replenish_name = #{replenishName}
</if>
<if test="salarySobIds != null and salarySobIds.size() > 0">
AND t.salary_sob_id IN
<foreach collection="salarySobIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
ORDER BY id DESC
</select>
<select id="listDTO" resultType="com.engine.salary.entity.salaryBill.dto.SalaryTemplateListDTO" databaseId="sqlserver">
select
t.id,
t.name,
t.replenish_name as replenishName,
s.name as salarysob,
t.use_type as useType,
t.description
from
hrsa_salary_template t left join hrsa_salary_sob s on t.salary_sob_id = s.id
where t.delete_type = 0
<if test="id != null and id != ''">
AND t.id = #{id}
</if>
<if test="name != null and name != ''">
AND t.name like '%'+#{name}+'%'
</if>
<if test="salarySobId != null and salarySobId != ''">
AND t.salary_sob_id = #{salarySobId}
</if>
<if test=" replenishName != null and replenishName != ''">
AND t.replenish_name = #{replenishName}
</if>
<if test="salarySobIds != null and salarySobIds.size() > 0">
AND t.salary_sob_id IN
<foreach collection="salarySobIds" open="(" item="id" separator="," close=")">
#{id}
</foreach>
</if>
ORDER BY id DESC
</select>
<!-- 更新不为NULL的字段 -->
<update id="updateIgnoreNull" parameterType="com.engine.salary.entity.salaryBill.po.SalaryTemplatePO">
UPDATE hrsa_salary_template

View File

@ -1,10 +1,13 @@
package com.engine.salary.service;
import com.engine.salary.entity.salaryBill.dto.SalaryTemplateListDTO;
import com.engine.salary.entity.salaryBill.dto.SalaryTemplateSalaryItemSetListDTO;
import com.engine.salary.entity.salaryBill.param.SalaryTemplateCopyParam;
import com.engine.salary.entity.salaryBill.param.SalaryTemplateDefaultUseParam;
import com.engine.salary.entity.salaryBill.param.SalaryTemplateQueryParam;
import com.engine.salary.entity.salaryBill.param.SalaryTemplateSaveParam;
import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO;
import com.engine.salary.util.page.PageInfo;
import java.util.Collection;
import java.util.List;
@ -102,4 +105,11 @@ public interface SalaryTemplateService {
* @return
*/
List<SalaryTemplatePO> getBySalarySobIds(Collection<Long> ids);
/**
* 工资单模板列表
* @param queryParam
* @return
*/
PageInfo<SalaryTemplateListDTO> listPage(SalaryTemplateQueryParam queryParam);
}

View File

@ -20,6 +20,10 @@ import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.service.SalarySobItemService;
import com.engine.salary.service.SalarySobService;
import com.engine.salary.service.SalaryTemplateService;
import com.engine.salary.service.TaxAgentService;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import com.mzlion.core.utils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
@ -47,6 +51,10 @@ public class SalaryTemplateServiceImpl extends Service implements SalaryTemplate
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
@Override
public SalaryTemplatePO getById(Long id) {
return mapper.getById(id);
@ -279,4 +287,32 @@ public class SalaryTemplateServiceImpl extends Service implements SalaryTemplate
public List<SalaryTemplatePO> getBySalarySobIds(Collection<Long> ids) {
return mapper.listSome(SalaryTemplatePO.builder().salarySobIds(ids).build());
}
@Override
public PageInfo<SalaryTemplateListDTO> listPage(SalaryTemplateQueryParam queryParam) {
List<SalaryTemplateListDTO> salaryTemplateDTOList = Collections.emptyList();
// 分权
long currentEmployeeId = user.getUID();
Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
if (needAuth) {
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO);
Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getId);
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(salarySobIds)) {
// 查询
salaryTemplateDTOList = mapper.listDTO(SalaryTemplatePO.builder()
.salarySobId(queryParam.getSalarySobId())
.name(queryParam.getName())
.salarySobIds(salarySobIds).build());
} else {
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), salaryTemplateDTOList, SalaryTemplateListDTO.class);
}
}else{
// 查询
salaryTemplateDTOList = mapper.listDTO(SalaryTemplatePO.builder().salarySobId(queryParam.getSalarySobId()).name(queryParam.getName()).build());
}
// 分页参数
PageInfo<SalaryTemplateListDTO> page = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), salaryTemplateDTOList, SalaryTemplateListDTO.class);
return page;
}
}

View File

@ -60,7 +60,7 @@ public class SalaryBillController {
@Produces(MediaType.APPLICATION_JSON)
public String templateList(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryTemplateQueryParam queryParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<SalaryTemplateQueryParam, Map<String, Object>>(user).run(getSalaryTemplateWrapper(user)::list, queryParam);
return new ResponseResult<SalaryTemplateQueryParam, PageInfo<SalaryTemplateListDTO>>(user).run(getSalaryTemplateWrapper(user)::list, queryParam);
}
/**

View File

@ -1,9 +1,7 @@
package com.engine.salary.wrapper;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.component.SalaryWeaTable;
import com.engine.salary.entity.salaryBill.dto.*;
import com.engine.salary.entity.salaryBill.param.*;
import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO;
@ -19,12 +17,11 @@ import com.engine.salary.service.impl.*;
import com.engine.salary.util.JsonUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.DBType;
import com.engine.salary.util.page.PageInfo;
import com.mzlion.core.utils.BeanUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import java.util.*;
@ -69,68 +66,70 @@ public class SalaryTemplateWrapper extends Service {
* @param queryParam
* @return
*/
public Map<String, Object> list(SalaryTemplateQueryParam queryParam) {
SalaryWeaTable<SalaryTemplateListDTO> table = new SalaryWeaTable<SalaryTemplateListDTO>(user, SalaryTemplateListDTO.class);
String fields = " t.id" +
" , t.name" +
" , t.replenish_name as replenishName" +
" , s.name as salarySob" +
" , t.use_type as useType" +
" , t.description";
String from = " from hrsa_salary_template t left join hrsa_salary_sob s on t.salary_sob_id = s.id ";
table.setBackfields(fields);
table.setSqlform(from);
table.setSqlwhere(makeSqlWhere(queryParam));
table.setSqlorderby("t.id DESC");
table.setSqlprimarykey("t.id");
table.setSqlisdistinct("false");
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(table.makeDataResult());
result.success();
return result.getResultMap();
public PageInfo<SalaryTemplateListDTO> list(SalaryTemplateQueryParam queryParam) {
PageInfo<SalaryTemplateListDTO> listPage = getSalaryTemplateService(user).listPage(queryParam);
return listPage;
// SalaryWeaTable<SalaryTemplateListDTO> table = new SalaryWeaTable<SalaryTemplateListDTO>(user, SalaryTemplateListDTO.class);
//
// String fields = " t.id" +
// " , t.name" +
// " , t.replenish_name as replenishName" +
// " , s.name as salarySob" +
// " , t.use_type as useType" +
// " , t.description";
//
// String from = " from hrsa_salary_template t left join hrsa_salary_sob s on t.salary_sob_id = s.id ";
//
// table.setBackfields(fields);
// table.setSqlform(from);
// table.setSqlwhere(makeSqlWhere(queryParam));
// table.setSqlorderby("t.id DESC");
// table.setSqlprimarykey("t.id");
// table.setSqlisdistinct("false");
//
// WeaResultMsg result = new WeaResultMsg(false);
// result.putAll(table.makeDataResult());
// result.success();
// return result.getResultMap();
}
private String makeSqlWhere(SalaryTemplateQueryParam queryParam) {
DBType dbType = DBType.get(new RecordSet().getDBType());
String sqlWhere = " t.delete_type = 0 ";
String name = queryParam.getName();
if (StringUtils.isNotBlank(name)) {
sqlWhere += " AND t.name " + dbType.like(name);
}
Collection<Long> ids = queryParam.getIds();
if (ids != null && ids.size() > 0) {
sqlWhere += " AND t.id in (" + ids.stream().map(Object::toString).collect(Collectors.joining(",")) + ") ";
}
Long salarySobId = queryParam.getSalarySobId();
if (salarySobId != null) {
sqlWhere += " AND t.salary_sob_id = " + salarySobId;
}
long currentEmployeeId = user.getUID();
Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
if (needAuth) {
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO);
Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getId);
if (CollectionUtils.isNotEmpty(salarySobIds)) {
sqlWhere += " AND t.salary_sob_id in (" + salarySobIds.stream().map(Object::toString).collect(Collectors.joining(",")) + ") ";
} else {
sqlWhere += " AND 1=2 ";
}
}
return sqlWhere;
}
// private String makeSqlWhere(SalaryTemplateQueryParam queryParam) {
// DBType dbType = DBType.get(new RecordSet().getDBType());
//
// String sqlWhere = " t.delete_type = 0 ";
//
// String name = queryParam.getName();
// if (StringUtils.isNotBlank(name)) {
// sqlWhere += " AND t.name " + dbType.like(name);
// }
//
// Collection<Long> ids = queryParam.getIds();
//
// if (ids != null && ids.size() > 0) {
// sqlWhere += " AND t.id in (" + ids.stream().map(Object::toString).collect(Collectors.joining(",")) + ") ";
// }
//
// Long salarySobId = queryParam.getSalarySobId();
//
// if (salarySobId != null) {
// sqlWhere += " AND t.salary_sob_id = " + salarySobId;
// }
//
// long currentEmployeeId = user.getUID();
// Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
// if (needAuth) {
// List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO);
// Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getId);
// if (CollectionUtils.isNotEmpty(salarySobIds)) {
// sqlWhere += " AND t.salary_sob_id in (" + salarySobIds.stream().map(Object::toString).collect(Collectors.joining(",")) + ") ";
// } else {
// sqlWhere += " AND 1=2 ";
// }
// }
//
//
// return sqlWhere;
// }
/**
* 获取工资单模板基础设置表单