parent
98eacfc014
commit
0eb62da6f8
@ -0,0 +1,45 @@
|
|||||||
|
package com.dsic.gj_erp.bean.zyjh;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 余料结存表
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@TableName("dm_yljc")
|
||||||
|
public class DmYlJc {
|
||||||
|
|
||||||
|
@TableId(type= IdType.INPUT)
|
||||||
|
private String zq;
|
||||||
|
|
||||||
|
private BigDecimal outWeight;
|
||||||
|
|
||||||
|
private BigDecimal outNum;
|
||||||
|
|
||||||
|
private BigDecimal inWeight;
|
||||||
|
|
||||||
|
private BigDecimal inNum;
|
||||||
|
|
||||||
|
public static DmYlJc ofIn(DmYlInfo ylInfo){
|
||||||
|
DmYlJc dmYlJc = new DmYlJc();
|
||||||
|
dmYlJc.setZq(ylInfo.获取帐期());
|
||||||
|
dmYlJc.setInNum(new BigDecimal(1));
|
||||||
|
dmYlJc.setInWeight(new BigDecimal(ylInfo.get重量()));
|
||||||
|
return dmYlJc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DmYlJc ofOut(DmYlInfo ylInfo){
|
||||||
|
DmYlJc dmYlJc = new DmYlJc();
|
||||||
|
dmYlJc.setZq(ylInfo.获取帐期());
|
||||||
|
dmYlJc.setInNum(new BigDecimal(1));
|
||||||
|
dmYlJc.setInWeight(new BigDecimal(ylInfo.get重量()));
|
||||||
|
return dmYlJc;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.dsic.gj_erp.mapper.zyjh;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.dsic.gj_erp.bean.zyjh.DmYlJc;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface DmYljcMapper extends BaseMapper<DmYlJc> {
|
||||||
|
|
||||||
|
@Update("update set in_weight=in_weight+#{inWeight} ,in_num=in_num+#{inNum} where zq=#{zq}")
|
||||||
|
void updateIn(DmYlJc dmYlJc);
|
||||||
|
|
||||||
|
@Update("update set out_weight=out_weight+#{outWeight} ,out_num=out_num+#{outNum} where zq=#{zq}")
|
||||||
|
void updateOut(DmYlJc dmYlJc);
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.dsic.gj_erp.service.zyjh;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.dsic.gj_erp.bean.zyjh.DmYlJc;
|
||||||
|
import com.dsic.gj_erp.exception.ServiceException;
|
||||||
|
import com.dsic.gj_erp.mapper.zyjh.DmYljcMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DmYljcService extends ServiceImpl<DmYljcMapper, DmYlJc> {
|
||||||
|
|
||||||
|
private final RedisTemplate<String,Object> redisTemplate;
|
||||||
|
|
||||||
|
private static final String YLJC_KEY="YLJC";
|
||||||
|
|
||||||
|
private static final Semaphore semaphore = new Semaphore(1);
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void saveIn(List<DmYlJc> list) throws InterruptedException {
|
||||||
|
semaphore.acquire();
|
||||||
|
try {
|
||||||
|
for (DmYlJc item : list) {
|
||||||
|
//使用redis加速
|
||||||
|
Boolean flag = redisTemplate.opsForHash().hasKey(YLJC_KEY, item.getZq());
|
||||||
|
if (flag){
|
||||||
|
baseMapper.updateIn(item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
insert(item);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
semaphore.release();
|
||||||
|
log.error("结存表处理失败: ", e);
|
||||||
|
throw new ServiceException(11001,"结存表处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void saveOut(List<DmYlJc> list) throws InterruptedException {
|
||||||
|
semaphore.acquire();
|
||||||
|
try {
|
||||||
|
for (DmYlJc item : list) {
|
||||||
|
//使用redis加速
|
||||||
|
Boolean flag = redisTemplate.opsForHash().hasKey(YLJC_KEY, item.getZq());
|
||||||
|
if (flag){
|
||||||
|
baseMapper.updateOut(item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
insert(item);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
semaphore.release();
|
||||||
|
log.error("结存表处理失败: ", e);
|
||||||
|
throw new ServiceException(11001,"结存表处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(DmYlJc item){
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForHash().put(YLJC_KEY,item.getZq(),1);
|
||||||
|
baseMapper.insert(item);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("初始化结存表失败: ", e);
|
||||||
|
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForHash().delete(YLJC_KEY,item.getZq());
|
||||||
|
}catch (Exception e1){
|
||||||
|
log.error("初始化结存表失败: ", e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ServiceException(11000,"初始化结存表失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue