bai 2 тижнів тому
батько
коміт
7b988d216a

+ 44 - 0
blade-service-api/blade-u9cloud-api/src/main/java/org/springblade/u9cloud/entity/ZCRMViewARBillHeadSel.java

@@ -0,0 +1,44 @@
+package org.springblade.u9cloud.entity;
+
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import org.springblade.core.mp.base.BaseEntity;
+
+/**
+ * <p>
+ * 应收单表
+ * </p>
+ *
+ * @author your-name
+ * @since 2025-07-30
+ */
+@Data
+@TableName("zcrm_view_zrbillhead_sel")
+public class ZCRMViewARBillHeadSel extends BaseEntity {
+
+	private static final long serialVersionUID = 1L;
+
+
+	/* ========== 通用字段 ========== */
+
+	@JsonProperty("ORG_ID")
+	@TableField("ORG_ID")
+	private Long orgId;
+
+	@JsonProperty("ORG_CODE")
+	@TableField("ORG_CODE")
+	private String orgCode;
+
+	@JsonProperty("ORG_NAME")
+	@TableField("ORG_NAME")
+	private String orgName;
+
+
+
+
+
+
+}

+ 268 - 0
blade-service/blade-factory/src/main/java/org/springblade/factory/api/controller/SalesOrderController.java

