Browse Source

增加批号

master
lihua 5 years ago
parent
commit
b396a07f5e
  1. 1
      sql/asset_manage.sql
  2. 31
      src/main/java/cn/redrock/assetmanage/controller/MaterialController.java
  3. 2
      src/main/java/cn/redrock/assetmanage/dto/Material.java
  4. 1
      src/main/java/cn/redrock/assetmanage/entity/AmMaterialLog.java
  5. 1
      src/main/java/cn/redrock/assetmanage/entity/MaterialInfo.java
  6. 3
      src/main/java/cn/redrock/assetmanage/mapper/AmMaterialLogMapper.java
  7. 2
      src/main/java/cn/redrock/assetmanage/service/MaterialLogService.java
  8. 4
      src/main/java/cn/redrock/assetmanage/service/impl/MaterialLogServiceImpl.java
  9. 2
      src/main/java/cn/redrock/assetmanage/service/impl/MaterialServiceImpl.java
  10. 5
      src/main/resources/mapper/AmMaterialLogMapper.xml

1
sql/asset_manage.sql

@ -70,6 +70,7 @@ create table am_material_log(
user_id int NOT NULL, user_id int NOT NULL,
description varchar(200), description varchar(200),
operate int NOT NULL, -- 0:in,1:out operate int NOT NULL, -- 0:in,1:out
batch varchar(100),
create_time datetime default CURRENT_TIMESTAMP create_time datetime default CURRENT_TIMESTAMP
); );

31
src/main/java/cn/redrock/assetmanage/controller/MaterialController.java

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

2
src/main/java/cn/redrock/assetmanage/dto/Material.java

