Browse Source

修改删除bug,及其他bug

master
lihua 5 years ago
parent
commit
8456d406cb
  1. 2
      src/main/java/cn/redrock/assetmanage/common/Constants.java
  2. 6
      src/main/java/cn/redrock/assetmanage/controller/MaterialController.java
  3. 6
      src/main/java/cn/redrock/assetmanage/controller/PublicAssetController.java
  4. 1
      src/main/java/cn/redrock/assetmanage/controller/UserController.java
  5. 4
      src/main/java/cn/redrock/assetmanage/dto/Material.java
  6. 2
      src/main/java/cn/redrock/assetmanage/service/MaterialService.java
  7. 2
      src/main/java/cn/redrock/assetmanage/service/PublicAssetService.java
  8. 23
      src/main/java/cn/redrock/assetmanage/service/impl/MaterialServiceImpl.java
  9. 4
      src/main/java/cn/redrock/assetmanage/service/impl/PublicAssetServiceImpl.java
  10. 10
      src/main/java/cn/redrock/assetmanage/service/impl/TokenServiceImpl.java
  11. 7
      src/main/java/cn/redrock/assetmanage/service/impl/UserServiceImpl.java
  12. 4
      src/main/java/cn/redrock/assetmanage/utils/ExcelUtils.java

2
src/main/java/cn/redrock/assetmanage/common/Constants.java

@ -13,7 +13,7 @@ public class Constants {
public static enum Status { public static enum Status {
FAILED(-1), FAILED(-1),
NO_AUDIT(0), NO_AUDIT(0),
SUCCESS(2); SUCCESS(1);
@Getter @Getter
private Integer status; private Integer status;

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

@ -163,9 +163,9 @@ public class MaterialController {
} }
@Admin @Admin
@DeleteMapping("/delete/{code}") @DeleteMapping("/delete/{id}")
public Result deleteMaterial(@PathVariable("code") String code) { public Result deleteMaterial(@PathVariable("id") Integer id) {
if(!materialService.delete(code)){ if(!materialService.delete(id)){
return Result.error(ResponseCode.ASSET_NO_EXISTED); return Result.error(ResponseCode.ASSET_NO_EXISTED);
} }
return Result.ok(); return Result.ok();

6
src/main/java/cn/redrock/assetmanage/controller/PublicAssetController.java

@ -45,9 +45,9 @@ public class PublicAssetController {
return Result.ok(); return Result.ok();
} }
@DeleteMapping("/delete/{code}") @DeleteMapping("/delete/{id}")
public Result deleteAsset(@PathVariable("code") String code) { public Result deleteAsset(@PathVariable("id") Integer id) {
if(!publicAssetService.delete(code)){ if(!publicAssetService.delete(id)){
return Result.error(ResponseCode.ASSET_NO_EXISTED); return Result.error(ResponseCode.ASSET_NO_EXISTED);
} }
return Result.ok(); return Result.ok();

1
src/main/java/cn/redrock/assetmanage/controller/UserController.java

@ -101,6 +101,7 @@ public class UserController {
public Result edit(@CurrentUser AmUser user,Integer userId, @RequestBody UserInfo userInfo) { public Result edit(@CurrentUser AmUser user,Integer userId, @RequestBody UserInfo userInfo) {
if(userId == null){ if(userId == null){
userId = user.getId(); userId = user.getId();
userInfo.setIsAdmin(user.getIsAdmin());
} }
if(!userService.editUser(userId,userInfo)){ if(!userService.editUser(userId,userInfo)){
return Result.error(ResponseCode.USER_EXISTED); return Result.error(ResponseCode.USER_EXISTED);

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

@ -16,12 +16,12 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class Material { public class Material {
private Integer id; private Integer id;
@ExcelColumn(value = "物料编号", col = 1)
@ExcelColumn(value = "物料编号", col = 1)
@NotBlank @NotBlank
private String code; private String code;
@ExcelColumn(value = "数量", col = 2)
@ExcelColumn(value = "数量", col = 2)
@NotNull @NotNull
private Integer num; private Integer num;

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

@ -20,6 +20,6 @@ public interface MaterialService {
void batchSub(List<Material> materials,List<Material> successMaterials,List<Material> failMaterials); void batchSub(List<Material> materials,List<Material> successMaterials,List<Material> failMaterials);
List<AmMaterial> search(String field, String content, Integer pageNum, Integer pageSize); List<AmMaterial> search(String field, String content, Integer pageNum, Integer pageSize);
boolean update(Material material); boolean update(Material material);
boolean delete(String code); boolean delete(Integer id);
PageInfo<AmMaterial> warn(Integer pageNum, Integer pageSize); PageInfo<AmMaterial> warn(Integer pageNum, Integer pageSize);
} }

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

@ -16,5 +16,5 @@ public interface PublicAssetService {
boolean add(PublicAsset publicAsset); boolean add(PublicAsset publicAsset);
List<AmPublicAsset> search(String field, String content, Integer pageNum, Integer pageSize); List<AmPublicAsset> search(String field, String content, Integer pageNum, Integer pageSize);
boolean update(PublicAsset publicAsset); boolean update(PublicAsset publicAsset);
boolean delete(String code); boolean delete(Integer id);
} }

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

@ -70,7 +70,7 @@ public class MaterialServiceImpl implements MaterialService {
newMaterial.setCode(material.getCode()); newMaterial.setCode(material.getCode());
newMaterial.setNum(num + material.getNum()); newMaterial.setNum(num + material.getNum());
} }
newMaterial.setUpdateTime(new Date()); newMaterial.setId(oldMaterial.getId());
if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){ if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){
log.info("update add material success from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); log.info("update add material success from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial));
}else{ }else{
@ -133,23 +133,12 @@ public class MaterialServiceImpl implements MaterialService {
log.error("update sub material failed from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial)); log.error("update sub material failed from {} to {} ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial));
} }
}else{ }else{
newMaterial.setId(oldMaterial.getId());
newMaterial.setCode(material.getCode());
newMaterial.setNum(0);
if(materialMapper.updateByPrimaryKeySelective(newMaterial) > 0){
log.info("update add material success from {} to {} for failed ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial));
}else{
log.error("update add material failed from {} to {} for failed ", JSON.toJSONString(oldMaterial),JSON.toJSONString(newMaterial));
}
BeanUtils.copyProperties(oldMaterial,errorMaterial); BeanUtils.copyProperties(oldMaterial,errorMaterial);
errorMaterial.setNum(material.getNum() - num);
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(material.getNum()); errorMaterial.setNum(-1);
failMaterials.add(errorMaterial); failMaterials.add(errorMaterial);
} }
} }
@ -182,12 +171,12 @@ public class MaterialServiceImpl implements MaterialService {
} }
@Override @Override
public boolean delete(String code) { public boolean delete(Integer id) {
if(materialMapper.deleteByPrimaryKey(code) > 0){ if(materialMapper.deleteByPrimaryKey(id) > 0){
log.info("delete material success {} ", code); log.info("delete material success {} ", id);
return true; return true;
} }
log.error("delete material failed {} ", code); log.error("delete material failed {} ", id);
return false; return false;
} }

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

@ -66,7 +66,7 @@ public class PublicAssetServiceImpl implements PublicAssetService {
} }
@Override @Override
public boolean delete(String code) { public boolean delete(Integer id) {
return publicAssetMapper.deleteByPrimaryKey(code) > 0; return publicAssetMapper.deleteByPrimaryKey(id) > 0;
} }
} }

