Browse Source

优化 计划初始化 区域提报

dev
xiaoyu 1 month ago
parent
commit
17954f3cca
  1. 22
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/gss/ReportInitializeController.java
  2. 45
      ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/ReportInitializeServiceImpl.java
  3. 37
      ruoyi-system/src/main/resources/mapper/system/SalesAreaReportMapper.xml

22
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gss/ReportInitializeController.java

@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -16,6 +17,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
// 修改服务接口的导入路径 // 修改服务接口的导入路径
import com.ruoyi.web.service.IReportInitializeService; import com.ruoyi.web.service.IReportInitializeService;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
@RestController @RestController
@RequestMapping("/gss/initialize") @RequestMapping("/gss/initialize")
public class ReportInitializeController extends BaseController { public class ReportInitializeController extends BaseController {
@ -40,16 +43,13 @@ public class ReportInitializeController extends BaseController {
} }
@PostMapping("/execute") @PostMapping("/execute")
@PreAuthorize("@ss.hasPermi('gss:initialize:add')") public AjaxResult execute(@RequestBody Map<String, String> params) {
public AjaxResult execute(@RequestParam String year, String year = params.get("year");
@RequestParam String week, String week = params.get("week");
@RequestParam String productCategory, String productCategory = params.get("productCategory");
@RequestParam String salesAreaCode) { String salesAreaCode = params.get("salesAreaCode");
try {
reportInitializeService.execute(year, week, productCategory, salesAreaCode); reportInitializeService.execute(year, week, productCategory, salesAreaCode);
return AjaxResult.success("初始化成功"); return AjaxResult.success();
} catch (Exception e) {
return AjaxResult.error("初始化失败:" + e.getMessage());
}
} }
} }

45
ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/ReportInitializeServiceImpl.java

@ -2,35 +2,68 @@ package com.ruoyi.web.service.impl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SalesAreaReportMapper; // 修改引用路径 import com.ruoyi.system.mapper.SalesAreaReportMapper;
import com.ruoyi.system.domain.SalesAreaReport; // 修改引用路径 import com.ruoyi.system.domain.SalesAreaReport;
import com.ruoyi.web.service.IReportInitializeService; import com.ruoyi.web.service.IReportInitializeService;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SalesRegion;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.ruoyi.system.mapper.SalesRegionMapper;
import java.util.Calendar;
@Service @Service
public class ReportInitializeServiceImpl implements IReportInitializeService { public class ReportInitializeServiceImpl implements IReportInitializeService {
@Autowired @Autowired
private SalesAreaReportMapper salesAreaReportMapper; // 修改变量名 private SalesAreaReportMapper salesAreaReportMapper;
@Autowired
private SalesRegionMapper salesRegionMapper; // 添加销售区域Mapper注入
@Override @Override
public void execute(String year, String week, String productCategory, String salesAreaCode) { public void execute(String year, String week, String productCategory, String salesAreaCode) {
if (salesAreaReportMapper.checkExists(year, week, productCategory, salesAreaCode) > 0) { if ("all".equals(salesAreaCode)) {
return; // 获取所有启用的销售区域
SalesRegion query = new SalesRegion();
query.setStatus("0"); // 只查询启用的销售区域
List<SalesRegion> regions = salesRegionMapper.selectSalesRegionList(query);
for (SalesRegion region : regions) {
createReport(year, week, productCategory, region.getRegionId().toString(), region.getRegionName());
}
} else {
SalesRegion region = salesRegionMapper.selectSalesRegionById(Long.valueOf(salesAreaCode));
if (region != null) {
createReport(year, week, productCategory, salesAreaCode, region.getRegionName());
}
} }
}
private void createReport(String year, String week, String productCategory, String salesAreaCode, String salesAreaName) {
SalesAreaReport report = new SalesAreaReport(); SalesAreaReport report = new SalesAreaReport();
// 根据年份和周次设置报告时间
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, Integer.parseInt(year));
calendar.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(week));
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
report.setReportTime(calendar.getTime());
if (salesAreaReportMapper.checkExists(year,week,productCategory,salesAreaCode) > 0) {
return;
}
report.setProductCategory(productCategory); report.setProductCategory(productCategory);
report.setProductCategoryName("商显"); report.setProductCategoryName("商显");
report.setSalesAreaCode(salesAreaCode); report.setSalesAreaCode(salesAreaCode);
report.setSalesAreaName("全部".equals(salesAreaCode) ? "全部" : "待完善"); report.setSalesAreaName(salesAreaName);
report.setManagerId(SecurityUtils.getUserId()); report.setManagerId(SecurityUtils.getUserId());
report.setManagerName(SecurityUtils.getUsername()); report.setManagerName(SecurityUtils.getUsername());
report.setReportStatus("0"); report.setReportStatus("0");
report.setCreateBy(SecurityUtils.getUsername()); report.setCreateBy(SecurityUtils.getUsername());
report.setCreateTime(new Date()); report.setCreateTime(new Date());
salesAreaReportMapper.insertSalesAreaReport(report); salesAreaReportMapper.insertSalesAreaReport(report);
} }
} }

37
ruoyi-system/src/main/resources/mapper/system/SalesAreaReportMapper.xml

@ -47,6 +47,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where report_id = #{reportId} where report_id = #{reportId}
</select> </select>
<!-- 在 updateSalesAreaReport 方法前添加 -->
<insert id="insertSalesAreaReport" parameterType="com.ruoyi.system.domain.SalesAreaReport">
insert into sales_area_report (
product_category,
product_category_name,
sales_area_code,
sales_area_name,
manager_id,
manager_name,
report_status,
report_time,
create_by,
create_time
) values (
#{productCategory},
#{productCategoryName},
#{salesAreaCode},
#{salesAreaName},
#{managerId},
#{managerName},
#{reportStatus},
#{reportTime},
#{createBy},
#{createTime}
)
</insert>
<!-- 在 selectSalesAreaReportList 方法前添加 -->
<select id="checkExists" resultType="Integer">
select count(1)
from sales_area_report
where DATE_FORMAT(report_time, '%Y') = #{year}
and WEEK(report_time) = #{week}
and product_category = #{productCategory}
and sales_area_code = #{salesAreaCode}
</select>
<update id="updateSalesAreaReport" parameterType="SalesAreaReport"> <update id="updateSalesAreaReport" parameterType="SalesAreaReport">
update sales_area_report update sales_area_report
<set> <set>

Loading…
Cancel
Save