|
@@ -0,0 +1,144 @@
|
|
|
+package cn.ezhizao.project.business.conversion.controller;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.*;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import cn.ezhizao.common.utils.poi.ExcelUtil;
|
|
|
+import cn.ezhizao.framework.aspectj.lang.annotation.Log;
|
|
|
+import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
|
|
|
+import cn.ezhizao.framework.web.controller.BaseController;
|
|
|
+import cn.ezhizao.framework.web.domain.AjaxResult;
|
|
|
+import cn.ezhizao.framework.web.page.TableDataInfo;
|
|
|
+import cn.ezhizao.project.business.conversion.domain.BizProductDrawingConversion;
|
|
|
+import cn.ezhizao.project.business.conversion.service.IBizProductDrawingConversionService;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 产品电子化率记录Controller
|
|
|
+ *
|
|
|
+ * @author ezhizao
|
|
|
+ * @date 2024-07-16
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/business/conversion")
|
|
|
+public class BizProductDrawingConversionController extends BaseController
|
|
|
+{
|
|
|
+ @Resource
|
|
|
+ private IBizProductDrawingConversionService bizProductDrawingConversionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询产品电子化率记录列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public AjaxResult list(BizProductDrawingConversion bizProductDrawingConversion) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ if (bizProductDrawingConversion.getYear()!=null ){
|
|
|
+ int year = Integer.parseInt(bizProductDrawingConversion.getYear());
|
|
|
+ // 将 LocalDate 转换为 Date
|
|
|
+ LocalDate startLocalDate = YearMonth.of(year, 1).atDay(1);
|
|
|
+ LocalDate endLocalDate = YearMonth.of(year, 12).atEndOfMonth();
|
|
|
+
|
|
|
+ // 使用 atStartOfDay 将 LocalDate 转换为 Date
|
|
|
+ Date startTime = Date.from(startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date endTime = Date.from(endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ bizProductDrawingConversion.setStartTime(startTime);
|
|
|
+ bizProductDrawingConversion.setEndTime(endTime);
|
|
|
+ }
|
|
|
+ List<BizProductDrawingConversion> list = bizProductDrawingConversionService.getList(bizProductDrawingConversion);
|
|
|
+
|
|
|
+ List<BizProductDrawingConversion> bizProductDrawingConversions = filterByMonth(list);
|
|
|
+ return success(bizProductDrawingConversions);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<BizProductDrawingConversion> filterByMonth(List<BizProductDrawingConversion> list) {
|
|
|
+ Map<Integer, BizProductDrawingConversion> latestRecords = new HashMap<>();
|
|
|
+
|
|
|
+ for (BizProductDrawingConversion record : list) {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(record.getDate());
|
|
|
+ int month = cal.get(Calendar.MONTH) + 1; // Calendar.MONTH 是从0开始的,所以需要+1
|
|
|
+ int year = cal.get(Calendar.YEAR);
|
|
|
+
|
|
|
+ // 将月份和年份组合成一个唯一的键
|
|
|
+ int key = (year * 100) + month;
|
|
|
+
|
|
|
+ if (!latestRecords.containsKey(key) || record.getDate().after(latestRecords.get(key).getDate())) {
|
|
|
+ latestRecords.put(key, record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将 Map 转换为 List 返回
|
|
|
+ return new ArrayList<>(latestRecords.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出产品电子化率记录列表
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:conversion:export')")
|
|
|
+ @Log(title = "产品电子化率记录", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/export")
|
|
|
+ public void export(HttpServletResponse response, BizProductDrawingConversion bizProductDrawingConversion) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ setTenantId(bizProductDrawingConversion);
|
|
|
+ List<BizProductDrawingConversion> list = bizProductDrawingConversionService.getList(bizProductDrawingConversion);
|
|
|
+ ExcelUtil<BizProductDrawingConversion> util = new ExcelUtil<BizProductDrawingConversion>(BizProductDrawingConversion.class);
|
|
|
+ util.exportExcel(response, list, "产品电子化率记录数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取产品电子化率记录详细信息
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:conversion:query')")
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
+ {
|
|
|
+ return success(bizProductDrawingConversionService.getById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增产品电子化率记录
|
|
|
+ */
|
|
|
+ @Log(title = "产品电子化率记录", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ public AjaxResult add(@RequestBody BizProductDrawingConversion bizProductDrawingConversion) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ bizProductDrawingConversion.setDate(new Date());
|
|
|
+ return toAjax(bizProductDrawingConversionService.save(bizProductDrawingConversion));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改产品电子化率记录
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:conversion:edit')")
|
|
|
+ @Log(title = "产品电子化率记录", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult edit(@RequestBody BizProductDrawingConversion bizProductDrawingConversion) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ setTenantId(bizProductDrawingConversion);
|
|
|
+ return toAjax(bizProductDrawingConversionService.updateById(bizProductDrawingConversion));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除产品电子化率记录
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('business:conversion:remove')")
|
|
|
+ @Log(title = "产品电子化率记录", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable List<Long> ids)
|
|
|
+ {
|
|
|
+ return toAjax(bizProductDrawingConversionService.removeBatchByIds(ids));
|
|
|
+ }
|
|
|
+}
|