@@ -0,0 +1,268 @@
+package org.springblade.factory.api.controller;
+
+
+import com.alibaba.cloud.commons.lang.StringUtils;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.apache.poi.ss.formula.functions.T;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.tool.api.R;
+import org.springblade.factory.entity.PcBladeCustomerAddress;
+import org.springblade.factory.entity.ViewItemSel;
+import org.springblade.factory.entity.ViewWhqohSel;
+import org.springblade.factory.service.PcBladeCustomerAddressService;
+import org.springblade.factory.service.ZcrmViewItemSelService;
+import org.springblade.factory.service.ZcrmViewWhqohSelService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springblade.core.secure.utils.AuthUtil;
+import springfox.documentation.annotations.ApiIgnore;
+
+import java.util.List;
+import java.util.Map;
+
+
+//	System.out.println(AuthUtil.getTenantId());
+//	System.out.println(AuthUtil.getClientId());
+//	System.out.println(AuthUtil.getDeptId());
+//	System.out.println(AuthUtil.getHeader());
+//	System.out.println(AuthUtil.getNickName());
+//	System.out.println(AuthUtil.getOauthId());
+//	System.out.println(AuthUtil.getPostId());
+//	System.out.println(AuthUtil.getUser());
+//	System.out.println(AuthUtil.getUserAccount());
+
+/**
+ * 销售订单接口 控制器
+ *
+ * @author horizon
+ * @since 2025-08-05
+ */
+@RestController
+@RequestMapping("/api/factory/salesOrder")
+@AllArgsConstructor
+public class SalesOrderController {
+
+	/* ========== 收获地址管理 ========== */
+	private final PcBladeCustomerAddressService pcBladeCustomerAddressService;
+	/**
+	 * 获取下单人收获地址列表
+	 * @return
+	 */
+	@GetMapping("/getAddressList")
+	public R<List<PcBladeCustomerAddress>> getAddressList() {
+		Long userId = AuthUtil.getUserId();
+		if (userId == null) {
+			return R.fail("未获取到用户信息");
+		}
+		List<PcBladeCustomerAddress> addressList = pcBladeCustomerAddressService.getByCreateUser(userId.toString());
+		return R.data(addressList);
+	}
+
+	/**
+	 * 添加收货地址
+	 * @param address 地址信息
+	 * @return 操作结果
+	 */
+	@PostMapping("/addAddress")
+	public R<String> addAddress(@RequestBody PcBladeCustomerAddress address) {
+		// 简单的参数校验
+		if (StringUtils.isEmpty(address.getReceiverName()) || StringUtils.isEmpty(address.getReceiverPhone())) {
+			return R.fail("收件人姓名和电话不能为空");
+		}
+
+		// 验证用户是否登录
+		Long userId = AuthUtil.getUserId();
+		if (userId == null) {
+			return R.fail("请先登录");
+		}
+
+		// 调用服务层添加地址
+		boolean success = pcBladeCustomerAddressService.addAddress(address);
+		return success ? R.data("200", "地址添加成功") : R.fail("地址添加失败");
+	}
+
+
+
+	/**
+	 * 修改收货地址
+	 * @param address 地址信息
+	 * @return 操作结果
+	 */
+	@PutMapping("/updateAddress")
+	public R<String> updateAddress(@RequestBody PcBladeCustomerAddress address) {
+		// 简单的参数校验
+		if (StringUtils.isEmpty(address.getReceiverName()) || StringUtils.isEmpty(address.getReceiverPhone())) {
+			return R.fail("收件人姓名和电话不能为空");
+		}
+
+		if (address.getId() == null) {
+			return R.fail("编辑地址不存在");
+		}
+
+		// 验证用户是否登录
+		Long userId = AuthUtil.getUserId();
+		if (userId == null) {
+			return R.fail("请先登录");
+		}
+
+		// 调用服务层添加地址
+		boolean success = pcBladeCustomerAddressService.updateAddress(address);
+		if (success) {
+			return R.data(200,"", "地址添加成功");
+		} else {
+			return R.fail("地址添加失败");
+		}
+	}
+
+	/**
+	 * 单独修改地址的默认状态
+	 * @param addressId 要设为默认的地址ID
+	 * @return 操作结果
+	 */
+	@PutMapping("/setDefaultAddress")
+	public R<String> setDefaultAddress(@RequestParam Long addressId) {
+		if (addressId == null || addressId <= 0) {
+			return R.fail("地址ID不能为空");
+		}
+
+		boolean success = pcBladeCustomerAddressService.setDefaultAddress(addressId);
+		if (success) {
+			return R.data(200,"", "设置默认地址成功");
+		} else {
+			return R.fail("设置默认地址失败,请检查地址是否存在或您是否有权限");
+		}
+	}
+
+	/**
+	 * 删除指定地址
+	 * @param addressId 要删除的地址ID
+	 * @return 操作结果
+	 */
+	@DeleteMapping("/deleteAddress")
+	public R<String> deleteAddress(@RequestParam Long addressId) {
+		if (addressId == null || addressId <= 0) {
+			return R.fail("地址ID不能为空");
+		}
+
+		boolean success = pcBladeCustomerAddressService.deleteAddress(addressId);
+		if (success) {
+			return R.data(200, "", "地址删除成功");
+		} else {
+			return R.fail("地址删除失败,请检查地址是否存在或您是否有权限");
+		}
+	}
+
+
+	/* ========== 订单提交 ========== */
+
+
+	/* ========== 订单修改 ========== */
+
+
+	/* ========== 创建订单 ========== */
+	@Autowired
+	private ZcrmViewWhqohSelService whqohService;
+	// 获取品牌 -- 接口
+
+	// 检查库存 -- 接口
+	/**
+	 * 仓库库存列表
+	 */
+	@GetMapping("/whqoh/list")
+	@ApiOperation(value = "仓库库存列表", notes = "")
+	public R<IPage<ViewWhqohSel>> whqohList(
+		@ApiIgnore @RequestParam Map<String, Object> params,
+		Query query,
+		ViewWhqohSel viewWhqohSel) {
+		// 1. 构建基础查询条件
+		QueryWrapper<ViewWhqohSel> queryWrapper = Condition.getQueryWrapper(params, ViewWhqohSel.class);
+		// 2. 执行分页查询
+		IPage<ViewWhqohSel> pages = whqohService.page(Condition.getPage(query), queryWrapper);
+		// 3. 返回结果
+		return R.data(pages);
+	}
+
+
+	/**
+	 * 仓库库存全量查询(不分页)
+	 */
+	@GetMapping("/whqoh/fullList")
+	@ApiOperation(value = "仓库库存全量查询", notes = "查询所有仓库库存数据,不分页")
+	public R<List<ViewWhqohSel>> whqohFullList(
+		@ApiIgnore @RequestParam Map<String, Object> params,
+		ViewWhqohSel viewWhqohSel) {
+		// 1. 构建查询条件(复用参数处理逻辑)
+		QueryWrapper<ViewWhqohSel> queryWrapper = Condition.getQueryWrapper(params, ViewWhqohSel.class);
+
+		// 2. 执行全量查询(不使用分页)
+		List<ViewWhqohSel> list = whqohService.list(queryWrapper);
+
+		// 3. 返回结果
+		return R.data(list);
+	}
+
+	/**
+	 * 单条查询
+	 */
+	@GetMapping("/whqoh/{id}")
+	public R<ViewWhqohSel> whqohGet(@PathVariable("id") Long id) {
+		ViewWhqohSel whqoh = whqohService.selectZcrmViewWhqohSelById(id);
+		return R.data(whqoh);
+	}
+
+
+
+	// 获取物料列表 -- 接口
+	@Autowired
+	private ZcrmViewItemSelService itemService;
+
+	/**
+	 * 料品档案列表
+	 */
+	@GetMapping("/item/list")
+	@ApiOperation(value = "料品档案列表", notes = "")
+	public R<IPage<ViewItemSel>> itemList(
+		@ApiIgnore @RequestParam Map<String, Object> params,
+		Query query,
+		ViewItemSel zcrmViewItemSel) {
+		// 1. 构建基础查询条件
+		QueryWrapper<ViewItemSel> queryWrapper = Condition.getQueryWrapper(params, ViewItemSel.class);
+		// 2. 执行分页查询
+		IPage<ViewItemSel> pages = itemService.page(Condition.getPage(query), queryWrapper);
+		// 3. 返回结果
+		return R.data(pages);
+	}
+
+
+	/**
+	 * 料品档案全量查询(不分页)
+	 */
+	@GetMapping("/item/fullList")
+	@ApiOperation(value = "料品档案全量查询", notes = "查询所有符合条件的料品档案数据,不分页")
+	public R<List<ViewItemSel>> itemFullList(
+		@ApiIgnore @RequestParam Map<String, Object> params,
+		ViewItemSel zcrmViewItemSel) {
+		// 1. 构建查询条件(复用参数处理逻辑)
+		QueryWrapper<ViewItemSel> queryWrapper = Condition.getQueryWrapper(params, ViewItemSel.class);
+
+		// 2. 执行全量查询(不使用分页)
+		List<ViewItemSel> list = itemService.list(queryWrapper);
+
+		// 3. 返回结果
+		return R.data(list);
+	}
+
+	/**
+	 * 单条查询
+	 */
+	@GetMapping("/item/{id}")
+	public R<ViewItemSel> itemGet(@PathVariable("id") Long id) {
+		ViewItemSel item = itemService.selectZcrmViewItemSelById(id);
+		return R.data(item);
+	}
+
+}

