【UPDATE】1.新增库存信息存入到Redis中 2.修改为批量插入Redis 3.同步库存数据后将库存数据存入到Redis中
| | |
| | | @PostMapping("/ApsStandardProcessRouteHeader/setProcessRouteDataToRedis") |
| | | R<Boolean> setProcessRouteDataToRedis(@RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | | |
| | | |
| | | /** |
| | | * 刷新物料数据到Redis |
| | | * @param source |
| | | * @return |
| | | */ |
| | | @PostMapping("/materialStorageManagement/setStorageDataToRedis") |
| | | R<Boolean> setStorageDataToRedis(@RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | | |
| | | } |
| | |
| | | { |
| | | return R.fail("工艺路线数据存储到Redis中失败:" + throwable.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public R<Boolean> setStorageDataToRedis(String source) |
| | | { |
| | | return R.fail("库存数据存储到Redis中失败:" + throwable.getMessage()); |
| | | } |
| | | }; |
| | | } |
| | | } |
| | |
| | | package com.aps.core.controller.basicData; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.aps.core.service.IApsMaterialStorageManagementService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.aps.common.core.utils.poi.ExcelUtil; |
| | | import com.aps.common.core.web.controller.BaseController; |
| | | import com.aps.common.core.web.domain.AjaxResult; |
| | | import com.aps.common.core.web.page.TableDataInfo; |
| | | import com.aps.common.log.annotation.Log; |
| | | import com.aps.common.log.enums.BusinessType; |
| | | import com.aps.common.security.annotation.RequiresPermissions; |
| | | import com.aps.core.domain.ApsMaterialStorageManagement; |
| | | import com.aps.common.core.web.controller.BaseController; |
| | | import com.aps.common.core.web.domain.AjaxResult; |
| | | import com.aps.common.core.utils.poi.ExcelUtil; |
| | | import com.aps.common.core.web.page.TableDataInfo; |
| | | import com.aps.core.service.IApsMaterialStorageManagementService; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 物料库存管理Controller |
| | |
| | | { |
| | | return toAjax(apsMaterialStorageManagementService.deleteApsMaterialStorageManagementByIds(ids)); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/setStorageDataToRedis") |
| | | public void setStorageDataToRedis() |
| | | { |
| | | apsMaterialStorageManagementService.setStorageDataToRedis("FORTUNA"); |
| | | } |
| | | |
| | | @PostMapping("/test") |
| | | public void test() |
| | | { |
| | | apsMaterialStorageManagementService.setStorageDataToRedis("FORTUNA"); |
| | | // apsMaterialStorageManagementService.getRdsStorage("FORTUNA", "A1501-001362"); |
| | | } |
| | | } |
| | |
| | | private String delFlag; |
| | | |
| | | private String mainItemCode; |
| | | private BigDecimal mainStock; |
| | | private BigDecimal subStock; |
| | | private String selfMade; |
| | | |
| | | } |
| | |
| | | package com.aps.core.mapper; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aps.core.domain.ApsBom; |
| | | import com.aps.core.domain.ApsBomHeader; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | |
| | | * @param orgCode BOM Header 数据管理 |
| | | * @return BOM Header 数据管理集合 |
| | | */ |
| | | List<JSONObject> selectBomRedisData(String orgCode); |
| | | List<ApsBom> selectBomRedisData(String orgCode); |
| | | } |
| | |
| | | package com.aps.core.service; |
| | | |
| | | import java.util.List; |
| | | import com.aps.core.domain.ApsMaterialStorageManagement; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 物料库存管理Service接口 |
| | |
| | | public int deleteApsMaterialStorageManagementById(String id); |
| | | |
| | | ApsMaterialStorageManagement getRdsStorage(String plant, String itemCode); |
| | | |
| | | |
| | | /** |
| | | * 同步库存数据到Redis |
| | | * @return |
| | | */ |
| | | public boolean setStorageDataToRedis(String orgCode); |
| | | } |
| | |
| | | package com.aps.core.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.core.domain.ApsBom; |
| | | import com.aps.core.domain.ApsBomHeader; |
| | | import com.aps.core.mapper.ApsBomHeaderMapper; |
| | | import com.aps.core.service.IApsBomHeaderService; |
| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * BOM Header 数据管理Service业务层处理 |
| | |
| | | @Override |
| | | public boolean setBomDataToRedis(String orgCode) { |
| | | try { |
| | | List<JSONObject> bomRedisData = apsBomHeaderMapper.selectBomRedisData(orgCode); |
| | | String nowMainItemCode = ""; |
| | | JSONArray bomLine = new JSONArray(); |
| | | for (int i=0,size=bomRedisData.size();i<size;i++) { |
| | | JSONObject jsonObject = bomRedisData.get(i); |
| | | if("".equals(nowMainItemCode)){ |
| | | nowMainItemCode = jsonObject.getString("mainitemcode"); |
| | | } |
| | | if(!nowMainItemCode.equals(jsonObject.getString("mainitemcode"))){ |
| | | redisTemplate.opsForValue().set("BOM:BOM_"+orgCode+"_"+nowMainItemCode, bomLine); |
| | | bomLine = new JSONArray(); |
| | | } |
| | | bomLine.add(jsonObject); |
| | | nowMainItemCode = jsonObject.getString("mainitemcode"); |
| | | if(i==size-1){ |
| | | redisTemplate.opsForValue().set("BOM:BOM_"+orgCode+"_"+nowMainItemCode, bomLine); |
| | | } |
| | | List<ApsBom> bomRedisData = apsBomHeaderMapper.selectBomRedisData(orgCode); |
| | | Map<String, List<ApsBom>> groupedByMainItemCode = bomRedisData.stream().collect(Collectors.groupingBy(ApsBom::getMainItemCode)); |
| | | Map<String, Object> bulkData = new HashMap<>(); |
| | | for (Map.Entry<String, List<ApsBom>> entry : groupedByMainItemCode.entrySet()) { |
| | | String mainItemCode = entry.getKey(); |
| | | JSONArray jsonArray = JSONArray.from(entry.getValue()); |
| | | bulkData.put("BOM:BOM_" + orgCode + "_" + mainItemCode, jsonArray); |
| | | } |
| | | redisTemplate.opsForValue().multiSet(bulkData); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | |
| | | package com.aps.core.service.impl; |
| | | |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.core.utils.StringUtils; |
| | | import com.aps.core.domain.ApsMaterialStorageManagement; |
| | | import com.aps.core.mapper.ApsMaterialStorageManagementMapper; |
| | | import com.aps.core.service.IApsMaterialStorageManagementService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import com.aps.core.mapper.ApsMaterialStorageManagementMapper; |
| | | import com.aps.core.domain.ApsMaterialStorageManagement; |
| | | import com.aps.core.service.IApsMaterialStorageManagementService; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | |
| | | /** |
| | | * 物料库存管理Service业务层处理 |
| | |
| | | // 返回库存信息对象 |
| | | return ams; |
| | | } |
| | | |
| | | /** |
| | | * 设置库存数据到redis |
| | | * @param orgCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean setStorageDataToRedis(String orgCode) { |
| | | try { |
| | | ApsMaterialStorageManagement temp = new ApsMaterialStorageManagement(); |
| | | if(!StringUtils.isEmpty(orgCode)){ |
| | | temp.setApplicableFactories(orgCode); |
| | | } |
| | | List<ApsMaterialStorageManagement> list = apsMaterialStorageManagementMapper.selectApsMaterialStorageManagementList(temp); |
| | | Map<String, Object> bulkData = new HashMap<>(); |
| | | list.forEach(apsMaterialStorageManagement -> { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("id", apsMaterialStorageManagement.getId()); |
| | | jsonObject.put("itemNumber", apsMaterialStorageManagement.getItemNumber()); |
| | | jsonObject.put("remainderStock", apsMaterialStorageManagement.getRemainderStock()); |
| | | jsonObject.put("applicableFactories", apsMaterialStorageManagement.getApplicableFactories()); |
| | | bulkData.put("MaterialStorage:Material_"+apsMaterialStorageManagement.getApplicableFactories()+"_"+apsMaterialStorageManagement.getItemNumber(), jsonObject); |
| | | }); |
| | | redisTemplate.opsForValue().multiSet(bulkData); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | // Set<String> keys = redisTemplate.keys("MaterialStorage:Material_*"); |
| | | // if (keys != null && !keys.isEmpty()) { |
| | | // redisTemplate.delete(keys); |
| | | // } |
| | | return true; |
| | | } |
| | | } |
| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 标准工艺路线HeaderService业务层处理 |
| | |
| | | public boolean setProcessRouteDataToRedis(String orgCode) { |
| | | try { |
| | | List<JSONObject> res = apsStandardProcessRouteHeaderMapper.selectProcessRouteStandardTimeData(orgCode); |
| | | Map<String, Object> bulkData = new HashMap<>(); |
| | | for (JSONObject jsonObject : res) { |
| | | redisTemplate.opsForValue().set("ROUTE:ROUTE_"+jsonObject.getString("org_code")+"_"+jsonObject.getString("item_code"), jsonObject.getBigDecimal("standardtime")); |
| | | bulkData.put("ROUTE:ROUTE_"+jsonObject.getString("org_code")+"_"+jsonObject.getString("item_code"), jsonObject.getBigDecimal("standardtime")); |
| | | } |
| | | redisTemplate.opsForValue().multiSet(bulkData); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <select id="selectBomRedisData" parameterType="String" resultType="com.alibaba.fastjson2.JSONObject"> |
| | | SELECT a.item_code as mainItemCode,f.num as mainStock,b.bom_line_id as bomLineId, b.item_code as itemCode,b.num ,c.num as subStock,d.self_made as selfMade |
| | | <select id="selectBomRedisData" parameterType="String" resultType="com.aps.core.domain.ApsBom"> |
| | | SELECT a.item_code as mainItemCode,b.bom_line_id as bomLineId, b.item_code as itemCode,b.num |
| | | FROM aps_bom_header a |
| | | LEFT JOIN aps_bom_line b on a.bom_header_id=b.bom_header_id |
| | | LEFT JOIN aps_material_storage_management c on b.item_code=c.item_number |
| | | LEFT JOIN aps_material_management d on b.item_code=d.item_number |
| | | LEFT JOIN aps_material_storage_management as f on a.item_code=f.item_number |
| | | <if test="orgCode != null and orgCode != ''"> |
| | | WHERE a.org_code=#{orgCode} and d.applicable_factories=#{orgCode} and c.applicable_factories=#{orgCode} |
| | | </if> |
| | | LEFT JOIN aps_bom_line b on a.bom_header_id=b.bom_header_id |
| | | LEFT JOIN aps_material_management d on b.item_code=d.item_number |
| | | LEFT JOIN aps_material_management c on a.item_code=c.item_number |
| | | <where> |
| | | <if test="orgCode != null and orgCode != ''"> |
| | | and a.org_code=#{orgCode} and d.applicable_factories=#{orgCode} |
| | | </if> |
| | | and d.material_type='制造件' |
| | | and c.material_type='制造件' |
| | | </where> |
| | | ORDER BY mainItemCode |
| | | </select> |
| | | </mapper> |
| | |
| | | <result property="plant" column="plant" /> |
| | | <result property="unmatchedQuantity" column="unmatched_quantity" /> |
| | | <result property="professionalAffiliation" column="professional_affiliation" /> |
| | | <result property="requireId" column="require_id" /> |
| | | <result property="version" column="version" /> |
| | | <!-- <result property="requireId" column="require_id" />--> |
| | | <!-- <result property="version" column="version" />--> |
| | | |
| | | </resultMap> |
| | | |
| | |
| | | next_process_deparment, is_suspended, is_outsourcing, account, advanced_materials, |
| | | advanced_document_number, advanced_requirement_day, is_plan_complete, is_stock_complete, |
| | | has_turnback, has_risk, std_op, op_status, next_op_name , |
| | | plant, unmatched_quantity, professional_affiliation, require_id, version, unmatchedQuantity |
| | | plant, unmatched_quantity, professional_affiliation, |
| | | -- require_id, version, |
| | | unmatched_quantity |
| | | from aps_part_plan |
| | | </sql> |
| | | |
| | |
| | | import com.aps.common.log.enums.BusinessType; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.job.domain.SysJob; |
| | | import com.aps.job.param.ApsWorkOrderJobParam; |
| | | import com.aps.job.service.*; |
| | | import com.aps.job.util.CronUtils; |
| | | import com.aps.job.util.ScheduleUtils; |
| | |
| | | import java.time.ZoneId; |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | public void test(@RequestBody SysJob job) throws Exception |
| | | { |
| | | System.out.println("start"); |
| | | //同步工单数据 |
| | | boolean continueFlag = true; |
| | | Integer currentPage = 1; |
| | | ApsWorkOrderJobParam param=new ApsWorkOrderJobParam(); |
| | | param.setPageIndex(currentPage); |
| | | param.setDocState(Arrays.asList(0,1,2,4)); |
| | | param.setPageSize(500); |
| | | while (continueFlag){ |
| | | param.setPageIndex(currentPage); |
| | | continueFlag= apsWorkOrderJobService.batchSaveByPager(param); |
| | | currentPage++; |
| | | } |
| | | //同步物料数据 |
| | | apsMaterialManagementJobService.syncApsMaterialData(1, 1000, "FORTUNA", ""); |
| | | // apsMaterialManagementJobService.syncApsMaterialData(1, 1000, "FORTUNA", ""); |
| | | //同步工艺路线数据 |
| | | // apsStandardProcessRouteHeaderJobService.syncProcessRouteData(1, 1000, "", ""); |
| | | //获取Redis缓存中的BOM数据 |
| | |
| | | */ |
| | | public void syncApsMaterialStorageDataJob(Integer pageIndex, Integer pageSize, String orgCode, String itemCodeList) |
| | | { |
| | | apsMaterialStorageManagementJobService.syncApsMaterialStorageDataJob(pageIndex, pageSize, orgCode, itemCodeList); |
| | | boolean res = apsMaterialStorageManagementJobService.syncApsMaterialStorageDataJob(pageIndex, pageSize, orgCode, itemCodeList); |
| | | if(res){ |
| | | remoteCoreService.setStorageDataToRedis(SecurityConstants.INNER); |
| | | } |
| | | } |
| | | |
| | | /** |