|
@@ -0,0 +1,258 @@
|
|
|
|
+package org.jeecg.modules.shiftConfiguration.controller;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
+import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
|
+import org.jeecg.modules.shiftConfiguration.entity.ShiftConfiguration;
|
|
|
|
+import org.jeecg.modules.shiftConfiguration.entity.ShiftConfigurationLog;
|
|
|
|
+import org.jeecg.modules.shiftConfiguration.service.IShiftConfigurationLogService;
|
|
|
|
+import org.jeecg.modules.shiftConfiguration.service.IShiftConfigurationService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Description: 班次配置
|
|
|
|
+ * @Author: jeecg-boot
|
|
|
|
+ * @Date: 2025-04-17
|
|
|
|
+ * @Version: V1.0
|
|
|
|
+ */
|
|
|
|
+@Api(tags = "班次配置")
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/shiftConfiguration/shiftConfiguration")
|
|
|
|
+@Slf4j
|
|
|
|
+public class ShiftConfigurationController extends JeecgController<ShiftConfiguration, IShiftConfigurationService> {
|
|
|
|
+ @Autowired
|
|
|
|
+ private IShiftConfigurationService shiftConfigurationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IShiftConfigurationLogService shiftConfigurationLogService;
|
|
|
|
+ @Autowired
|
|
|
|
+ public RedisTemplate redisTemplate;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 分页列表查询
|
|
|
|
+ *
|
|
|
|
+ * @param shiftConfiguration
|
|
|
|
+ * @param pageNo
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @param req
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ //@AutoLog(value = "班次配置-分页列表查询")
|
|
|
|
+ @ApiOperation(value = "班次配置-分页列表查询", notes = "班次配置-分页列表查询")
|
|
|
|
+ @GetMapping(value = "/list")
|
|
|
|
+ public Result<IPage<ShiftConfiguration>> queryPageList(ShiftConfiguration shiftConfiguration,
|
|
|
|
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
|
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
|
+ HttpServletRequest req) {
|
|
|
|
+ QueryWrapper<ShiftConfiguration> queryWrapper = QueryGenerator.initQueryWrapper(shiftConfiguration, req.getParameterMap());
|
|
|
|
+ Page<ShiftConfiguration> page = new Page<ShiftConfiguration>(pageNo, pageSize);
|
|
|
|
+ IPage<ShiftConfiguration> pageList = shiftConfigurationService.page(page, queryWrapper);
|
|
|
|
+ return Result.OK(pageList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 添加
|
|
|
|
+ *
|
|
|
|
+ * @param shiftConfiguration
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @AutoLog(value = "班次配置-添加")
|
|
|
|
+ @ApiOperation(value = "班次配置-添加", notes = "班次配置-添加")
|
|
|
|
+ @RequiresPermissions("shiftConfiguration:shift_configuration:add")
|
|
|
|
+ @PostMapping(value = "/add")
|
|
|
|
+ public Result<String> add(@RequestBody ShiftConfiguration shiftConfiguration) {
|
|
|
|
+
|
|
|
|
+ // 参数校验
|
|
|
|
+ if (shiftConfiguration.getDate() == null ||
|
|
|
|
+ StrUtil.isBlank(shiftConfiguration.getShift()) ||
|
|
|
|
+ StrUtil.isBlank(shiftConfiguration.getShiftGroup())) {
|
|
|
|
+ return Result.error("班次日期、班别、班组不能为空!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Date shiftDate = shiftConfiguration.getDate();
|
|
|
|
+ String shift = shiftConfiguration.getShift();
|
|
|
|
+ String shiftGroup = shiftConfiguration.getShiftGroup();
|
|
|
|
+
|
|
|
|
+ // 日期只保留年月日
|
|
|
|
+ LocalDate localDate = shiftDate.toInstant()
|
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
|
+ .toLocalDate();
|
|
|
|
+
|
|
|
|
+ // 构造当天 00:00:00 和 23:59:59 范围
|
|
|
|
+ LocalDateTime startOfDay = localDate.atStartOfDay();
|
|
|
|
+ LocalDateTime endOfDay = localDate.atTime(LocalTime.MAX);
|
|
|
|
+
|
|
|
|
+ Date start = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
+ Date end = Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
+
|
|
|
|
+ // 查询同一天相同班组和班别是否存在
|
|
|
|
+ LambdaQueryWrapper<ShiftConfiguration> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.between(ShiftConfiguration::getDate, start, end)
|
|
|
|
+ .eq(ShiftConfiguration::getShift, shift)
|
|
|
|
+ .eq(ShiftConfiguration::getShiftGroup, shiftGroup);
|
|
|
|
+
|
|
|
|
+ boolean exists = shiftConfigurationService.count(queryWrapper) > 0;
|
|
|
|
+ if (exists) {
|
|
|
|
+ return Result.error("该班别和班组在当天已存在,不能重复添加!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ shiftConfigurationService.save(shiftConfiguration);
|
|
|
|
+ return Result.OK("添加成功!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 编辑
|
|
|
|
+ *
|
|
|
|
+ * @param shiftConfiguration
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @AutoLog(value = "班次配置-编辑")
|
|
|
|
+ @ApiOperation(value = "班次配置-编辑", notes = "班次配置-编辑")
|
|
|
|
+ @RequiresPermissions("shiftConfiguration:shift_configuration:edit")
|
|
|
|
+ @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
|
|
|
+ public Result<String> edit(@RequestBody ShiftConfiguration shiftConfiguration) {
|
|
|
|
+ // 获取当前用户
|
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
|
+ String username = sysUser.getUsername();
|
|
|
|
+
|
|
|
|
+ // 查询原数据用于对比
|
|
|
|
+ ShiftConfiguration oldConfig = shiftConfigurationService.getById(shiftConfiguration.getId());
|
|
|
|
+
|
|
|
|
+ shiftConfigurationService.updateById(shiftConfiguration);
|
|
|
|
+
|
|
|
|
+ // 构造变更内容
|
|
|
|
+ String content = String.format("编辑储运配置[id=%s],原值:%s,新值:%s",
|
|
|
|
+ shiftConfiguration.getId(),
|
|
|
|
+ oldConfig.toString(),
|
|
|
|
+ shiftConfiguration.toString());
|
|
|
|
+
|
|
|
|
+ // 保存操作日志
|
|
|
|
+ ShiftConfigurationLog log = new ShiftConfigurationLog();
|
|
|
|
+ log.setOperationUser(username);
|
|
|
|
+ log.setOperationTime(new Date());
|
|
|
|
+ log.setOperationType("编辑");
|
|
|
|
+ log.setOperationContent(content);
|
|
|
|
+ log.setBizId(shiftConfiguration.getId());
|
|
|
|
+ shiftConfigurationLogService.save(log);
|
|
|
|
+ return Result.OK("编辑成功!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过id删除
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @AutoLog(value = "班次配置-通过id删除")
|
|
|
|
+ @ApiOperation(value = "班次配置-通过id删除", notes = "班次配置-通过id删除")
|
|
|
|
+ @RequiresPermissions("shiftConfiguration:shift_configuration:delete")
|
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
|
+ public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
|
+ shiftConfigurationService.removeById(id);
|
|
|
|
+ return Result.OK("删除成功!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量删除
|
|
|
|
+ *
|
|
|
|
+ * @param ids
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @AutoLog(value = "班次配置-批量删除")
|
|
|
|
+ @ApiOperation(value = "班次配置-批量删除", notes = "班次配置-批量删除")
|
|
|
|
+ @RequiresPermissions("shiftConfiguration:shift_configuration:deleteBatch")
|
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
|
+ public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
|
|
+ this.shiftConfigurationService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过id查询
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ //@AutoLog(value = "班次配置-通过id查询")
|
|
|
|
+ @ApiOperation(value = "班次配置-通过id查询", notes = "班次配置-通过id查询")
|
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
|
+ public Result<ShiftConfiguration> queryById(@RequestParam(name = "id", required = true) String id) {
|
|
|
|
+ ShiftConfiguration shiftConfiguration = shiftConfigurationService.getById(id);
|
|
|
|
+ if (shiftConfiguration == null) {
|
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
|
+ }
|
|
|
|
+ return Result.OK(shiftConfiguration);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 导出excel
|
|
|
|
+ *
|
|
|
|
+ * @param request
|
|
|
|
+ * @param shiftConfiguration
|
|
|
|
+ */
|
|
|
|
+ @RequiresPermissions("shiftConfiguration:shift_configuration:exportXls")
|
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, ShiftConfiguration shiftConfiguration) {
|
|
|
|
+ return super.exportXls(request, shiftConfiguration, ShiftConfiguration.class, "班次配置");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过excel导入数据
|
|
|
|
+ *
|
|
|
|
+ * @param request
|
|
|
|
+ * @param response
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequiresPermissions("shiftConfiguration:shift_configuration:importExcel")
|
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ return super.importExcel(request, response, ShiftConfiguration.class);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/getShiftInfo")
|
|
|
|
+ @ApiOperation(value = "获取当前班组班别", notes = "获取当前班组班别")
|
|
|
|
+ public Result<Map<String, String>> getShiftInfo() {
|
|
|
|
+ String shiftGroup = getShiftInfoFromRedis("5", "class:shift:group:%s");
|
|
|
|
+ String shift = getShiftInfoFromRedis("5", "class:shift:%s");
|
|
|
|
+
|
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
|
+ result.put("shiftGroup", shiftGroup);
|
|
|
|
+ result.put("shift", shift);
|
|
|
|
+
|
|
|
|
+ return Result.OK(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getShiftInfoFromRedis(String castingNo, String keyPattern) {
|
|
|
|
+ String key = String.format(keyPattern, castingNo);
|
|
|
|
+ return oConvertUtils.getString(redisTemplate.opsForValue().get(key));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|