+ 39 - 0
blade-service/blade-factory/src/main/java/org/springblade/factory/service/PcBladeCustomerAddressService.java

@@ -37,4 +37,43 @@ public interface PcBladeCustomerAddressService extends BaseService<PcBladeCustom
 	public boolean updatePcBladeCustomerAddress(PcBladeCustomerAddress pcBladeCustomerAddress);
 
 
+	/* ========== 业务 ========== */
+
+	/**
+	 * 根据创建人获取列表
+	 * @param createUser
+	 * @return
+	 */
+	List<PcBladeCustomerAddress> getByCreateUser(String createUser);
+
+	/**
+	 * 用户添加一条数据
+	 * @param address
+	 * @return
+	 */
+	boolean addAddress(PcBladeCustomerAddress address);
+
+	/**
+	 * 用户修改一条数据
+	 * @param address
+	 * @return
+	 */
+	boolean updateAddress(PcBladeCustomerAddress address);
+
+	/**
+	 * 用户修改默认地址一条数据
+	 * @param addressId
+	 * @return
+	 */
+	boolean setDefaultAddress(Long addressId);
+
+
+	/**
+	 * 用户删除地址一条数据
+	 * @param addressId
+	 * @return
+	 */
+	boolean deleteAddress(Long addressId);
+
+
 }

+ 138 - 0
blade-service/blade-factory/src/main/java/org/springblade/factory/service/impl/PcBladeCustomerAddressServiceImpl.java

@@ -4,11 +4,13 @@ package org.springblade.factory.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.AllArgsConstructor;
 import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.factory.entity.PcBladeCustomerAddress;
 import org.springblade.factory.mapper.PcBladeCustomerAddressMapper;
 import org.springblade.factory.service.PcBladeCustomerAddressService;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.List;
 
 @Service
@@ -38,4 +40,140 @@ public class PcBladeCustomerAddressServiceImpl
 		return this.updateById(pcBladeCustomerAddress);
 	}
 
