mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 23:57:12 +08:00
添加重新计算接口
This commit is contained in:
@@ -69,6 +69,13 @@ public class WeightDeviceDataController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/recalculate")
|
||||||
|
public Object recalculate(@RequestBody IdRequest request) {
|
||||||
|
this.service.recalculate(request);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/archive")
|
@PostMapping("/archive")
|
||||||
public Object archive(@RequestBody IdRequest request) {
|
public Object archive(@RequestBody IdRequest request) {
|
||||||
this.service.archive(request);
|
this.service.archive(request);
|
||||||
|
|||||||
@@ -303,18 +303,16 @@ where 更新时间>='%s' and 更新时间<='%s'
|
|||||||
throw new BizException("部分数据已归档,无法编辑或删除");
|
throw new BizException("部分数据已归档,无法编辑或删除");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object cnt = em.createQuery("select count(1) from PurchaseOrderEntity p join p.weightDataList w where w.id in :ids")
|
Object cnt =
|
||||||
.setParameter("ids", request.getIds())
|
em.createQuery(
|
||||||
.getSingleResult();
|
"select count(1) from PurchaseOrderEntity p join p.weightDataList w where w.id in :ids")
|
||||||
|
.setParameter("ids", request.getIds())
|
||||||
|
.getSingleResult();
|
||||||
|
|
||||||
|
if (Integer.parseInt(cnt.toString()) > 0) {
|
||||||
if (Integer.parseInt(cnt.toString()) > 0){
|
|
||||||
throw new BizException("部分数据已经被采购单引用, 无法删除");
|
throw new BizException("部分数据已经被采购单引用, 无法删除");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.repository.deleteAllById(request.getIds());
|
this.repository.deleteAllById(request.getIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,12 +324,8 @@ where 更新时间>='%s' and 更新时间<='%s'
|
|||||||
|
|
||||||
public Page<WeightDeviceDataDto> list(CommonQuery query) {
|
public Page<WeightDeviceDataDto> list(CommonQuery query) {
|
||||||
|
|
||||||
|
|
||||||
Specification specification = query.specification(conversionService);
|
Specification specification = query.specification(conversionService);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Page<WeightDeviceDataEntity> page =
|
Page<WeightDeviceDataEntity> page =
|
||||||
repository.findAll(
|
repository.findAll(
|
||||||
specification.and(
|
specification.and(
|
||||||
@@ -363,15 +357,54 @@ where 更新时间>='%s' and 更新时间<='%s'
|
|||||||
this.repository.unArchive(dto);
|
this.repository.unArchive(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void recalculate(IdRequest id) {
|
||||||
|
List<WeightColumnConfigEntity> configs = getConfigs(Ctx.currentUser().getOrganizationId());
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(configs)) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (WeightDeviceDataEntity entity : this.findAllByIds(id.getIds())) {
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(configs)) {
|
||||||
|
|
||||||
|
for (WeightColumnConfigEntity config : configs) {
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(config.getScript())) {
|
||||||
|
|
||||||
|
Object result = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
result =
|
||||||
|
GroovyScriptUtils.exec(
|
||||||
|
config.getScript(), BeanUtil.beanToMap(entity));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(
|
||||||
|
"exec script error {} {}",
|
||||||
|
config.getCode(),
|
||||||
|
config.getScript(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
ReflectUtils.writeField(entity, config.getCode(), result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("write field error {}", config.getCode(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.save(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WeightDeviceDataEntity save(WeightDeviceDataEntity entity) {
|
public WeightDeviceDataEntity save(WeightDeviceDataEntity entity) {
|
||||||
|
|
||||||
List<WeightColumnConfigEntity> configs =
|
List<WeightColumnConfigEntity> configs = getConfigs(entity.getOrganizationId());
|
||||||
em.createQuery(
|
|
||||||
"select w from WeightColumnConfigEntity w where w.organizationId = :organizationId and w.script is not null and length(w.script) > 0 and w.status = 1 order by w.sortKey asc ",
|
|
||||||
WeightColumnConfigEntity.class)
|
|
||||||
.setParameter("organizationId", entity.getOrganizationId())
|
|
||||||
.getResultList();
|
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(configs)) {
|
if (!CollectionUtils.isEmpty(configs)) {
|
||||||
|
|
||||||
@@ -387,7 +420,8 @@ where 更新时间>='%s' and 更新时间<='%s'
|
|||||||
GroovyScriptUtils.exec(
|
GroovyScriptUtils.exec(
|
||||||
config.getScript(), BeanUtil.beanToMap(entity));
|
config.getScript(), BeanUtil.beanToMap(entity));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("exec script error {} {}", config.getCode(), config.getScript(), e);
|
log.error(
|
||||||
|
"exec script error {} {}", config.getCode(), config.getScript(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -403,6 +437,14 @@ where 更新时间>='%s' and 更新时间<='%s'
|
|||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<WeightColumnConfigEntity> getConfigs(String organizationId) {
|
||||||
|
return em.createQuery(
|
||||||
|
"select w from WeightColumnConfigEntity w where w.organizationId = :organizationId and w.script is not null and length(w.script) > 0 and w.status = 1 order by w.sortKey asc ",
|
||||||
|
WeightColumnConfigEntity.class)
|
||||||
|
.setParameter("organizationId", organizationId)
|
||||||
|
.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
public Page report(WeightDeviceDataReportRequest request) {
|
public Page report(WeightDeviceDataReportRequest request) {
|
||||||
|
|
||||||
if (StringUtils.isEmpty(request.getTimeDimension())) {
|
if (StringUtils.isEmpty(request.getTimeDimension())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user