|
|
@@ -0,0 +1,191 @@
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import com.jeesite.common.collect.ListUtils;
|
|
|
+import com.jeesite.common.collect.MapUtils;
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.common.lang.DateUtils;
|
|
|
+import com.jeesite.common.mybatis.mapper.query.QueryType;
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
+import com.jeesite.modules.file.entity.FileUpload;
|
|
|
+import com.jeesite.modules.file.service.FileUploadService;
|
|
|
+import com.jeesite.modules.mes.entity.MesPhoto;
|
|
|
+import com.jeesite.modules.mes.service.MesPhotoService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 照片IdController
|
|
|
+ * @author sxl
|
|
|
+ * @version 2026-09-09
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesPhoto")
|
|
|
+public class MesPhotoController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesPhotoService mesPhotoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileUploadService fileUploadService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据
|
|
|
+ */
|
|
|
+ @ModelAttribute
|
|
|
+ public MesPhoto get(String id, boolean isNewRecord) {
|
|
|
+ return mesPhotoService.get(id, isNewRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesPhoto:view")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(MesPhoto mesPhoto, Model model) {
|
|
|
+ model.addAttribute("mesPhoto", mesPhoto);
|
|
|
+ return "modules/mes/mesPhotoList";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesPhoto:view")
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
+ @ResponseBody
|
|
|
+ public Page<MesPhoto> listData(MesPhoto mesPhoto, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ mesPhoto.setPage(new Page<>(request, response));
|
|
|
+ Page<MesPhoto> page = mesPhotoService.findPage(mesPhoto);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看编辑表单
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesPhoto:view")
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(MesPhoto mesPhoto, Model model) {
|
|
|
+ model.addAttribute("mesPhoto", mesPhoto);
|
|
|
+ return "modules/mes/mesPhotoForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesPhoto:edit")
|
|
|
+ @PostMapping(value = "save")
|
|
|
+ @ResponseBody
|
|
|
+ public String save(@Validated MesPhoto mesPhoto) {
|
|
|
+ mesPhotoService.save(mesPhoto);
|
|
|
+ return renderResult(Global.TRUE, text("保存照片Id成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesPhoto:edit")
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
+ @ResponseBody
|
|
|
+ public String delete(MesPhoto mesPhoto) {
|
|
|
+ mesPhotoService.delete(mesPhoto);
|
|
|
+ return renderResult(Global.TRUE, text("删除照片Id成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 接收创建时间和图片,写入 mes_photo,并以主键ID为bizKey存储图片
|
|
|
+ * 图片传参方式与项目其他模块一致(bizType = mesPhoto_image)
|
|
|
+ */
|
|
|
+ @PostMapping(value = "upload")
|
|
|
+ @ResponseBody
|
|
|
+ public String upload(MesPhoto mesPhoto) {
|
|
|
+ if (mesPhoto == null) {
|
|
|
+ return renderResult(Global.FALSE, text("参数不能为空!"));
|
|
|
+ }
|
|
|
+ if (mesPhoto.getCreateDate() == null) {
|
|
|
+ return renderResult(Global.FALSE, text("创建时间不能为空!"));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ mesPhoto.setIsNewRecord(true);
|
|
|
+ mesPhoto.setId(null);
|
|
|
+ mesPhotoService.save(mesPhoto);
|
|
|
+ return renderResult(Global.TRUE, text("保存成功!"), mesPhoto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("照片上传保存失败", e);
|
|
|
+ return renderResult(Global.FALSE, text("保存失败!"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按年、月筛选创建时间匹配的照片并返回图片列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesPhoto:view")
|
|
|
+ @RequestMapping(value = "listByMonth")
|
|
|
+ @ResponseBody
|
|
|
+ public List<Map<String, Object>> listByMonth(Integer year, Integer month, HttpServletRequest request) {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ if (year == null || month == null || month < 1 || month > 12) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.clear();
|
|
|
+ cal.set(year, month - 1, 1, 0, 0, 0);
|
|
|
+ Date start = cal.getTime();
|
|
|
+ cal.add(Calendar.MONTH, 1);
|
|
|
+ cal.add(Calendar.SECOND, -1);
|
|
|
+ Date end = cal.getTime();
|
|
|
+
|
|
|
+ MesPhoto query = new MesPhoto();
|
|
|
+ query.getSqlMap().getWhere()
|
|
|
+ .and("a.create_date", QueryType.GTE, start)
|
|
|
+ .and("a.create_date", QueryType.LTE, end);
|
|
|
+ List<MesPhoto> photoList = mesPhotoService.findList(query);
|
|
|
+ if (ListUtils.isEmpty(photoList)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/js";
|
|
|
+ for (MesPhoto photo : photoList) {
|
|
|
+ FileUpload fu = new FileUpload();
|
|
|
+ fu.setBizKey(photo.getId());
|
|
|
+ fu.setBizType("mesPhoto_image");
|
|
|
+ List<FileUpload> files = fileUploadService.findList(fu);
|
|
|
+ if (ListUtils.isEmpty(files)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String createDateText = photo.getCreateDate() == null
|
|
|
+ ? ""
|
|
|
+ : DateUtils.formatDate(photo.getCreateDate(), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (FileUpload fi : files) {
|
|
|
+ Map<String, Object> map = MapUtils.newHashMap();
|
|
|
+ map.put("photoId", photo.getId());
|
|
|
+ map.put("createDate", createDateText);
|
|
|
+ map.put("name", fi.getFileName());
|
|
|
+ map.put("url", host + fi.getFileUrl());
|
|
|
+ if (fi.getFileEntity() != null) {
|
|
|
+ map.put("id", fi.getFileEntity().getFileId());
|
|
|
+ map.put("size", fi.getFileEntity().getFileSize());
|
|
|
+ }
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|