Commit 79d410d2 authored by 耿迪迪's avatar 耿迪迪

aoi检测结果同步

parent 0bcdd4b0
...@@ -76,6 +76,14 @@ ...@@ -76,6 +76,14 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
</dependency> </dependency>
<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.zehong.controller;
import com.zehong.entity.AjaxResult;
import com.zehong.service.AoiTestResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* AOI检查结果
* @author geng
*/
@RestController
@RequestMapping("/aoi")
public class AoiTestResultController extends BaseController{
@Autowired
private AoiTestResultService aoiTestResultService;
@PostMapping("/syncAoiResult")
public AjaxResult syncAoiResult(@RequestBody String result){
return toAjax(aoiTestResultService.syncAoiResult(result));
}
}
...@@ -4,6 +4,17 @@ import com.zehong.entity.AjaxResult; ...@@ -4,6 +4,17 @@ import com.zehong.entity.AjaxResult;
public class BaseController { public class BaseController {
/**
* 响应返回结果
*
* @param rows 影响行数
* @return 操作结果
*/
protected AjaxResult toAjax(int rows)
{
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
}
/** /**
* 响应返回结果 * 响应返回结果
* *
......
package com.zehong.dao;
import com.zehong.entity.PcbaDevices;
import java.util.List;
public interface AoiTestResultMapper {
/**
* 根据主板号查询设备信息
* @param motherboardCode 主板吗
* @return
*/
List<PcbaDevices> selectPcbaDeviceInfoByBoardCode(String motherboardCode);
/**
* 更新设备信息
* @param devices 设备信息
* @return
*/
int updatePcbaDeviceInfo(PcbaDevices devices);
}
package com.zehong.entity;
public class PcbaDevices {
/** id */
private Long pcbaDevicesId;
/** 主板码 */
private String motherboardCode;
/** pcba生产任务单号 */
private String pcbaProductionTasksNumber;
/** PCBA批次码 */
private String pcbaBatchNumber;
/**aoi检测结果*/
private String aoiDetectionResult;
public Long getPcbaDevicesId() {
return pcbaDevicesId;
}
public void setPcbaDevicesId(Long pcbaDevicesId) {
this.pcbaDevicesId = pcbaDevicesId;
}
public String getMotherboardCode() {
return motherboardCode;
}
public void setMotherboardCode(String motherboardCode) {
this.motherboardCode = motherboardCode;
}
public String getPcbaProductionTasksNumber() {
return pcbaProductionTasksNumber;
}
public void setPcbaProductionTasksNumber(String pcbaProductionTasksNumber) {
this.pcbaProductionTasksNumber = pcbaProductionTasksNumber;
}
public String getPcbaBatchNumber() {
return pcbaBatchNumber;
}
public void setPcbaBatchNumber(String pcbaBatchNumber) {
this.pcbaBatchNumber = pcbaBatchNumber;
}
public String getAoiDetectionResult() {
return aoiDetectionResult;
}
public void setAoiDetectionResult(String aoiDetectionResult) {
this.aoiDetectionResult = aoiDetectionResult;
}
}
package com.zehong.service;
/**
* AOI检查结果
* @author geng
*/
public interface AoiTestResultService {
/**
* AOI检查结果同步
* @param result
*/
int syncAoiResult(String result);
}
package com.zehong.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.zehong.dao.AoiTestResultMapper;
import com.zehong.entity.PcbaDevices;
import com.zehong.service.AoiTestResultService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
/**
* AOI检查结果
* @author geng
*/
@Service
@DS("mes")
public class AoiTestResultServiceImpl implements AoiTestResultService{
private static final Logger log = LoggerFactory.getLogger(AoiTestResultServiceImpl.class);
@Resource
private AoiTestResultMapper aoiTestResultMapper;
/**
* AOI检查结果同步
* @param result
*/
public int syncAoiResult(String result){
int insertResult = 0;
JSONObject resultJson = JSON.parseObject(result);
log.info("aoi检测结果=====" + resultJson);
JSONArray boardData = resultJson.getJSONArray("board_data");
if(null != boardData){
for(Object obj : boardData){
JSONObject boardInfo = (JSONObject)obj;
String motherboardCode = boardInfo.getString("board_sn");
List<PcbaDevices> devices = aoiTestResultMapper.selectPcbaDeviceInfoByBoardCode(motherboardCode);
if(!CollectionUtils.isEmpty(devices)){
for(PcbaDevices device : devices){
String finalResult = boardInfo.getString("board_final_result");
device.setAoiDetectionResult(finalResult);
insertResult += aoiTestResultMapper.updatePcbaDeviceInfo(device);
}
}
}
}
return insertResult;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.dao.AoiTestResultMapper">
<resultMap type="PcbaDevices" id="PcbaDevicesResult">
<result property="pcbaDevicesId" column="f_pcba_devices_id" />
<result property="motherboardCode" column="f_motherboard_code" />
<result property="pcbaProductionTasksNumber" column="f_pcba_production_tasks_number" />
<result property="pcbaBatchNumber" column="f_pcba_batch_number" />
<result property="aoiDetectionResult" column="f_aoi_detection_result" />
</resultMap>
<select id="selectPcbaDeviceInfoByBoardCode" parameterType="String" resultMap="PcbaDevicesResult">
SELECT
f_pcba_devices_id,
f_motherboard_code,
f_pcba_production_tasks_number,
f_pcba_batch_number,
f_aoi_detection_result
FROM
t_pcba_devices
WHERE f_motherboard_code = #{ motherboardCode }
</select>
<update id="updatePcbaDeviceInfo" parameterType="PcbaDevices">
update t_pcba_devices
<trim prefix="SET" suffixOverrides=",">
<if test="motherboardCode != null">f_motherboard_code = #{motherboardCode},</if>
<if test="pcbaProductionTasksNumber != null">f_pcba_production_tasks_number = #{pcbaProductionTasksNumber},</if>
<if test="pcbaBatchNumber != null">f_pcba_batch_number = #{pcbaBatchNumber},</if>
<if test="aoiDetectionResult != null">f_aoi_detection_result = #{aoiDetectionResult},</if>
</trim>
where f_pcba_devices_id = #{pcbaDevicesId}
</update>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment