Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/ecp' into ecp

纪新园 1 settimana fa
parent
commit
b498128602

+ 23 - 32
blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Dept.java

@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -19,6 +20,7 @@ import java.math.BigDecimal;
 @Data
 @TableName("blade_dept")
 @ApiModel(value = "Dept对象", description = "Dept对象")
+@NoArgsConstructor
 public class Dept implements Serializable {
 
 	private static final long serialVersionUID = 1L;
@@ -100,34 +102,6 @@ public class Dept implements Serializable {
 	private String appletsId;
 
 	/**
-	 * 装货港 id
-	 */
-	@ApiModelProperty(value = "装货港 id")
-	private Long polId;
-	/**
-	 * 装货港中文名称
-	 */
-	@ApiModelProperty(value = "装货港中文名称")
-	private String polCnName;
-
-	/**
-	 * 装货港英文名称
-	 */
-	@ApiModelProperty(value = "装货港英文名称")
-	private String polEnName;
-	/**
-	 * 装货港英文名称打印 默认等于pol_en_name 可以编辑
-	 */
-	@ApiModelProperty(value = "装货港英文名称打印 默认等于pol_en_name 可以编辑")
-	private String polNamePrint;
-
-	/**
-	 * 装货港代码
-	 */
-	@ApiModelProperty(value = "装货港代码")
-	private String polCode;
-
-	/**
 	 * 英文全称
 	 */
 	@ApiModelProperty(value = "英文全称")
@@ -220,14 +194,31 @@ public class Dept implements Serializable {
 	/**
 	 * 联系人
 	 */
-	@TableField(exist = false)
-	private String contacts;
+//	@TableField(exist = false)
+//	private String contacts;
 
 	/**
 	 * 报表时间
 	 */
-	@TableField(exist = false)
-	private String date;
+//	@TableField(exist = false)
+//	private String date;
+
+	/**
+	 * 状态
+	 * 0启用
+	 * 1禁用
+	 */
+	private Integer status;
+
+
+	public Dept(Long parentId, String deptName, String fullName,
+				Integer deptCategory, String tenantId) {
+		this.parentId = parentId;
+		this.deptName = deptName;
+		this.fullName = fullName;
+		this.deptCategory = deptCategory;
+		this.tenantId = tenantId;
+	}
 
 
 }

+ 48 - 0
blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java

@@ -70,6 +70,18 @@ public interface ISysClient {
 	String GET_DEPT_BY_ID = API_PREFIX + "/getDeptById";
 
 
+	String GET_CHILD_DEPT_LIST_BY_PARENT_ID = API_PREFIX + "/getChildDeptListByParentId";
+
+
+	String INSERT_DEPT = API_PREFIX + "/insertDept";
+
+
+	String UPDATE_DEPT_BATCH = API_PREFIX + "/updateDeptBatch";
+
+
+	String GET_DEALER_DEPT = API_PREFIX + "/getDealerDept";
+
+
 	/**
 	 * 通过租户id获取全部租户别名
 	 */
@@ -390,4 +402,40 @@ public interface ISysClient {
 
 	@GetMapping(GET_DEPT_BY_ID)
 	Dept getDeptById(@RequestParam(value = "sharedCompanyId", required = false) String sharedCompanyId);
+
+
+	/**
+	 * 获取子部门
+	 *
+	 * @param id 部门id
+	 * @return 结果
+	 */
+	@PostMapping(GET_CHILD_DEPT_LIST_BY_PARENT_ID)
+	List<Dept> getChildDeptListByParentId(@RequestParam("id") Long id);
+
+	/**
+	 * 新增部门
+	 *
+	 * @param insertDept 部门
+	 * @return 结果
+	 */
+	@PostMapping(INSERT_DEPT)
+	boolean insertDept(@RequestBody Dept insertDept);
+
+	/**
+	 * 批量更新部门
+	 *
+	 * @param updateDeptList 部门
+	 * @return 批量结果
+	 */
+	@PostMapping(UPDATE_DEPT_BATCH)
+	boolean updateDeptBatch(@RequestBody List<Dept> updateDeptList);
+
+	/**
+	 * 获取经销商部门
+	 *
+	 * @return 经销商部门
+	 */
+	@GetMapping(GET_DEALER_DEPT)
+	Dept getDealerDept();
 }

+ 21 - 0
blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java

@@ -5,6 +5,7 @@ import org.springblade.core.tool.api.R;
 import org.springblade.system.entity.*;
 import org.springframework.stereotype.Component;
 
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -215,4 +216,24 @@ public class ISysClientFallback implements ISysClient {
 		return null;
 	}
 
+	@Override
+	public List<Dept> getChildDeptListByParentId(Long id) {
+		return Collections.emptyList();
+	}
+
+	@Override
+	public boolean insertDept(Dept insertDept) {
+		return false;
+	}
+
+	@Override
+	public boolean updateDeptBatch(List<Dept> updateDeptList) {
+		return false;
+	}
+
+	@Override
+	public Dept getDealerDept() {
+		return null;
+	}
+
 }

+ 1 - 1
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/User.java

@@ -124,7 +124,7 @@ public class User extends TenantEntity {
 	/**
 	 * 运行状态(0正常,1禁用)
 	 */
-	private String workingStatus;
+	private Integer workingStatus;
 
 	/**
 	 * 积分余额

+ 40 - 0
blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java

@@ -9,11 +9,15 @@ import org.springblade.core.tenant.annotation.NonDS;
 import org.springblade.core.tool.api.R;
 import org.springblade.system.entity.*;
 import org.springblade.system.service.*;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;
 
+import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 系统服务Feign实现类
@@ -291,6 +295,42 @@ public class SysClient implements ISysClient {
 	}
 
 	@Override
+	@PostMapping(GET_CHILD_DEPT_LIST_BY_PARENT_ID)
+	public List<Dept> getChildDeptListByParentId(Long id) {
+		return deptService.list(new LambdaQueryWrapper<Dept>().eq(Dept::getParentId, id));
+	}
+
+	@Override
+	@PostMapping(INSERT_DEPT)
+	public boolean insertDept(Dept insertDept) {
+		return deptService.save(insertDept);
+	}
+
+	@Override
+	@PostMapping(UPDATE_DEPT_BATCH)
+	public boolean updateDeptBatch(List<Dept> updateDeptList) {
+		return deptService.saveOrUpdateBatch(updateDeptList);
+	}
+
+	@Override
+	@GetMapping(GET_DEALER_DEPT)
+	public Dept getDealerDept() {
+		Dept parentDept = deptService.getOne(new LambdaQueryWrapper<Dept>()
+			.eq(Dept::getFullName, "库比森轮胎(江苏)有限公司")
+			.eq(Dept::getParentId, 0)
+			.eq(Dept::getTenantId, AuthUtil.getTenantId())
+			.eq(Dept::getIsDeleted, 0).orderByAsc(Dept::getSort).last("limit 1"));
+		if (ObjectUtils.isNull(parentDept)) {
+			return null;
+		}
+		return deptService.getOne(new LambdaQueryWrapper<Dept>()
+			.eq(Dept::getFullName, "经销商")
+			.eq(Dept::getParentId, parentDept.getId())
+			.eq(Dept::getTenantId, AuthUtil.getTenantId())
+			.eq(Dept::getIsDeleted, 0).orderByAsc(Dept::getSort).last("limit 1"));
+	}
+
+	@Override
 	@GetMapping(TENANT_ID)
 	public R<Tenant> getTenant(String tenantId) {
 		return R.data(tenantService.getByTenantId(tenantId));

+ 76 - 28
blade-service/blade-user/src/main/java/org/springblade/system/user/feign/UserClient.java

@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
+import org.apache.ibatis.datasource.DataSourceException;
 import org.springblade.common.config.MD5Util;
 //import org.springblade.common.utils.PinYinUtil;
+import org.springblade.common.enums.NumberEnum;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.secure.utils.SecureUtil;
@@ -311,55 +313,101 @@ public class UserClient implements IUserClient {
 			return R.fail("缺少经销商角色,请先维护角色");
 		}
 		BladeUser bladeUser = AuthUtil.getUser();
-		R<Dept> dealerDept = sysClient.getDeptIByName(bladeUser.getTenantId(), "经销商");
-		if (!dealerDept.isSuccess() || Objects.isNull(dealerDept.getData())) {
-			return R.fail("缺少经销商部门,请先维护部门");
+		Dept dept = sysClient.getDealerDept();
+		if (Objects.isNull(dept)) {
+			return R.fail("缺少经销商部门,请先在\" 库比森轮胎(江苏)有限公司 \" 下维护 \" 经销商 \" 部门");
 		}
-		Dept dept = dealerDept.getData();
+		List<Dept> dealerDeptList = sysClient.getChildDeptListByParentId(dept.getId());
 		String dealerRoleId = String.valueOf(dealerRole.getData());
 		List<User> dealerUserList = service.list(new LambdaQueryWrapper<User>().eq(User::getTenantId, bladeUser.getTenantId()).eq(User::getUserTypeRole, 2));
 		List<User> insertOrUpdateUserList = new ArrayList<>();
+		List<Dept> updateDeptList = new ArrayList<>();
 		Date nowDate = DateUtil.now();
 		if (!CollectionUtils.isEmpty(dealerUserList)) {
 			dealerUserList.forEach(usr -> usr.setIsDeleted(1));
 		}
 		for (ZcrmViewCustomerSel customerSel : customerSelList) {
-			User insertOrUpdateUser = new User();
-			insertOrUpdateUserList.add(insertOrUpdateUser);
-			User srcUser = dealerUserList.stream().filter(u -> customerSel.getCustomerId().equals(u.getCustomerId()) && customerSel.getCustomerCode().equals(u.getCode())).findFirst().orElse(null);
-			if (srcUser == null) {
-				insertOrUpdateUser.setPassword(DigestUtil.hex(MD5Util.encryptionData("Kbs@888")));
-				insertOrUpdateUser.setCreateTime(nowDate);
+			User srcUser = dealerUserList.stream().filter(u -> customerSel.getCustomerId().equals(u.getCustomerId())
+				&& customerSel.getCustomerCode().equals(u.getCode())).findFirst().orElse(null);
+			User userToSave = new User();
+			boolean isNewUser = (srcUser == null);
+			if (isNewUser) {
+				// 新建用户
+				userToSave.setPassword(DigestUtil.hex(MD5Util.encryptionData("Kbs@888")));
+				userToSave.setCreateTime(nowDate);
 			} else {
-				insertOrUpdateUser.setId(srcUser.getId());
-				insertOrUpdateUser.setUpdateTime(nowDate);
-				srcUser.setIsDeleted(0);
+				// 更新已有用户
+				userToSave.setId(srcUser.getId());
+				userToSave.setUpdateTime(nowDate);
+				userToSave.setWorkingStatus(0);
 			}
-			insertOrUpdateUser.setDeptId(String.valueOf(dept.getId()));
-			insertOrUpdateUser.setUserType(1);
-			insertOrUpdateUser.setCode(customerSel.getCustomerCode());
-			insertOrUpdateUser.setName(customerSel.getCustomerName());
-			insertOrUpdateUser.setRealName(customerSel.getCustomerName());
-			insertOrUpdateUser.setCustomerId(customerSel.getCustomerId());
-			insertOrUpdateUser.setRoleId(dealerRoleId);
-			insertOrUpdateUser.setAccount(customerSel.getCustomerCode());
-			// insertOrUpdateUser.setAccount(customerSel.getDescFlexFieldPrivateDescSeg1());
-			insertOrUpdateUser.setPhone(customerSel.getDescFlexFieldPrivateDescSeg2());
-			insertOrUpdateUser.setBankDeposit(customerSel.getBuyerBankAccount());
-			insertOrUpdateUser.setBankAccount(customerSel.getBuyerBankAccountCode());
-			insertOrUpdateUser.setUserTypeRole(2);
+			// 处理部门逻辑
+			Dept deptToUse = handleDepartment(customerSel.getCustomerName(), srcUser, dealerDeptList, dept.getId(), bladeUser.getTenantId(), updateDeptList);
+			userToSave.setDeptId(String.valueOf(deptToUse.getId()));
+			insertOrUpdateUserList.add(userToSave);
+			userToSave.setDeptId(String.valueOf(dept.getId()));
+			userToSave.setUserType(1);
+			userToSave.setCode(customerSel.getCustomerCode());
+			userToSave.setName(customerSel.getCustomerName());
+			userToSave.setRealName(customerSel.getCustomerName());
+			userToSave.setCustomerId(customerSel.getCustomerId());
+			userToSave.setRoleId(dealerRoleId);
+			userToSave.setAccount(customerSel.getCustomerCode());
+			// userToSave.setAccount(customerSel.getDescFlexFieldPrivateDescSeg1());
+			userToSave.setPhone(customerSel.getDescFlexFieldPrivateDescSeg2());
+			userToSave.setBankDeposit(customerSel.getBuyerBankAccount());
+			userToSave.setBankAccount(customerSel.getBuyerBankAccountCode());
+			userToSave.setUserTypeRole(2);
 		}
 		List<User> delUserList = dealerUserList.stream().filter(u -> u.getIsDeleted() == 1).collect(Collectors.toList());
 		for (User user : delUserList) {
+			Dept existingDept = dealerDeptList.stream().filter(d -> d.getId().equals(Long.valueOf(user.getDeptId()))).findFirst().orElse(null);
+			if (existingDept != null) {
+				existingDept.setStatus(1);
+				updateDeptList.add(existingDept);
+			}
 			User delUser = new User();
 			delUser.setId(user.getId());
-			delUser.setIsDeleted(1);
+			delUser.setWorkingStatus(1);
 			delUser.setUpdateTime(nowDate);
 			insertOrUpdateUserList.add(delUser);
 		}
+		// 批量启用、禁用部门
+		if (!CollectionUtils.isEmpty(updateDeptList)) {
+			boolean updateSuccess = sysClient.updateDeptBatch(updateDeptList);
+			if (!updateSuccess) {
+				throw new RuntimeException("更新部门失败");
+			}
+		}
 		boolean updateCount = service.saveOrUpdateBatch(insertOrUpdateUserList);
-		return updateCount ? R.success("成功") : R.fail("失败");
+		if (!updateCount) {
+			throw new RuntimeException("更新用户失败");
+		}
+		return R.success("成功");
 	}
 
 
+	private Dept handleDepartment(String customerName, User srcUser, List<Dept> dealerDeptList,
+								  Long parentId, String tenantId, List<Dept> updateDeptList) {
+		if (srcUser != null && srcUser.getDeptId() != null) {
+			Long deptId = Long.valueOf(srcUser.getDeptId());
+			Dept existingDept = dealerDeptList.stream().filter(d -> d.getId().equals(deptId)).findFirst().orElse(null);
+			if (existingDept != null) {
+				// 更新现有部门信息
+				existingDept.setStatus(0);
+				existingDept.setDeptName(customerName);
+				existingDept.setFullName(customerName);
+				updateDeptList.add(existingDept);
+				return existingDept;
+			}
+		}
+		// 创建新部门
+		Dept newDept = new Dept(parentId, customerName, customerName, NumberEnum.THREE.number, tenantId);
+		boolean success = sysClient.insertDept(newDept);
+		if (!success) {
+			throw new DataSourceException("添加部门失败");
+		}
+		return newDept;
+	}
+
 }