commit 4a081d6ad9caf13041aa4fcb24f1073295e0dc40 Author: 钱涛 <15850646081@163.com> Date: Fri Feb 25 19:41:22 2022 +0800 初始化项目结构、demo样例、mybatis使用样例 diff --git a/src/com/api/salary/web/DemoController.java b/src/com/api/salary/web/DemoController.java new file mode 100644 index 000000000..4b7179e8c --- /dev/null +++ b/src/com/api/salary/web/DemoController.java @@ -0,0 +1,7 @@ +package com.api.salary.web; + +import javax.ws.rs.Path; + +@Path("/bs/hrmsalary/demo") +public class DemoController extends com.engine.salary.web.DemoController{ +} diff --git a/src/com/api/salary/web/TaxAgentController.java b/src/com/api/salary/web/TaxAgentController.java new file mode 100644 index 000000000..2e699c1e8 --- /dev/null +++ b/src/com/api/salary/web/TaxAgentController.java @@ -0,0 +1,7 @@ +package com.api.salary.web; + +import javax.ws.rs.Path; + +@Path("/bs/hrmsalary/taxAgent") +public class TaxAgentController extends com.engine.salary.web.TaxAgentController{ +} diff --git a/src/com/api/salary/web/TaxRateController.java b/src/com/api/salary/web/TaxRateController.java new file mode 100644 index 000000000..9cb45a9be --- /dev/null +++ b/src/com/api/salary/web/TaxRateController.java @@ -0,0 +1,7 @@ +package com.api.salary.web; + +import javax.ws.rs.Path; + +@Path("/bs/hrmsalary/taxrate") +public class TaxRateController extends com.engine.salary.web.TaxRateController{ +} diff --git a/src/com/engine/salary/annotation/TableTitle.java b/src/com/engine/salary/annotation/TableTitle.java new file mode 100644 index 000000000..6f96beeb1 --- /dev/null +++ b/src/com/engine/salary/annotation/TableTitle.java @@ -0,0 +1,12 @@ +package com.engine.salary.annotation; + +import java.lang.annotation.*; + +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface TableTitle { + String title(); + String dataIndex(); + String key(); +} diff --git a/src/com/engine/salary/cmd/TaxAgent/TaxAgentGetFromCmd.java b/src/com/engine/salary/cmd/TaxAgent/TaxAgentGetFromCmd.java new file mode 100644 index 000000000..f90fcab85 --- /dev/null +++ b/src/com/engine/salary/cmd/TaxAgent/TaxAgentGetFromCmd.java @@ -0,0 +1,79 @@ +package com.engine.salary.cmd.TaxAgent; + +import com.api.browser.bean.SearchConditionGroup; +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.util.ConditionFactory; +import com.api.browser.util.ConditionType; +import com.cloudstore.eccom.constant.WeaBoolAttr; +import com.cloudstore.eccom.pc.table.WeaTable; +import com.cloudstore.eccom.pc.table.WeaTableColumn; +import com.cloudstore.eccom.result.WeaResultMsg; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.PageIdConst; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +public class TaxAgentGetFromCmd extends AbstractCommonCommand> { + + public TaxAgentGetFromCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + //定义返回数据 + Map apidatas = new HashMap(); + + if (null == user) { + apidatas.put("hasRight", false); + return apidatas; + } + apidatas.put("hasRight", true); + + ConditionFactory conditionFactory = new ConditionFactory(user); + + List addGroups = new ArrayList(); + List inputItems = new ArrayList(); + + //名称 + SearchConditionItem nameInput = conditionFactory.createCondition(ConditionType.INPUT, 502327, "name"); + nameInput.setColSpan(1);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 + nameInput.setFieldcol(12); //条件输入框所占宽度,默认值18 + nameInput.setViewAttr(3); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 + nameInput.setLength(10); // 设置输入长度 + nameInput.setLabel("名称"); //设置文本值 这个将覆盖多语言标签的值 + nameInput.setRules("required"); //设置字段填入规则 + inputItems.add(nameInput); + + //描述 + SearchConditionItem descriptionInput = conditionFactory.createCondition(ConditionType.INPUT, 502327, "description"); + descriptionInput.setColSpan(1);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 + descriptionInput.setFieldcol(12); //条件输入框所占宽度,默认值18 + descriptionInput.setViewAttr(3); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 + descriptionInput.setLength(10); // 设置输入长度 + descriptionInput.setLabel("描述"); //设置文本值 这个将覆盖多语言标签的值 + inputItems.add(nameInput); + + + addGroups.add(new SearchConditionGroup("", true, inputItems)); + + apidatas.put("condition", addGroups ); + + return apidatas; + } + + +} diff --git a/src/com/engine/salary/cmd/TaxAgent/TaxAgentListCmd.java b/src/com/engine/salary/cmd/TaxAgent/TaxAgentListCmd.java new file mode 100644 index 000000000..55fd6bff6 --- /dev/null +++ b/src/com/engine/salary/cmd/TaxAgent/TaxAgentListCmd.java @@ -0,0 +1,101 @@ +package com.engine.salary.cmd.TaxAgent; + +import com.cloudstore.eccom.constant.WeaBoolAttr; +import com.cloudstore.eccom.pc.table.WeaTable; +import com.cloudstore.eccom.pc.table.WeaTableColumn; +import com.cloudstore.eccom.result.WeaResultMsg; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.PageIdConst; +import weaver.hrm.User; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class TaxAgentListCmd extends AbstractCommonCommand> { + + public TaxAgentListCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + + Map apidatas = new HashMap(16); + + WeaResultMsg result = new WeaResultMsg(false); + String pageID = "a4f85287-e3f9-4275-ab18-7d06e54y6rj8"; + String pageUid = pageID + "_" + user.getUID(); + String pageSize = PageIdConst.getPageSize(pageID, user.getUID()); + + + String fileds = "id, name, description, create_time, update_time, creator, delete_type, tenant_key"; + String fromSql = "FROM hrsa_tax_agent"; + String sqlWhere = makeSqlWhere(params); + WeaTable table = new WeaTable(); + table.setPageUID(pageUid); + table.setPageID(pageID); + table.setPagesize(pageSize); + table.setBackfields(fileds); + table.setSqlform(fromSql); + table.setSqlwhere(sqlWhere); + table.setSqlorderby("id desc"); + table.setSqlprimarykey("id"); + table.setSqlisdistinct("false"); + + table.getColumns().add(new WeaTableColumn("id").setDisplay(WeaBoolAttr.FALSE)); + table.getColumns().add(new WeaTableColumn("40%", "个税扣缴义务人名称", "description", "")); + table.getColumns().add(new WeaTableColumn("40%", "备注", "description", "")); + + //设置check是否可用 + table.setCheckboxList(null); + table.setCheckboxpopedom(null); + result.putAll(table.makeDataResult()); + result.success(); + apidatas = result.getResultMap(); + return apidatas; + } + + /** + * sql条件 + * @param params + * @return + */ + private String makeSqlWhere(Map params) { + + RecordSet rs = new RecordSet(); + StringBuilder sqlWhere = new StringBuilder("where 1 = 1"); + Collection ids = (Collection) params.get("ids"); + if (CollectionUtils.isNotEmpty(ids)) { + sqlWhere.append(" AND id in (").append(String.join(",", ids)).append(")"); + } + //模糊查询 + String name = (String) params.get("name"); + if (StringUtils.isNotBlank(name)) { + if ("mysql".equalsIgnoreCase(rs.getDBType())) { + sqlWhere.append(" AND name like CONCAT('%',").append(name).append(",'%') "); + } else if ("sqlserver".equalsIgnoreCase(rs.getDBType())) { + sqlWhere.append(" AND name like CONCAT('%',").append(name).append(",'%') "); + } else if ("oracle".equalsIgnoreCase(rs.getDBType())) { + sqlWhere.append(" AND name like '%'||").append(name).append("||'%' "); + } else { + sqlWhere.append(" AND name like '%'").append(name).append("'%' "); + } + } + + return sqlWhere.toString(); + } + + +} diff --git a/src/com/engine/salary/cmd/TaxAgent/TaxAgentSaveCmd.java b/src/com/engine/salary/cmd/TaxAgent/TaxAgentSaveCmd.java new file mode 100644 index 000000000..8763f4c92 --- /dev/null +++ b/src/com/engine/salary/cmd/TaxAgent/TaxAgentSaveCmd.java @@ -0,0 +1,55 @@ +package com.engine.salary.cmd.TaxAgent; + +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.salary.entity.salaryarchive.bo.TaxAgentBO; +import com.engine.salary.entity.salaryarchive.po.TaxAgentPO; +import com.engine.salary.entity.taxrate.TaxAgent; +import com.engine.salary.exception.SalaryRunTimeException; +import com.engine.salary.mapper.TaxAgentMapper; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.ibatis.session.SqlSession; +import weaver.conn.mybatis.MyBatisFactory; +import weaver.general.Util; +import weaver.hrm.User; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TaxAgentSaveCmd extends AbstractCommonCommand> { + + public TaxAgentSaveCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + Map apidatas = new HashMap(16); + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + TaxAgentMapper mapper = sqlSession.getMapper(TaxAgentMapper.class); + + List list = mapper.listByName(Util.null2String(this.params.get("name"))); + if (CollectionUtils.isNotEmpty(list)) { + throw new SalaryRunTimeException("名称不允许重复"); + } + + TaxAgent taxAgent = TaxAgentBO.convertToPO(params, (long) user.getUID()); + mapper.insert(taxAgent); + + } finally { + sqlSession.close(); + } + return apidatas; + } + + +} diff --git a/src/com/engine/salary/cmd/TaxAgent/TaxAgentUpdateCmd.java b/src/com/engine/salary/cmd/TaxAgent/TaxAgentUpdateCmd.java new file mode 100644 index 000000000..c2b8fcf6c --- /dev/null +++ b/src/com/engine/salary/cmd/TaxAgent/TaxAgentUpdateCmd.java @@ -0,0 +1,82 @@ +package com.engine.salary.cmd.TaxAgent; + +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.salary.entity.salaryarchive.po.TaxAgentPO; +import com.engine.salary.entity.taxrate.TaxAgent; +import com.engine.salary.exception.SalaryRunTimeException; +import com.engine.salary.mapper.TaxAgentMapper; +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.session.SqlSession; +import org.springframework.beans.BeanUtils; +import weaver.conn.mybatis.MyBatisFactory; +import weaver.general.Util; +import weaver.hrm.User; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class TaxAgentUpdateCmd extends AbstractCommonCommand> { + + public TaxAgentUpdateCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + Map apidatas = new HashMap(16); + String name = Util.null2String(params.get("name")); + if (StringUtils.isBlank(name)) { + throw new SalaryRunTimeException("名称必填"); + } + if (params.get("id") == null) { + throw new SalaryRunTimeException("参数错误"); + } + + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + TaxAgentMapper taxAgentMapper = sqlSession.getMapper(TaxAgentMapper.class); + + TaxAgent taxAgent = taxAgentMapper.getById((Long) params.get("id")); + if (taxAgent == null) { + throw new SalaryRunTimeException("个税扣缴义务人不存在"); + } + List individualTaxWithholdingAgents = taxAgentMapper.listByName(name); + boolean nameExist = individualTaxWithholdingAgents.stream().anyMatch(e -> !Objects.equals(e.getId(), (Long)params.get("id"))); + if (nameExist) { + throw new SalaryRunTimeException("名称不允许重复"); + } + + TaxAgent taxAgentNew = new TaxAgent(); + BeanUtils.copyProperties(taxAgent, taxAgentNew); + taxAgentNew.setName(name); + taxAgentNew.setDescription(Util.null2String(params.get("description"))); + taxAgentNew.setUpdateTime(LocalDateTime.now()); + + taxAgentMapper.updateIgnoreNull(taxAgentNew); + +// taxAgentMapper.updateById(taxAgentNew); +// // 记录日志 +// SalaryLoggerUtil.recordUpdateSingleLog(taxAgentLoggerTemplate, +// taxAgent.getId(), +// taxAgentNew.getName(), +// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 93767, "编辑个税扣缴义务人"), +// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 93767, "编辑个税扣缴义务人"), +// taxAgent, +// taxAgentNew); + + + return apidatas; + } + + +} diff --git a/src/com/engine/salary/cmd/demo/DemoPageCmd.java b/src/com/engine/salary/cmd/demo/DemoPageCmd.java new file mode 100644 index 000000000..575d6d15c --- /dev/null +++ b/src/com/engine/salary/cmd/demo/DemoPageCmd.java @@ -0,0 +1,47 @@ +package com.engine.salary.cmd.demo; + +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.salary.entity.DemoPo; +import com.engine.salary.mapper.DemoMapper; +import com.engine.salary.util.page.PageInfo; +import com.engine.salary.util.page.PageUtil; +import org.apache.commons.compress.utils.Lists; +import org.apache.ibatis.session.SqlSession; +import weaver.conn.mybatis.MyBatisFactory; +import weaver.hrm.User; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DemoPageCmd extends AbstractCommonCommand> { + + public DemoPageCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + Map apidatas = new HashMap(16); + SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); + try { + DemoMapper mapper = sqlSession.getMapper(DemoMapper.class); + PageUtil.start(params); + List page = mapper.page(); + PageInfo pageInfo = new PageInfo<>(page,DemoPo.class); + apidatas.put("pageInfo", pageInfo); + } finally { + sqlSession.close(); + } + return apidatas; + } +} diff --git a/src/com/engine/salary/entity/DemoPo.java b/src/com/engine/salary/entity/DemoPo.java new file mode 100644 index 000000000..9cec014ab --- /dev/null +++ b/src/com/engine/salary/entity/DemoPo.java @@ -0,0 +1,12 @@ +package com.engine.salary.entity; + +import com.engine.salary.annotation.TableTitle; +import lombok.Data; + +@Data +public class DemoPo { + @TableTitle(title = "序号", key = "id", dataIndex = "id") + Integer id; + @TableTitle(title = "名称", key = "name", dataIndex = "name") + String name; +} diff --git a/src/com/engine/salary/entity/taxrate/TaxAgent.java b/src/com/engine/salary/entity/taxrate/TaxAgent.java new file mode 100644 index 000000000..f0281680f --- /dev/null +++ b/src/com/engine/salary/entity/taxrate/TaxAgent.java @@ -0,0 +1,52 @@ +package com.engine.salary.entity.taxrate; + +import java.time.LocalDateTime; +import java.util.Date; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 个税扣缴义务人表 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TaxAgent { + /** + * 创建时间 + */ + private Date createTime; + /** + * 创建人 + */ + private Long creator; + /** + * 是否已删除。0:未删除、1:已删除 + */ + private Integer deleteType; + /** + * 描述 + */ + private String description; + /** + * 主键 + */ + private Long id; + /** + * 名称 + */ + private String name; + /** + * 租户ID + */ + private String tenantKey; + /** + * 更新时间 + */ + private LocalDateTime updateTime; + +} \ No newline at end of file diff --git a/src/com/engine/salary/exception/SalaryRunTimeException.java b/src/com/engine/salary/exception/SalaryRunTimeException.java new file mode 100644 index 000000000..77b87830b --- /dev/null +++ b/src/com/engine/salary/exception/SalaryRunTimeException.java @@ -0,0 +1,10 @@ +package com.engine.salary.exception; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SalaryRunTimeException extends RuntimeException { + public SalaryRunTimeException(String message) { + super(message); + } +} diff --git a/src/com/engine/salary/mapper/DemoMapper.java b/src/com/engine/salary/mapper/DemoMapper.java new file mode 100644 index 000000000..6ffe82775 --- /dev/null +++ b/src/com/engine/salary/mapper/DemoMapper.java @@ -0,0 +1,25 @@ +package com.engine.salary.mapper; + + +import com.engine.salary.entity.DemoPo; +import com.engine.salary.entity.salaryarchive.po.TaxAgentPO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; + +/** + * @Description: 个税扣缴义务人 + * @Author: wangxiangzhong + * @Date: 2021/10/29 16:55 + */ +@Mapper +public interface DemoMapper { + + @Select("SELECT * FROM hrsa_tax_rate_base") + List page(); + + +} diff --git a/src/com/engine/salary/mapper/TaxAgentMapper.java b/src/com/engine/salary/mapper/TaxAgentMapper.java new file mode 100644 index 000000000..f65429966 --- /dev/null +++ b/src/com/engine/salary/mapper/TaxAgentMapper.java @@ -0,0 +1,71 @@ +package com.engine.salary.mapper; + +import java.util.List; + +import com.engine.salary.entity.taxrate.TaxAgent; +import org.apache.ibatis.annotations.Select; + +public interface TaxAgentMapper { + + /** + * 查询所有记录 + * + * @return 返回集合,没有返回空List + */ + List listAll(); + + + /** + * 根据主键查询 + * + * @param id 主键 + * @return 返回记录,没有返回null + */ + TaxAgent getById(Long id); + + /** + * 新增,插入所有字段 + * + * @param taxAgent 新增的记录 + * @return 返回影响行数 + */ + int insert(TaxAgent taxAgent); + + /** + * 新增,忽略null字段 + * + * @param taxAgent 新增的记录 + * @return 返回影响行数 + */ + int insertIgnoreNull(TaxAgent taxAgent); + + /** + * 修改,修改所有字段 + * + * @param taxAgent 修改的记录 + * @return 返回影响行数 + */ + int update(TaxAgent taxAgent); + + /** + * 修改,忽略null字段 + * + * @param taxAgent 修改的记录 + * @return 返回影响行数 + */ + int updateIgnoreNull(TaxAgent taxAgent); + + /** + * 删除记录 + * + * @param taxAgent 待删除的记录 + * @return 返回影响行数 + */ + int delete(TaxAgent taxAgent); + + @Select("SELECT * FROM hrsa_tax_agent WHERE deleteType = 0 and name = #{name}") + List listByName(String name); + + + +} \ No newline at end of file diff --git a/src/com/engine/salary/mapper/TaxAgentMapper.xml b/src/com/engine/salary/mapper/TaxAgentMapper.xml new file mode 100644 index 000000000..8054cf6b5 --- /dev/null +++ b/src/com/engine/salary/mapper/TaxAgentMapper.xml @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + t.create_time + , t.creator + , t.delete_type + , t.description + , t.id + , t.name + , t.tenant_key + , t.update_time + + + + + + + + + + + INSERT INTO hrsa_tax_agent + + create_time, + creator, + delete_type, + description, + id, + name, + tenant_key, + update_time, + + + #{createTime}, + #{creator}, + #{deleteType}, + #{description}, + #{id}, + #{name}, + #{tenantKey}, + #{updateTime}, + + + + + + INSERT INTO hrsa_tax_agent + + + + create_time, + + + creator, + + + delete_type, + + + description, + + + id, + + + name, + + + tenant_key, + + + update_time, + + + + + #{createTime}, + + + #{creator}, + + + #{deleteType}, + + + #{description}, + + + #{id}, + + + #{name}, + + + #{tenantKey}, + + + #{updateTime}, + + + + + + + UPDATE hrsa_tax_agent + + create_time=#{createTime}, + creator=#{creator}, + delete_type=#{deleteType}, + description=#{description}, + name=#{name}, + tenant_key=#{tenantKey}, + update_time=#{updateTime}, + + WHERE id = #{id} AND delete_type = 0 + + + + + + UPDATE hrsa_tax_agent + + + create_time=#{createTime}, + + + creator=#{creator}, + + + delete_type=#{deleteType}, + + + description=#{description}, + + + name=#{name}, + + + tenant_key=#{tenantKey}, + + + update_time=#{updateTime}, + + + WHERE id = #{id} AND delete_type = 0 + + + + + + UPDATE hrsa_tax_agent + SET delete_type=1 + WHERE id = #{id} + AND delete_type = 0AND delete_type = 0 + + + + \ No newline at end of file diff --git a/src/com/engine/salary/service/DemoService.java b/src/com/engine/salary/service/DemoService.java new file mode 100644 index 000000000..07549f173 --- /dev/null +++ b/src/com/engine/salary/service/DemoService.java @@ -0,0 +1,15 @@ +package com.engine.salary.service; + +import java.util.Map; + +public interface DemoService { + + Map list(Map params); + + Map getForm(Map params); + + Map save(Map params); + + + +} diff --git a/src/com/engine/salary/service/TaxAgentService.java b/src/com/engine/salary/service/TaxAgentService.java new file mode 100644 index 000000000..9225978d5 --- /dev/null +++ b/src/com/engine/salary/service/TaxAgentService.java @@ -0,0 +1,18 @@ +package com.engine.salary.service; + +import com.cloudstore.eccom.pc.table.WeaTable; +import weaver.hrm.User; + +import java.util.Map; + +public interface TaxAgentService { + + Map list(Map params); + + Map getForm(Map params); + + Map save(Map params); + + Map update(Map params); + +} diff --git a/src/com/engine/salary/service/impl/DemoServiceImpl.java b/src/com/engine/salary/service/impl/DemoServiceImpl.java new file mode 100644 index 000000000..74bfd2cf6 --- /dev/null +++ b/src/com/engine/salary/service/impl/DemoServiceImpl.java @@ -0,0 +1,27 @@ +package com.engine.salary.service.impl; + +import com.engine.core.impl.Service; +import com.engine.salary.cmd.TaxAgent.TaxAgentGetFromCmd; +import com.engine.salary.cmd.TaxAgent.TaxAgentSaveCmd; +import com.engine.salary.cmd.demo.DemoPageCmd; +import com.engine.salary.service.DemoService; + +import java.util.Map; + +public class DemoServiceImpl extends Service implements DemoService { + + @Override + public Map list(Map params) { + return commandExecutor.execute(new DemoPageCmd(params,user)); + } + + @Override + public Map getForm(Map params) { + return commandExecutor.execute(new TaxAgentGetFromCmd(params,user)); + } + + @Override + public Map save(Map params) { + return commandExecutor.execute(new TaxAgentSaveCmd(params,user)); + } +} diff --git a/src/com/engine/salary/service/impl/TaxAgentServiceImpl.java b/src/com/engine/salary/service/impl/TaxAgentServiceImpl.java new file mode 100644 index 000000000..275b07b0a --- /dev/null +++ b/src/com/engine/salary/service/impl/TaxAgentServiceImpl.java @@ -0,0 +1,36 @@ +package com.engine.salary.service.impl; + +import com.cloudstore.eccom.pc.table.WeaTable; +import com.engine.core.impl.Service; +import com.engine.portrait.cmd.individual.GetIndividualItemDataCmd; +import com.engine.salary.cmd.TaxAgent.TaxAgentGetFromCmd; +import com.engine.salary.cmd.TaxAgent.TaxAgentListCmd; +import com.engine.salary.cmd.TaxAgent.TaxAgentSaveCmd; +import com.engine.salary.cmd.TaxAgent.TaxAgentUpdateCmd; +import com.engine.salary.service.TaxAgentService; +import weaver.hrm.User; + +import java.util.Map; + +public class TaxAgentServiceImpl extends Service implements TaxAgentService { + + @Override + public Map list(Map params) { + return commandExecutor.execute(new TaxAgentListCmd(params,user)); + } + + @Override + public Map getForm(Map params) { + return commandExecutor.execute(new TaxAgentGetFromCmd(params,user)); + } + + @Override + public Map save(Map params) { + return commandExecutor.execute(new TaxAgentSaveCmd(params,user)); + } + + @Override + public Map update(Map params) { + return commandExecutor.execute(new TaxAgentUpdateCmd(params,user)); + } +} diff --git a/src/com/engine/salary/util/ResponseResult.java b/src/com/engine/salary/util/ResponseResult.java new file mode 100644 index 000000000..98d987a18 --- /dev/null +++ b/src/com/engine/salary/util/ResponseResult.java @@ -0,0 +1,52 @@ +package com.engine.salary.util; + + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.engine.salary.exception.SalaryRunTimeException; +import weaver.general.BaseBean; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + + +public class ResponseResult extends HashMap { + + private static final long serialVersionUID = 1L; + + /** + * 统一返回方法 + */ + public static String run(Function,Map> f,Map m) { + try { + return Ok(f.apply(m)); + } catch (SalaryRunTimeException e) { + return Error(e.getMessage()); + } catch (Exception e) { + BaseBean b = new BaseBean(); + b.writeLog(e); + return Error(e.getMessage()); + } + } + + /** + * 成功返回 + */ + private static String Ok(Map map) { + Map apidatas = new HashMap<>(); + apidatas.put("status", true); + apidatas.put("data",map); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } + + /** + * 失败返回 + */ + private static String Error(String message) { + Map apidatas = new HashMap<>(); + apidatas.put("status", false); + apidatas.put("errormsg", message); + return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect); + } +} diff --git a/src/com/engine/salary/util/SalaryPageUtil.java b/src/com/engine/salary/util/SalaryPageUtil.java new file mode 100644 index 000000000..4b3331af6 --- /dev/null +++ b/src/com/engine/salary/util/SalaryPageUtil.java @@ -0,0 +1,47 @@ +package com.engine.salary.util; + +import com.github.pagehelper.Page; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.Collections; +import java.util.List; + +/** + * @description: 分页相关的工具类 + * @author: xiajun + * @modified By: xiajun + * @date: Created in 11/22/21 2:03 PM + * @version:v1.0 + */ +public class SalaryPageUtil { + + private SalaryPageUtil() { + throw new IllegalStateException("Utility class"); + } + + public static Page buildPage(Integer pageNo, Integer pageSize) { + pageNo = pageNo == null || pageNo <= 0 ? 1 : pageNo; + pageSize = pageSize == null || pageSize <= 0 ? 10 : pageSize; + return new Page(pageNo, pageSize, true); + } + + /** + * 分页 + * + * @param pageNo 页码(从1开始) + * @param pageSize 每页条数 + * @param source 待分页的数据 + * @param 范型制定类 + * @return + */ + public static List subList(int pageNo, int pageSize, List source) { + if (CollectionUtils.isEmpty(source)) { + return Collections.emptyList(); + } + int endIndex = pageNo * pageSize; + int startIndex = (pageNo - 1) * pageSize; + startIndex = startIndex < 0 ? 0 : startIndex; + return source.subList(startIndex > source.size() ? source.size() : startIndex, + endIndex > source.size() ? source.size() : endIndex); + } +} diff --git a/src/com/engine/salary/util/page/Column.java b/src/com/engine/salary/util/page/Column.java new file mode 100644 index 000000000..71dad2257 --- /dev/null +++ b/src/com/engine/salary/util/page/Column.java @@ -0,0 +1,16 @@ +package com.engine.salary.util.page; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Column { + String title; + String dataIndex; + String key; +} diff --git a/src/com/engine/salary/util/page/DataSource.java b/src/com/engine/salary/util/page/DataSource.java new file mode 100644 index 000000000..379b99023 --- /dev/null +++ b/src/com/engine/salary/util/page/DataSource.java @@ -0,0 +1,9 @@ +package com.engine.salary.util.page; + +import lombok.Data; + +@Data +public class DataSource { + String key; + String title; +} diff --git a/src/com/engine/salary/util/page/PageInfo.java b/src/com/engine/salary/util/page/PageInfo.java new file mode 100644 index 000000000..af8d06447 --- /dev/null +++ b/src/com/engine/salary/util/page/PageInfo.java @@ -0,0 +1,43 @@ +package com.engine.salary.util.page; + +import com.engine.salary.annotation.TableTitle; +import lombok.Data; +import lombok.ToString; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +@Data +@ToString +public class PageInfo extends com.github.pagehelper.PageInfo { + Class clazz; + List columns = new ArrayList<>(); + List dataSource = new ArrayList<>(); + + public PageInfo(List list) { + super(list); + } + + public PageInfo(List list, Class clazz) { + super(list); + this.clazz = clazz; + } + + + public List getColumns() { + Field[] fields = clazz.getDeclaredFields(); + for (Field f : fields) { + boolean isanno = f.isAnnotationPresent(TableTitle.class); + if (isanno) { + TableTitle annotation = f.getAnnotation(TableTitle.class); + String title = annotation.title(); + String dataIndex = annotation.dataIndex(); + String key = annotation.key(); + Column column = Column.builder().title(title).dataIndex(dataIndex).key(key).build(); + columns.add(column); + } + } + return columns; + } +} diff --git a/src/com/engine/salary/util/page/PageUtil.java b/src/com/engine/salary/util/page/PageUtil.java new file mode 100644 index 000000000..5cd29a5b2 --- /dev/null +++ b/src/com/engine/salary/util/page/PageUtil.java @@ -0,0 +1,48 @@ +package com.engine.salary.util.page; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import org.apache.commons.collections4.CollectionUtils; +import weaver.general.Util; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + + +public class PageUtil { + + public static void start(Map params) { + int pageNum = Util.getIntValue(Util.null2String(params.get("pageNum"))); + int pageSize = Util.getIntValue(Util.null2String(params.get("pageSize"))); + pageNum = pageNum <= 0 ? 1 : pageNum; + pageSize = pageSize <= 0 ? 10 : pageSize; + PageHelper.startPage(pageNum, pageSize); + } + + public static Page buildPage(Integer pageNo, Integer pageSize) { + pageNo = pageNo == null || pageNo <= 0 ? 1 : pageNo; + pageSize = pageSize == null || pageSize <= 0 ? 10 : pageSize; + return new Page(pageNo, pageSize, true); + } + + /** + * 分页 + * + * @param pageNo 页码(从1开始) + * @param pageSize 每页条数 + * @param source 待分页的数据 + * @param 范型制定类 + * @return + */ + public static List subList(int pageNo, int pageSize, List source) { + if (CollectionUtils.isEmpty(source)) { + return Collections.emptyList(); + } + int endIndex = pageNo * pageSize; + int startIndex = (pageNo - 1) * pageSize; + startIndex = startIndex < 0 ? 0 : startIndex; + return source.subList(startIndex > source.size() ? source.size() : startIndex, + endIndex > source.size() ? source.size() : endIndex); + } +} diff --git a/src/com/engine/salary/web/DemoController.java b/src/com/engine/salary/web/DemoController.java new file mode 100644 index 000000000..60618d6d0 --- /dev/null +++ b/src/com/engine/salary/web/DemoController.java @@ -0,0 +1,54 @@ +package com.engine.salary.web; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.salary.service.DemoService; +import com.engine.salary.service.TaxAgentService; +import com.engine.salary.service.impl.DemoServiceImpl; +import com.engine.salary.service.impl.TaxAgentServiceImpl; +import com.engine.salary.util.ResponseResult; +import weaver.general.BaseBean; +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; + +public class DemoController { + + private BaseBean logger = new BaseBean(); + + private DemoService getService(User user) { + return (DemoService) ServiceUtil.getService(DemoServiceImpl.class, user); + } + + @GET + @Path("/list") + @Produces(MediaType.TEXT_PLAIN) + public String list(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::list, ParamUtil.request2Map(request)); + } + + @GET + @Path("/getForm") + @Produces(MediaType.TEXT_PLAIN) + public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::getForm, ParamUtil.request2Map(request)); + } + + @POST + @Path("/save") + @Produces(MediaType.TEXT_PLAIN) + public String getFrom(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::save, ParamUtil.request2Map(request)); + } +} diff --git a/src/com/engine/salary/web/TaxAgentController.java b/src/com/engine/salary/web/TaxAgentController.java new file mode 100644 index 000000000..df366ac88 --- /dev/null +++ b/src/com/engine/salary/web/TaxAgentController.java @@ -0,0 +1,70 @@ +package com.engine.salary.web; + +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.salary.service.TaxAgentService; +import com.engine.salary.service.impl.TaxAgentServiceImpl; +import com.engine.salary.util.ResponseResult; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.beanutils.BeanUtils; +import weaver.general.BaseBean; +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; + +public class TaxAgentController { + + private BaseBean logger = new BaseBean(); + + private TaxAgentService getService(User user) { + return (TaxAgentService) ServiceUtil.getService(TaxAgentServiceImpl.class, user); + } + + //个税扣缴义务人列表 + @GET + @Path("/list") + @Produces(MediaType.TEXT_PLAIN) + public String list(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::list, ParamUtil.request2Map(request)); + } + + //获取个税扣缴义务人表单 + @GET + @Path("/getForm") + @Produces(MediaType.TEXT_PLAIN) + public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::getForm, ParamUtil.request2Map(request)); + } + + //新建个税扣缴义务人 + @POST + @Path("/save") + @Produces(MediaType.TEXT_PLAIN) + public String getFrom(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::save, ParamUtil.request2Map(request)); + } + + /** + * 编辑个税扣缴义务人 + */ + @POST + @Path("/update") + @Produces(MediaType.TEXT_PLAIN) + public String update(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + return ResponseResult.run(getService(user)::update, ParamUtil.request2Map(request)); + } + + +} diff --git a/src/com/engine/salary/web/TaxRateController.java b/src/com/engine/salary/web/TaxRateController.java new file mode 100644 index 000000000..9e90c1429 --- /dev/null +++ b/src/com/engine/salary/web/TaxRateController.java @@ -0,0 +1,20 @@ +package com.engine.salary.web; + +import com.engine.common.util.ServiceUtil; +import com.engine.salary.service.TaxAgentService; +import com.engine.salary.service.impl.TaxAgentServiceImpl; +import weaver.general.BaseBean; +import weaver.hrm.User; + +public class TaxRateController { + + private BaseBean logger = new BaseBean(); + +// private TaxAgentService getService(User user) { +// return (TaxRateService) ServiceUtil.getService(TaxAgentServiceImpl.class, user); +// } + + + + +}