diff --git a/flood-application/src/main/java/com/prevention/flood/application/constant/Constant.java b/flood-application/src/main/java/com/prevention/flood/application/constant/Constant.java new file mode 100644 index 0000000000000000000000000000000000000000..b891d032f4b6cf882608882755f4962daebfdbd7 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/constant/Constant.java @@ -0,0 +1,41 @@ +package com.prevention.flood.application.constant; + +public interface Constant { + + /** + *有效 + */ + Integer STATUS_ENABLE = 1; + + /** + *作废 + */ + Integer STATUS_DISABLE = 0; + + /** + * 删除 + */ + Integer DEL_FLAG_1 = 1; + + /** + * 未删除 + */ + Integer DEL_FLAG_0 = 0; + + /** + * 防汛物资使用类型-储备 + */ + Integer USE_TYPE_STORE = 0; + /** + * 防汛物资使用类型-归还 + */ + Integer USE_TYPE_RETURN = 1; + /** + * 防汛物资使用类型-领用 + */ + Integer USE_TYPE_RECEIVE = 2; + /** + * 防汛物资使用类型-报废 + */ + Integer USE_TYPE_SCRAP = 3; +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/controller/controlFund/FloodControlFundController.java b/flood-application/src/main/java/com/prevention/flood/application/controller/controlFund/FloodControlFundController.java new file mode 100644 index 0000000000000000000000000000000000000000..5298ee6a4c5e7d38e709830e33334fc963c23060 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/controller/controlFund/FloodControlFundController.java @@ -0,0 +1,123 @@ +package com.prevention.flood.application.controller.controlFund; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.prevention.flood.application.configs.annotation.CurrentUser; +import com.prevention.flood.application.configs.annotation.SymLog; +import com.prevention.flood.application.constant.BscSysCodeEnum; +import com.prevention.flood.application.dto.common.IdDto; +import com.prevention.flood.application.dto.controlFund.FloodControlFundDto; +import com.prevention.flood.application.model.common.R; +import com.prevention.flood.application.model.controlFund.FloodControlFund; +import com.prevention.flood.application.model.system.User; +import com.prevention.flood.application.service.controlFund.IFloodControlFundService; +import com.prevention.flood.application.util.DateUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * @author + */ +@Api(tags="防汛经费") +@RestController +@RequestMapping("/flood/controlFund") +public class FloodControlFundController { + + @Autowired + private IFloodControlFundService floodControlFundService; + + @SymLog(message = "防汛经费列表查询") + @ApiOperation(value="防汛经费列表查询", notes="防汛经费列表查询") + @PostMapping(value = "/list") + public R> list(@RequestBody FloodControlFundDto floodControlFundDto, + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) { + EntityWrapper wrapper = new EntityWrapper<>(); + String startTime = floodControlFundDto.getStartOccurDate(); + String endTime = floodControlFundDto.getEndOccurDate(); + if(StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){ + wrapper.between("occur_date", DateUtil.parseDate(startTime),DateUtil.parseDate(endTime)); + } + if(!StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){ + wrapper.le("occur_date",DateUtil.parseDate(endTime)); + } + if(StringUtils.isNotEmpty(startTime) && !StringUtils.isNotEmpty(endTime)){ + wrapper.ge("occur_date",DateUtil.parseDate(startTime)); + } + if(Objects.nonNull(floodControlFundDto.getOccurType())){ + wrapper.eq("occur_type",floodControlFundDto.getOccurType()); + } + if(Objects.nonNull(floodControlFundDto.getStatus())){ + wrapper.eq("status",floodControlFundDto.getStatus()); + } + wrapper.orderBy("create_time",false); + Page page = new Page<>(pageNo, pageSize); + Page selectPage = floodControlFundService.selectPage(page, wrapper); + handleOccurDate(selectPage.getRecords()); + return R.ok(selectPage); + } + + private List handleOccurDate(List records) { + if(CollectionUtils.isNotEmpty(records)){ + for (FloodControlFund record : records) { + record.setOverDays(DateUtil.getDaySub(record.getCreateTime(),new Date()) >= 30); + } + } + return records; + } + + @SymLog(message = "防汛经费添加") + @ApiOperation(value="防汛经费添加", notes="防汛经费添加") + @PostMapping("/save") + public R save(@RequestBody @Valid FloodControlFund floodControlFund, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + floodControlFund.setCreateBy(user.getId()); + floodControlFund.setCreateByName(user.getName()); + floodControlFundService.save(floodControlFund); + return R.ok(); + } + + @SymLog(message = "防汛经费修改") + @ApiOperation(value="防汛经费修改", notes="防汛经费修改") + @PostMapping("/update") + public R update(@RequestBody @Valid FloodControlFund floodControlFund, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + floodControlFundService.updateData(floodControlFund); + return R.ok(); + } + + @SymLog(message = "防汛经费详情") + @ApiOperation(value="防汛经费详情", notes="防汛经费详情") + @GetMapping("/getById") + public R getById(@RequestParam(name = "id")Integer id, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + return R.ok(floodControlFundService.selectById(id)); + } + + @SymLog(message = "作废") + @ApiOperation(value="作废", notes="作废") + @PostMapping("/disable") + public R disable(@RequestBody IdDto idDto, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + floodControlFundService.disable(idDto.getId()); + return R.ok(); + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/controller/controlFund/MaterialInfoController.java b/flood-application/src/main/java/com/prevention/flood/application/controller/controlFund/MaterialInfoController.java new file mode 100644 index 0000000000000000000000000000000000000000..6bbdb8f37fc740c4b375b1a9e18e396a11b3d780 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/controller/controlFund/MaterialInfoController.java @@ -0,0 +1,123 @@ +package com.prevention.flood.application.controller.controlFund; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.prevention.flood.application.configs.annotation.CurrentUser; +import com.prevention.flood.application.configs.annotation.SymLog; +import com.prevention.flood.application.constant.BscSysCodeEnum; +import com.prevention.flood.application.constant.Constant; +import com.prevention.flood.application.dto.common.IdDto; +import com.prevention.flood.application.dto.controlFund.MaterialInfoDto; +import com.prevention.flood.application.model.common.R; +import com.prevention.flood.application.model.controlFund.MaterialInfo; +import com.prevention.flood.application.model.controlFund.MaterialRecord; +import com.prevention.flood.application.model.system.User; +import com.prevention.flood.application.service.controlFund.IMaterialInfoService; +import com.prevention.flood.application.util.SimpleUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.Objects; + +/** + * @author + */ +@Api(tags="防汛物资") +@RestController +@RequestMapping("/materialInfo") +public class MaterialInfoController { + + @Autowired + private IMaterialInfoService materialInfoService; + + @SymLog(message = "防汛物资列表查询") + @ApiOperation(value="防汛物资列表查询", notes="防汛物资列表查询") + @PostMapping(value = "/list") + public R> list(@RequestBody MaterialInfoDto materialInfoDto, + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) { + EntityWrapper wrapper = new EntityWrapper<>(); + handleWrapperCondition(wrapper,materialInfoDto); + Page page = new Page<>(pageNo, pageSize); + Page selectPage = materialInfoService.selectPage(page, wrapper); + return R.ok(selectPage); + } + + private void handleWrapperCondition(EntityWrapper wrapper, MaterialInfoDto materialInfoDto) { + if(StringUtils.isNotEmpty(materialInfoDto.getMaterialCode())){ + String specialStr = SimpleUtil.handleSpecialStr(materialInfoDto.getMaterialCode()); + wrapper.like("material_code",specialStr); + } + if(StringUtils.isNotEmpty(materialInfoDto.getDepotName())){ + String specialStr = SimpleUtil.handleSpecialStr(materialInfoDto.getDepotName()); + wrapper.like("depot_name",specialStr); + } + if(StringUtils.isNotEmpty(materialInfoDto.getMaterialName())){ + String specialStr = SimpleUtil.handleSpecialStr(materialInfoDto.getMaterialName()); + wrapper.like("material_name",specialStr); + } + if(StringUtils.isNotEmpty(materialInfoDto.getHeader())){ + String specialStr = SimpleUtil.handleSpecialStr(materialInfoDto.getHeader()); + wrapper.like("header",specialStr); + } + if(Objects.nonNull(materialInfoDto.getMaterialType())){ + wrapper.eq("material_type",materialInfoDto.getMaterialType()); + } + if(Objects.nonNull(materialInfoDto.getAreaType())){ + wrapper.eq("area_type",materialInfoDto.getAreaType()); + } + wrapper.eq("del_flag", Constant.DEL_FLAG_0); + wrapper.orderBy("update_time",false); + } + + @SymLog(message = "防汛物资添加") + @ApiOperation(value="防汛物资添加", notes="防汛物资添加") + @PostMapping("/save") + public R save(@RequestBody @Valid MaterialInfo materialInfo, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + materialInfo.setCreateBy(user.getName()); + materialInfoService.save(materialInfo); + return R.ok(); + } + + @SymLog(message = "防汛物资修改") + @ApiOperation(value="防汛物资修改", notes="防汛物资修改") + @PostMapping("/update") + public R update(@RequestBody @Valid MaterialInfo materialInfo, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + materialInfoService.updateData(materialInfo); + return R.ok(); + } + + @SymLog(message = "删除") + @ApiOperation(value="删除", notes="删除") + @PostMapping("/delete") + public R delete(@RequestBody IdDto idDto, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + materialInfoService.deleteData(idDto.getId()); + return R.ok(); + } + + @SymLog(message = "防汛物资操作(存储,领用,归还,报废)") + @ApiOperation(value="防汛物资操作(0储备1归还2领用3报废)", notes="防汛物资操作(0储备1归还2领用3报废)") + @PostMapping("/operate") + public R operate(@RequestBody MaterialRecord materialRecord, @CurrentUser @ApiIgnore User user) { + if(Objects.isNull(user)){ + return R.failed(BscSysCodeEnum.LOGIN_IS_NULL); + } + materialRecord.setCreateBy(user.getName()); + materialInfoService.operate(materialRecord); + return R.ok(); + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/FloodControlFundDao.java b/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/FloodControlFundDao.java new file mode 100644 index 0000000000000000000000000000000000000000..715849c51beedf8b3a6dd34e089a7617b8a3705c --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/FloodControlFundDao.java @@ -0,0 +1,8 @@ +package com.prevention.flood.application.dao.controlFund; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.prevention.flood.application.model.controlFund.FloodControlFund; + +public interface FloodControlFundDao extends BaseMapper { + +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/MaterialInfoDao.java b/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/MaterialInfoDao.java new file mode 100644 index 0000000000000000000000000000000000000000..e17b4567809b8e4c0210ac7ebf2e900bd2c64aa1 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/MaterialInfoDao.java @@ -0,0 +1,8 @@ +package com.prevention.flood.application.dao.controlFund; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.prevention.flood.application.model.controlFund.MaterialInfo; + +public interface MaterialInfoDao extends BaseMapper { + +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/MaterialRecordDao.java b/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/MaterialRecordDao.java new file mode 100644 index 0000000000000000000000000000000000000000..a51bd2302147267dcbcf8c49c88212ba03c5eb09 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/dao/controlFund/MaterialRecordDao.java @@ -0,0 +1,8 @@ +package com.prevention.flood.application.dao.controlFund; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.prevention.flood.application.model.controlFund.MaterialRecord; + +public interface MaterialRecordDao extends BaseMapper { + +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/dto/common/IdDto.java b/flood-application/src/main/java/com/prevention/flood/application/dto/common/IdDto.java new file mode 100644 index 0000000000000000000000000000000000000000..c5b01a91b4d5374d48c67f7576121f0c6f67c9f1 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/dto/common/IdDto.java @@ -0,0 +1,16 @@ +package com.prevention.flood.application.dto.common; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class IdDto { + + @ApiModelProperty(value = "主键ID") + private Integer id; +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/dto/controlFund/FloodControlFundDto.java b/flood-application/src/main/java/com/prevention/flood/application/dto/controlFund/FloodControlFundDto.java new file mode 100644 index 0000000000000000000000000000000000000000..4b0501cadf68054bc8a7ad8b6058bd6dde494e05 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/dto/controlFund/FloodControlFundDto.java @@ -0,0 +1,23 @@ +package com.prevention.flood.application.dto.controlFund; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class FloodControlFundDto { + + + @ApiModelProperty("发生日期-开始") + private String startOccurDate; + + @ApiModelProperty("发生日期-结束") + private String endOccurDate; + + @ApiModelProperty("发生方式(0收入1支出)") + private Integer occurType; + + @ApiModelProperty("状态(0作废1有效)") + private Integer status; + + +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/dto/controlFund/MaterialInfoDto.java b/flood-application/src/main/java/com/prevention/flood/application/dto/controlFund/MaterialInfoDto.java new file mode 100644 index 0000000000000000000000000000000000000000..e456464866e73626eb80818a95bead5bac9b8994 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/dto/controlFund/MaterialInfoDto.java @@ -0,0 +1,29 @@ +package com.prevention.flood.application.dto.controlFund; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MaterialInfoDto { + + + @ApiModelProperty("物资仓库") + private String depotName; + + @ApiModelProperty("物资编码") + private String materialCode; + + @ApiModelProperty("物资类别(0物资1工具与设备)") + private Integer materialType; + + @ApiModelProperty("物资名称") + private String materialName; + + @ApiModelProperty("行政区划") + private String areaType; + + @ApiModelProperty("负责人") + private String header; + + +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/FloodControlFund.java b/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/FloodControlFund.java new file mode 100644 index 0000000000000000000000000000000000000000..4b90c305544840d0bbb77461cadd0e14e1709273 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/FloodControlFund.java @@ -0,0 +1,85 @@ +package com.prevention.flood.application.model.controlFund; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 防汛经费表 + */ +@Data +@ApiModel(value="防汛经费对象", description="防汛经费对象") +@TableName("flood_control_fund") +public class FloodControlFund extends Model { + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("流水号") + private String serialCode; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty("发生日期") + @NotNull(message = "发生日期不能为空") + private Date occurDate; + + @ApiModelProperty("发生方式(0收入1支出)") + @NotNull(message = "发生方式不能为空") + private Integer occurType; + + @ApiModelProperty("发生费用") + @NotNull(message = "发生费用不能为空") + private BigDecimal occurFee; + + @ApiModelProperty("发生单位") + @NotBlank(message = "发生单位不能为空") + private String occurCompany; + + @ApiModelProperty("经办人") + @NotBlank(message = "经办人不能为空") + private String agentPerson; + + @ApiModelProperty("状态(0作废1有效)") + private Integer status; + + @ApiModelProperty("费用说明") + private String content; + + @ApiModelProperty("创建时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + + @ApiModelProperty("创建人") + private Integer createBy; + + @ApiModelProperty("创建人名字") + private String createByName; + + @ApiModelProperty("附件") + private String fileUrl; + + @ApiModelProperty("是否超过30天") + @TableField(exist = false) + private Boolean overDays; + + + @Override + protected Serializable pkVal() { + return this.id; + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/MaterialInfo.java b/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/MaterialInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..33a2d6be41b833bcfa634a47e078ba3e54596eae --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/MaterialInfo.java @@ -0,0 +1,109 @@ +package com.prevention.flood.application.model.controlFund; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableField; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 防汛物资信息表 + */ +@Data +@ApiModel(value="防汛物资信息表", description="防汛物资信息表") +@TableName("material_info") +public class MaterialInfo extends Model { + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("物资编码") + private String materialCode; + + @ApiModelProperty("物资类别(0物资1工具与设备)") + @NotNull(message = "物资类别不能为空") + private Integer materialType; + + @ApiModelProperty("物资名称") + @NotBlank(message = "物资名称不能为空") + private String materialName; + + @ApiModelProperty("所在仓库id") + private Integer depot; + + @ApiModelProperty("所在仓库") + private String depotName; + + @ApiModelProperty("新增人") + private String addPerson; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty("新增时间") + private Date addTime; + + @ApiModelProperty("物资数量") + @NotNull(message = "物资数量不能为空") + private Integer materialNum; + + @ApiModelProperty("物资单位") + @NotBlank(message = "物资单位不能为空") + private String materialUnit; + + @ApiModelProperty("物资规格") + private String materialSpec; + + @ApiModelProperty("物资模型") + private String materialModel; + + @ApiModelProperty("行政区划") + private String areaType; + + @ApiModelProperty("存放地点") + private String storageLocation; + + @ApiModelProperty("经度") + private Double lng; + + @ApiModelProperty("纬度") + private Double lat; + + @ApiModelProperty("负责人") + private String header; + + @ApiModelProperty("手机号") + private String phone; + + @ApiModelProperty("物资用途") + private String materialUsage; + + @ApiModelProperty("备注说明") + private String remark; + + @ApiModelProperty("更新时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date updateTime; + + @ApiModelProperty("创建人") + private String createBy; + + @ApiModelProperty("删除标识") + private Integer delFlag; + + @Override + protected Serializable pkVal() { + return this.id; + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/MaterialRecord.java b/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/MaterialRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..21d5ba3ca0f0ae00e1231d8e902fe0c8840fca9f --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/model/controlFund/MaterialRecord.java @@ -0,0 +1,62 @@ +package com.prevention.flood.application.model.controlFund; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableName; +import com.baomidou.mybatisplus.enums.IdType; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +/** + * 防汛物资使用记录 + */ +@Data +@ApiModel(value="防汛物资使用记录", description="防汛物资使用记录") +@TableName("material_record") +public class MaterialRecord extends Model { + + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("物资数量") + @NotNull(message = "物资数量不能为空") + private Integer num; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @ApiModelProperty("物资使用日期") + private Date operateDate; + + @ApiModelProperty("使用类型(0储备1归还2领用3报废)") + private Integer useType; + + @ApiModelProperty("物资操作人") + private String operator; + + @ApiModelProperty("物资操作说明") + private String operateIntro; + + @ApiModelProperty("更新时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date updateTime; + + @ApiModelProperty("创建人") + private String createBy; + + @ApiModelProperty("物资id") + private Integer materialId; + + @Override + protected Serializable pkVal() { + return this.id; + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IFloodControlFundService.java b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IFloodControlFundService.java new file mode 100644 index 0000000000000000000000000000000000000000..5367d5a54d6113c675496afb0370ef9b377cea77 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IFloodControlFundService.java @@ -0,0 +1,16 @@ +package com.prevention.flood.application.service.controlFund; + + +import com.baomidou.mybatisplus.service.IService; +import com.prevention.flood.application.model.controlFund.FloodControlFund; + +public interface IFloodControlFundService extends IService { + + FloodControlFund getByOccurDate(String nowDate); + + void save(FloodControlFund floodControlFund); + + void updateData(FloodControlFund floodControlFund); + + void disable(Integer id); +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IMaterialInfoService.java b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IMaterialInfoService.java new file mode 100644 index 0000000000000000000000000000000000000000..6abe88f7fc232d9d3b6e0f4eb6001434a9fae2e5 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IMaterialInfoService.java @@ -0,0 +1,17 @@ +package com.prevention.flood.application.service.controlFund; + + +import com.baomidou.mybatisplus.service.IService; +import com.prevention.flood.application.model.controlFund.MaterialInfo; +import com.prevention.flood.application.model.controlFund.MaterialRecord; + +public interface IMaterialInfoService extends IService { + + void save(MaterialInfo materialInfo); + + void updateData(MaterialInfo materialInfo); + + void deleteData(Integer id); + + void operate(MaterialRecord materialRecord); +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IMaterialRecordService.java b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IMaterialRecordService.java new file mode 100644 index 0000000000000000000000000000000000000000..3373902e79447475bd506d523011981c227083f9 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/IMaterialRecordService.java @@ -0,0 +1,13 @@ +package com.prevention.flood.application.service.controlFund; + + +import com.baomidou.mybatisplus.service.IService; +import com.prevention.flood.application.model.controlFund.MaterialInfo; +import com.prevention.flood.application.model.controlFund.MaterialRecord; + +import java.util.List; + +public interface IMaterialRecordService extends IService { + + List getListByMaterialId(Integer id); +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/FloodControlFundServiceImpl.java b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/FloodControlFundServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..d0e41c97df4da4bcc090a54461f862d9200e1f79 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/FloodControlFundServiceImpl.java @@ -0,0 +1,61 @@ +package com.prevention.flood.application.service.controlFund.impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.prevention.flood.application.configs.globalExceptionHandling.BaseException; +import com.prevention.flood.application.constant.Constant; +import com.prevention.flood.application.dao.controlFund.FloodControlFundDao; +import com.prevention.flood.application.model.controlFund.FloodControlFund; +import com.prevention.flood.application.service.controlFund.IFloodControlFundService; +import com.prevention.flood.application.util.CodeGenUtil; +import com.prevention.flood.application.util.DateUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.Optional; + + +@Slf4j +@Service +public class FloodControlFundServiceImpl extends ServiceImpl implements IFloodControlFundService { + + @Autowired + private CodeGenUtil codeGenUtil; + + @Override + public FloodControlFund getByOccurDate(String nowDate) { + EntityWrapper wrapper = new EntityWrapper<>(); + wrapper.eq("occur_date", DateUtil.parseDate(nowDate)); + wrapper.orderBy("occur_date",false); + List list = selectList(wrapper); + if(CollectionUtils.isNotEmpty(list)){ + return list.get(0); + } + return null; + } + + @Override + public void save(FloodControlFund floodControlFund) { + floodControlFund.setCreateTime(new Date()); + floodControlFund.setStatus(Constant.STATUS_ENABLE); + floodControlFund.setSerialCode(codeGenUtil.genCode()); + insert(floodControlFund); + } + + @Override + public void updateData(FloodControlFund floodControlFund) { + updateById(floodControlFund); + } + + @Override + public void disable(Integer id) { + FloodControlFund floodControlFund = selectById(id); + Optional.ofNullable(floodControlFund).orElseThrow(()->new BaseException("未找到对应的数据")); + floodControlFund.setStatus(Constant.STATUS_DISABLE); + updateById(floodControlFund); + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/MaterialInfoServiceImpl.java b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/MaterialInfoServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..4f8fffd06200d912fc1d91615632be7a2eca83f9 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/MaterialInfoServiceImpl.java @@ -0,0 +1,81 @@ +package com.prevention.flood.application.service.controlFund.impl; + +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.prevention.flood.application.configs.globalExceptionHandling.BaseException; +import com.prevention.flood.application.constant.Constant; +import com.prevention.flood.application.dao.controlFund.MaterialInfoDao; +import com.prevention.flood.application.dto.emergency.EmeWarehouseVo; +import com.prevention.flood.application.model.controlFund.MaterialInfo; +import com.prevention.flood.application.model.controlFund.MaterialRecord; +import com.prevention.flood.application.service.controlFund.IMaterialInfoService; +import com.prevention.flood.application.service.controlFund.IMaterialRecordService; +import com.prevention.flood.application.service.emergency.EmergencyWarehouseService; +import com.prevention.flood.application.util.CodeGenUtil; +import com.prevention.flood.application.util.DateUtil; +import com.prevention.flood.application.util.SimpleUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; +import java.util.Optional; + + +@Slf4j +@Service +public class MaterialInfoServiceImpl extends ServiceImpl implements IMaterialInfoService { + + @Autowired + private IMaterialRecordService materialRecordService; + @Autowired + private EmergencyWarehouseService emergencyWarehouseService; + + @Override + public void save(MaterialInfo materialInfo) { + EmeWarehouseVo warehouseVo = emergencyWarehouseService.queryById(materialInfo.getDepot().toString()); + materialInfo.setDepotName(warehouseVo.getName()); + materialInfo.setMaterialCode(DateUtil.getDays() + SimpleUtil.getRandomString(4)); + materialInfo.setUpdateTime(new Date()); + materialInfo.setDelFlag(Constant.DEL_FLAG_0); + insert(materialInfo); + } + + @Override + public void updateData(MaterialInfo materialInfo) { + materialInfo.setUpdateTime(new Date()); + updateById(materialInfo); + } + + @Override + public void deleteData(Integer id) { + List list = materialRecordService.getListByMaterialId(id); + if(CollectionUtils.isNotEmpty(list)){ + throw new BaseException("该物资下已经有相应的操作记录,删除失败"); + } + MaterialInfo materialInfo = selectById(id); + materialInfo.setDelFlag(Constant.DEL_FLAG_1); + updateById(materialInfo); + } + + @Transactional + @Override + public void operate(MaterialRecord materialRecord) { + Optional.ofNullable(materialRecord.getMaterialId()).orElseThrow(()->new BaseException("未选择需要操作的物资")); + materialRecord.setUpdateTime(new Date()); + MaterialInfo materialInfo = selectById(materialRecord.getMaterialId()); + if(Constant.USE_TYPE_RECEIVE.equals(materialRecord.getUseType()) || Constant.USE_TYPE_SCRAP.equals(materialRecord.getUseType())){ + if(materialInfo.getMaterialNum() - materialRecord.getNum() < 0){ + throw new BaseException("该物资数量库存已不足,操作失败"); + } + materialInfo.setMaterialNum(materialInfo.getMaterialNum() - materialRecord.getNum()); + }else { + materialInfo.setMaterialNum(materialInfo.getMaterialNum() + materialRecord.getNum()); + } + materialInfo.setUpdateTime(new Date()); + updateById(materialInfo); + materialRecordService.insert(materialRecord); + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/MaterialRecordServiceImpl.java b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/MaterialRecordServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..d37d2c527150c265875569a79eba9459003a3259 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/service/controlFund/impl/MaterialRecordServiceImpl.java @@ -0,0 +1,25 @@ +package com.prevention.flood.application.service.controlFund.impl; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.prevention.flood.application.dao.controlFund.MaterialRecordDao; +import com.prevention.flood.application.model.controlFund.MaterialRecord; +import com.prevention.flood.application.service.controlFund.IMaterialRecordService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Slf4j +@Service +public class MaterialRecordServiceImpl extends ServiceImpl implements IMaterialRecordService { + + @Override + public List getListByMaterialId(Integer id) { + EntityWrapper wrapper = new EntityWrapper<>(); + wrapper.eq("material_id",id); + List list = selectList(wrapper); + return list; + } +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/util/CodeGenUtil.java b/flood-application/src/main/java/com/prevention/flood/application/util/CodeGenUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..06cc9509c7a306e7316d92f9eafa18b83122d5ef --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/util/CodeGenUtil.java @@ -0,0 +1,58 @@ +package com.prevention.flood.application.util; + +import com.prevention.flood.application.model.controlFund.FloodControlFund; +import com.prevention.flood.application.service.controlFund.IFloodControlFundService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +@Component +public class CodeGenUtil { + + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private IFloodControlFundService floodControlFundService; + + public String genCode() { + String days = DateUtil.getDays(); + String codeCache = redisTemplate.opsForValue().get(days); + if (StringUtils.isEmpty(codeCache)) { + FloodControlFund floodControlFund = floodControlFundService.getByOccurDate(days); + if (Objects.isNull(floodControlFund)) { + Long incr = redisTemplate.opsForValue().increment(days, 1); + return days + jointCode(incr.toString(), 3); + } else { + String serialCode = floodControlFund.getSerialCode(); + Integer anInt = Integer.parseInt(serialCode.substring(serialCode.length() - 3)); + redisTemplate.opsForValue().set(days, anInt.toString(), 60 * 60 * 24, TimeUnit.SECONDS); + Long incr = redisTemplate.opsForValue().increment(days, 1); + return days + jointCode(incr.toString(), 3); + } + }else { + Long incr = redisTemplate.opsForValue().increment(days, 1); + return days + jointCode(incr.toString(),3); + } + } + + public static String jointCode(String incr, Integer length) { + int i = incr.length(); + if (i == length) { + return incr; + } + if (i > length) { + return "0" + incr; + } + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < length - i; j++) { + sb.append("0"); + } + sb.append(incr); + return sb.toString(); + } + +} diff --git a/flood-application/src/main/java/com/prevention/flood/application/util/DateUtil.java b/flood-application/src/main/java/com/prevention/flood/application/util/DateUtil.java index be0d0637e7ae0e1c64aba502561f1c3f9d16247f..e0423c7e607d6f7827553ab861f5cb96fd9c1a77 100644 --- a/flood-application/src/main/java/com/prevention/flood/application/util/DateUtil.java +++ b/flood-application/src/main/java/com/prevention/flood/application/util/DateUtil.java @@ -15,6 +15,7 @@ */ package com.prevention.flood.application.util; +import com.prevention.flood.application.configs.globalExceptionHandling.BaseException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; @@ -26,10 +27,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; public class DateUtil { @@ -443,4 +441,11 @@ public class DateUtil { } return daysStrList; } + + public static long getDaySub(Date beginDate, Date endDate) { + Optional.ofNullable(beginDate).orElseThrow(()->new BaseException("开始时间为空")); + Optional.ofNullable(endDate).orElseThrow(()->new BaseException("结束时间为空")); + long day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000); + return day; + } } diff --git a/flood-application/src/main/java/com/prevention/flood/application/util/SimpleUtil.java b/flood-application/src/main/java/com/prevention/flood/application/util/SimpleUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..a94a17c9245f914c926b6b154f037a058f2a68a5 --- /dev/null +++ b/flood-application/src/main/java/com/prevention/flood/application/util/SimpleUtil.java @@ -0,0 +1,32 @@ +package com.prevention.flood.application.util; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Random; + +public class SimpleUtil { + + public static String handleSpecialStr(String str){ + + if(StringUtils.isEmpty(str) || !str.contains("%")){ + return str; + } + String[] arr = str.split("%"); + StringBuilder sb = new StringBuilder(); + for (String ele : arr) { + sb.append(ele).append("\\%"); + } + return sb.toString(); + } + + public static String getRandomString(int length) { + String base = "0123456789"; + Random random = new Random(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + int number = random.nextInt(base.length()); + sb.append(base.charAt(number)); + } + return sb.toString(); + } +}