10
src/main/java/cn/redrock/assetmanage/service/impl/TokenServiceImpl.java

@ -39,9 +39,13 @@ public class TokenServiceImpl implements TokenService {
amToken.setToken(token); amToken.setToken(token);
tokenMapper.insert(amToken); tokenMapper.insert(amToken);
}else{ }else{
amToken.setToken(token); if(amToken.getExpireTime().getTime() - new Date().getTime() < 0){
amToken.setExpireTime(expireTime); amToken.setToken(token);
tokenMapper.updateTokenById(amToken); amToken.setExpireTime(expireTime);
tokenMapper.updateTokenById(amToken);
}else{
token = amToken.getToken();
}
} }
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("token", token); map.put("token", token);

7
src/main/java/cn/redrock/assetmanage/service/impl/UserServiceImpl.java

@ -75,14 +75,9 @@ public class UserServiceImpl implements UserService {
log.info("can't find user with id {}",userId); log.info("can't find user with id {}",userId);
return false; return false;
} }
if(user.getName() != null && !oldUser.getName().equals(user.getName())){
if(userMapper.findUserByName(user.getName()) != null){
log.info("user {} already exists",user.getName());
return false;
}
}
BeanUtilsExt.copyPropertiesIgnoreNull(user,oldUser); BeanUtilsExt.copyPropertiesIgnoreNull(user,oldUser);
oldUser.setUpdateTime(new Date()); oldUser.setUpdateTime(new Date());
oldUser.setName(null);
return userMapper.updateByPrimaryKeySelective(oldUser) > 0; return userMapper.updateByPrimaryKeySelective(oldUser) > 0;
} }

4
src/main/java/cn/redrock/assetmanage/utils/ExcelUtils.java

@ -237,7 +237,7 @@ public class ExcelUtils {
})).collect(Collectors.toList()); })).collect(Collectors.toList());
Workbook wb = new XSSFWorkbook(); Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("sheet1"); Sheet sheet = wb.createSheet("Sheet1");
AtomicInteger ai = new AtomicInteger(); AtomicInteger ai = new AtomicInteger();
{ {
Row row = sheet.createRow(ai.getAndIncrement()); Row row = sheet.createRow(ai.getAndIncrement());
@ -288,7 +288,7 @@ public class ExcelUtils {
}); });
} }
//冻结窗格 //冻结窗格
wb.getSheet("sheet1").createFreezePane(0, 1, 0, 1); wb.getSheet("Sheet1").createFreezePane(0, 1, 0, 1);
return wb; return wb;
} }

Loading…
Cancel
Save