增加编码状态更改记录
This commit is contained in:
parent
5ecbf25188
commit
bd953a8796
|
|
@ -12,6 +12,7 @@ import com.bonus.material.ma.domain.MachineSynch;
|
|||
import com.bonus.material.ma.domain.Type;
|
||||
import com.bonus.material.ma.domain.vo.MachineVo;
|
||||
import com.bonus.material.ma.domain.vo.SampleSync;
|
||||
import com.bonus.material.task.domain.TmTask;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
|
|
@ -261,4 +262,38 @@ public interface MachineMapper
|
|||
int updateCheckTimeBatch(@Param("maIds") Long[] maIds,
|
||||
@Param("thisCheckTime") Date thisCheckTime,
|
||||
@Param("nextCheckTime") Date nextCheckTime);
|
||||
|
||||
/**
|
||||
* 根据id查询机具信息
|
||||
* @param maId
|
||||
* @return
|
||||
*/
|
||||
Machine selectMachineByMaIdNew(Long maId);
|
||||
/**
|
||||
* 根据编码和TypeId查询机具信息
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
Machine getMachineInfoByCode(Machine bean);
|
||||
|
||||
/**
|
||||
* 修改机具状态
|
||||
* @param machine
|
||||
* @return
|
||||
*/
|
||||
int updateMaStatusNew(Machine machine);
|
||||
|
||||
/**
|
||||
* 根据任务id查询任务信息
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
TmTask selectTaskCodeByTaskId(Integer taskId);
|
||||
|
||||
/**
|
||||
* 新增机具状态日志
|
||||
* @param machine
|
||||
* @return
|
||||
*/
|
||||
int insertMaStatusLog(Machine machine);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,4 +166,11 @@ public interface IMachineService
|
|||
* @return
|
||||
*/
|
||||
AjaxResult updateDate(Machine info);
|
||||
|
||||
/**
|
||||
* 系统更改设备状态统一入口
|
||||
* @param machine 机具设备管理
|
||||
* @return 结果
|
||||
*/
|
||||
int updateMaStatusEntrance(Machine machine);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.bonus.material.ma.service.impl;
|
|||
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.bonus.common.biz.domain.lease.LeaseApplyInfo;
|
||||
|
|
@ -21,6 +22,7 @@ import com.bonus.material.ma.domain.vo.SampleSync;
|
|||
import com.bonus.material.purchase.config.RemoteConfig;
|
||||
import com.bonus.material.scrap.domain.ScrapApplyDetails;
|
||||
import com.bonus.material.scrap.mapper.ScrapApplyDetailsMapper;
|
||||
import com.bonus.material.task.domain.TmTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.validator.internal.util.StringHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -60,6 +62,8 @@ public class MachineServiceImpl implements IMachineService
|
|||
@Resource
|
||||
private LeaseApplyDetailsMapper leaseApplyDetailsMapper;
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock(true);
|
||||
|
||||
/**
|
||||
* 查询机具设备管理
|
||||
*
|
||||
|
|
@ -563,12 +567,22 @@ public class MachineServiceImpl implements IMachineService
|
|||
|
||||
@Override
|
||||
public AjaxResult editMachineStatus(Machine machine) {
|
||||
machine.setUpdateTime(DateUtils.getNowDate());
|
||||
int result = machineMapper.editMachineStatus(machine);
|
||||
if (result > 0) {
|
||||
return success(HttpCodeEnum.SUCCESS.getMsg(), result);
|
||||
try {
|
||||
//调用编码更新统一接口
|
||||
Machine model = new Machine();
|
||||
model.setModelTitle("修改机具状态");
|
||||
model.setType("9");
|
||||
model.setMaStatus(machine.getMaStatus());
|
||||
model.setMaId(machine.getMaId());
|
||||
int result = updateMaStatusEntrance(model);
|
||||
if (result > 0) {
|
||||
return success(HttpCodeEnum.SUCCESS.getMsg(), result);
|
||||
}
|
||||
return error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||
}
|
||||
return error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -660,4 +674,72 @@ public class MachineServiceImpl implements IMachineService
|
|||
return error("检验时间更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统更改设备状态统一入口
|
||||
* todo 目前只应用在设备管理直接修改状态
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateMaStatusEntrance(Machine machine) {
|
||||
// 获取锁(公平锁会按线程等待请求顺序分配锁)
|
||||
lock.lock();
|
||||
try {
|
||||
int res=0;
|
||||
machine.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getUserId()+"");
|
||||
if ("1".equals(machine.getType()) || "2".equals(machine.getType())){
|
||||
//新增设备编码
|
||||
res = machineMapper.insertMachine(machine);
|
||||
if (res<=0){
|
||||
throw new RuntimeException("添加设备失败");
|
||||
}
|
||||
} else {
|
||||
Machine machineInfo=new Machine();
|
||||
//1、先查询当前设备状态
|
||||
if (machine.getMaId() != null){
|
||||
machineInfo = machineMapper.selectMachineByMaIdNew(machine.getMaId());
|
||||
if (machineInfo == null){
|
||||
throw new RuntimeException("设备不存在");
|
||||
}
|
||||
} else if (machine.getMaCode() != null && machine.getTypeId()!= null){
|
||||
machineInfo = machineMapper.getMachineInfoByCode(machine);
|
||||
if (machineInfo == null){
|
||||
throw new RuntimeException("设备不存在");
|
||||
}
|
||||
machine.setMaId(machineInfo.getMaId());
|
||||
} else {
|
||||
throw new RuntimeException("设备参数为空");
|
||||
}
|
||||
//2、修改设备状态
|
||||
res = machineMapper.updateMaStatusNew(machine);
|
||||
if (res>0){
|
||||
//3、增加设备状态修改记录
|
||||
machine.setTypeId(machineInfo.getTypeId());
|
||||
machine.setOldStatus(machineInfo.getMaStatus());
|
||||
} else {
|
||||
throw new RuntimeException("更改设备类型失败");
|
||||
}
|
||||
}
|
||||
//如果任务单号为空,则用taskId查询
|
||||
if (StringHelper.isNullOrEmptyString(machine.getCode())){
|
||||
if (machine.getTaskId() != null){
|
||||
TmTask tmTask = machineMapper.selectTaskCodeByTaskId(machine.getTaskId());
|
||||
if (tmTask != null){
|
||||
machine.setCode(tmTask.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
machineMapper.insertMaStatusLog(machine);
|
||||
|
||||
return res;
|
||||
} catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return -1;
|
||||
}finally {
|
||||
// 释放锁
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -609,7 +609,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</update>
|
||||
<update id="editMachineStatus">
|
||||
update ma_machine
|
||||
set ma_status = #{maStatus}
|
||||
set ma_status = #{maStatus},
|
||||
update_time = NOW()
|
||||
where ma_id = #{maId}
|
||||
</update>
|
||||
|
||||
|
|
@ -1216,4 +1217,73 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
)
|
||||
|
||||
</insert>
|
||||
<select id="selectMachineByMaIdNew" resultType="com.bonus.material.ma.domain.Machine">
|
||||
SELECT
|
||||
type_id AS typeId,
|
||||
ma_id AS maId,
|
||||
ma_code AS maCode,
|
||||
ma_status AS maStatus
|
||||
FROM
|
||||
ma_machine
|
||||
WHERE
|
||||
ma_id = #{maId}
|
||||
</select>
|
||||
<select id="getMachineInfoByCode" resultType="com.bonus.material.ma.domain.Machine">
|
||||
SELECT
|
||||
type_id AS typeId,
|
||||
ma_id AS maId,
|
||||
ma_code AS maCode,
|
||||
ma_status AS maStatus
|
||||
FROM
|
||||
ma_machine
|
||||
WHERE
|
||||
ma_code = #{maCode}
|
||||
AND type_id = #{typeId}
|
||||
</select>
|
||||
<update id="updateMaStatusNew">
|
||||
update ma_machine
|
||||
set
|
||||
<if test="thisCheckTime != null">
|
||||
this_check_time = #{thisCheckTime},
|
||||
</if>
|
||||
<if test="nextCheckTime != null">
|
||||
next_check_time = #{nextCheckTime},
|
||||
</if>
|
||||
<if test="inOutNum != null">
|
||||
in_out_num = ifnull(in_out_num,0) + 1,
|
||||
</if>
|
||||
ma_status = #{maStatus},
|
||||
update_time=now()
|
||||
where ma_id = #{maId}
|
||||
</update>
|
||||
<select id="selectTaskCodeByTaskId" resultType="com.bonus.material.task.domain.TmTask">
|
||||
SELECT `code`
|
||||
FROM tm_task
|
||||
WHERE task_id = #{taskId} limit 1
|
||||
</select>
|
||||
<insert id="insertMaStatusLog">
|
||||
insert into update_ma_status_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="modelTitle != null">model_title,</if>
|
||||
<if test="code != null">code,</if>
|
||||
<if test="typeId != null">type_id,</if>
|
||||
<if test="maId != null">ma_id,</if>
|
||||
<if test="oldStatus != null">old_status,</if>
|
||||
<if test="maStatus != null">new_status,</if>
|
||||
<if test="type != null">type,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
create_time,
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="modelTitle != null">#{modelTitle},</if>
|
||||
<if test="code != null">#{code},</if>
|
||||
<if test="typeId != null">#{typeId},</if>
|
||||
<if test="maId != null">#{maId},</if>
|
||||
<if test="oldStatus != null">#{oldStatus},</if>
|
||||
<if test="maStatus != null">#{maStatus},</if>
|
||||
<if test="type != null">#{type},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
NOW(),
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue