Commit 0dee97a6 by huluobin

update

parent 23d83cf2
package com.blt.other.common.lock;
import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock;
/**
* 分段锁,系统提供一定数量的原始锁,根据传入用户id值获取对应的锁并加锁
* 注意:要锁的用户id值如果发生改变,有可能导致锁无法成功释放!!!
*/
public class CostPlanNoLock {
private final static HashMap<Integer, ReentrantLock> lockMap = new HashMap<>();
private Integer segments = 500;// 默认分段数量
private CostPlanNoLock() {
init(null, false);
}
private CostPlanNoLock(Integer counts, boolean fair) {
init(counts, fair);
}
/*静态内部类实现单例*/
public static CostPlanNoLock getInstance() {
return SingletonHolder.instance;
}
private void init(Integer counts, boolean fair) {
if (counts != null) {
segments = counts;
}
for (int i = 0; i < segments; i++) {
lockMap.put(i, new ReentrantLock(fair));
}
}
public void lock(int key) {
ReentrantLock lock = lockMap.get(key % segments);
lock.lock();
}
public void unlock(int key) {
ReentrantLock lock = lockMap.get(key % segments);
lock.unlock();
}
@Override
public String toString() {
return "SegmentLock [segments=" + segments + ", lockMap=" + lockMap
+ "]";
}
/*静态内部类实现单例*/
private static class SingletonHolder {
private static final CostPlanNoLock instance = new CostPlanNoLock(null, true);
}
}
package com.blt.other.module.cost.controller;
import com.blt.other.common.lock.CostPlanNoLock;
import com.blt.other.common.util.CurUtils;
import com.blt.other.database.model.CostPlanDomain;
import com.blt.other.module.cost.dto.response.RestResp;
......@@ -41,13 +42,19 @@ public class CostPlanNewController {
@PostMapping("/affirm")
public Map<String, Object> affirm(@RequestParam String costPlanNo) {
Map<String, Object> result = new HashMap<>();
CostPlanService costPlanService = CostPlanServiceFactory.getCostPlanService(costPlanNo);
CostPlanNoLock lock = CostPlanNoLock.getInstance();
try {
lock.lock(costPlanNo.hashCode());
CostPlanService costPlanService = CostPlanServiceFactory.getCostPlanService(costPlanNo);
Integer affirm = costPlanService.affirm(costPlanNo);
result.put("success", true);
result.put("msg", "已生成 " + affirm + " 张费用单");
Integer affirm = costPlanService.affirm(costPlanNo);
result.put("success", true);
result.put("msg", "已生成 " + affirm + " 张费用单");
return result;
return result;
} finally {
lock.unlock(costPlanNo.hashCode());
}
}
@ApiOperation("/删除费用计划")
......
......@@ -57,7 +57,6 @@ public class CostDomain implements Serializable {
private String costNo;
@ApiModelProperty("费用计划编号")
private String costPlanNo;
@ApiModelProperty("当前部门id")
private Integer costDepartmentId;
......
package com.blt.other.module.cost.service.impl.costtemplate;
package com.blt.other.module.cost.service.impl;
import com.bailuntec.common.BeanUtils;
import com.bailuntec.common.ListUtil;
......
package com.blt.other.module.cost.service.impl.costtemplate;
package com.blt.other.module.cost.service.impl;
import com.bailuntec.common.ListUtil;
import com.bailuntec.common.StringUtils;
......
package com.blt.other.module.cost.service.impl.costtemplate;
package com.blt.other.module.cost.service.impl;
import com.bailuntec.common.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......
......@@ -4,7 +4,9 @@ import com.bailuntec.common.ListUtil;
import com.bailuntec.cost.api.dto.CostPlanDto;
import com.blt.other.common.exception.BizRuntimeException;
import com.blt.other.database.model.*;
import com.blt.other.module.auth.dao.OaUserMapper;
import com.blt.other.module.auth.dao.UserDao;
import com.blt.other.module.auth.model.OaUser;
import com.blt.other.module.cost.dao.*;
import com.blt.other.module.cost.dto.request.GetAllCostPlanReq;
import com.blt.other.module.cost.dto.response.GetAllCostPlanResp;
......@@ -179,6 +181,9 @@ public abstract class AbstractCostPlanService implements CostPlanService {
return result;
}
@Resource
OaUserMapper oaUserMapper;
protected CostDomain planToCost(String costPlanNo) {
CostDomain costDomain = new CostDomain();
CostPlanDomain costPlanDomain = costPlanDao.selectByNo(costPlanNo);
......
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