| | |
| | | package org.springblade.modules.traceability.controller; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.modules.recovery.entity.Recovery; |
| | | import org.springblade.modules.recovery.service.RecoveryService; |
| | | import org.springblade.modules.traceability.dto.TraceabilityDTO; |
| | | import org.springblade.modules.traceability.entity.Traceability; |
| | | import org.springblade.modules.traceability.service.TraceabilityService; |
| | | import org.springblade.modules.traceability.vo.TraceabilityVO; |
| | | import org.springframework.retry.annotation.Recover; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | |
| | | public class TraceabilityController extends BladeController { |
| | | |
| | | private final TraceabilityService traceabilityService; |
| | | |
| | | |
| | | private final RecoveryService recoveryService; |
| | | |
| | | /** |
| | | * 详情 |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R save(@Valid @RequestBody Traceability traceability) { |
| | | traceability.setCreateTime(new Date()); |
| | | //生成溯源码编号 |
| | | //去生成保安证编号 |
| | | String pre = getCodePre(); |
| | | //查询当前前缀下最大的编号 |
| | | int max = recoveryService.getCodePreCount(pre); |
| | | String result = null; |
| | | if (max == 0) { |
| | | result = pre + "0000001"; |
| | | } else { |
| | | //格式化 |
| | | DecimalFormat decimalFormat = new DecimalFormat("0000000"); |
| | | max++; |
| | | result = pre + (decimalFormat.format(max)); |
| | | } |
| | | traceability.setCode(result); |
| | | //新增 |
| | | return R.status(traceabilityService.save(traceability)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 编号前缀 |
| | | * @return |
| | | */ |
| | | private String getCodePre() { |
| | | String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); |
| | | return nowDate.substring(2,4)+nowDate.substring(5,7); |
| | | } |
| | | |
| | | /** |
| | |
| | | @PostMapping("/update") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "修改", notes = "传入traceability") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R update(@Valid @RequestBody Traceability traceability) { |
| | | //更新并返回 |
| | | return R.status(traceabilityService.updateById(traceability)); |
| | |
| | | return R.status(traceabilityService.removeByIds(Func.toLongList(ids))); |
| | | } |
| | | |
| | | /** |
| | | * 获取溯源简介信息 |
| | | * @param traceability |
| | | * @return |
| | | */ |
| | | @GetMapping("/getSimpleInfo") |
| | | public R<TraceabilityDTO> getSimpleInfo(Traceability traceability) { |
| | | TraceabilityDTO traceabilityDTO = traceabilityService.getSimpleInfo(traceability); |
| | | return R.data(traceabilityDTO); |
| | | } |
| | | |
| | | } |