+	/* ========== 业务 ========== */
+
+	@Override
+	public List<PcBladeCustomerAddress> getByCreateUser(String createUser) {
+		QueryWrapper<PcBladeCustomerAddress> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("create_user", createUser);
+		queryWrapper.eq("is_deleted", 0);
+		// 可以根据需要添加排序,比如按创建时间倒序
+		queryWrapper.orderByDesc("create_time");
+		return this.list(queryWrapper);
+	}
+
+	@Override
+	public boolean addAddress(PcBladeCustomerAddress address) {
+		// 设置创建人ID(从当前登录用户获取)
+		address.setCreateUser(AuthUtil.getUserId());
+		QueryWrapper<PcBladeCustomerAddress> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("create_user", AuthUtil.getUserId().toString());
+		queryWrapper.eq("is_default",0);
+		// 可以根据需要添加排序,比如按创建时间倒序
+		queryWrapper.orderByDesc("create_time");
+		List<PcBladeCustomerAddress> pcBladeCustomerAddressesList = this.list(queryWrapper);
+		// 查询出来后修改
+		if(pcBladeCustomerAddressesList != null && !pcBladeCustomerAddressesList.isEmpty()) {
+			for(PcBladeCustomerAddress pcBladeCustomerAddress : pcBladeCustomerAddressesList) {
+				pcBladeCustomerAddress.setIsDefault(0);
+				pcBladeCustomerAddress.setUpdateTime(new Date());
+				this.updateById(pcBladeCustomerAddress);
+			}
+		}
+		// 设置创建时间
+		address.setCreateTime(new Date());
+		// 设置更新时间
+		address.setUpdateTime(new Date());
+		address.setIsDefault(1);
+		// 可以根据业务需求设置其他默认值,如是否为默认地址等
+		return this.save(address);
+	}
+
+	@Override
+	public boolean updateAddress(PcBladeCustomerAddress address) {
+		// 第一步:查询出当前要修改的地址数据
+		PcBladeCustomerAddress existingAddress = this.getById(address.getId());
+		if (existingAddress == null) {
+			// 地址不存在,返回修改失败
+			return false;
+		}
+
+		// 第二步:验证数据权限,确保当前登录用户只能修改自己创建的地址
+		Long currentUserId = AuthUtil.getUserId();
+		// 比较当前登录用户ID与地址的创建人ID是否一致
+		if (!currentUserId.equals(existingAddress.getCreateUser())) {
+			// 没有权限修改他人地址,返回失败
+			return false;
+		}
+
+		// 第三步:处理默认地址逻辑
+		if (address.getIsDefault() != null && address.getIsDefault() == 1) {
+			// 如果要将当前地址设为默认,需要先将该用户的其他默认地址改为非默认
+			QueryWrapper<PcBladeCustomerAddress> queryWrapper = new QueryWrapper<>();
+			queryWrapper.eq("create_user", currentUserId)
+				.eq("is_default", 1)
+				// 排除当前正在修改的地址
+				.ne("id", address.getId());
+
+			List<PcBladeCustomerAddress> otherDefaultAddresses = this.list(queryWrapper);
+			for (PcBladeCustomerAddress defaultAddr : otherDefaultAddresses) {
+				defaultAddr.setIsDefault(0);
+				defaultAddr.setUpdateTime(new Date());
+				this.updateById(defaultAddr);
+			}
+		}
+
+		// 设置更新时间
+		address.setUpdateTime(new Date());
+		// 执行更新操作
+		return this.updateById(address);
+	}
+
+
+
+	@Override
+	public boolean setDefaultAddress(Long addressId) {
+		// 1. 获取当前登录用户ID
+		Long userId = AuthUtil.getUserId();
+		if (userId == null) {
+			// 用户未登录,返回失败
+			return false;
+		}
+
+		// 2. 查询要设为默认的地址是否存在且属于当前用户
+		PcBladeCustomerAddress targetAddress = this.getById(addressId);
+		if (targetAddress == null || !userId.equals(targetAddress.getCreateUser())) {
+			// 地址不存在或不属于当前用户,返回失败
+			return false;
+		}
+
+		// 3. 将该用户所有其他默认地址改为非默认
+		QueryWrapper<PcBladeCustomerAddress> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("create_user", userId)
+			.eq("is_default", 1)
+			.ne("id", addressId); // 排除当前要设为默认的地址
+
+		List<PcBladeCustomerAddress> otherDefaultAddresses = this.list(queryWrapper);
+		for (PcBladeCustomerAddress addr : otherDefaultAddresses) {
+			addr.setIsDefault(0);
+			addr.setUpdateTime(new Date());
+			this.updateById(addr);
+		}
+
+		// 4. 将目标地址设为默认
+		targetAddress.setIsDefault(1);
+		targetAddress.setUpdateTime(new Date());
+		return this.updateById(targetAddress);
+	}
+
+
+	@Override
+	public boolean deleteAddress(Long addressId) {
+		// 1. 获取当前登录用户ID
+		Long userId = AuthUtil.getUserId();
+		if (userId == null) {
+			return false;
+		}
+
+		// 2. 验证地址是否存在且属于当前用户
+		PcBladeCustomerAddress address = this.getById(addressId);
+		if (address == null || !userId.equals(address.getCreateUser())) {
+
+			return false;
+		}
+
+		// 3. 执行删除操作(逻辑删除)
+		 return this.removeById(addressId);
+	}
+
 }

+ 108 - 0
blade-service/blade-u9cloud/src/main/java/org/springblade/u9cloud/Test/TestU9cloudController.java

