From f8d68fa7bca3058f1599e12bc42186cfbb27e8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E6=B6=9B?= <15850646081@163.com> Date: Mon, 21 Mar 2022 09:33:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/engine/salary/biz/SalaryItemBiz.java | 72 +++++ .../engine/salary/common/BaseQueryParam.java | 15 ++ .../salary/component/PageInterceptor.java | 177 ++++++++++++ .../engine/salary/component/ReflectUtil.java | 174 ++++++++++++ .../salary/component/WeaFormOption.java | 44 +++ .../engine/salary/demo/DemoController.java | 3 +- src/com/engine/salary/demo/DemoPageCmd.java | 12 +- .../entity/salaryitem/bo/SalaryItemBO.java | 181 ++++++------- .../entity/salaryitem/bo/SysSalaryItemBO.java | 252 +++++++++--------- .../param/SalaryItemSearchParam.java | 46 ++-- .../entity/salarysob/po/SalarySobItemPO.java | 83 ++++++ src/com/engine/salary/init.sql | 3 + .../mapper/salaryitem/SalaryItemMapper.java | 4 +- .../mapper/salaryitem/SalaryItemMapper.xml | 100 ++++++- .../salary/service/SalaryItemService.java | 68 ++--- .../salary/service/SalarySobItemService.java | 103 +++++++ .../service/impl/SalaryItemServiceImpl.java | 205 +++++++------- .../impl/SysSalaryItemServiceImpl.java | 5 +- .../engine/salary/util/ResponseResult.java | 54 ++++ .../salary/web/SalaryItemController.java | 66 +++-- .../salary/wrapper/SalaryItemWrapper.java | 216 +++++++-------- 21 files changed, 1359 insertions(+), 524 deletions(-) create mode 100644 src/com/engine/salary/common/BaseQueryParam.java create mode 100644 src/com/engine/salary/component/PageInterceptor.java create mode 100644 src/com/engine/salary/component/ReflectUtil.java create mode 100644 src/com/engine/salary/component/WeaFormOption.java create mode 100644 src/com/engine/salary/entity/salarysob/po/SalarySobItemPO.java create mode 100644 src/com/engine/salary/service/SalarySobItemService.java diff --git a/src/com/engine/salary/biz/SalaryItemBiz.java b/src/com/engine/salary/biz/SalaryItemBiz.java index c9e3dcf87..81b362d75 100644 --- a/src/com/engine/salary/biz/SalaryItemBiz.java +++ b/src/com/engine/salary/biz/SalaryItemBiz.java @@ -1,10 +1,14 @@ package com.engine.salary.biz; +import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.mapper.salaryitem.SalaryItemMapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import org.apache.ibatis.session.SqlSession; import weaver.conn.mybatis.MyBatisFactory; +import java.util.Collection; import java.util.List; public class SalaryItemBiz { @@ -32,4 +36,72 @@ public class SalaryItemBiz { public List listSome(SalaryItemPO build) { return null; } + + public void batchSave(Collection salaryItems) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class); + mapper.batchInsert(salaryItems); + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + public void insert(SalaryItemPO salaryItemPO) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class); + mapper.insertIgnoreNull(salaryItemPO); + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + public void updateById(SalaryItemPO newSalaryItemPO) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class); + mapper.updateIgnoreNull(newSalaryItemPO); + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + public void deleteByIds(Collection ids) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class); + mapper.deleteByIds(ids); + sqlSession.commit(); + } finally { + sqlSession.close(); + } + } + + public PageInfo listPageByParam(SalaryItemSearchParam searchParam) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class); +// PageUtil.start(searchParam.getPageNum(), searchParam.getPageSize()); + return PageHelper.startPage(searchParam.getPageNum(), searchParam.getPageSize()).doSelectPageInfo(mapper::listAll); +// List salaryItemPOS = mapper.listAll(); + + } finally { + sqlSession.close(); + } + + } + + public List listByParam(SalaryItemSearchParam searchParam) { + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + SalaryItemMapper mapper = sqlSession.getMapper(SalaryItemMapper.class); + return mapper.listByParam(searchParam); + } finally { + sqlSession.close(); + } + } } diff --git a/src/com/engine/salary/common/BaseQueryParam.java b/src/com/engine/salary/common/BaseQueryParam.java new file mode 100644 index 000000000..ada4271cd --- /dev/null +++ b/src/com/engine/salary/common/BaseQueryParam.java @@ -0,0 +1,15 @@ +package com.engine.salary.common; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BaseQueryParam { + + private Integer pageNum = 1; + + private Integer pageSize = 10; +} diff --git a/src/com/engine/salary/component/PageInterceptor.java b/src/com/engine/salary/component/PageInterceptor.java new file mode 100644 index 000000000..50958baf7 --- /dev/null +++ b/src/com/engine/salary/component/PageInterceptor.java @@ -0,0 +1,177 @@ +package com.engine.salary.component; + + +import com.github.pagehelper.Page; +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.binding.MapperMethod; +import org.apache.ibatis.executor.parameter.ParameterHandler; +import org.apache.ibatis.executor.statement.RoutingStatementHandler; +import org.apache.ibatis.executor.statement.StatementHandler; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.mapping.ParameterMapping; +import org.apache.ibatis.plugin.*; +import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; +import weaver.conn.RecordSet; + +import javax.xml.bind.PropertyException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.Properties; + + +@Intercepts({@Signature(method = "prepare", type = StatementHandler.class, args = {Connection.class,Integer.class})}) +@SuppressWarnings("rawtypes") +public class PageInterceptor implements Interceptor { + private static String databaseType = "";// 数据库类型,不同的数据库有不同的分页方法 + + /** + * 拦截后要执行的方法 + */ + public Object intercept(Invocation invocation) throws Throwable { + + RoutingStatementHandler handler = (RoutingStatementHandler) invocation + .getTarget(); + StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate"); + BoundSql boundSql = delegate.getBoundSql(); + Object params = boundSql.getParameterObject(); + Page page = null; + if (params instanceof Page) { + page = (Page) params; + } else if (params instanceof MapperMethod.ParamMap) { + MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) params; + for (Object key : paramMap.keySet()) { + if (paramMap.get(key) instanceof Page) { + page = (Page) paramMap.get(key); + break; + } + } + } + + if (page != null) { + MappedStatement mappedStatement = (MappedStatement) ReflectUtil + .getFieldValue(delegate, "mappedStatement"); + Connection connection = (Connection) invocation.getArgs()[0]; + String sql = boundSql.getSql(); + this.setTotalRecord(page, (MapperMethod.ParamMap) params, + mappedStatement, connection); + String pageSql = this.getPageSql(page, sql); + ReflectUtil.setFieldValue(boundSql, "sql", pageSql); + } + return invocation.proceed(); + } + + /** + * 拦截器对应的封装原始对象的方法 + */ + public Object plugin(Object target) { + return Plugin.wrap(target, this); + } + + public void setProperties(Properties p) { + databaseType = p.getProperty("databaseType"); + if (StringUtils.isEmpty(databaseType)) { + try { + throw new PropertyException("databaseType is not found!"); + } catch (PropertyException e) { + e.printStackTrace(); + } + } + } + + private String getPageSql(Page page, String sql) { + StringBuffer sqlBuffer = new StringBuffer(sql); + RecordSet recordSet = new RecordSet(); + + String dbType = recordSet.getDBType(); + if ("mysql".equalsIgnoreCase(dbType)) { + return getMysqlPageSql(page, sqlBuffer); + } else if ("oracle".equalsIgnoreCase(dbType)) { + return getOraclePageSql(page, sqlBuffer); + } else if ("sqlserver".equalsIgnoreCase(dbType)) { + return getSqlserverPageSql(page, sqlBuffer); + } + return sqlBuffer.toString(); + } + + private String getSqlserverPageSql(Page page, StringBuffer sqlBuffer) { + // 计算第一条记录的位置,Sqlserver中记录的位置是从0开始的。 + int startRowNum = (page.getPageNum() - 1) * page.getPageSize() + 1; + int endRowNum = startRowNum + page.getPageSize(); + String sql = "select appendRowNum.row,* from (select ROW_NUMBER() OVER (order by (select 0)) AS row,* from (" + + sqlBuffer.toString() + + ") as innerTable" + + ")as appendRowNum where appendRowNum.row >= " + + startRowNum + + " AND appendRowNum.row <= " + endRowNum; + return sql; + } + + private String getMysqlPageSql(Page page, StringBuffer sqlBuffer) { + // 计算第一条记录的位置,Mysql中记录的位置是从0开始的。 + int offset = (page.getPageNum() - 1) * page.getPageSize(); + sqlBuffer.append(" limit ").append(offset).append(",").append(page.getPageSize()); + return sqlBuffer.toString(); + } + + private String getOraclePageSql(Page page, StringBuffer sqlBuffer) { + // 计算第一条记录的位置,Oracle分页是通过rownum进行的,而rownum是从1开始的 + int offset = (page.getPageNum() - 1) * page.getPageSize() + 1; + sqlBuffer.insert(0, "select u.*, rownum r from (").append(") u where rownum < ") + .append(offset + page.getPageSize()); + sqlBuffer.insert(0, "select * from (").append(") where r >= ").append(offset); + return sqlBuffer.toString(); + } + + /** + * 给当前的参数对象page设置总记录数 + * + * @param page Mapper映射语句对应的参数对象 + * @param mappedStatement Mapper映射语句 + * @param connection + */ + private void setTotalRecord(Page page, MapperMethod.ParamMap params, + MappedStatement mappedStatement, Connection connection) { + BoundSql boundSql = mappedStatement.getBoundSql(params); + String sql = boundSql.getSql(); + String countSql = this.getCountSql(sql); + List parameterMappings = boundSql.getParameterMappings(); + BoundSql countBoundSql = new BoundSql(mappedStatement.getConfiguration(), countSql, parameterMappings, params); + ParameterHandler parameterHandler = new DefaultParameterHandler( + mappedStatement, params, countBoundSql); + PreparedStatement pstmt = null; + ResultSet rs = null; + try { + pstmt = connection.prepareStatement(countSql); + parameterHandler.setParameters(pstmt); + rs = pstmt.executeQuery(); + if (rs.next()) { + int totalRecord = rs.getInt(1); +// page.setTotalRecord(totalRecord); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + if (rs != null) rs.close(); + if (pstmt != null) pstmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + /** + * 根据原Sql语句获取对应的查询总记录数的Sql语句 + * + * @param sql + * @return + */ + private String getCountSql(String sql) { + return "select count(*) from (" + sql + ") as countRecord"; + } + +} diff --git a/src/com/engine/salary/component/ReflectUtil.java b/src/com/engine/salary/component/ReflectUtil.java new file mode 100644 index 000000000..75d777b22 --- /dev/null +++ b/src/com/engine/salary/component/ReflectUtil.java @@ -0,0 +1,174 @@ +package com.engine.salary.component; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.Assert; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + + +/** + * 利用反射进行操作的一个工具类 + */ +public class ReflectUtil { + /** + * 利用反射获取指定对象的指定属性 + * + * @param obj + * 目标对象 + * @param fieldName + * 目标属性 + * @return 目标属性的值 + */ + public static Object getFieldValue(Object obj, String fieldName) { + Object result = null; + Field field = ReflectUtil.getField(obj, fieldName); + if (field != null) { + field.setAccessible(true); + try { + result = field.get(obj); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return result; + } + + /** + * 利用反射获取指定对象里面的指定属性 + * + * @param obj + * 目标对象 + * @param fieldName + * 目标属性 + * @return 目标字段 + */ + private static Field getField(Object obj, String fieldName) { + Field field = null; + for (Class clazz = obj.getClass(); clazz != Object.class; clazz = clazz + .getSuperclass()) { + try { + field = clazz.getDeclaredField(fieldName); + break; + } catch (NoSuchFieldException e) { + // 这里不用做处理,子类没有该字段可能对应的父类有,都没有就返回null。 + } + } + return field; + } + + /** + * 利用反射设置指定对象的指定属性为指定的值 + * + * @param obj + * 目标对象 + * @param fieldName + * 目标属性 + * @param fieldValue + * 目标值 + */ + public static void setFieldValue(Object obj, String fieldName, + String fieldValue) { + Field field = ReflectUtil.getField(obj, fieldName); + if (field != null) { + try { + field.setAccessible(true); + field.set(obj, fieldValue); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + + /** + * 两者属性名一致时,拷贝source里的属性到dest里 + * + * @return void + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws InvocationTargetException + */ + @SuppressWarnings("unchecked") + public static void copyPorperties(Object dest, Object source) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException{ + Class srcCla = source.getClass(); + Field[] fsF = srcCla.getDeclaredFields(); + + for (Field s : fsF) + { + String name = s.getName(); + Object srcObj = invokeGetterMethod(source, name); + try + { + BeanUtils.setProperty(dest, name, srcObj); + } + catch (Exception e){ + e.printStackTrace(); + } + + } + } + + /** + * 调用Getter方法. + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static Object invokeGetterMethod(Object target, String propertyName) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException + { + String getterMethodName = "get" + StringUtils.capitalize(propertyName); + return invokeMethod(target, getterMethodName, new Class[] {}, + new Object[] {}); + } + + /** + * 直接调用对象方法, 无视private/protected修饰符. + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public static Object invokeMethod(final Object object, + final String methodName, final Class[] parameterTypes, + final Object[] parameters) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException{ + Method method = getDeclaredMethod(object, methodName, parameterTypes); + if (method == null) + { + throw new IllegalArgumentException("Could not find method [" + + methodName + "] parameterType " + parameterTypes + + " on target [" + object + "]"); + } + + method.setAccessible(true); + return method.invoke(object, parameters); + } + + /** + * 循环向上转型, 获取对象的DeclaredMethod. + * + * 如向上转型到Object仍无法找到, 返回null. + */ + protected static Method getDeclaredMethod(Object object, String methodName, + Class[] parameterTypes) + { + Assert.notNull(object, "object不能为空"); + + for (Class superClass = object.getClass(); superClass != Object.class; superClass = superClass + .getSuperclass()) + { + try{ + return superClass.getDeclaredMethod(methodName, parameterTypes); + } + catch (NoSuchMethodException e) + {// NOSONAR + // Method不在当前类定义,继续向上转型 + } + } + return null; + } +} diff --git a/src/com/engine/salary/component/WeaFormOption.java b/src/com/engine/salary/component/WeaFormOption.java new file mode 100644 index 000000000..75ec121af --- /dev/null +++ b/src/com/engine/salary/component/WeaFormOption.java @@ -0,0 +1,44 @@ +package com.engine.salary.component; + +import java.io.Serializable; + +public class WeaFormOption implements Serializable { + private static final long serialVersionUID = -4539753893868901626L; + private String id; + private String content; + private boolean disabled; + + public WeaFormOption() { + this.disabled = Boolean.FALSE; + } + + public WeaFormOption(String id, String content) { + this.disabled = Boolean.FALSE; + this.id = id; + this.content = content; + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getContent() { + return this.content; + } + + public void setContent(String content) { + this.content = content; + } + + public boolean isDisabled() { + return this.disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } +} diff --git a/src/com/engine/salary/demo/DemoController.java b/src/com/engine/salary/demo/DemoController.java index 05b0919a5..85d2a8abc 100644 --- a/src/com/engine/salary/demo/DemoController.java +++ b/src/com/engine/salary/demo/DemoController.java @@ -25,8 +25,9 @@ public class DemoController { @GET @Path("/list") - @Produces(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) public String list(@Context HttpServletRequest request, @Context HttpServletResponse response) { + new BaseBean().writeLog("page in ..."); User user = HrmUserVarify.getUser(request, response); return ResponseResult.run(getService(user)::list, ParamUtil.request2Map(request)); } diff --git a/src/com/engine/salary/demo/DemoPageCmd.java b/src/com/engine/salary/demo/DemoPageCmd.java index 6afdabd51..47ff70a46 100644 --- a/src/com/engine/salary/demo/DemoPageCmd.java +++ b/src/com/engine/salary/demo/DemoPageCmd.java @@ -5,9 +5,10 @@ import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; import com.engine.salary.mapper.DemoMapper; import com.engine.salary.util.page.PageInfo; -import com.engine.salary.util.page.PageUtil; +import com.github.pagehelper.PageHelper; import org.apache.ibatis.session.SqlSession; import weaver.conn.mybatis.MyBatisFactory; +import weaver.general.BaseBean; import weaver.hrm.User; import java.util.HashMap; @@ -32,10 +33,13 @@ public class DemoPageCmd extends AbstractCommonCommand> { SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); try { DemoMapper mapper = sqlSession.getMapper(DemoMapper.class); - PageUtil.start(2, 10); - List page = mapper.page(); - PageInfo pageInfo = new PageInfo<>(page, DemoPo.class); +// PageHelper.startPage(1,5); + com.github.pagehelper.PageInfo objectPageInfo = PageHelper.startPage(1, 1).doSelectPageInfo(mapper::page); + List list = objectPageInfo.getList(); + PageInfo pageInfo = new PageInfo<>(list, DemoPo.class); apidatas.put("pageInfo", pageInfo); + } catch (Exception e) { + new BaseBean().writeLog(e); } finally { sqlSession.close(); } diff --git a/src/com/engine/salary/entity/salaryitem/bo/SalaryItemBO.java b/src/com/engine/salary/entity/salaryitem/bo/SalaryItemBO.java index fc06065c2..c9d8921d4 100644 --- a/src/com/engine/salary/entity/salaryitem/bo/SalaryItemBO.java +++ b/src/com/engine/salary/entity/salaryitem/bo/SalaryItemBO.java @@ -1,46 +1,34 @@ -//package com.engine.salary.entity.salaryitem.bo; -// -//import com.baomidou.mybatisplus.core.conditions.Wrapper; -//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -//import com.baomidou.mybatisplus.core.toolkit.Wrappers; -//import com.engine.salary.constant.SalaryDefaultTenantConstant; -//import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam; -//import com.engine.salary.entity.salaryitem.po.SalaryItemPO; -//import com.engine.salary.enums.SalaryDataSourceEnum; -//import com.engine.salary.enums.SalaryRoundingModeEnum; -//import com.engine.salary.enums.SalarySystemTypeEnum; -//import com.engine.salary.enums.SalaryValueTypeEnum; -//import com.weaver.excel.formula.api.entity.ExpressFormula; -//import com.weaver.hrm.salary.entity.salaryitem.dto.SalaryItemFormDTO; -//import com.weaver.hrm.salary.entity.salaryitem.dto.SalaryItemListDTO; -//import com.weaver.hrm.salary.entity.salaryitem.param.SalaryItemSearchParam; -//import com.weaver.hrm.salary.enums.*; -//import com.weaver.hrm.salary.util.SalaryEntityUtil; -//import com.weaver.hrm.salary.util.SalaryI18nUtil; -//import org.apache.commons.lang3.StringUtils; -//import org.apache.commons.lang3.math.NumberUtils; -// -//import java.time.LocalDateTime; -//import java.util.*; -//import java.util.stream.Collectors; -// -///** -// * @description: 薪资项目 -// * @author: xiajun -// * @modified By: xiajun -// * @date: Created in 10/28/21 4:55 PM -// * @version:v1.0 -// */ -//public class SalaryItemBO { -// -// /** -// * 构建薪资项目的查询参数 -// * -// * @param searchParam -// * @param tenantKey -// * @return -// */ +package com.engine.salary.entity.salaryitem.bo; + +import com.engine.salary.constant.SalaryDefaultTenantConstant; +import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam; +import com.engine.salary.entity.salaryitem.po.SalaryItemPO; +import com.engine.salary.enums.SalaryDataSourceEnum; +import com.engine.salary.enums.SalaryRoundingModeEnum; +import com.engine.salary.enums.SalarySystemTypeEnum; +import com.engine.salary.enums.SalaryValueTypeEnum; +import org.apache.commons.lang3.math.NumberUtils; + +import java.util.Date; +import java.util.Objects; +import java.util.Optional; + +/** + * @description: 薪资项目 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 10/28/21 4:55 PM + * @version:v1.0 + */ +public class SalaryItemBO { + + /** + * 构建薪资项目的查询参数 + * + * @param searchParam + * @param tenantKey + * @return + */ // public static Wrapper buildQueryWrapper(SalaryItemSearchParam searchParam, String tenantKey) { // LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); // wrapper.eq(SalaryItemPO::getTenantKey, tenantKey) @@ -66,14 +54,14 @@ // wrapper.orderByDesc(SalaryItemPO::getId); // return wrapper; // } -// -// /** -// * 薪资项目po转换成薪资项目列表dto -// * -// * @param salaryItems 薪资项目po -// * @param expressFormulas 公式详情 -// * @return -// */ + + /** + * 薪资项目po转换成薪资项目列表dto + * + * @param salaryItems 薪资项目po + * @param expressFormulas 公式详情 + * @return + */ // public static List convert2ListDTO(Collection salaryItems, List expressFormulas) { // if (CollectionUtils.isEmpty(salaryItems)) { // return Collections.emptyList(); @@ -120,7 +108,7 @@ // } // ).collect(Collectors.toList()); // } -// + // /** // * 转换成薪资项目详情dto // * @@ -143,48 +131,47 @@ // .setDescription(salaryItemPO.getDescription()) // .setCanEdit(salaryItemPO.getCanEdit()); // } -// -// /** -// * 保存参数/更新参数 转换成薪资项目po -// * -// * @param saveParam 保存参数/更新参数 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// * @return -// */ -// public static SalaryItemPO convert2SalaryItemPO(SalaryItemSaveParam saveParam, Long employeeId) { -// Date now = new Date(); -//// long id = IdGenerator.generate(); -// SalaryItemPO salaryItemPO = SalaryItemPO.builder() -//// .id(id) -//// .code(String.valueOf(id)) -// .name(saveParam.getName()) -// .systemType(SalarySystemTypeEnum.CUSTOM.getValue()) -// .sysSalaryItemId(NumberUtils.LONG_ZERO) -// .category(saveParam.getCategory().getValue()) -// .itemType(saveParam.getItemType().getValue()) -// .useDefault(saveParam.getUseDefault()) -// .useInEmployeeSalary(saveParam.getUseInEmployeeSalary()) -// .roundingMode(Optional.ofNullable(saveParam.getRoundingMode()).map(SalaryRoundingModeEnum::getValue).orElse(SalaryRoundingModeEnum.ROUNDING.getValue())) -// .pattern(Optional.ofNullable(saveParam.getPattern()).orElse(2)) -// .valueType(saveParam.getValueType().getValue()) -// .datasource(saveParam.getValueType() == SalaryValueTypeEnum.INPUT ? SalaryDataSourceEnum.INPUT_IMPORT.getValue() : SalaryDataSourceEnum.CUSTOM_FORMULA.getValue()) -// .formulaId(saveParam.getValueType() == SalaryValueTypeEnum.FORMULA ? Optional.ofNullable(saveParam.getFormulaId()).orElse(NumberUtils.LONG_ZERO) : NumberUtils.LONG_ZERO) -// .description(saveParam.getDescription()) -// .canEdit(NumberUtils.INTEGER_ONE) -// .canDelete(NumberUtils.INTEGER_ONE) -// .creator(employeeId) -// .deleteType(NumberUtils.INTEGER_ZERO) -// .createTime(now) -// .updateTime(now) -// .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) -// .build(); -// // 开启了"薪资档案引用",取值方式固定为输入,数据来源固定为薪资档案 -// if (Objects.equals(saveParam.getUseInEmployeeSalary(), NumberUtils.INTEGER_ONE)) { -// salaryItemPO.setValueType(SalaryValueTypeEnum.INPUT.getValue()); -// salaryItemPO.setDatasource(SalaryDataSourceEnum.SALARY_ARCHIVES.getValue()); -// salaryItemPO.setFormulaId(NumberUtils.LONG_ZERO); -// } -// return salaryItemPO; -// } -//} + + /** + * 保存参数/更新参数 转换成薪资项目po + * + * @param saveParam 保存参数/更新参数 + * @param employeeId 人员id + * @return + */ + public static SalaryItemPO convert2SalaryItemPO(SalaryItemSaveParam saveParam, Long employeeId) { + Date now = new Date(); +// long id = IdGenerator.generate(); + SalaryItemPO salaryItemPO = SalaryItemPO.builder() +// .id(id) +// .code(String.valueOf(id)) + .name(saveParam.getName()) + .systemType(SalarySystemTypeEnum.CUSTOM.getValue()) + .sysSalaryItemId(NumberUtils.LONG_ZERO) + .category(saveParam.getCategory().getValue()) + .itemType(saveParam.getItemType().getValue()) + .useDefault(saveParam.getUseDefault()) + .useInEmployeeSalary(saveParam.getUseInEmployeeSalary()) + .roundingMode(Optional.ofNullable(saveParam.getRoundingMode()).map(SalaryRoundingModeEnum::getValue).orElse(SalaryRoundingModeEnum.ROUNDING.getValue())) + .pattern(Optional.ofNullable(saveParam.getPattern()).orElse(2)) + .valueType(saveParam.getValueType().getValue()) + .datasource(saveParam.getValueType() == SalaryValueTypeEnum.INPUT ? SalaryDataSourceEnum.INPUT_IMPORT.getValue() : SalaryDataSourceEnum.CUSTOM_FORMULA.getValue()) + .formulaId(saveParam.getValueType() == SalaryValueTypeEnum.FORMULA ? Optional.ofNullable(saveParam.getFormulaId()).orElse(NumberUtils.LONG_ZERO) : NumberUtils.LONG_ZERO) + .description(saveParam.getDescription()) + .canEdit(NumberUtils.INTEGER_ONE) + .canDelete(NumberUtils.INTEGER_ONE) + .creator(employeeId) + .deleteType(NumberUtils.INTEGER_ZERO) + .createTime(now) + .updateTime(now) + .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) + .build(); + // 开启了"薪资档案引用",取值方式固定为输入,数据来源固定为薪资档案 + if (Objects.equals(saveParam.getUseInEmployeeSalary(), NumberUtils.INTEGER_ONE)) { + salaryItemPO.setValueType(SalaryValueTypeEnum.INPUT.getValue()); + salaryItemPO.setDatasource(SalaryDataSourceEnum.SALARY_ARCHIVES.getValue()); + salaryItemPO.setFormulaId(NumberUtils.LONG_ZERO); + } + return salaryItemPO; + } +} diff --git a/src/com/engine/salary/entity/salaryitem/bo/SysSalaryItemBO.java b/src/com/engine/salary/entity/salaryitem/bo/SysSalaryItemBO.java index 7c8b5a710..8f3a0510d 100644 --- a/src/com/engine/salary/entity/salaryitem/bo/SysSalaryItemBO.java +++ b/src/com/engine/salary/entity/salaryitem/bo/SysSalaryItemBO.java @@ -1,38 +1,27 @@ -//package com.engine.salary.entity.salaryitem.bo; -// -//import com.baomidou.mybatisplus.core.conditions.Wrapper; -//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -//import com.baomidou.mybatisplus.core.toolkit.Wrappers; -//import com.engine.salary.entity.salaryitem.dto.SalaryItemFormDTO; -//import com.engine.salary.entity.salaryitem.po.SalaryItemPO; -//import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO; -//import com.engine.salary.enums.SalaryItemCategoryEnum; -//import com.engine.salary.enums.SalaryItemTypeEnum; -//import com.engine.salary.enums.SalarySystemTypeEnum; -//import com.engine.salary.enums.SalaryValueTypeEnum; -//import com.weaver.hrm.salary.constant.SalaryDefaultTenantConstant; -//import com.weaver.hrm.salary.entity.salaryitem.dto.SysSalaryItemListDTO; -//import com.weaver.hrm.salary.entity.salaryitem.param.SysSalaryItemSearchParam; -//import com.weaver.hrm.salary.enums.*; -//import com.weaver.hrm.salary.util.SalaryEntityUtil; -//import com.weaver.hrm.salary.util.SalaryI18nUtil; -//import org.apache.commons.collections4.CollectionUtils; -//import org.apache.commons.lang3.StringUtils; -//import org.apache.commons.lang3.math.NumberUtils; -// -//import java.time.LocalDateTime; -//import java.util.*; -//import java.util.stream.Collectors; -// -///** -// * @description: 系统薪资项目 -// * @author: xiajun -// * @modified By: xiajun -// * @date: Created in 11/2/21 1:30 PM -// * @version:v1.0 -// */ -//public class SysSalaryItemBO { -// +package com.engine.salary.entity.salaryitem.bo; + +import com.engine.salary.entity.salaryitem.dto.SysSalaryItemListDTO; +import com.engine.salary.entity.salaryitem.po.SalaryItemPO; +import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO; +import com.engine.salary.enums.*; +import com.engine.salary.util.SalaryI18nUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; + +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @description: 系统薪资项目 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 11/2/21 1:30 PM + * @version:v1.0 + */ +public class SysSalaryItemBO { + // /** // * 查询参数构建queryWrapper // * @@ -54,43 +43,43 @@ // wrapper.orderByDesc(SysSalaryItemPO::getId); // return wrapper; // } -// -// /** -// * 系统薪资项目po转换成系统薪资项目列表dto -// * -// * @param sysSalaryItems 系统薪资项目集合 -// * @return -// */ -// public static List convert2ListDTO(Collection sysSalaryItems) { -// if (CollectionUtils.isEmpty(sysSalaryItems)) { -// return Collections.emptyList(); -// } -// return sysSalaryItems.stream().map(sysSalaryItemPO -> { -// SalaryItemCategoryEnum salaryItemCategoryEnum = SalaryItemCategoryEnum.parseByValue(sysSalaryItemPO.getCategory()); -// SalaryItemTypeEnum salaryItemTypeEnum = SalaryItemTypeEnum.parseByValue(sysSalaryItemPO.getItemType()); -// SalaryRoundingModeEnum salaryRoundingModeEnum = SalaryRoundingModeEnum.parseByValue(sysSalaryItemPO.getRoundingMode()); -// SalaryValueTypeEnum salaryValueTypeEnum = SalaryValueTypeEnum.parseByValue(sysSalaryItemPO.getValueType()); -// return SysSalaryItemListDTO.builder() -// .id(sysSalaryItemPO.getId()) -// .name(sysSalaryItemPO.getName()) -// .category(Optional.ofNullable(salaryItemCategoryEnum) -// .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) -// .orElse(StringUtils.EMPTY)) -// .itemType(Optional.ofNullable(salaryItemTypeEnum) -// .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) -// .orElse(StringUtils.EMPTY)) -// .roundingMode(Optional.ofNullable(salaryRoundingModeEnum) -// .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) -// .orElse(StringUtils.EMPTY)) -// .pattern(sysSalaryItemPO.getPattern()) -// .valueType(Optional.ofNullable(salaryValueTypeEnum) -// .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) -// .orElse(StringUtils.EMPTY)) -// .build(); -// } -// ).collect(Collectors.toList()); -// } -// + + /** + * 系统薪资项目po转换成系统薪资项目列表dto + * + * @param sysSalaryItems 系统薪资项目集合 + * @return + */ + public static List convert2ListDTO(Collection sysSalaryItems) { + if (CollectionUtils.isEmpty(sysSalaryItems)) { + return Collections.emptyList(); + } + return sysSalaryItems.stream().map(sysSalaryItemPO -> { + SalaryItemCategoryEnum salaryItemCategoryEnum = SalaryItemCategoryEnum.parseByValue(sysSalaryItemPO.getCategory()); + SalaryItemTypeEnum salaryItemTypeEnum = SalaryItemTypeEnum.parseByValue(sysSalaryItemPO.getItemType()); + SalaryRoundingModeEnum salaryRoundingModeEnum = SalaryRoundingModeEnum.parseByValue(sysSalaryItemPO.getRoundingMode()); + SalaryValueTypeEnum salaryValueTypeEnum = SalaryValueTypeEnum.parseByValue(sysSalaryItemPO.getValueType()); + return SysSalaryItemListDTO.builder() + .id(sysSalaryItemPO.getId()) + .name(sysSalaryItemPO.getName()) + .category(Optional.ofNullable(salaryItemCategoryEnum) + .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) + .orElse(StringUtils.EMPTY)) + .itemType(Optional.ofNullable(salaryItemTypeEnum) + .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) + .orElse(StringUtils.EMPTY)) + .roundingMode(Optional.ofNullable(salaryRoundingModeEnum) + .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) + .orElse(StringUtils.EMPTY)) + .pattern(sysSalaryItemPO.getPattern()) + .valueType(Optional.ofNullable(salaryValueTypeEnum) + .map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())) + .orElse(StringUtils.EMPTY)) + .build(); + } + ).collect(Collectors.toList()); + } + // /** // * 转换成薪资项目详情dto // * @@ -113,62 +102,63 @@ // .setFormulaId(sysSalaryItemPO.getFormulaId()) // .setDescription(sysSalaryItemPO.getDescription()); // } -// -// /** -// * 系统薪资项目转换成自定义薪资项目 -// * -// * @param sysSalaryItems 系统薪资项目集合 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// * @return -// */ -// public static List convert2SalaryItemPO(Collection sysSalaryItems, Long employeeId, String tenantKey) { -// if (CollectionUtils.isEmpty(sysSalaryItems)) { -// return Collections.emptyList(); -// } -// LocalDateTime now = LocalDateTime.now(); -// return sysSalaryItems.stream() -// .map(e -> convert2SalaryItemPO(e, now, employeeId, tenantKey)) -// .filter(Objects::nonNull) -// .collect(Collectors.toList()); -// } -// -// /** -// * 系统薪资项目转换成自定义薪资项目 -// * -// * @param sysSalaryItemPO 系统薪资项目 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// * @return -// */ -// private static SalaryItemPO convert2SalaryItemPO(SysSalaryItemPO sysSalaryItemPO, LocalDateTime now, Long employeeId, String tenantKey) { -// if (sysSalaryItemPO == null) { -// return null; -// } -//// long id = IdGenerator.generate(); -// return SalaryItemPO.builder() -//// .id(id) -// .code(sysSalaryItemPO.getCode()) -// .name(sysSalaryItemPO.getName()) -// .systemType(SalarySystemTypeEnum.SYSTEM.getValue()) -// .sysSalaryItemId(sysSalaryItemPO.getId()) -// .category(sysSalaryItemPO.getCategory()) -// .itemType(sysSalaryItemPO.getItemType()) -// .useDefault(sysSalaryItemPO.getUseDefault()) -// .useInEmployeeSalary(sysSalaryItemPO.getUseInEmployeeSalary()) -// .roundingMode(sysSalaryItemPO.getRoundingMode()) -// .pattern(sysSalaryItemPO.getPattern()) -// .valueType(sysSalaryItemPO.getValueType()) -// .datasource(sysSalaryItemPO.getDatasource()) -// .formulaId(sysSalaryItemPO.getFormulaId()) -// .description(sysSalaryItemPO.getDescription()) -// .canEdit(sysSalaryItemPO.getCanEdit()) -// .canDelete(sysSalaryItemPO.getCanDelete()) -// .creator(employeeId) -// .deleteType(NumberUtils.INTEGER_ZERO) -// .createTime(now) -// .updateTime(now) -// .tenantKey(tenantKey) -// .build(); -// } -//} + + /** + * 系统薪资项目转换成自定义薪资项目 + * + * @param sysSalaryItems 系统薪资项目集合 + * @param employeeId 人员id + * @param tenantKey 租户key + * @return + */ + public static List convert2SalaryItemPO(Collection sysSalaryItems, Long employeeId, String tenantKey) { + if (CollectionUtils.isEmpty(sysSalaryItems)) { + return Collections.emptyList(); + } + LocalDateTime now = LocalDateTime.now(); + return sysSalaryItems.stream() + .map(e -> convert2SalaryItemPO(e, employeeId, tenantKey)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + /** + * 系统薪资项目转换成自定义薪资项目 + * + * @param sysSalaryItemPO 系统薪资项目 + * @param employeeId 人员id + * @param tenantKey 租户key + * @return + */ + private static SalaryItemPO convert2SalaryItemPO(SysSalaryItemPO sysSalaryItemPO, Long employeeId, String tenantKey) { + if (sysSalaryItemPO == null) { + return null; + } + Date now = new Date(); +// long id = IdGenerator.generate(); + return SalaryItemPO.builder() +// .id(id) + .code(sysSalaryItemPO.getCode()) + .name(sysSalaryItemPO.getName()) + .systemType(SalarySystemTypeEnum.SYSTEM.getValue()) + .sysSalaryItemId(sysSalaryItemPO.getId()) + .category(sysSalaryItemPO.getCategory()) + .itemType(sysSalaryItemPO.getItemType()) + .useDefault(sysSalaryItemPO.getUseDefault()) + .useInEmployeeSalary(sysSalaryItemPO.getUseInEmployeeSalary()) + .roundingMode(sysSalaryItemPO.getRoundingMode()) + .pattern(sysSalaryItemPO.getPattern()) + .valueType(sysSalaryItemPO.getValueType()) + .datasource(sysSalaryItemPO.getDatasource()) + .formulaId(sysSalaryItemPO.getFormulaId()) + .description(sysSalaryItemPO.getDescription()) + .canEdit(sysSalaryItemPO.getCanEdit()) + .canDelete(sysSalaryItemPO.getCanDelete()) + .creator(employeeId) + .deleteType(NumberUtils.INTEGER_ZERO) + .createTime(now) + .updateTime(now) + .tenantKey(tenantKey) + .build(); + } +} diff --git a/src/com/engine/salary/entity/salaryitem/param/SalaryItemSearchParam.java b/src/com/engine/salary/entity/salaryitem/param/SalaryItemSearchParam.java index 725d19256..25b2554b4 100644 --- a/src/com/engine/salary/entity/salaryitem/param/SalaryItemSearchParam.java +++ b/src/com/engine/salary/entity/salaryitem/param/SalaryItemSearchParam.java @@ -1,9 +1,6 @@ package com.engine.salary.entity.salaryitem.param; -import com.engine.salary.enums.SalaryItemCategoryEnum; -import com.engine.salary.enums.SalaryItemTypeEnum; -import com.engine.salary.enums.SalaryOnOffEnum; -import com.engine.salary.enums.SalaryValueTypeEnum; +import com.engine.salary.common.BaseQueryParam; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -12,39 +9,40 @@ import lombok.NoArgsConstructor; import java.util.Collection; /** - * @description: 薪资项目查询参数 - * @author: xiajun - * @modified By: xiajun - * @date: Created in 12/20/21 4:42 PM - * @version:v1.0 - */ + * 薪资项目查询参数 + *

