|
|
@ -15,6 +15,7 @@ import cn.redrock.assetmanage.utils.DateUtil; |
|
|
|
import cn.redrock.assetmanage.utils.ExcelUtils; |
|
|
|
import cn.redrock.assetmanage.utils.StringUtil; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.format.annotation.DateTimeFormat; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
@ -51,22 +52,29 @@ public class MaterialController { |
|
|
|
materialLog.setStatus(status.getStatus()); |
|
|
|
materialLog.setDescription(material.getDescription()); |
|
|
|
materialLog.setUserId(userId); |
|
|
|
materialLog.setBatch(material.getCode()+"_"+material.getNum()+"_"+DateUtil.dateToStr(new Date(),"yyyyMMddHHmmss")); |
|
|
|
return materialLog; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private List<AmMaterialLog> buildBatchLog(Integer userId,Constants.Operate operate, Constants.Status status,List<Material> materials){ |
|
|
|
private List<AmMaterialLog> buildBatchLog(Integer userId,Constants.Operate operate, Constants.Status status,List<Material> materials,String batch){ |
|
|
|
List<AmMaterialLog> materialLogs = new ArrayList<>(); |
|
|
|
for(Material material : materials){ |
|
|
|
AmMaterialLog log = buildLog(userId,operate,status,material); |
|
|
|
if(log != null){ |
|
|
|
log.setBatch(batch); |
|
|
|
materialLogs.add(log); |
|
|
|
} |
|
|
|
} |
|
|
|
return materialLogs; |
|
|
|
} |
|
|
|
|
|
|
|
private String getBatch(MultipartFile file){ |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
return StringUtils.substringBeforeLast(fileName,"."); |
|
|
|
} |
|
|
|
|
|
|
|
@Admin |
|
|
|
@PostMapping("/add") |
|
|
|
public Result addMaterial(@CurrentUser AmUser user,@Valid @RequestBody Material material) { |
|
|
@ -92,10 +100,10 @@ public class MaterialController { |
|
|
|
ret = materialService.batchAdd(list,false); |
|
|
|
} |
|
|
|
if(!ret){ |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.IN, Constants.Status.FAILED,list)); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.IN, Constants.Status.FAILED,list,getBatch(file))); |
|
|
|
return Result.error(ResponseCode.ASSET_BATCH_ADD_FAIL); |
|
|
|
} |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.IN,Constants.Status.NO_AUDIT,list)); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.IN,Constants.Status.NO_AUDIT,list,getBatch(file))); |
|
|
|
return Result.ok(); |
|
|
|
} |
|
|
|
|
|
|
@ -125,14 +133,14 @@ public class MaterialController { |
|
|
|
if(user.getIsAdmin() == 1){ |
|
|
|
materialService.batchSub(list,successMaterial,failMaterial); |
|
|
|
if(!successMaterial.isEmpty() && failMaterial.isEmpty()){ |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.SUCCESS,list)); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.SUCCESS,list,getBatch(file))); |
|
|
|
}else{ |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.FAILED,failMaterial)); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.SUCCESS,successMaterial)); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.FAILED,failMaterial,getBatch(file))); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.SUCCESS,successMaterial,getBatch(file))); |
|
|
|
return Result.ok(failMaterial); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.NO_AUDIT,list)); |
|
|
|
materialLogService.batchWriteLog(buildBatchLog(user.getId(),Constants.Operate.OUT, Constants.Status.NO_AUDIT,list,getBatch(file))); |
|
|
|
} |
|
|
|
return Result.ok(); |
|
|
|
} |
|
|
@ -192,13 +200,18 @@ public class MaterialController { |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/log") |
|
|
|
public Result queryMaterialLog(@RequestParam Integer operate,@RequestParam Integer status, |
|
|
|
public Result queryMaterialLog(@CurrentUser AmUser user, |
|
|
|
@RequestParam Integer operate,@RequestParam Integer status, |
|
|
|
@RequestParam(required = false) String field, |
|
|
|
@RequestParam(required = false) String content, |
|
|
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTm, |
|
|
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTm, |
|
|
|
Integer pageNum, Integer pageSize) { |
|
|
|
return Result.ok(materialLogService.queryLog(operate,status,field,content,startTm,endTm,pageNum,pageSize)); |
|
|
|
Integer userId = null; |
|
|
|
if(user.getIsAdmin() == 0){ |
|
|
|
userId = user.getId(); |
|
|
|
} |
|
|
|
return Result.ok(materialLogService.queryLog(userId,operate,status,field,content,startTm,endTm,pageNum,pageSize)); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/warn") |
|
|
|