@@ -693,6 +693,114 @@ public class TestU9cloudController {
 	}
 
 
+	/**
+	 * ZCRM_View_RecBillHead_Sel
+	 * 收款单
+	 * @return
+	 */
+	@GetMapping("/viewRecBillHeadSel")
+	public R<Boolean> viewRecBillHeadSel()
+	{
+		// 1. 构建标准化URL(不带查询参数)
+		String url = UriComponentsBuilder.fromHttpUrl(BASE_URL + PATH_API)
+			.encode(StandardCharsets.UTF_8)
+			.toUriString();
+
+		// 2. 构建POST请求参数(放在请求体中)
+		Map<String, String> requestBody = new HashMap<>();
+		requestBody.put("SqlString", "select * from ZCRM_View_RecBillHead_Sel");
+
+		// 3. 设置请求头
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_JSON);
+		String token = getToken();
+		headers.set("token", token);
+		System.out.println(token);
+		// 4. 构建请求实体
+		HttpEntity<Map<String, Object>> requestEntity = new HttpEntity(requestBody, headers);
+
+		// 4. 发送 POST
+		RestTemplate restTemplate = new RestTemplate();
+		ParameterizedTypeReference<ViewApiResponse<ZcrmViewShipSel>> typeRef =
+			new ParameterizedTypeReference<ViewApiResponse<ZcrmViewShipSel>>() {};
+
+		ResponseEntity<ViewApiResponse<ZcrmViewShipSel>> response =
+			restTemplate.exchange(url, HttpMethod.POST, requestEntity, typeRef);
+
+		// 5. 处理结果
+		ViewApiResponse apiResponse = response.getBody();
+		System.out.println(apiResponse);
+//		List<ZcrmViewShipSel> items = apiResponse.getData();
+//		if (apiResponse != null && apiResponse.isSuccess()) {
+//			if (!items.isEmpty()) {
+//				zcrmViewShipSelService.insertBatchShips(items);
+//				items.forEach(c -> {
+//					System.out.println(c);
+//					System.out.println("组织 ID: " + c.getOrgId());
+//					System.out.println("组织 编码: " + c.getOrgCode());
+//					System.out.println("组织 名称: " + c.getOrgName());
+//				});
+//			}
+//		} else {
+//			System.err.println("请求失败: " + (apiResponse != null ? apiResponse.getResMsg() : "响应为空"));
+//		}
+		return R.data(true, "执行成功");
+	}
+
+
+
+	/**
+	 * ZCRM_View_ARBillHead_Sel
+	 * 应收单
+	 * @return
+	 */
+	@GetMapping("/viewARBillHeadSel")
+	public R<Boolean> viewARBillHeadSel()
+	{
+		// 1. 构建标准化URL(不带查询参数)
+		String url = UriComponentsBuilder.fromHttpUrl(BASE_URL + PATH_API)
+			.encode(StandardCharsets.UTF_8)
+			.toUriString();
+
+		// 2. 构建POST请求参数(放在请求体中)
+		Map<String, String> requestBody = new HashMap<>();
+		requestBody.put("SqlString", "select * from ZCRM_View_ARBillHead_Sel");
+
+		// 3. 设置请求头
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_JSON);
+		String token = getToken();
+		headers.set("token", token);
+		// 4. 构建请求实体
+		HttpEntity<Map<String, Object>> requestEntity = new HttpEntity(requestBody, headers);
+
+		// 4. 发送 POST
+		RestTemplate restTemplate = new RestTemplate();
+		ParameterizedTypeReference<ViewApiResponse<ZcrmViewShipSel>> typeRef =
+			new ParameterizedTypeReference<ViewApiResponse<ZcrmViewShipSel>>() {};
+
+		ResponseEntity<ViewApiResponse<ZcrmViewShipSel>> response =
+			restTemplate.exchange(url, HttpMethod.POST, requestEntity, typeRef);
+
+		// 5. 处理结果
+		ViewApiResponse apiResponse = response.getBody();
+		List<ZcrmViewShipSel> items = apiResponse.getData();
+		if (apiResponse != null && apiResponse.isSuccess()) {
+			if (!items.isEmpty()) {
+				zcrmViewShipSelService.insertBatchShips(items);
+				items.forEach(c -> {
+					System.out.println(c);
+					System.out.println("组织 ID: " + c.getOrgId());
+					System.out.println("组织 编码: " + c.getOrgCode());
+					System.out.println("组织 名称: " + c.getOrgName());
+				});
+			}
+		} else {
+			System.err.println("请求失败: " + (apiResponse != null ? apiResponse.getResMsg() : "响应为空"));
+		}
+		return R.data(true, "执行成功");
+	}
+