Copyright: Copyright (c) 2022

+ *

Company: 泛微软件

+ * + * @author qiantao + * @version 1.0 + **/ @Data @Builder @NoArgsConstructor @AllArgsConstructor -public class SalaryItemSearchParam { +public class SalaryItemSearchParam extends BaseQueryParam { - //名称") + //名称@see private String name; - //备注") + //备注@see private String description; - //属性") - private SalaryItemCategoryEnum category; + //属性 SalaryItemCategoryEnum + private Integer category; - //分类") - private SalaryItemTypeEnum itemType; + //分类 @see SalaryItemTypeEnum + private Integer itemType; - //是否薪资档案引用") - private SalaryOnOffEnum useInEmployeeSalary; + //是否薪资档案引用@see SalaryOnOffEnum + private Integer useInEmployeeSalary; - //是否默认使用") - private SalaryOnOffEnum useDefault; + //是否默认使用@see SalaryOnOffEnum + private Integer useDefault; - //取值方式") - private SalaryValueTypeEnum valueType; + //取值方式@seeSalaryValueTypeEnum + private Integer valueType; - //需要排除的系统薪资项目") + //需要排除的系统薪资项目@see private Collection excludeIds; } diff --git a/src/com/engine/salary/entity/salarysob/po/SalarySobItemPO.java b/src/com/engine/salary/entity/salarysob/po/SalarySobItemPO.java new file mode 100644 index 000000000..7c14d2547 --- /dev/null +++ b/src/com/engine/salary/entity/salarysob/po/SalarySobItemPO.java @@ -0,0 +1,83 @@ +package com.engine.salary.entity.salarysob.po; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @description: 薪资账套薪资项目 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 11/9/21 10:50 AM + * @version:v1.0 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +//hrsa_salary_sob_item +public class SalarySobItemPO { + + /** + * 主键id + */ + private Long id; + + /** + * 薪资账套的id + */ + private Long salarySobId; + + /** + * 薪资项目的id + */ + private Long salaryItemId; + + /** + * 薪资账套薪资项目分组id + */ + private Long salarySobItemGroupId; + + /** + * 公式 + */ + private Long formulaId; + + /** + * 排序字段 + */ + private Integer sortedIndex; + + /** + * 备注 + */ + private String description; + + /** + * 租户key + */ + private String tenantKey; + + /** + * 创建人id + */ + private Long creator; + + /** + * 是否删除 + */ + private Integer deleteType; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; +} diff --git a/src/com/engine/salary/init.sql b/src/com/engine/salary/init.sql index f99793aed..dd2fe22cf 100644 --- a/src/com/engine/salary/init.sql +++ b/src/com/engine/salary/init.sql @@ -8,6 +8,9 @@ alter table hrsa_other_deduction modify id bigint auto_increment; alter table hrsa_attend_quote_field modify id bigint auto_increment; alter table hrsa_attend_quote_sync_set modify id bigint auto_increment; +alter table hrsa_salary_item modify id bigint auto_increment; + + --福利方案主键自增增加 alter table hrsa_social_security_scheme modify id bigint auto_increment; alter table hrsa_scheme_detail modify id bigint auto_increment; diff --git a/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.java b/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.java index aa0a625b0..0268f3ce6 100644 --- a/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.java +++ b/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.java @@ -1,5 +1,6 @@ package com.engine.salary.mapper.salaryitem; +import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import org.apache.ibatis.annotations.Param; @@ -59,5 +60,6 @@ public interface SalaryItemMapper { void batchInsert(Collection salaryItems); void deleteByIds(@Param("ids") Collection ids); - + + List listByParam(@Param("param") SalaryItemSearchParam param); } \ No newline at end of file diff --git a/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.xml b/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.xml index b89511da0..ed1237578 100644 --- a/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.xml +++ b/src/com/engine/salary/mapper/salaryitem/SalaryItemMapper.xml @@ -347,7 +347,7 @@ update_time, creator, delete_type, tenant_key) - select #{item.name}, #{item.code}, #{item.systemType}, #{item.sysSalaryItemId}, + select #{item.name}, #{item.code}, #{item.systemType}, #{item.sysSalaryItemId}, #{item.category}, #{item.itemType}, #{item.useDefault}, #{item.useInEmployeeSalary}, #{item.roundingMode}, #{item.pattern}, @@ -381,5 +381,103 @@ + + + + + AND name like CONCAT('%',#{param.name},'%') + + + AND description like CONCAT('%',#{param.description},'%') + + + AND id NOT IN + + #{id} + + + + AND category = #{param.category} + + + AND item_type = #{param.itemType} + + + AND use_in_employee_salary = #{param.useInEmployeeSalary} + + + AND use_default = #{param.useDefault} + + + AND value_type = #{param.valueType} + + + + + AND name like '%'||#{param.name}||'%' + + + AND description like '%'||#{param.description}||'%' + + + AND id NOT IN + + #{id} + + + + AND category = #{param.category} + + + AND item_type = #{param.itemType} + + + AND use_in_employee_salary = #{param.useInEmployeeSalary} + + + AND use_default = #{param.useDefault} + + + AND value_type = #{param.valueType} + + + + + AND name like '%'+#{param.name}+'%' + + + AND description like '%'+#{param.description}+'%' + + + AND id NOT IN + + #{id} + + + + AND category = #{param.category} + + + AND item_type = #{param.itemType} + + + AND use_in_employee_salary = #{param.useInEmployeeSalary} + + + AND use_default = #{param.useDefault} + + + AND value_type = #{param.valueType} + + + \ No newline at end of file diff --git a/src/com/engine/salary/service/SalaryItemService.java b/src/com/engine/salary/service/SalaryItemService.java index 9307ef047..a129d3b2b 100644 --- a/src/com/engine/salary/service/SalaryItemService.java +++ b/src/com/engine/salary/service/SalaryItemService.java @@ -1,7 +1,10 @@ package com.engine.salary.service; +import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam; +import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.enums.SalarySystemTypeEnum; +import com.github.pagehelper.PageInfo; import java.util.Collection; import java.util.List; @@ -76,41 +79,38 @@ public interface SalaryItemService { * 根据查询参数获取薪资项目(分页) * * @param searchParam 查询参数 - * @param tenantKey 租户key * @return */ -// Page listPageByParam(SalaryItemSearchParam searchParam, String tenantKey); + List listByParam(SalaryItemSearchParam searchParam); -// /** -// * 保存 -// * -// * @param saveParam 保存参数 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// */ -// void save(SalaryItemSaveParam saveParam, Long employeeId, String tenantKey); -// -// /** -// * 批量保存 -// * -// * @param salaryItemPOS 薪资项目 -// */ -// void batchSave(Collection salaryItemPOS); -// -// /** -// * 更新 -// * -// * @param saveParam 更新参数 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// */ -// void update(SalaryItemSaveParam saveParam, Long employeeId, String tenantKey); -// -// /** -// * 根据主键id删除薪资项目 -// * -// * @param ids 主键id -// * @param tenantKey 租户key -// */ -// void deleteByIds(Collection ids, String tenantKey); + PageInfo listPageByParam(SalaryItemSearchParam searchParam); + + + /** + * 保存 + * + * @param saveParam 保存参数 + */ + void save(SalaryItemSaveParam saveParam); + + /** + * 批量保存 + * + * @param salaryItemPOS 薪资项目 + */ + void batchSave(Collection salaryItemPOS); + + /** + * 更新 + * + * @param saveParam 更新参数 + */ + void update(SalaryItemSaveParam saveParam); + + /** + * 根据主键id删除薪资项目 + * + * @param ids 主键id + */ + void deleteByIds(Collection ids); } diff --git a/src/com/engine/salary/service/SalarySobItemService.java b/src/com/engine/salary/service/SalarySobItemService.java new file mode 100644 index 000000000..507b8ceb6 --- /dev/null +++ b/src/com/engine/salary/service/SalarySobItemService.java @@ -0,0 +1,103 @@ +package com.engine.salary.service; + +import com.engine.salary.entity.salarysob.po.SalarySobItemPO; + +import java.util.Collection; +import java.util.List; + +/** + * @description: 薪资账套的薪资项目副本 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 1/17/22 7:26 PM + * @version:v1.0 + */ +public interface SalarySobItemService { + + /** + * 查询所有薪资账套的薪资项目副本 + * + * @param tenantKey 租户key + * @return + */ + List list(); + + /** + * 根据薪资账套id查询薪资账套的薪资项目副本 + * + * @param salarySobId 薪资账套的id + * @param tenantKey 租户key + * @return + */ + List listBySalarySobId(Long salarySobId, String tenantKey); + + /** + * 根据薪资账套id查询薪资账套的薪资项目副本 + * + * @param salarySobIds 薪资账套的id + * @param tenantKey 租户key + * @return + */ + List listBySalarySobIds(Collection salarySobIds, String tenantKey); + + /** + * 根据薪资账套id、薪资项目id查询薪资账套的薪资项目副本 + * + * @param salarySobId 薪资账套id + * @param salaryItemIds 薪资项目id + * @param tenantKey 租户key + * @return + */ + List listBySalarySobIdAndSalaryItemIdNotIn(Long salarySobId, Collection salaryItemIds, String tenantKey); + + /** + * 根据薪资项目id查询薪资账套的薪资项目副本 + * + * @param salaryItemIds 薪资项目的主键id + * @param tenantKey 租户key + * @return + */ + List listBySalaryItemIds(Collection salaryItemIds, String tenantKey); + + /** + * 根据薪资账套id查询薪资账套的薪资项目副本所关联的薪资项目 + * + * @param salarySobId 薪资账套id + * @param tenantKey 租户key + * @return + */ +// List listBySalarySobId4SalaryItem(Long salarySobId, String tenantKey); + + /** + * 根据薪资账套id获取薪资账套的薪资项目聚合(员工信息、薪资项目副本、薪资项目分类) + * + * @param salarySobId + * @param tenantKey + * @return + */ +// SalarySobItemAggregateDTO getAggregateBySalarySobId(Long salarySobId, String tenantKey); + + /** + * 保存 + * + * @param saveParam 保存参数 + * @param employeeId 人员id + * @param tenantKey 租户key + */ +// void save(SalarySobItemSaveParam saveParam, Long employeeId, String tenantKey); + + /** + * 批量保存 + * + * @param salarySobItemPOS 薪资账套的薪资项目副本 + */ + void batchSave(Collection salarySobItemPOS); + + /** + * 根据薪资账套id删除薪资账套的薪资项目副本 + * + * @param salarySobIds 薪资账套的id + * @param tenantKey 租户key + */ + void deleteBySalarySobIds(Collection salarySobIds, String tenantKey); +} diff --git a/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java b/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java index 5772296c1..ade136b39 100644 --- a/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java @@ -2,14 +2,24 @@ package com.engine.salary.service.impl; import com.engine.core.impl.Service; import com.engine.salary.biz.SalaryItemBiz; +import com.engine.salary.biz.SysSalaryItemBiz; +import com.engine.salary.entity.salaryitem.bo.SalaryItemBO; +import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam; +import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; +import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO; +import com.engine.salary.enums.SalaryDataSourceEnum; import com.engine.salary.enums.SalarySystemTypeEnum; +import com.engine.salary.enums.SalaryValueTypeEnum; +import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.service.SalaryItemService; +import com.engine.salary.util.SalaryEntityUtil; +import com.engine.salary.util.SalaryI18nUtil; +import com.github.pagehelper.PageInfo; import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.BeanUtils; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * 薪资项目 @@ -21,22 +31,21 @@ import java.util.List; **/ public class SalaryItemServiceImpl extends Service implements SalaryItemService { - SalaryItemBiz salaryItemMapper; -// @Autowired + private SalaryItemBiz salaryItemBiz = new SalaryItemBiz(); + // @Autowired // private SalarySobItemService salarySobItemService; -// @Autowired -// private SysSalaryItemService sysSalaryItemService; + private SysSalaryItemBiz sysSalaryItemBiz = new SysSalaryItemBiz(); // @Autowired // private LoggerTemplate salaryItemLoggerTemplate; @Override public SalaryItemPO getById(Long id) { - return salaryItemMapper.getById(id); + return salaryItemBiz.getById(id); } @Override public List listAll() { - return salaryItemMapper.listAll(); + return salaryItemBiz.listAll(); } @Override @@ -44,7 +53,7 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService if (CollectionUtils.isEmpty(ids)) { return Collections.emptyList(); } - return salaryItemMapper.listSome(SalaryItemPO.builder().ids(ids).build()); + return salaryItemBiz.listSome(SalaryItemPO.builder().ids(ids).build()); } @Override @@ -52,22 +61,32 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService if (CollectionUtils.isEmpty(sysSalaryItemIds)) { return Collections.emptyList(); } - return salaryItemMapper.listSome(SalaryItemPO.builder().sysSalaryItemIds(sysSalaryItemIds).build()); + return salaryItemBiz.listSome(SalaryItemPO.builder().sysSalaryItemIds(sysSalaryItemIds).build()); } @Override public List listByName(String name) { - return salaryItemMapper.listSome(SalaryItemPO.builder().name(name).build()); + return salaryItemBiz.listSome(SalaryItemPO.builder().name(name).build()); } @Override public List listBySystemType(SalarySystemTypeEnum systemType) { - return salaryItemMapper.listSome(SalaryItemPO.builder().systemType(systemType.getValue()).build()); + return salaryItemBiz.listSome(SalaryItemPO.builder().systemType(systemType.getValue()).build()); } @Override public List listBySystemTypeAndUseDefault(SalarySystemTypeEnum systemType, Integer useDefault) { - return salaryItemMapper.listSome(SalaryItemPO.builder().systemType(systemType.getValue()).useDefault(useDefault).build()); + return salaryItemBiz.listSome(SalaryItemPO.builder().systemType(systemType.getValue()).useDefault(useDefault).build()); + } + + @Override + public List listByParam(SalaryItemSearchParam searchParam) { + return salaryItemBiz.listByParam(searchParam); + } + + @Override + public PageInfo listPageByParam(SalaryItemSearchParam searchParam) { + return salaryItemBiz.listPageByParam(searchParam); } // @Override @@ -77,25 +96,25 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService // // 构建查询参数 // Wrapper queryWrapper = SalaryItemBO.buildQueryWrapper(searchParam, tenantKey); // // 返回查询结果 -// return salaryItemMapper.selectPage(page, queryWrapper); +// return SalaryItemBiz.selectPage(page, queryWrapper); // } -// @Override -// public void save(SalaryItemSaveParam saveParam, Long employeeId) { -// // 名称不能和已有的自定义薪资项目重名 -// List salaryItemPOS = listByName(saveParam.getName()); -// if (CollectionUtils.isNotEmpty(salaryItemPOS)) { -// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98326, "薪资项目名称已存在,请重新命名")); -// } -// // 名称不能和已有的系统薪资项目重名 -// List sysSalaryItemPOS = sysSalaryItemService.listByName(saveParam.getName()); -// if (CollectionUtils.isNotEmpty(sysSalaryItemPOS)) { -// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98328, "自定义薪资项目的名称不能和系统薪资项目的名称重名")); -// } -// // 保存薪资项目 -// SalaryItemPO salaryItemPO = SalaryItemBO.convert2SalaryItemPO(saveParam, Long.valueOf(user.getUID())); -// salaryItemMapper.insert(salaryItemPO); -// // 记录日志 + @Override + public void save(SalaryItemSaveParam saveParam) { + // 名称不能和已有的自定义薪资项目重名 + List salaryItemPOS = listByName(saveParam.getName()); + if (CollectionUtils.isNotEmpty(salaryItemPOS)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98326, "薪资项目名称已存在,请重新命名")); + } + // 名称不能和已有的系统薪资项目重名 + List sysSalaryItemPOS = sysSalaryItemBiz.listSome(SysSalaryItemPO.builder().name(saveParam.getName()).build()); + if (CollectionUtils.isNotEmpty(sysSalaryItemPOS)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98328, "自定义薪资项目的名称不能和系统薪资项目的名称重名")); + } + // 保存薪资项目 + SalaryItemPO salaryItemPO = SalaryItemBO.convert2SalaryItemPO(saveParam, Long.valueOf(user.getUID())); + salaryItemBiz.insert(salaryItemPO); + // todo 记录日志 // LoggerContext loggerContext = new LoggerContext<>(); // loggerContext.setTargetId(String.valueOf(salaryItemPO.getId())); // loggerContext.setTargetName(salaryItemPO.getName()); @@ -104,53 +123,53 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService // loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(98329, "新建薪资项目") + ": " + salaryItemPO.getName()); // loggerContext.setNewValues(salaryItemPO); // salaryItemLoggerTemplate.write(loggerContext); -// } -// -// @Override -// public void batchSave(Collection salaryItemPOS) { -// salaryItemMapper.batchInsert(salaryItemPOS); -// } -// -// @Override -// public void update(SalaryItemSaveParam saveParam, Long employeeId, String tenantKey) { -// // 查询薪资项目,判断薪资项目是否存在 -// SalaryItemPO salaryItemPO = getById(saveParam.getId(), tenantKey); -// if (Objects.isNull(salaryItemPO)) { -// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除")); -// } -// // 名称不能和已有的自定义薪资项目重名 -// List salaryItemPOS = listByName(saveParam.getName(), tenantKey); -// boolean nameExist = salaryItemPOS.stream().anyMatch(e -> !Objects.equals(salaryItemPO.getId(), e.getId())); -// if (nameExist) { -// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98326, "薪资项目名称已存在,请重新命名")); -// } -// // 名称不能和已有的系统薪资项目重名 -// List sysSalaryItemPOS = sysSalaryItemService.listByName(saveParam.getName()); -// boolean sysNameExist = sysSalaryItemPOS.stream().anyMatch(e -> !Objects.equals(salaryItemPO.getSysSalaryItemId(), e.getId())); -// if (sysNameExist) { -// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98328, "自定义薪资项目的名称不能和系统薪资项目的名称重名")); -// } -// // 更新薪资项目 -// SalaryItemPO newSalaryItemPO = new SalaryItemPO(); -// BeanUtils.copyProperties(salaryItemPO, newSalaryItemPO); -// // 系统薪资项目的"属性"和"类型"不允许编辑 -// if (Objects.equals(newSalaryItemPO.getSystemType(), SalarySystemTypeEnum.CUSTOM.getValue())) { -// newSalaryItemPO.setCategory(saveParam.getCategory().getValue()); -// newSalaryItemPO.setItemType(saveParam.getItemType().getValue()); -// } -// newSalaryItemPO.setName(saveParam.getName()); -// newSalaryItemPO.setUseDefault(saveParam.getUseDefault()); -// newSalaryItemPO.setUseInEmployeeSalary(saveParam.getUseInEmployeeSalary()); -// newSalaryItemPO.setRoundingMode(saveParam.getRoundingMode().getValue()); -// newSalaryItemPO.setPattern(saveParam.getPattern()); -// newSalaryItemPO.setValueType(saveParam.getValueType().getValue()); -// newSalaryItemPO.setFormulaId(saveParam.getValueType() == SalaryValueTypeEnum.INPUT ? 0L : saveParam.getFormulaId()); -// newSalaryItemPO.setDatasource(saveParam.getValueType() == SalaryValueTypeEnum.INPUT ? SalaryDataSourceEnum.INPUT_IMPORT.getValue() -// : SalaryDataSourceEnum.CUSTOM_FORMULA.getValue()); -// newSalaryItemPO.setDescription(saveParam.getDescription()); -// newSalaryItemPO.setUpdateTime(LocalDateTime.now()); -// salaryItemMapper.updateById(newSalaryItemPO); -// // 记录日志 + } + + @Override + public void batchSave(Collection salaryItemPOS) { + salaryItemBiz.batchSave(salaryItemPOS); + } + + @Override + public void update(SalaryItemSaveParam saveParam) { + // 查询薪资项目,判断薪资项目是否存在 + SalaryItemPO salaryItemPO = getById(saveParam.getId()); + if (Objects.isNull(salaryItemPO)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除")); + } + // 名称不能和已有的自定义薪资项目重名 + List salaryItemPOS = listByName(saveParam.getName()); + boolean nameExist = salaryItemPOS.stream().anyMatch(e -> !Objects.equals(salaryItemPO.getId(), e.getId())); + if (nameExist) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98326, "薪资项目名称已存在,请重新命名")); + } + // 名称不能和已有的系统薪资项目重名 + List sysSalaryItemPOS = sysSalaryItemBiz.listSome(SysSalaryItemPO.builder().name(saveParam.getName()).build()); + boolean sysNameExist = sysSalaryItemPOS.stream().anyMatch(e -> !Objects.equals(salaryItemPO.getSysSalaryItemId(), e.getId())); + if (sysNameExist) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98328, "自定义薪资项目的名称不能和系统薪资项目的名称重名")); + } + // 更新薪资项目 + SalaryItemPO newSalaryItemPO = new SalaryItemPO(); + BeanUtils.copyProperties(salaryItemPO, newSalaryItemPO); + // 系统薪资项目的"属性"和"类型"不允许编辑 + if (Objects.equals(newSalaryItemPO.getSystemType(), SalarySystemTypeEnum.CUSTOM.getValue())) { + newSalaryItemPO.setCategory(saveParam.getCategory().getValue()); + newSalaryItemPO.setItemType(saveParam.getItemType().getValue()); + } + newSalaryItemPO.setName(saveParam.getName()); + newSalaryItemPO.setUseDefault(saveParam.getUseDefault()); + newSalaryItemPO.setUseInEmployeeSalary(saveParam.getUseInEmployeeSalary()); + newSalaryItemPO.setRoundingMode(saveParam.getRoundingMode().getValue()); + newSalaryItemPO.setPattern(saveParam.getPattern()); + newSalaryItemPO.setValueType(saveParam.getValueType().getValue()); + newSalaryItemPO.setFormulaId(saveParam.getValueType() == SalaryValueTypeEnum.INPUT ? 0L : saveParam.getFormulaId()); + newSalaryItemPO.setDatasource(saveParam.getValueType() == SalaryValueTypeEnum.INPUT ? SalaryDataSourceEnum.INPUT_IMPORT.getValue() + : SalaryDataSourceEnum.CUSTOM_FORMULA.getValue()); + newSalaryItemPO.setDescription(saveParam.getDescription()); + newSalaryItemPO.setUpdateTime(new Date()); + salaryItemBiz.updateById(newSalaryItemPO); + //todo 记录日志 // LoggerContext loggerContext = new LoggerContext<>(); // loggerContext.setTargetId(String.valueOf(newSalaryItemPO.getId())); // loggerContext.setTargetName(newSalaryItemPO.getName()); @@ -160,24 +179,24 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService // loggerContext.setOldValues(salaryItemPO); // loggerContext.setNewValues(newSalaryItemPO); // salaryItemLoggerTemplate.write(loggerContext); -// } -// -// @Override -// public void deleteByIds(Collection ids, String tenantKey) { -// // 查询薪资项目 -// List salaryItemPOS = listByIds(ids, tenantKey); -// if (CollectionUtils.isEmpty(salaryItemPOS)) { -// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除")); -// } -// // 查询薪资账套的薪资项目副本,被薪资账套引用的薪资项目不允许删除 + } + + @Override + public void deleteByIds(Collection ids) { + // 查询薪资项目 + List salaryItemPOS = listByIds(ids); + if (CollectionUtils.isEmpty(salaryItemPOS)) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除")); + } + // todo 查询薪资账套的薪资项目副本,被薪资账套引用的薪资项目不允许删除 // List salarySobItemPOS = salarySobItemService.listBySalaryItemIds(ids, tenantKey); // if (CollectionUtils.isNotEmpty(salarySobItemPOS)) { // throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98322, "薪资账套正在使用该薪资项目,不允许删除")); // } -// // 删除薪资项目 -// ids = SalaryEntityUtil.properties(salaryItemPOS, SalaryItemPO::getId); -// salaryItemMapper.deleteByIds(ids, tenantKey); -// // 记录删除日志 + // 删除薪资项目 + ids = SalaryEntityUtil.properties(salaryItemPOS, SalaryItemPO::getId); + salaryItemBiz.deleteByIds(ids); + //todo 记录删除日志 // salaryItemPOS.forEach(salaryItemPO -> { // LoggerContext loggerContext = new LoggerContext<>(); // loggerContext.setTargetId(String.valueOf(salaryItemPO.getId())); @@ -188,5 +207,5 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService // loggerContext.setOldValues(salaryItemPO); // salaryItemLoggerTemplate.write(loggerContext); // }); -// } + } } diff --git a/src/com/engine/salary/service/impl/SysSalaryItemServiceImpl.java b/src/com/engine/salary/service/impl/SysSalaryItemServiceImpl.java index d46761229..e4b55eec2 100644 --- a/src/com/engine/salary/service/impl/SysSalaryItemServiceImpl.java +++ b/src/com/engine/salary/service/impl/SysSalaryItemServiceImpl.java @@ -3,6 +3,7 @@ package com.engine.salary.service.impl; import com.engine.core.impl.Service; import com.engine.salary.biz.SalaryItemBiz; import com.engine.salary.biz.SysSalaryItemBiz; +import com.engine.salary.entity.salaryitem.bo.SysSalaryItemBO; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO; import com.engine.salary.enums.SalarySystemTypeEnum; @@ -80,8 +81,8 @@ public class SysSalaryItemServiceImpl extends Service implements SysSalaryItemSe throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98350, "已经添加过的系统薪资项目不能重复添加")); } // 保存 -// List salaryItems = SysSalaryItemBO.convert2SalaryItemPO(sysSalaryItemPOS, employeeId, tenantKey); -// salaryItemService.batchSave(salaryItems); + List salaryItems = SysSalaryItemBO.convert2SalaryItemPO(sysSalaryItemPOS, employeeId, tenantKey); + salaryItemService.batchSave(salaryItems); //todo 记录日志 // sysSalaryItemPOS.forEach(sysSalaryItemPO -> { // LoggerContext loggerContext = new LoggerContext<>(); diff --git a/src/com/engine/salary/util/ResponseResult.java b/src/com/engine/salary/util/ResponseResult.java index 4b5895590..0936c0584 100644 --- a/src/com/engine/salary/util/ResponseResult.java +++ b/src/com/engine/salary/util/ResponseResult.java @@ -9,7 +9,9 @@ import weaver.general.BaseBean; import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; public class ResponseResult { @@ -77,6 +79,48 @@ public class ResponseResult { } } + /** + * 统一返回方法(有参无返回) + */ + public String run(Consumer f, T t) { + try { + f.accept(t); + return Ok(); + } catch (SalaryRunTimeException e) { + return Error(e.getMessage()); + } catch (ECException e) { + BaseBean b = new BaseBean(); + b.writeLog(e); + Throwable cause = e.getCause(); + return Error(cause.getMessage()); + } catch (Exception e) { + BaseBean b = new BaseBean(); + b.writeLog(e); + return Error(e.getMessage()); + } + } + + + /** + * 统一返回方法(无参有返回) + */ + public String run(Supplier f) { + try { + return Ok(f.get()); + } catch (SalaryRunTimeException e) { + return Error(e.getMessage()); + } catch (ECException e) { + BaseBean b = new BaseBean(); + b.writeLog(e); + Throwable cause = e.getCause(); + return Error(cause.getMessage()); + } catch (Exception e) { + BaseBean b = new BaseBean(); + b.writeLog(e); + return Error(e.getMessage()); + } + } + /** * 成功返回 */ @@ -88,4 +132,14 @@ public class ResponseResult { } + /** + * 成功返回 + */ + private String Ok() { + Map apidatas = new HashMap<>(); + apidatas.put("status", true); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + + } diff --git a/src/com/engine/salary/web/SalaryItemController.java b/src/com/engine/salary/web/SalaryItemController.java index b2151ad9a..8731ddae6 100644 --- a/src/com/engine/salary/web/SalaryItemController.java +++ b/src/com/engine/salary/web/SalaryItemController.java @@ -1,5 +1,25 @@ package com.engine.salary.web; +import com.engine.common.util.ServiceUtil; +import com.engine.salary.component.WeaFormOption; +import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; +import com.engine.salary.util.ResponseResult; +import com.engine.salary.wrapper.SalaryItemWrapper; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import weaver.hrm.HrmUserVarify; +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.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.List; +import java.util.Map; + /** * 薪资项目 *

Copyright: Copyright (c) 2022

@@ -10,20 +30,26 @@ package com.engine.salary.web; **/ public class SalaryItemController { -// @Autowired -// private SalaryItemWrapper salaryItemWrapper; + private SalaryItemWrapper getSalaryItemWrapper(User user) { + return ServiceUtil.getService(SalaryItemWrapper.class, user); + } + // @Autowired // private SysSalaryItemWrapper sysSalaryItemWrapper; // // /**********************************自定义薪资项目 start*********************************/ -// -// @PostMapping("/list") -// @ApiOperation("薪资项目列表") -// @WeaPermission -// public WeaResult> listSalaryItem(@RequestBody SalaryItemSearchParam searchParam) { -// return WeaResult.success(salaryItemWrapper.listPage(searchParam, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey())); -// } -// + + /** + * 薪资项目列表 + */ + @POST + @Path("/list") + @Produces(MediaType.APPLICATION_JSON) + public String listSalaryItem(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryItemSearchParam searchParam) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult>().run(getSalaryItemWrapper(user)::listPage, searchParam); + } + // @PostMapping("/listCanDelete") // @ApiOperation("可删除的薪资项目列表") // @WeaPermission @@ -56,13 +82,19 @@ public class SalaryItemController { // return WeaResult.success(salaryItemWrapper.getForm(id, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey())); // } // -// @GetMapping("/listSalaryItemTypeOption") -// @ApiOperation("获取薪资项目可选的类型(与属性有联动)") -// @WeaPermission -// public WeaResult>> listSalaryItemTypeOption() { -// Map> resultMap = salaryItemWrapper.listSalaryItemTypeOption(UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey()); -// return WeaResult.success(resultMap); -// } + + /** + * "获取薪资项目可选的类型(与属性有联动)" + * + * @return + */ + @GET + @Path("/listSalaryItemTypeOption") + @Produces(MediaType.APPLICATION_JSON) + public String listSalaryItemTypeOption(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult>>().run(getSalaryItemWrapper(user)::listSalaryItemTypeOption); + } // // @PostMapping("/delete") // @ApiOperation("批量删除薪资项目") diff --git a/src/com/engine/salary/wrapper/SalaryItemWrapper.java b/src/com/engine/salary/wrapper/SalaryItemWrapper.java index 4a55e3e79..045c0ff14 100644 --- a/src/com/engine/salary/wrapper/SalaryItemWrapper.java +++ b/src/com/engine/salary/wrapper/SalaryItemWrapper.java @@ -1,71 +1,55 @@ -//package com.engine.salary.wrapper; -// -//import com.engine.salary.entity.salaryitem.dto.SalaryItemListDTO; -//import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam; -//import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; -//import com.engine.salary.entity.salaryitem.po.SalaryItemPO; -//import com.google.common.collect.Lists; -//import com.weaver.common.component.form.WeaForm; -//import com.weaver.common.component.form.item.WeaFormItem; -//import com.weaver.common.component.form.item.WeaFormOption; -//import com.weaver.common.component.search.WeaSearchCondition; -//import com.weaver.common.component.table.WeaTable; -//import com.weaver.common.component.table.page.Page; -//import com.weaver.common.component.table.permission.Permission; -//import com.weaver.common.component.table.type.WeaTableTypeEnum; -//import com.weaver.excel.formula.api.entity.ExpressFormula; -//import com.weaver.hrm.salary.entity.salaryitem.bo.SalaryItemBO; -//import com.weaver.hrm.salary.entity.salaryitem.bo.SysSalaryItemBO; -//import com.weaver.hrm.salary.entity.salaryitem.dto.SalaryItemFormDTO; -//import com.weaver.hrm.salary.entity.salaryitem.dto.SalaryItemSearchConditionDTO; -//import com.weaver.hrm.salary.entity.salaryitem.po.SysSalaryItemPO; -//import com.weaver.hrm.salary.entity.salarysob.po.SalarySobItemPO; -//import com.weaver.hrm.salary.enums.SalaryItemTypeEnum; -//import com.weaver.hrm.salary.exception.SalaryRunTimeException; -//import com.weaver.hrm.salary.service.SalaryFormulaService; -//import com.weaver.hrm.salary.service.SalaryItemService; -//import com.weaver.hrm.salary.service.SalarySobItemService; -//import com.weaver.hrm.salary.service.SysSalaryItemService; -//import com.weaver.hrm.salary.util.SalaryEntityUtil; -//import com.weaver.hrm.salary.util.SalaryFormatUtil; -//import com.weaver.hrm.salary.util.SalaryI18nUtil; -//import org.apache.commons.collections4.CollectionUtils; -//import org.apache.commons.lang3.math.NumberUtils; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Component; -// -//import java.util.*; -// -///** -// * @description: 薪资项目 -// * @author: xiajun -// * @modified By: xiajun -// * @date: Created in 1/17/22 4:00 PM -// * @version:v1.0 -// */ -//@Component -//public class SalaryItemWrapper { -// -// @Autowired -// private SalaryItemService salaryItemService; -// @Autowired -// private SalaryFormulaService salaryFormulaService; -// @Autowired -// private SalarySobItemService salarySobItemService; -// @Autowired -// private SysSalaryItemService sysSalaryItemService; -// -// /** -// * 薪资项目列表 -// * -// * @param searchParam 查询参数 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// * @return -// */ -// public WeaTable listPage(SalaryItemSearchParam searchParam, Long employeeId, String tenantKey) { -// // 查询薪资项目 -// Page page = salaryItemService.listPageByParam(searchParam, tenantKey); +package com.engine.salary.wrapper; + +import com.engine.common.util.ServiceUtil; +import com.engine.core.impl.Service; +import com.engine.salary.component.WeaFormOption; +import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam; +import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam; +import com.engine.salary.entity.salaryitem.po.SalaryItemPO; +import com.engine.salary.enums.SalaryItemTypeEnum; +import com.engine.salary.service.SalaryItemService; +import com.engine.salary.service.SalarySobItemService; +import com.engine.salary.service.SysSalaryItemService; +import com.engine.salary.service.impl.SalaryItemServiceImpl; +import com.engine.salary.util.SalaryEntityUtil; +import com.engine.salary.util.SalaryI18nUtil; +import com.github.pagehelper.PageInfo; +import weaver.hrm.User; + +import java.util.*; + +/** + * 薪资项目 + *

Copyright: Copyright (c) 2022

+ *

Company: 泛微软件

+ * + * @author qiantao + * @version 1.0 + **/ +public class SalaryItemWrapper extends Service { + + private SalaryItemService salaryItemService; + private SalaryItemService getSalaryItemService(User user) { + return (SalaryItemService)ServiceUtil.getService(SalaryItemServiceImpl.class, user); + } + + + // private SalaryFormulaService salaryFormulaService; + private SalarySobItemService salarySobItemService; + private SysSalaryItemService sysSalaryItemService; + + /** + * 薪资项目列表 + * + * @param searchParam 查询参数 + * @return + */ + public Map listPage(SalaryItemSearchParam searchParam) { + // 查询薪资项目 + PageInfo page = getSalaryItemService(user).listPageByParam(searchParam); + Map objectObjectHashMap = new HashMap<>(); + objectObjectHashMap.put("a",page); + return objectObjectHashMap; // Page dtoPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal(), page.isSearchCount()); // // 被薪资账套引用的薪资项目 // List salarySobItems = Lists.newArrayListWithExpectedSize((int) page.getSize()); @@ -94,8 +78,8 @@ // } // } // return weaTable; -// } -// + } + // /** // * 可以删除的薪资项目列表 // * @@ -104,15 +88,15 @@ // * @param tenantKey 租户key // * @return // */ -// public WeaTable listPage4CanDelete(SalaryItemSearchParam searchParam, Long employeeId, String tenantKey) { +// public WeaTable listPage4CanDelete(SalaryItemSearchParam searchParam) { // // 查询所有薪资账套中的薪资项目副本 -// List salarySobItemPOS = salarySobItemService.list(tenantKey); +// List salarySobItemPOS = salarySobItemService.list(); // // 被引用的薪资项目id // Set salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId); // // 排除被引用的薪资项目(被引用的薪资项目不可以删除) // searchParam.setExcludeIds(salaryItemIds); // // 转换成前端所需的数据格式 -// WeaTable weaTable = listPage(searchParam, employeeId, tenantKey); +// WeaTable weaTable = listPage(searchParam); // weaTable.setTableType(WeaTableTypeEnum.CHECKBOX); // weaTable.setOperates(Collections.emptyList()); // weaTable.setPageUid("canDeleteSalaryItemList"); @@ -200,49 +184,43 @@ // } // return weaForm; // } -// -// /** -// * 获取薪资项目可选的类型(与属性有联动) -// * -// * @param employeeId 人员id -// * @param tenantKey 租户key -// * @return -// */ -// public Map> listSalaryItemTypeOption(Long employeeId, String tenantKey) { -// return SalaryEntityUtil.group2ListMap(Arrays.asList(SalaryItemTypeEnum.values()), -// e -> e.getCategory().name(), -// e -> new WeaFormOption(e.name(), SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, e.getLabelId(), e.getDefaultLabel()))); -// } -// -// /** -// * 保存薪资项目 -// * -// * @param saveParam 保存参数 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// */ -// public void save(SalaryItemSaveParam saveParam, Long employeeId, String tenantKey) { -// salaryItemService.save(saveParam, employeeId, tenantKey); -// } -// -// /** -// * 编辑薪资项目 -// * -// * @param saveParam 更新参数 -// * @param employeeId 人员id -// * @param tenantKey 租户key -// */ -// public void update(SalaryItemSaveParam saveParam, Long employeeId, String tenantKey) { -// salaryItemService.update(saveParam, employeeId, tenantKey); -// } -// -// /** -// * 删除薪资项目 -// * -// * @param ids 主键id -// * @param tenantKey 租户key -// */ -// public void delete(Collection ids, String tenantKey) { -// salaryItemService.deleteByIds(ids, tenantKey); -// } -//} + + /** + * 获取薪资项目可选的类型(与属性有联动) + * + * @return + */ + public Map> listSalaryItemTypeOption() { + return SalaryEntityUtil.group2ListMap(Arrays.asList(SalaryItemTypeEnum.values()), + e -> e.getCategory().name(), + e -> new WeaFormOption(e.name(), SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel()))); + } + + /** + * 保存薪资项目 + * + * @param saveParam 保存参数 + */ + public void save(SalaryItemSaveParam saveParam) { + salaryItemService.save(saveParam); + } + + /** + * 编辑薪资项目 + * + * @param saveParam 更新参数 + */ + public void update(SalaryItemSaveParam saveParam) { + salaryItemService.update(saveParam); + } + + /** + * 删除薪资项目 + * + * @param ids 主键id + * @param tenantKey 租户key + */ + public void delete(Collection ids, String tenantKey) { + salaryItemService.deleteByIds(ids); + } +}