diff --git a/ruoyi-web/lib/gson-2.8.0.jar b/common-ruoyi/ruoyi-common/lib/gson-2.8.0.jar similarity index 100% rename from ruoyi-web/lib/gson-2.8.0.jar rename to common-ruoyi/ruoyi-common/lib/gson-2.8.0.jar diff --git a/ruoyi-web/lib/k3cloud-webapi-sdk8.0.6.jar b/common-ruoyi/ruoyi-common/lib/k3cloud-webapi-sdk8.0.6.jar similarity index 100% rename from ruoyi-web/lib/k3cloud-webapi-sdk8.0.6.jar rename to common-ruoyi/ruoyi-common/lib/k3cloud-webapi-sdk8.0.6.jar diff --git a/common-ruoyi/ruoyi-common/pom.xml b/common-ruoyi/ruoyi-common/pom.xml index ce56631..9e8286b 100644 --- a/common-ruoyi/ruoyi-common/pom.xml +++ b/common-ruoyi/ruoyi-common/pom.xml @@ -16,6 +16,25 @@ + + + com.k3cloud + webapi-sdk + 8.0.6 + system + + ${pom.basedir}/lib/k3cloud-webapi-sdk8.0.6.jar + + + + + com.google + gson + 2.8.0 + system + + ${pom.basedir}/lib/gson-2.8.0.jar + diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java index fb18c5c..439ba22 100644 --- a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java @@ -6,15 +6,18 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; + +import lombok.Data; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.domain.BaseEntity; /** * 部门表 sys_dept - * + * * @author ruoyi */ +@Data public class SysDept extends BaseEntity { private static final long serialVersionUID = 1L; @@ -29,18 +32,24 @@ public class SysDept extends BaseEntity private String ancestors; /** 部门名称 */ + @NotBlank(message = "部门名称不能为空") + @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符") private String deptName; /** 显示顺序 */ + @NotNull(message = "显示顺序不能为空") private Integer orderNum; /** 负责人 */ private String leader; /** 联系电话 */ + @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") private String phone; /** 邮箱 */ + @Email(message = "邮箱格式不正确") + @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") private String email; /** 部门状态:0正常,1停用 */ @@ -51,153 +60,13 @@ public class SysDept extends BaseEntity /** 父部门名称 */ private String parentName; - + + // ERP部门ID + private String erpId; + + // ERP部门编码 + private String erpNumber; + /** 子部门 */ private List children = new ArrayList(); - - public Long getDeptId() - { - return deptId; - } - - public void setDeptId(Long deptId) - { - this.deptId = deptId; - } - - public Long getParentId() - { - return parentId; - } - - public void setParentId(Long parentId) - { - this.parentId = parentId; - } - - public String getAncestors() - { - return ancestors; - } - - public void setAncestors(String ancestors) - { - this.ancestors = ancestors; - } - - @NotBlank(message = "部门名称不能为空") - @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符") - public String getDeptName() - { - return deptName; - } - - public void setDeptName(String deptName) - { - this.deptName = deptName; - } - - @NotNull(message = "显示顺序不能为空") - public Integer getOrderNum() - { - return orderNum; - } - - public void setOrderNum(Integer orderNum) - { - this.orderNum = orderNum; - } - - public String getLeader() - { - return leader; - } - - public void setLeader(String leader) - { - this.leader = leader; - } - - @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") - public String getPhone() - { - return phone; - } - - public void setPhone(String phone) - { - this.phone = phone; - } - - @Email(message = "邮箱格式不正确") - @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") - public String getEmail() - { - return email; - } - - public void setEmail(String email) - { - this.email = email; - } - - public String getStatus() - { - return status; - } - - public void setStatus(String status) - { - this.status = status; - } - - public String getDelFlag() - { - return delFlag; - } - - public void setDelFlag(String delFlag) - { - this.delFlag = delFlag; - } - - public String getParentName() - { - return parentName; - } - - public void setParentName(String parentName) - { - this.parentName = parentName; - } - - public List getChildren() - { - return children; - } - - public void setChildren(List children) - { - this.children = children; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("deptId", getDeptId()) - .append("parentId", getParentId()) - .append("ancestors", getAncestors()) - .append("deptName", getDeptName()) - .append("orderNum", getOrderNum()) - .append("leader", getLeader()) - .append("phone", getPhone()) - .append("email", getEmail()) - .append("status", getStatus()) - .append("delFlag", getDelFlag()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .toString(); - } } diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java index 89e9e52..dd4ac18 100644 --- a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/enums/RedisLockKey.java @@ -11,7 +11,8 @@ import lombok.Getter; @AllArgsConstructor public enum RedisLockKey { - SYNC_PROD_BILL("sync_prod_bill", "同步生产订单"); + SYNC_PROD_BILL("sync_prod_bill", "同步生产订单"), + SAVE_MATERIAL("save_material", "保存物料"); private final String key; diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/enums/LogBizType.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/enums/LogBizType.java index 9c2ddb3..8e7dd4c 100644 --- a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/enums/LogBizType.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/enums/LogBizType.java @@ -15,7 +15,8 @@ public enum LogBizType { UNKNOWN("0", "未知"), PRICE("1", "单价"), REPORT("2", "报表"), - PROD_ORDER("3", "生产订单" ); + PROD_ORDER("3", "生产订单" ), + MATERIAL("4", "物料"); private final String type; private final String msg; diff --git a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/config/K3CloudConfig.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/config/K3CloudConfig.java similarity index 89% rename from ruoyi-web/src/main/java/com/ruoyi/k3cloud/config/K3CloudConfig.java rename to common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/config/K3CloudConfig.java index aab8cce..e4aaa90 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/config/K3CloudConfig.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/config/K3CloudConfig.java @@ -1,4 +1,4 @@ -package com.ruoyi.k3cloud.config; +package com.ruoyi.common.k3cloud.config; import com.kingdee.bos.webapi.sdk.K3CloudApi; import org.springframework.context.annotation.Bean; diff --git a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/constants/K3Constants.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/K3Constants.java similarity index 83% rename from ruoyi-web/src/main/java/com/ruoyi/k3cloud/constants/K3Constants.java rename to common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/K3Constants.java index d53554a..21b5dac 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/constants/K3Constants.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/K3Constants.java @@ -1,4 +1,4 @@ -package com.ruoyi.k3cloud.constants; +package com.ruoyi.common.k3cloud.constants; /** * 金蝶常量 diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/K3FormIds.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/K3FormIds.java new file mode 100644 index 0000000..ff4521a --- /dev/null +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/K3FormIds.java @@ -0,0 +1,23 @@ +package com.ruoyi.common.k3cloud.constants; + +/** + * @author wjh + * 2024/11/11 + */ +public class K3FormIds { + + /** + * 生产订单 + */ + public static final String PROD_ORDER = "PRD_MO"; + + /** + * 物料 + */ + public static final String MATERIAL = "BD_MATERIAL"; + + /** + * 部门 + */ + public static final String DEPT = "BD_Department"; +} diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/fileds/K3MaterialField.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/fileds/K3MaterialField.java new file mode 100644 index 0000000..1e1b738 --- /dev/null +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/fileds/K3MaterialField.java @@ -0,0 +1,14 @@ +package com.ruoyi.common.k3cloud.constants.fileds; + +/** + * @author wjh + * 2024/11/12 + */ +public class K3MaterialField { + + public static final String F_NAME = "FName"; // 名称 + public static final String F_NUMBER = "FNumber"; // 编码 + public static final String F_SPECIFICATION = "FSpecification"; // 规格型号 + public static final String F_MATERIAL_ID = "FMATERIALID"; // 物料ID + +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/business/prodOrder/constants/K3ProdField.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/fileds/K3ProdField.java similarity index 91% rename from ruoyi-web/src/main/java/com/ruoyi/k3cloud/business/prodOrder/constants/K3ProdField.java rename to common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/fileds/K3ProdField.java index 73e44ff..2e91369 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/business/prodOrder/constants/K3ProdField.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/constants/fileds/K3ProdField.java @@ -1,4 +1,4 @@ -package com.ruoyi.k3cloud.business.prodOrder.constants; +package com.ruoyi.common.k3cloud.constants.fileds; /** * @author wjh @@ -13,6 +13,7 @@ public class K3ProdField { public static final String F_DESCRIPTION = "FDescription"; // 备注 public static final String F_DATE = "FDate"; // 单据日期 public static final String F_IS_REWORK = "FIsRework"; // 是否返工 + public static final String F_MATERIAL_ID = "FMaterialId"; // 物料ID public static final String F_ROW_ID = "FRowId"; // 明细.行标识 public static final String F_MEMO_ITEM = "FMemoItem"; // 明细.备注 public static final String F_CONVEY_DATE = "FConveyDate"; // 明细.下达日期 diff --git a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/service/K3Service.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/service/K3Service.java similarity index 52% rename from ruoyi-web/src/main/java/com/ruoyi/k3cloud/service/K3Service.java rename to common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/service/K3Service.java index b0268a3..d8a2d1f 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/k3cloud/service/K3Service.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/k3cloud/service/K3Service.java @@ -1,19 +1,25 @@ -package com.ruoyi.k3cloud.service; +package com.ruoyi.common.k3cloud.service; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.google.gson.Gson; +import com.kingdee.bos.webapi.entity.IdentifyInfo; +import com.kingdee.bos.webapi.entity.RepoRet; import com.kingdee.bos.webapi.sdk.K3CloudApi; import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.k3cloud.business.prodOrder.constants.K3ProdField; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.*; /** - * 金蝶生产订单Service + * 金蝶Service * @author wjh * 2024/10/30 */ @@ -52,4 +58,38 @@ public class K3Service { throw new ServiceException("获取云星空数据失败"); } } + + public T selectOneByNumber(String formId, String number, Class clazz) { + return selectOne(formId, number, "", "0", false, clazz); + } + public T selectOneById(String formId, String id, Class clazz) { + return selectOne(formId, "", id, "0", false, clazz); + } + + /** + * 查看表单内容 + * @param formId 表单类型 + * @param number 单据编号 + * @param id 单据ID + * @param createOrgId 创建组织 + * @param isSortBySeq + * @param clazz 返回值类型 + */ + public T selectOne(String formId, String number, String id, String createOrgId, boolean isSortBySeq, Class clazz) { + try { + JSONObject params = new JSONObject(); + params.put("CreateOrgId", createOrgId); + params.put("Number", number); + params.put("Id", id); + params.put("IsSortBySeq", isSortBySeq); + String res = api.view(formId, params.toJSONString()); + if (StringUtils.isBlank(res)) { + return null; + } + return JSONObject.parseObject(res, clazz); + } catch (Exception e) { + log.error("获取云星空数据失败: formId = {}, message = {}", formId, e.getMessage()); + throw new ServiceException("获取云星空数据失败"); + } + } } diff --git a/common-ruoyi/ruoyi-generator/src/main/resources/vm/java/controller.java.vm b/common-ruoyi/ruoyi-generator/src/main/resources/vm/java/controller.java.vm index 2d1e220..bbea209 100644 --- a/common-ruoyi/ruoyi-generator/src/main/resources/vm/java/controller.java.vm +++ b/common-ruoyi/ruoyi-generator/src/main/resources/vm/java/controller.java.vm @@ -64,7 +64,7 @@ public class ${ClassName}Controller extends BaseController * 导出${functionName}列表 */ @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") - @Log(title = "导出${functionName}", businessType = BusinessType.EXPORT) + @Log(title = "${functionName}", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, ${ClassName}Query query) { @@ -87,7 +87,7 @@ public class ${ClassName}Controller extends BaseController * 新增${functionName} */ @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") - @Log(title = "新增${functionName}", businessType = BusinessType.INSERT) + @Log(title = "${functionName}", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody ${ClassName} ${className}) { @@ -98,7 +98,7 @@ public class ${ClassName}Controller extends BaseController * 修改${functionName} */ @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") - @Log(title = "修改${functionName}", businessType = BusinessType.UPDATE) + @Log(title = "${functionName}", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody ${ClassName} ${className}) { @@ -109,7 +109,7 @@ public class ${ClassName}Controller extends BaseController * 删除${functionName} */ @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") - @Log(title = "删除${functionName}", businessType = BusinessType.DELETE) + @Log(title = "${functionName}", businessType = BusinessType.DELETE) @DeleteMapping("/{${pkColumn.javaField}s}") public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) { diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index d46f35c..29f9f8f 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -6,6 +6,11 @@ import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; +import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.common.k3cloud.constants.K3Constants; +import com.ruoyi.common.k3cloud.constants.K3FormIds; +import com.ruoyi.common.k3cloud.service.K3Service; +import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.system.domain.dto.SysDeptQuery; import org.springframework.beans.factory.annotation.Autowired; @@ -39,6 +44,9 @@ public class SysDeptServiceImpl implements ISysDeptService @Autowired private SysRoleMapper roleMapper; + @Autowired + private K3Service k3Service; + /** * 查询部门管理数据 * @@ -223,9 +231,36 @@ public class SysDeptServiceImpl implements ISysDeptService throw new ServiceException("部门停用,不允许新增"); } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + + // 设置ERP部门ID + this.setDeptErpId(dept); + return deptMapper.insertDept(dept); } + /** + * 根据编码设置ERP部门ID + */ + private void setDeptErpId(SysDept dept) { + if (dept == null || StringUtils.isBlank(dept.getErpNumber())) { + return; + } + JSONObject obj = k3Service.selectOneByNumber(K3FormIds.DEPT, dept.getErpNumber(), JSONObject.class); + + if (obj != null) { + JSONObject result = obj.getJSONObject("Result"); + if (result != null) { + JSONObject result1 = result.getJSONObject("Result"); + if (result1 != null) { + String erpId = result1.getString("Id"); + dept.setErpId(erpId); + return; + } + } + } + throw new ServiceException("当前部门编号在ERP中不存在"); + } + /** * 修改保存部门信息 * @@ -244,6 +279,8 @@ public class SysDeptServiceImpl implements ISysDeptService dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); } + // 设置ERP部门ID + this.setDeptErpId(dept); int result = deptMapper.updateDept(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals("0", dept.getAncestors())) diff --git a/common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 2a615e3..6f1a071 100644 --- a/common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -4,26 +4,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - + - select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time + select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time, d.erp_id, d.erp_number from sys_dept d @@ -42,6 +26,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND `status` = #{status} + + AND `erp_id` = #{erpId} + AND dept_name in @@ -65,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + insert into bst_material + + erp_id, + erp_number, + erp_name, + erp_spec, + work_shops, + category, + size, + surface, + cover, + + + #{erpId}, + #{erpNumber}, + #{erpName}, + #{erpSpec}, + #{workShops,typeHandler=com.ruoyi.common.mybatis.typehandler.StringSplitListTypeHandler}, + #{category}, + #{size}, + #{surface}, + #{cover}, + + + + + update bst_material + + + + where id = #{data.id} + + + + erp_id = #{data.erpId}, + erp_number = #{data.erpNumber}, + erp_name = #{data.erpName}, + erp_spec = #{data.erpSpec}, + work_shops = #{data.workShops,typeHandler=com.ruoyi.common.mybatis.typehandler.StringSplitListTypeHandler}, + category = #{data.category}, + size = #{data.size}, + surface = #{data.surface}, + cover = #{data.cover}, + + + + delete from bst_material where id = #{id} + + + + delete from bst_material where id in + + #{id} + + + diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/MaterialConverter.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/MaterialConverter.java new file mode 100644 index 0000000..737fc7b --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/MaterialConverter.java @@ -0,0 +1,20 @@ +package com.ruoyi.web.yh.material.service; + +import com.alibaba.fastjson2.JSONArray; +import com.ruoyi.web.yh.material.domain.Material; + +import java.util.List; + +/** + * @author wjh + * 2024/11/12 + */ +public interface MaterialConverter { + + /** + * 将ERP数据转为PO列表 + * @param headers 表头 + * @param erpList 数据列表 + */ + List toPoByErpList(List headers, List erpList); +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/MaterialService.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/MaterialService.java new file mode 100644 index 0000000..b8925f2 --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/MaterialService.java @@ -0,0 +1,66 @@ +package com.ruoyi.web.yh.material.service; + +import java.util.List; +import com.ruoyi.web.yh.material.domain.Material; +import com.ruoyi.web.yh.material.domain.MaterialVO; +import com.ruoyi.web.yh.material.domain.MaterialQuery; + +/** + * 物料Service接口 + * + * @author ruoyi + * @date 2024-11-12 + */ +public interface MaterialService +{ + /** + * 查询物料 + * + * @param id 物料主键 + * @return 物料 + */ + public MaterialVO selectMaterialById(Long id); + + /** + * 查询物料列表 + * + * @param material 物料 + * @return 物料集合 + */ + public List selectMaterialList(MaterialQuery material); + + /** + * 新增物料 + * + * @param material 物料 + * @return 结果 + */ + public int insertMaterial(Material material); + + /** + * 修改物料 + * + * @param material 物料 + * @return 结果 + */ + public int updateMaterial(Material material); + + /** + * 批量删除物料 + * + * @param ids 需要删除的物料主键集合 + * @return 结果 + */ + public int deleteMaterialByIds(Long[] ids); + + /** + * 删除物料信息 + * + * @param id 物料主键 + * @return 结果 + */ + public int deleteMaterialById(Long id); + + int sync(); + +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/impl/MaterialConverterImpl.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/impl/MaterialConverterImpl.java new file mode 100644 index 0000000..0471adc --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/impl/MaterialConverterImpl.java @@ -0,0 +1,70 @@ +package com.ruoyi.web.yh.material.service.impl; + +import com.alibaba.fastjson2.JSONArray; +import com.ruoyi.common.k3cloud.constants.fileds.K3MaterialField; +import com.ruoyi.web.yh.material.domain.Material; +import com.ruoyi.web.yh.material.domain.vo.MaterialNumberSplitVO; +import com.ruoyi.web.yh.material.service.MaterialConverter; +import com.ruoyi.web.yh.material.utils.MaterialUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author wjh + * 2024/11/12 + */ +@Service +public class MaterialConverterImpl implements MaterialConverter { + @Override + public List toPoByErpList(List headers, List erpList) { + + if (CollectionUtils.isEmpty(headers) || CollectionUtils.isEmpty(erpList)) { + return Collections.emptyList(); + } + + // 创建erpList大小的对象列表 + List result = new ArrayList<>(erpList.size()); + + for (JSONArray row : erpList) { + Material po = new Material(); + for (int i = 0; i < headers.size(); i++) { + String header = headers.get(i); + switch (header) { + case K3MaterialField.F_MATERIAL_ID: + po.setErpId(row.getString(i)); + break; + case K3MaterialField.F_NAME: + po.setErpName(row.getString(i)); + break; + case K3MaterialField.F_NUMBER: + po.setErpNumber(row.getString(i)); + break; + case K3MaterialField.F_SPECIFICATION: + po.setErpSpec(row.getString(i)); + break; + default: + break; + } + } + // 处理物料编码 + MaterialNumberSplitVO vo = MaterialUtil.parseToSplit(po.getErpNumber()); + if (vo != null) { + po.setWorkShops(vo.getWorkShops()); + po.setCategory(vo.getCategory()); + po.setSize(vo.getSize()); + po.setSurface(vo.getSurface()); + po.setCover(vo.getCover()); + } + + result.add(po); + } + + + + return result; + } +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/impl/MaterialServiceImpl.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/impl/MaterialServiceImpl.java new file mode 100644 index 0000000..8bedb15 --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/service/impl/MaterialServiceImpl.java @@ -0,0 +1,216 @@ +package com.ruoyi.web.yh.material.service.impl; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import com.alibaba.fastjson2.JSONArray; +import com.github.pagehelper.PageHelper; +import com.ruoyi.common.core.redis.RedisLock; +import com.ruoyi.common.core.redis.enums.RedisLockKey; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.ServiceUtil; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.common.k3cloud.constants.K3FormIds; +import com.ruoyi.common.k3cloud.constants.fileds.K3MaterialField; +import com.ruoyi.common.k3cloud.service.K3Service; +import com.ruoyi.web.yh.material.service.MaterialConverter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.web.yh.material.mapper.MaterialMapper; +import com.ruoyi.web.yh.material.domain.Material; +import com.ruoyi.web.yh.material.domain.MaterialVO; +import com.ruoyi.web.yh.material.domain.MaterialQuery; +import com.ruoyi.web.yh.material.service.MaterialService; + +/** + * 物料Service业务层处理 + * + * @author ruoyi + * @date 2024-11-12 + */ +@Service +@Slf4j +public class MaterialServiceImpl implements MaterialService +{ + @Autowired + private MaterialMapper materialMapper; + + @Autowired + private MaterialConverter materialConverter; + + @Autowired + private K3Service k3Service; + + @Autowired + private ScheduledExecutorService scheduledExecutorService; + + @Autowired + private RedisLock redisLock; + + /** + * 查询物料 + * + * @param id 物料主键 + * @return 物料 + */ + @Override + public MaterialVO selectMaterialById(Long id) + { + return materialMapper.selectMaterialById(id); + } + + /** + * 查询物料列表 + * + * @param material 物料 + * @return 物料 + */ + @Override + public List selectMaterialList(MaterialQuery material) + { + return materialMapper.selectMaterialList(material); + } + + /** + * 新增物料 + * + * @param material 物料 + * @return 结果 + */ + @Override + public int insertMaterial(Material material) + { + return materialMapper.insertMaterial(material); + } + + /** + * 修改物料 + * + * @param material 物料 + * @return 结果 + */ + @Override + public int updateMaterial(Material material) + { + return materialMapper.updateMaterial(material); + } + + /** + * 批量删除物料 + * + * @param ids 需要删除的物料主键 + * @return 结果 + */ + @Override + public int deleteMaterialByIds(Long[] ids) + { + return materialMapper.deleteMaterialByIds(ids); + } + + /** + * 删除物料信息 + * + * @param id 物料主键 + * @return 结果 + */ + @Override + public int deleteMaterialById(Long id) + { + return materialMapper.deleteMaterialById(id); + } + + @Override + public int sync() { + // 查询字段 + List fieldKeys = Arrays.asList( + K3MaterialField.F_MATERIAL_ID, + K3MaterialField.F_NUMBER, + K3MaterialField.F_NAME, + K3MaterialField.F_SPECIFICATION + ); + int startRow = 0; + int limit = 10000; + int size = 0; + + // 一直查询,直到查到的数据量比limit小,说明查完了 + while(true) { + // 查询ERP数据 + List erpList = k3Service.selectList(K3FormIds.MATERIAL, fieldKeys, startRow, limit); + + // 转为PO + List materialList = materialConverter.toPoByErpList(fieldKeys, erpList); + + // 保存 + for (Material material : materialList) { + scheduledExecutorService.schedule(() -> { + this.saveByErpId(material); + }, 0, TimeUnit.SECONDS); + } + + size += materialList.size(); + + if (materialList.size() < limit) { + break; + } else { + startRow += limit; + } + } + + return size; + } + + /** + * 通过物料编码新增或修改 + */ + private int saveByErpId(Material material) { + String errorMsg = "成功"; + try { + if (material == null || StringUtils.isBlank(material.getErpId())) { + throw new ServiceException("参数错误"); + } + String lockKey = material.getErpId(); + ServiceUtil.assertion(!redisLock.lock(RedisLockKey.SAVE_MATERIAL, lockKey), "当前物料正在处理中,请稍后重试"); + + try { + // 若数据库中没有,则新增,否则修改 + MaterialVO old = this.selectMaterialByErpId(material.getErpId()); + if (old == null) { + return this.insertMaterial(material); + } else { + material.setId(old.getId()); + return this.updateMaterial(material); + } + } finally { + redisLock.unlock(RedisLockKey.SAVE_MATERIAL, lockKey); + } + } catch (Exception e) { + errorMsg = e.getMessage(); + return 0; + } finally { + // TODO 记录日志 + log.info("保存物料:{}", errorMsg); + } + } + + private MaterialVO selectMaterialByErpId(String erpId) { + if (StringUtils.isBlank(erpId)) { + return null; + } + MaterialQuery query = new MaterialQuery(); + query.setErpId(erpId); + return this.selectOne(query); + } + + private MaterialVO selectOne(MaterialQuery query) { + PageHelper.startPage(1,1 ); + List list = this.selectMaterialList(query); + if (CollectionUtils.isEmpty(list)) { + return null; + } + return list.get(0); + } +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/utils/MaterialUtil.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/utils/MaterialUtil.java new file mode 100644 index 0000000..dc09401 --- /dev/null +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/material/utils/MaterialUtil.java @@ -0,0 +1,62 @@ +package com.ruoyi.web.yh.material.utils; + +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.web.yh.material.domain.vo.MaterialNumberSplitVO; +import lombok.extern.slf4j.Slf4j; + +import java.util.Arrays; + +/** + * 物料工具类 + * @author wjh + * 2024/11/15 + */ +@Slf4j +public class MaterialUtil { + + /** + * 将物料编码拆分成各个部分 + */ + public static MaterialNumberSplitVO parseToSplit(String materialNumber) { + if (StringUtils.isBlank(materialNumber)) { + return null; + } + + String regex = "\\."; + String[] split = materialNumber.split(regex); + + MaterialNumberSplitVO vo = new MaterialNumberSplitVO(); + if (split.length > 2) { + String workShopIds = split[2]; + vo.setWorkShops(Arrays.asList(workShopIds.split("-"))); + } + if (split.length > 3) { + vo.setCategory(split[3]); + } + if (split.length > 4) { + String sizeString = split[4]; + try { + vo.setSize(String.valueOf(Integer.parseInt(sizeString))); + } catch (Exception e) { + vo.setSize(sizeString); + log.error("sizeString 转换异常", e); + } + } + if (split.length > 5) { + String surfaceAndCover = split[5]; + String[] split1 = surfaceAndCover.split("/"); + vo.setSurface(split1[0]); + } + + // 处理盖子 + if (materialNumber.contains("/")) { + String[] coverSplit = materialNumber.split("/"); + if (coverSplit.length > 1) { + vo.setCover(coverSplit[1]); + } + } + + return vo; + } + +} diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrder.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrder.java index ec0f4c7..18b3043 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrder.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrder.java @@ -50,8 +50,8 @@ public class ProdOrder extends BaseEntity @ApiModelProperty("ERP备注") private String erpDescription; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @Excel(name = "ERP单据日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "ERP单据日期", width = 30, dateFormat = "yyyy-MM-dd") @ApiModelProperty("ERP单据日期") private LocalDateTime erpDate; @@ -100,4 +100,9 @@ public class ProdOrder extends BaseEntity @ApiModelProperty("ERP明细单位") private String erpUnitId; + @Excel(name = "ERP物料ID") + @ApiModelProperty("ERP物料ID") + private String erpMaterialId; + + } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrderVO.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrderVO.java index 4ad704b..7cac88a 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrderVO.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/domain/ProdOrderVO.java @@ -1,5 +1,6 @@ package com.ruoyi.web.yh.prodOrder.domain; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -8,4 +9,11 @@ import lombok.Data; */ @Data public class ProdOrderVO extends ProdOrder { + + @ApiModelProperty("物料编码") + private String materialNumber; + + @ApiModelProperty("生产车间名称") + private String workShopName; + } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/mapper/ProdOrderMapper.xml b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/mapper/ProdOrderMapper.xml index 15705fc..163a4b8 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/mapper/ProdOrderMapper.xml +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/mapper/ProdOrderMapper.xml @@ -27,8 +27,13 @@ bpo.dept_id, bpo.erp_base_unit_qty, bpo.erp_unit_id, - bpo.create_time + bpo.create_time, + bpo.erp_material_id, + bm.erp_number as material_number, + sd.dept_name as work_shop_name from bst_prod_order bpo + left join bst_material bm on bm.erp_id = bpo.erp_material_id + left join sys_dept sd on sd.erp_id = bpo.erp_work_shop_id @@ -44,9 +49,10 @@ and bpo.erp_row_id = #{query.eqErpRowId} and bpo.erp_memo_item like concat('%', #{query.erpMemoItem}, '%') and bpo.erp_status = #{query.erpStatus} - and bpo.erp_work_shop_id like concat('%', #{query.erpWorkShopId}, '%') + and bpo.erp_work_shop_id = #{query.erpWorkShopId} and bpo.erp_req_src = #{query.erpReqSrc} and bpo.dept_id = #{query.deptId} + and bpo.erp_material_id = #{query.erpMaterialId} ${query.params.dataScope} @@ -84,6 +90,7 @@ erp_base_unit_qty, erp_unit_id, create_time, + erp_material_id, #{erpId}, @@ -105,6 +112,7 @@ #{erpBaseUnitQty}, #{erpUnitId}, #{createTime}, + #{erpMaterialId}, @@ -136,6 +144,7 @@ erp_base_unit_qty = #{data.erpBaseUnitQty}, erp_unit_id = #{data.erpUnitId}, create_time = #{data.createTime}, + erp_material_id = #{data.erpMaterialId}, diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderConverterImpl.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderConverterImpl.java index 95d2f9e..3473bd8 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderConverterImpl.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderConverterImpl.java @@ -2,11 +2,13 @@ package com.ruoyi.web.yh.prodOrder.service.impl; import com.alibaba.fastjson2.JSONArray; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.k3cloud.business.prodOrder.constants.K3ProdField; +import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.common.k3cloud.constants.fileds.K3ProdField; +import com.ruoyi.web.yh.material.service.MaterialService; import com.ruoyi.web.yh.prodOrder.domain.ProdOrder; import com.ruoyi.web.yh.prodOrder.service.ProdOrderConverter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.Collections; @@ -18,6 +20,10 @@ import java.util.List; */ @Service public class ProdOrderConverterImpl implements ProdOrderConverter { + + @Autowired + private MaterialService materialService; + /** * 将ERP数据转为PO列表 * @@ -89,6 +95,9 @@ public class ProdOrderConverterImpl implements ProdOrderConverter { case K3ProdField.F_UNIT_ID: po.setErpUnitId(row.getString(i)); break; + case K3ProdField.F_MATERIAL_ID: + po.setErpMaterialId(row.getString(i)); + break; default: break; } } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderServiceImpl.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderServiceImpl.java index 47a5cd7..eb7e640 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderServiceImpl.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/prodOrder/service/impl/ProdOrderServiceImpl.java @@ -13,9 +13,9 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.k3cloud.business.prodOrder.constants.K3ProdField; -import com.ruoyi.k3cloud.constants.K3FormIds; -import com.ruoyi.k3cloud.service.K3Service; +import com.ruoyi.common.k3cloud.constants.fileds.K3ProdField; +import com.ruoyi.common.k3cloud.constants.K3FormIds; +import com.ruoyi.common.k3cloud.service.K3Service; import com.ruoyi.web.yh.prodOrder.service.ProdOrderConverter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -145,16 +145,40 @@ public class ProdOrderServiceImpl implements ProdOrderService K3ProdField.F_REQ_SRC, K3ProdField.F_BASE_UNIT_QTY, K3ProdField.F_QTY, - K3ProdField.F_UNIT_ID + K3ProdField.F_UNIT_ID, + K3ProdField.F_MATERIAL_ID ); - // 查询ERP数据 - List erpList = k3Service.selectList(K3FormIds.PROD_ORDER, fieldKeys,0, 2000); + int startRow = 0; + int limit = 10000; + int size = 0; - // 转为PO - List prodOrderList = prodOrderConverter.toPoByErpList(fieldKeys, erpList); + String filterString = "FStatus in (4,5,6,7)"; - // 新增或修改 - return this.syncByBillNo(prodOrderList); + // 一直查询,直到查到的数据量比limit小,说明查完了 + while(true) { + // 查询ERP数据 + List erpList = k3Service.selectList(K3FormIds.PROD_ORDER, fieldKeys, startRow, limit, filterString, ""); + + // 转为PO + List prodOrderList = prodOrderConverter.toPoByErpList(fieldKeys, erpList); + + // 保存 + for (ProdOrder prodOrder : prodOrderList) { + scheduledExecutorService.schedule(() -> { + this.saveByErpRowId(prodOrder); + }, 0, TimeUnit.SECONDS); + } + + size += prodOrderList.size(); + + if (prodOrderList.size() < limit) { + break; + } else { + startRow += limit; + } + } + + return size; } /** @@ -191,23 +215,10 @@ public class ProdOrderServiceImpl implements ProdOrderService /** * 新增或修改 */ - private int syncByBillNo(List prodOrderList) { - int result = 0; - - // 异步操作 - for (ProdOrder prodOrder : prodOrderList) { - scheduledExecutorService.schedule(() -> { - this.syncByBillNo(prodOrder); - }, 0, TimeUnit.SECONDS); - } - - return result; - } - - private int syncByBillNo(ProdOrder prodOrder) { + private int saveByErpRowId(ProdOrder prodOrder) { String errorMsg = "成功"; try { - if (prodOrder == null || StringUtils.isBlank(prodOrder.getErpBillNo())) { + if (prodOrder == null || StringUtils.isBlank(prodOrder.getErpRowId())) { throw new ServiceException("参数错误"); } String lockKey = prodOrder.getErpRowId(); @@ -217,6 +228,7 @@ public class ProdOrderServiceImpl implements ProdOrderService // 若数据库中没有,则新增,否则修改 ProdOrderVO old = this.selectByErpRowId(prodOrder.getErpRowId()); if (old == null) { + return this.insertProdOrder(prodOrder); } else { prodOrder.setId(old.getId()); diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/controller/ReportController.java b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/controller/ReportController.java index 4adda63..a9b0005 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/controller/ReportController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/controller/ReportController.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constants.LogTitle; import com.ruoyi.common.core.validate.ValidGroup; import com.ruoyi.common.enums.LogBizType; @@ -50,6 +51,7 @@ public class ReportController extends BaseController /** * 查询报表列表 */ + @DataScope(deptAlias = "sd", userAlias = "su") @PreAuthorize("@ss.hasAnyPermi({'yh:report:list', 'yh:report:groupList'})") @GetMapping("/list") public TableDataInfo list(ReportQuery query) diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/mapper/ReportMapper.xml b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/mapper/ReportMapper.xml index e623ef1..ebfe6e4 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/mapper/ReportMapper.xml +++ b/ruoyi-web/src/main/java/com/ruoyi/web/yh/report/mapper/ReportMapper.xml @@ -27,6 +27,7 @@ sd.dept_name as dept_name from bst_report br left join sys_dept sd on sd.dept_id = br.dept_id + left join sys_user su on su.user_id = br.create_id