@ -15,7 +15,7 @@ import javax.validation.constraints.NotNull;
*/ */
@Data @Data
public class Material { public class Material {
private Integer id; private Integer id; //日志ID
@ExcelColumn(value = "物料编号", col = 1) @ExcelColumn(value = "物料编号", col = 1)
@NotBlank @NotBlank

1
src/main/java/cn/redrock/assetmanage/entity/AmMaterialLog.java

@ -31,6 +31,7 @@ public class AmMaterialLog {
private Integer operate; private Integer operate;
private String batch;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@Column(name = "create_time",updatable=false) @Column(name = "create_time",updatable=false)
private Date createTime; private Date createTime;

1
src/main/java/cn/redrock/assetmanage/entity/MaterialInfo.java

@ -38,6 +38,7 @@ public class MaterialInfo {
private Integer status; private Integer status;
private String batch;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@Column(name = "create_time",updatable=false) @Column(name = "create_time",updatable=false)
private Date createTime; private Date createTime;

3
src/main/java/cn/redrock/assetmanage/mapper/AmMaterialLogMapper.java

@ -10,7 +10,8 @@ import java.util.List;
@org.apache.ibatis.annotations.Mapper @org.apache.ibatis.annotations.Mapper
public interface AmMaterialLogMapper extends Mapper<AmMaterialLog> { public interface AmMaterialLogMapper extends Mapper<AmMaterialLog> {
List<MaterialInfo> queryLog(@Param("operate") Integer operate, List<MaterialInfo> queryLog(@Param("userId") Integer userId,
@Param("operate") Integer operate,
@Param("status") Integer status, @Param("status") Integer status,
@Param("field") String field, @Param("field") String field,
@Param("content") String content, @Param("content") String content,

2
src/main/java/cn/redrock/assetmanage/service/MaterialLogService.java

@ -19,5 +19,5 @@ public interface MaterialLogService {
void writeLog(AmMaterialLog materialLog); void writeLog(AmMaterialLog materialLog);
void batchWriteLog(List<AmMaterialLog> materialLogs); void batchWriteLog(List<AmMaterialLog> materialLogs);
void updateLog(List<Material> materials,Integer status); void updateLog(List<Material> materials,Integer status);
PageInfo<MaterialInfo> queryLog(Integer operate, Integer status,String field,String content, Date startTm, Date endTm,Integer pageNum, Integer pageSize); PageInfo<MaterialInfo> queryLog(Integer userId,Integer operate, Integer status,String field,String content, Date startTm, Date endTm,Integer pageNum, Integer pageSize);
} }

4
src/main/java/cn/redrock/assetmanage/service/impl/MaterialLogServiceImpl.java

@ -55,10 +55,10 @@ public class MaterialLogServiceImpl implements MaterialLogService {
} }
@Override @Override
public PageInfo<MaterialInfo> queryLog(Integer operate, Integer status,String field,String content,Date startTm, Date endTm, Integer pageNum, Integer pageSize) { public PageInfo<MaterialInfo> queryLog(Integer userId,Integer operate, Integer status,String field,String content,Date startTm, Date endTm, Integer pageNum, Integer pageSize) {
if(pageNum != null && pageSize != null){ if(pageNum != null && pageSize != null){
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
} }
return PageInfo.of(materialLogMapper.queryLog(operate,status,field,content,startTm,endTm)); return PageInfo.of(materialLogMapper.queryLog(userId,operate,status,field,content,startTm,endTm));
} }
} }

2
src/main/java/cn/redrock/assetmanage/service/impl/MaterialServiceImpl.java

@ -134,9 +134,11 @@ public class MaterialServiceImpl implements MaterialService {
} }
}else{ }else{
BeanUtils.copyProperties(oldMaterial,errorMaterial); BeanUtils.copyProperties(oldMaterial,errorMaterial);
errorMaterial.setId(material.getId());
failMaterials.add(errorMaterial); failMaterials.add(errorMaterial);
} }
}else{ }else{
errorMaterial.setId(material.getId());
errorMaterial.setCode(material.getCode()); errorMaterial.setCode(material.getCode());
errorMaterial.setNum(-1); errorMaterial.setNum(-1);
failMaterials.add(errorMaterial); failMaterials.add(errorMaterial);

5
src/main/resources/mapper/AmMaterialLogMapper.xml

@ -9,6 +9,7 @@
<result column="user_id" jdbcType="INTEGER" property="userId" /> <result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="description" jdbcType="VARCHAR" property="description" /> <result column="description" jdbcType="VARCHAR" property="description" />
<result column="operate" jdbcType="INTEGER" property="operate" /> <result column="operate" jdbcType="INTEGER" property="operate" />
<result column="batch" jdbcType="VARCHAR" property="batch" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap> </resultMap>
<resultMap id="MaterialInfo" type="cn.redrock.assetmanage.entity.MaterialInfo"> <resultMap id="MaterialInfo" type="cn.redrock.assetmanage.entity.MaterialInfo">
@ -22,6 +23,7 @@
<result column="position" jdbcType="VARCHAR" property="position" /> <result column="position" jdbcType="VARCHAR" property="position" />
<result column="description" jdbcType="VARCHAR" property="description" /> <result column="description" jdbcType="VARCHAR" property="description" />
<result column="status" jdbcType="INTEGER" property="status" /> <result column="status" jdbcType="INTEGER" property="status" />
<result column="batch" jdbcType="VARCHAR" property="batch" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap> </resultMap>
<select id="queryLog" resultMap="MaterialInfo"> <select id="queryLog" resultMap="MaterialInfo">
@ -34,6 +36,9 @@
<if test="startTm != null and endTm != null "> <if test="startTm != null and endTm != null ">
and a.create_time between #{startTm} and #{endTm} and a.create_time between #{startTm} and #{endTm}
</if> </if>
<if test="userId != null ">
and a.user_id = #{userId}
</if>
) t ) t
where 1 = 1 where 1 = 1
<if test="field != null and field != '' and content != null and content != '' "> <if test="field != null and field != '' and content != null and content != '' ">

Loading…
Cancel
Save