diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/BmProject.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/BmProject.java index 2710e38..5f7839f 100644 --- a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/BmProject.java +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/BmProject.java @@ -13,6 +13,7 @@ import lombok.EqualsAndHashCode; import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; /** * 工程管理信息表 @@ -89,6 +90,8 @@ public class BmProject extends BaseEntity implements Serializable { * 联系方式 */ @ApiModelProperty(value = "联系方式") + @NotBlank(message = "联系方式不能为空") + @Size(min = 11, max = 11, message = "联系方式长度必须为11位") private String telphone; /** @@ -101,7 +104,7 @@ public class BmProject extends BaseEntity implements Serializable { * 项目性质 */ @ApiModelProperty(value = "项目性质") - private String nature; + private Integer nature; /** * 项目性质 @@ -114,15 +117,17 @@ public class BmProject extends BaseEntity implements Serializable { */ @ApiModelProperty(value = "联系方式") @Excel(name = "联系电话") + @NotBlank(message = "联系电话不能为空") + @Size(min = 11, max = 11, message = "联系电话长度必须为11位") private String phone; /** * 工程状态 */ @ApiModelProperty(value = "工程状态") - @NotBlank(message = "工程状态不能为空") + @NotNull(message = "工程状态不能为空") @Excel(name = "工程状态") - private String stats; + private Integer stats; /** * 工程状态 diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/SysDeptTree.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/SysDeptTree.java index 6c42d6d..d1f8139 100644 --- a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/SysDeptTree.java +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/SysDeptTree.java @@ -16,7 +16,9 @@ import java.util.List; */ @Data public class SysDeptTree implements Serializable { + private static final long serialVersionUID = 991828482042492876L; + /** * 更新时间 */ diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java index c6cb3a8..ef9302b 100644 --- a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java @@ -1,17 +1,20 @@ package com.bonus.base.api.domain; -import com.bonus.system.api.domain.SysDept; +import com.bonus.system.api.domain.SysUser; import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.Setter; import java.io.Serializable; import java.util.List; import java.util.stream.Collectors; /** - * Treeselect树结构实体类 - * + * TreeSelect树结构实体类 * @author ruoyi */ +@Setter +@Getter public class TreeSelect implements Serializable { private static final long serialVersionUID = 1L; @@ -37,16 +40,16 @@ public class TreeSelect implements Serializable @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children; - public TreeSelect(SysDeptTree dept) - { + private List userList; + + public TreeSelect(SysDeptTree dept) { this.id = dept.getDeptId(); this.parentId = dept.getParentId(); this.label = dept.getDeptName(); this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } - public TreeSelect(MaType maType) - { + public TreeSelect(MaType maType) { this.parentId = maType.getParentId(); this.code = maType.getCode(); this.level = Integer.valueOf(maType.getLevel()); @@ -56,67 +59,7 @@ public class TreeSelect implements Serializable this.children = maType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } + public TreeSelect() { - public String getParentId() { - return parentId; - } - - public void setParentId(String parentId) { - this.parentId = parentId; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - - public String getId() - { - return id; - } - - public void setId(String id) - { - this.id = id; - } - - public Integer getLevel() { - return level; - } - - public void setLevel(Integer level) { - this.level = level; - } - - public String getLabel() - { - return label; - } - - public void setLabel(String label) - { - this.label = label; - } - - public String getCompanyId() { - return companyId; - } - - public void setCompanyId(String companyId) { - this.companyId = companyId; - } - - public List getChildren() - { - return children; - } - - public void setChildren(List children) - { - this.children = children; } } diff --git a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/NumberUtils.java b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/NumberUtils.java new file mode 100644 index 0000000..8b8e729 --- /dev/null +++ b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/NumberUtils.java @@ -0,0 +1,85 @@ +package com.bonus.common.core.utils; + +/** + * @author : 阮世耀 + * @version : 1.0 + * @PackagePath: com.bonus.common.core.utils + * @CreateTime: 2024-08-19 09:39 + * @Description: 数字计算工具类 + */ +public class NumberUtils { + + + /** + * 将对象转换为int + * @param obj 对象 + * @return 转换后的值,如果对象为null,则返回0 + */ + public static int getInt(Object obj) { + if (obj == null) { + return 0; + } + if (obj instanceof Integer) { + return (Integer) obj; + } + try { + if (obj instanceof String) { + return Integer.parseInt((String) obj); + } + } catch (NumberFormatException e) { + throw new RuntimeException("输入的不是正确的int格式字符串:" + obj + ",错误信息:" + e.getMessage()); + } + return 0; + } + + + /** + * 对两个金额进行乘法运算。 + * + * @param amount1 第一个金额 + * @param amount2 第二个金额 + * @param operation 运算符 ('*') + * @param scale 运算结果的倍数 100倍 / 1000倍 + * @return 运算结果 + */ + public static int operate(int amount1, int amount2, char operation, int scale) { + int result; + + if (scale != 100 && scale != 1000) { + throw new IllegalArgumentException("此方法只适用于100倍,1000倍的计算方法"); + } + + if (operation == '*') { + result = (amount1 / scale) * (amount2 / scale) * scale; + } else { + throw new IllegalArgumentException("请输入正确的(*)运算符: " + operation); + } + return result; + } + + + /** + * 对两个金额进行加、减运算。 + * + * @param amount1 第一个金额 + * @param amount2 第二个金额 + * @param operation 运算符 ('+', '-') + * @return 运算结果 + */ + public static int operate(int amount1, int amount2, char operation) { + int result; + switch (operation) { + case '+': + result = (amount1 + amount2); + break; + case '-': + result = (amount1 - amount2); + break; + default: + throw new IllegalArgumentException("请输入正确的(+ -)运算符: " + operation); + } + return result; + } + + +} diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BaseTreeController.java b/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BaseTreeController.java index 178a223..7bd4a17 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BaseTreeController.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BaseTreeController.java @@ -1,14 +1,25 @@ package com.bonus.base.controller; +import com.bonus.base.api.domain.SysDeptTree; +import com.bonus.base.api.domain.TreeSelect; +import com.bonus.base.service.IBmCustomerService; +import com.bonus.base.service.impl.BaseTreeService; import com.bonus.common.core.domain.R; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.annotation.RequiresPermissions; import com.bonus.system.api.RemoteDictService; import com.bonus.system.api.domain.SysDictData; +import com.bonus.system.api.domain.SysUser; +//import com.bonus.system.service.ISysUserService; +import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; @@ -26,6 +37,15 @@ public class BaseTreeController { @Resource private RemoteDictService remoteDictService; + @Resource + private IBmCustomerService customerService; + +// @Resource +// private ISysUserService userService; + + @Resource + private BaseTreeService baseTreeService; + /** * 获取工程类型 */ @@ -51,4 +71,22 @@ public class BaseTreeController { return R.ok(bmProNature); } + /** + * 查询部门用户树 + */ + @ApiOperation(value = "查询部门用户树") + @GetMapping("/getDeptUserTree") + public AjaxResult selectDeptTree(SysDeptTree sysDept) { + List deptList = customerService.selectDeptTree(sysDept); + List userList = new ArrayList<>(); + SysUser su1 = new SysUser(); + su1.setDeptId(103L); + su1.setUserName("admin"); + su1.setUserId(1L); + userList.add(su1); +// List userList = userService.selectUserList(new SysUser()); + baseTreeService.deptUserTreeScope(deptList.get(0), userList); + return AjaxResult.success(deptList); + } + } diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BmProjectController.java b/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BmProjectController.java index cf28f80..9a8bc59 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BmProjectController.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/base/controller/BmProjectController.java @@ -1,8 +1,6 @@ package com.bonus.base.controller; -import cn.hutool.core.util.PhoneUtil; -import com.alibaba.nacos.common.utils.StringUtils; -import com.bonus.base.api.domain.BmCustomer; +import cn.hutool.core.collection.CollectionUtil; import com.bonus.base.api.domain.BmProject; import com.bonus.base.service.BmProjectService; import com.bonus.common.core.domain.ResultBean; @@ -23,7 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.Positive; +import java.util.Collections; import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; /** * 工程项目管理(bm_project)表控制层 @@ -91,29 +92,10 @@ public class BmProjectController extends BaseController { if (this.bmProjectService.selectByName(obj.getName()) != 0) { return ResultBean.error("工程名称重复"); } - String ajaxResult = getAjaxResult(obj); - if (ajaxResult != null) { - return ResultBean.error(ajaxResult); - } int result = this.bmProjectService.insertSelective(obj); return result > 0 ? ResultBean.success(true) : ResultBean.error(0, "增加失败"); } - /** - * 联系方式格式校验方法抽取 - * @param customer - * @return - */ - private String getAjaxResult(BmProject customer) { - if (StringUtils.isNotBlank(customer.getPhone()) && !PhoneUtil.isMobile(customer.getPhone())) { - return "手机号码格式不正确"; - } - if (StringUtils.isNotBlank(customer.getTelphone()) && !PhoneUtil.isMobile(customer.getTelphone())) { - return "联系人手机号码格式不正确"; - } - return null; - } - /** * 修改数据 * @@ -122,14 +104,10 @@ public class BmProjectController extends BaseController { */ @PutMapping(value = "/update") @RequiresPermissions("base:project:edit") - public ResultBean edit(@NotNull @RequestBody BmProject obj) { + public ResultBean edit(@NotNull @Valid @RequestBody BmProject obj) { if (this.bmProjectService.selectByName(obj.getName()) > 1) { return ResultBean.error("工程名称重复"); } - String ajaxResult = getAjaxResult(obj); - if (ajaxResult != null) { - return ResultBean.error(ajaxResult); - } this.bmProjectService.updateByPrimaryKeySelective(obj); return ResultBean.success(true); } @@ -154,14 +132,12 @@ public class BmProjectController extends BaseController { */ @PostMapping("/export") @RequiresPermissions("base:project:export") - public void export(HttpServletResponse response, BmProject bmProject) { - List list = bmProjectService.selectAll(bmProject); + public void export(HttpServletResponse response, @RequestBody List ids) { + List list = Optional.ofNullable(CollectionUtil.isEmpty(ids) + ? bmProjectService.selectAll(new BmProject()) + : bmProjectService.findAllInId(ids)).orElse(Collections.emptyList()); list.forEach(record -> { - if (record.getProId() == null) { - record.setIsMatchI8("不匹配"); - } else { - record.setIsMatchI8("匹配"); - } + record.setIsMatch(StringHelper.isNotEmpty(record.getIsMatch()) ? "匹配" : "不匹配"); }); ExcelUtil util = new ExcelUtil<>(BmProject.class); util.exportExcel(response, list, "工程管理数据"); diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/base/mapper/BmProjectMapper.java b/bonus-modules/bonus-base/src/main/java/com/bonus/base/mapper/BmProjectMapper.java index eef9354..e1fa246 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/base/mapper/BmProjectMapper.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/base/mapper/BmProjectMapper.java @@ -1,4 +1,5 @@ package com.bonus.base.mapper; +import java.util.Collection; import org.apache.ibatis.annotations.Param; import com.bonus.base.api.domain.BmProject; @@ -51,6 +52,10 @@ public interface BmProjectMapper { List selectAll(BmProject bmProject); + List findAllInId(@Param("idCollection")Collection idCollection); + + + /** * update record selective * @param record the updated record diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/BmProjectService.java b/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/BmProjectService.java index 0c329c2..0bed5c2 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/BmProjectService.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/BmProjectService.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import com.bonus.base.api.domain.BmProject; +import java.util.Collection; import java.util.List; /** @@ -67,4 +68,11 @@ public class BmProjectService{ return bmProjectMapper.selectByName(name); } + public List findAllInId(Collection idCollection){ + return bmProjectMapper.findAllInId(idCollection); + } + + + + } diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/impl/BaseTreeService.java b/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/impl/BaseTreeService.java new file mode 100644 index 0000000..7aca71d --- /dev/null +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/base/service/impl/BaseTreeService.java @@ -0,0 +1,71 @@ +package com.bonus.base.service.impl; + +import com.bonus.base.api.domain.TreeSelect; +import com.bonus.system.api.domain.SysUser; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author : 阮世耀 + * @version : 1.0 + * @PackagePath: com.bonus.base.service.impl + * @CreateTime: 2024-08-16 13:17 + * @Description: 基础公用tree、下拉框逻辑处理类 + */ +@Service +public class BaseTreeService { + + /** + * 部门用户关联树处理 + * @param sysDept 部门树根结构 + * @return 树结构 + */ + public TreeSelect deptUserTreeScope(TreeSelect sysDept, List userList) { + for (SysUser sysUser : userList) { + findDepartmentById(sysDept, sysUser, sysUser.getDeptId()); + } + return sysDept; + } + + + /** + * 递归查询部门结构,匹配用户id + * @param root 部门树 + * @param id 用户id + * @return 匹配上的部门信息 + */ + private static TreeSelect findDepartmentById(TreeSelect root, SysUser sysUser, Long id) { + // 只在方法开始处检查一次root是否为null + if (root == null) { + return null; + } + + // 检查当前节点是否匹配id + if (id != null && root.getId() == id.intValue()) { + return root; + } + + // 遍历子节点 + for (TreeSelect sysDept : root.getChildren()) { + TreeSelect found = findDepartmentById(sysDept, sysUser, id); + if (found != null) { + List children = new ArrayList<>(); + TreeSelect treeSelect = new TreeSelect(); + if (id != null) { + treeSelect.setId(sysUser.getUserId().intValue()); + treeSelect.setLabel(sysUser.getUserName()); + } + children.add(treeSelect); + found.setChildren(children); + // 找到匹配的节点,返回结果 + return found; + } + } + + // 如果没有找到匹配的节点,返回null + return null; + } + +} diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseController.java b/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseController.java index b9ce147..be4ca20 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseController.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseController.java @@ -107,8 +107,7 @@ public class MaHouseController extends BaseController { @ApiOperation(value = "导出仓库列表") @RequiresPermissions("material:maHouse:export") @PostMapping("/export") - public void export(HttpServletResponse response, MaHouse maHouse) - { + public void export(HttpServletResponse response, MaHouse maHouse) { List list = maHouseService.queryByPage(maHouse); ExcelUtil util = new ExcelUtil<>(MaHouse.class); util.exportExcel(response, list, "仓库列表数据"); diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseSetController.java b/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseSetController.java index 42d0458..f593592 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseSetController.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaHouseSetController.java @@ -82,7 +82,7 @@ public class MaHouseSetController extends BaseController { * @param id 主键 * @return 删除是否成功 */ - @PostMapping(value = "/delete/{id}") + @DeleteMapping(value = "/delete/{id}") @RequiresPermissions("material:maHouseSet:remove") public ResultBean< Boolean> deleteById(@PathVariable("id") Integer id) { this.maHouseSetService.deleteByPrimaryKey(id); diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaUserSetController.java b/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaUserSetController.java index 7d43b3e..70e37d6 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaUserSetController.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/material/controller/MaUserSetController.java @@ -81,7 +81,7 @@ public class MaUserSetController extends BaseController { * @param id 主键 * @return 删除是否成功 */ - @PostMapping(value = "/delete/{id}") + @DeleteMapping(value = "/delete/{id}") @RequiresPermissions("material:maUserSet:remove") public ResultBean< Boolean> deleteById(@PathVariable("id") Integer id) { this.maUserSetService.deleteByPrimaryKey(id); diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/material/mapper/MaHouseSetMapper.java b/bonus-modules/bonus-base/src/main/java/com/bonus/material/mapper/MaHouseSetMapper.java index e5a483b..62ea20a 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/material/mapper/MaHouseSetMapper.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/material/mapper/MaHouseSetMapper.java @@ -1,4 +1,5 @@ package com.bonus.material.mapper; +import java.util.Collection; import org.apache.ibatis.annotations.Param; import com.bonus.material.domain.MaHouseSet; @@ -62,5 +63,7 @@ public interface MaHouseSetMapper { List selectAll(MaHouseSet record); + List findAll(); + } \ No newline at end of file diff --git a/bonus-modules/bonus-base/src/main/java/com/bonus/material/service/impl/MaHouseSetService.java b/bonus-modules/bonus-base/src/main/java/com/bonus/material/service/impl/MaHouseSetService.java index 6ec0917..030adcf 100644 --- a/bonus-modules/bonus-base/src/main/java/com/bonus/material/service/impl/MaHouseSetService.java +++ b/bonus-modules/bonus-base/src/main/java/com/bonus/material/service/impl/MaHouseSetService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; +import java.util.Collection; import java.util.List; import com.bonus.material.domain.MaHouseSet; @@ -65,4 +66,5 @@ public class MaHouseSetService{ return maHouseSetMapper.selectAll(maHouseSet); } + } diff --git a/bonus-modules/bonus-base/src/main/resources/mapper/base/BmProjectMapper.xml b/bonus-modules/bonus-base/src/main/resources/mapper/base/BmProjectMapper.xml index e2c2c2a..70392f5 100644 --- a/bonus-modules/bonus-base/src/main/resources/mapper/base/BmProjectMapper.xml +++ b/bonus-modules/bonus-base/src/main/resources/mapper/base/BmProjectMapper.xml @@ -711,4 +711,15 @@ from bm_project where `name`= #{name,jdbcType=VARCHAR} + + + diff --git a/bonus-modules/bonus-base/src/main/resources/mapper/material/MaHouseSetMapper.xml b/bonus-modules/bonus-base/src/main/resources/mapper/material/MaHouseSetMapper.xml index 330f4a7..5f8c4f7 100644 --- a/bonus-modules/bonus-base/src/main/resources/mapper/material/MaHouseSetMapper.xml +++ b/bonus-modules/bonus-base/src/main/resources/mapper/material/MaHouseSetMapper.xml @@ -144,5 +144,11 @@ + + \ No newline at end of file