工程导出修改、增加倍数计算工具类、部门用户树

This commit is contained in:
syruan 2024-08-19 11:19:03 +08:00
parent 4803a55b7b
commit d4123947bf
16 changed files with 263 additions and 109 deletions

View File

@ -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;
/**
* 工程状态

View File

@ -16,7 +16,9 @@ import java.util.List;
*/
@Data
public class SysDeptTree implements Serializable {
private static final long serialVersionUID = 991828482042492876L;
/**
* 更新时间
*/

View File

@ -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<TreeSelect> children;
public TreeSelect(SysDeptTree dept)
{
private List<SysUser> 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<TreeSelect> getChildren()
{
return children;
}
public void setChildren(List<TreeSelect> children)
{
this.children = children;
}
}

View File

@ -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;
}
}

View File

@ -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<TreeSelect> deptList = customerService.selectDeptTree(sysDept);
List<SysUser> userList = new ArrayList<>();
SysUser su1 = new SysUser();
su1.setDeptId(103L);
su1.setUserName("admin");
su1.setUserId(1L);
userList.add(su1);
// List<SysUser> userList = userService.selectUserList(new SysUser());
baseTreeService.deptUserTreeScope(deptList.get(0), userList);
return AjaxResult.success(deptList);
}
}

View File

@ -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<Boolean> edit(@NotNull @RequestBody BmProject obj) {
public ResultBean<Boolean> 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<BmProject> list = bmProjectService.selectAll(bmProject);
public void export(HttpServletResponse response, @RequestBody List<Integer> ids) {
List<BmProject> 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<BmProject> util = new ExcelUtil<>(BmProject.class);
util.exportExcel(response, list, "工程管理数据");

View File

@ -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<BmProject> selectAll(BmProject bmProject);
List<BmProject> findAllInId(@Param("idCollection")Collection<Integer> idCollection);
/**
* update record selective
* @param record the updated record

View File

@ -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<BmProject> findAllInId(Collection<Integer> idCollection){
return bmProjectMapper.findAllInId(idCollection);
}
}

View File

@ -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<SysUser> 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<TreeSelect> 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;
}
}

View File

@ -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<MaHouse> list = maHouseService.queryByPage(maHouse);
ExcelUtil<MaHouse> util = new ExcelUtil<>(MaHouse.class);
util.exportExcel(response, list, "仓库列表数据");

View File

@ -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);

View File

@ -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);

View File

@ -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<MaHouseSet> selectAll(MaHouseSet record);
List<MaHouseSet> findAll();
}

View File

@ -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);
}
}

View File

@ -711,4 +711,15 @@
from bm_project
where `name`= #{name,jdbcType=VARCHAR}
</select>
<!--by syruan on 2024-08-15-->
<select id="findAllInId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from bm_project
where id in
<foreach item="item" index="index" collection="idCollection" open="(" separator="," close=")">
#{item,jdbcType=INTEGER}
</foreach>
</select>
</mapper>

View File

@ -144,5 +144,11 @@
</trim>
</insert>
<!--by syruan on 2024-08-15-->
<select id="findAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from ma_house_set
</select>
</mapper>