zhaocaiapi提交
This commit is contained in:
@@ -48,6 +48,10 @@
|
||||
<artifactId>blade-core-auto</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-tool</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+24
-8
@@ -37,33 +37,49 @@ import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.tenant.annotation.NonDS;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.zhaocai.pojo.entity.ProcurementPlan;
|
||||
import org.springblade.zhaocai.pojo.vo.ProcurementPlanVO;
|
||||
import org.springblade.zhaocai.service.IBillCodeService;
|
||||
import org.springblade.zhaocai.service.IProcurementPlanService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 招采计划控制器
|
||||
* 年度招采计划控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@NonDS
|
||||
@RestController
|
||||
@RequestMapping("procurement-plan")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "招采计划", description = "招采计划接口")
|
||||
@PreAuth(menu = "procurement-plan")
|
||||
@Tag(name = "年度招采计划", description = "年度招采计划接口")
|
||||
public class ProcurementPlanController extends BladeController {
|
||||
|
||||
private final IProcurementPlanService procurementPlanService;
|
||||
private final IBillCodeService billCodeService;
|
||||
|
||||
/**
|
||||
* 生成单据号
|
||||
*/
|
||||
@GetMapping("/bill-no")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "生成单据号", description = "生成唯一单据号")
|
||||
public R<String> generateBillNo() {
|
||||
return R.data(billCodeService.generateBillCode("PROCUREMENT_PLAN"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情(含明细)
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "详情", description = "传入id")
|
||||
public R<ProcurementPlanVO> detail(@Parameter(name = "id", description = "主键", in = ParameterIn.QUERY, schema = @Schema(type = "integer")) @RequestParam Long id) {
|
||||
ProcurementPlanVO detail = procurementPlanService.detail(id);
|
||||
@@ -79,7 +95,7 @@ public class ProcurementPlanController extends BladeController {
|
||||
@Parameter(name = "billNo", description = "单据号", in = ParameterIn.QUERY, schema = @Schema(type = "string")),
|
||||
@Parameter(name = "year", description = "年度", in = ParameterIn.QUERY, schema = @Schema(type = "string"))
|
||||
})
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "分页", description = "传入procurementPlan")
|
||||
public R<IPage<ProcurementPlan>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> procurementPlan, Query query) {
|
||||
IPage<ProcurementPlan> pages = procurementPlanService.page(Condition.getPage(query), Condition.getQueryWrapper(procurementPlan, ProcurementPlan.class));
|
||||
@@ -90,7 +106,7 @@ public class ProcurementPlanController extends BladeController {
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增", description = "传入procurementPlan")
|
||||
public R save(@RequestBody ProcurementPlanVO procurementPlanVO) {
|
||||
return R.status(procurementPlanService.submit(procurementPlanVO));
|
||||
@@ -100,7 +116,7 @@ public class ProcurementPlanController extends BladeController {
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "修改", description = "传入procurementPlan")
|
||||
public R update(@RequestBody ProcurementPlanVO procurementPlanVO) {
|
||||
return R.status(procurementPlanService.submit(procurementPlanVO));
|
||||
@@ -110,7 +126,7 @@ public class ProcurementPlanController extends BladeController {
|
||||
* 新增或修改
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "新增或修改", description = "传入procurementPlan")
|
||||
public R submit(@RequestBody ProcurementPlanVO procurementPlanVO) {
|
||||
return R.status(procurementPlanService.submit(procurementPlanVO));
|
||||
@@ -120,7 +136,7 @@ public class ProcurementPlanController extends BladeController {
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||
public R remove(@Parameter(name = "ids", description = "主键集合", in = ParameterIn.QUERY, schema = @Schema(type = "string")) @RequestParam String ids) {
|
||||
boolean temp = procurementPlanService.deleteLogic(Func.toLongList(ids));
|
||||
|
||||
+12
-6
@@ -14,15 +14,20 @@
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="plan_id" property="planId"/>
|
||||
<result column="year" property="year"/>
|
||||
<result column="plan" property="plan"/>
|
||||
<result column="plan_type" property="planType"/>
|
||||
<result column="plan_no" property="planNo"/>
|
||||
<result column="sort_no" property="sortNo"/>
|
||||
<result column="project_name" property="projectName"/>
|
||||
<result column="project_type" property="projectType"/>
|
||||
<result column="contact_person" property="contactPerson"/>
|
||||
<result column="contact_person_id" property="contactPersonId"/>
|
||||
<result column="apply_date" property="applyDate"/>
|
||||
<result column="expect_date" property="expectDate"/>
|
||||
<result column="project_attr" property="projectAttr"/>
|
||||
<result column="purchase_requirement" property="purchaseRequirement"/>
|
||||
<result column="budget_amount" property="budgetAmount"/>
|
||||
<result column="bidding_method" property="biddingMethod"/>
|
||||
<result column="project_intro" property="projectIntro"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<result column="material_detail" property="materialDetail"/>
|
||||
</resultMap>
|
||||
|
||||
@@ -30,20 +35,21 @@
|
||||
<sql id="baseColumnList">
|
||||
select
|
||||
id, tenant_id, create_user, create_time, update_user, update_time, status, is_deleted,
|
||||
plan_id, year, plan, plan_type, sort_no, project_name, project_type, contact_person,
|
||||
apply_date, expect_date, project_attr, material_detail
|
||||
plan_id, year, plan_no, sort_no, project_name, project_type, contact_person, contact_person_id,
|
||||
apply_date, expect_date, project_attr, purchase_requirement, budget_amount, bidding_method,
|
||||
project_intro, remark, material_detail
|
||||
</sql>
|
||||
|
||||
<select id="selectByPlanId" resultMap="procurementPlanDetailResultMap">
|
||||
<include refid="baseColumnList"/>
|
||||
from blade_procurement_plan_detail
|
||||
from zc_procurement_plan_project
|
||||
where plan_id = #{planId}
|
||||
and is_deleted = 0
|
||||
order by sort_no asc
|
||||
</select>
|
||||
|
||||
<delete id="deleteByPlanId">
|
||||
delete from blade_procurement_plan_detail where plan_id = #{planId}
|
||||
delete from zc_procurement_plan_project where plan_id = #{planId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
+5
-2
@@ -24,18 +24,21 @@
|
||||
<result column="estimated_amount" property="estimatedAmount"/>
|
||||
<result column="amount_upper" property="amountUpper"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<result column="flow_status" property="flowStatus"/>
|
||||
<result column="process_instance_id" property="processInstanceId"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="baseColumnList">
|
||||
select
|
||||
id, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted,
|
||||
applicant, apply_time, phone, company, bill_no, year, dept, apply_company, estimated_amount, amount_upper, remark
|
||||
applicant, apply_time, phone, company, bill_no, year, dept, apply_company, estimated_amount, amount_upper,
|
||||
remark, flow_status, process_instance_id
|
||||
</sql>
|
||||
|
||||
<select id="selectProcurementPlanPage" resultMap="procurementPlanResultMap">
|
||||
<include refid="baseColumnList"/>
|
||||
from blade_procurement_plan
|
||||
from zc_procurement_plan
|
||||
where is_deleted = 0
|
||||
<if test="procurementPlan.applicant != null and procurementPlan.applicant != ''">
|
||||
and applicant like concat('%', #{procurementPlan.applicant}, '%')
|
||||
|
||||
+156
-10
@@ -32,17 +32,25 @@ import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.zhaocai.mapper.ProcurementPlanMapper;
|
||||
import org.springblade.zhaocai.pojo.entity.ProcurementPlan;
|
||||
import org.springblade.zhaocai.pojo.entity.ProcurementPlanDetail;
|
||||
import org.springblade.zhaocai.pojo.entity.ProcurementPlanMaterial;
|
||||
import org.springblade.zhaocai.pojo.vo.ProcurementPlanDetailVO;
|
||||
import org.springblade.zhaocai.pojo.vo.ProcurementPlanMaterialVO;
|
||||
import org.springblade.zhaocai.pojo.vo.ProcurementPlanVO;
|
||||
import org.springblade.zhaocai.service.IBillCodeService;
|
||||
import org.springblade.zhaocai.service.IProcurementPlanDetailService;
|
||||
import org.springblade.zhaocai.service.IProcurementPlanMaterialService;
|
||||
import org.springblade.zhaocai.service.IProcurementPlanService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 招采计划服务实现类
|
||||
* 年度招采计划服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -51,6 +59,8 @@ import java.util.List;
|
||||
public class ProcurementPlanServiceImpl extends BaseServiceImpl<ProcurementPlanMapper, ProcurementPlan> implements IProcurementPlanService {
|
||||
|
||||
private final IProcurementPlanDetailService procurementPlanDetailService;
|
||||
private final IProcurementPlanMaterialService procurementPlanMaterialService;
|
||||
private final IBillCodeService billCodeService;
|
||||
|
||||
@Override
|
||||
public IPage<ProcurementPlan> selectProcurementPlanPage(IPage<ProcurementPlan> page, ProcurementPlan procurementPlan) {
|
||||
@@ -69,34 +79,170 @@ public class ProcurementPlanServiceImpl extends BaseServiceImpl<ProcurementPlanM
|
||||
vo.setDetailList(detailList.stream().map(detail -> {
|
||||
ProcurementPlanDetailVO detailVO = new ProcurementPlanDetailVO();
|
||||
Func.copy(detail, detailVO);
|
||||
List<ProcurementPlanMaterial> materialList = procurementPlanMaterialService.listByProjectId(detail.getId());
|
||||
detailVO.setMaterialList(materialList.stream().map(material -> {
|
||||
ProcurementPlanMaterialVO materialVO = new ProcurementPlanMaterialVO();
|
||||
Func.copy(material, materialVO);
|
||||
return materialVO;
|
||||
}).collect(Collectors.toList()));
|
||||
return detailVO;
|
||||
}).toList());
|
||||
}).collect(Collectors.toList()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean submit(ProcurementPlanVO procurementPlanVO) {
|
||||
// 新建时生成单据号
|
||||
if (procurementPlanVO.getId() == null && !StringUtils.hasText(procurementPlanVO.getBillNo())) {
|
||||
String billNo = billCodeService.generateBillCode("PROCUREMENT_PLAN");
|
||||
procurementPlanVO.setBillNo(billNo);
|
||||
}
|
||||
|
||||
// 自动计算项目属性、招标方式、主表金额
|
||||
this.calculateDetail(procurementPlanVO);
|
||||
|
||||
// 保存主表
|
||||
boolean result = saveOrUpdate(procurementPlanVO);
|
||||
Long planId = procurementPlanVO.getId();
|
||||
// 删除旧明细
|
||||
|
||||
// 删除旧项目明细和物料明细
|
||||
procurementPlanDetailService.removeByPlanId(planId);
|
||||
// 保存新明细
|
||||
procurementPlanMaterialService.removeByPlanId(planId);
|
||||
|
||||
// 保存项目明细及物料明细
|
||||
List<ProcurementPlanDetailVO> detailVOList = procurementPlanVO.getDetailList();
|
||||
if (Func.isNotEmpty(detailVOList)) {
|
||||
List<ProcurementPlanDetail> detailList = detailVOList.stream().map(detailVO -> {
|
||||
for (int i = 0; i < detailVOList.size(); i++) {
|
||||
ProcurementPlanDetailVO detailVO = detailVOList.get(i);
|
||||
ProcurementPlanDetail detail = new ProcurementPlanDetail();
|
||||
Func.copy(detailVO, detail);
|
||||
detail.setPlanId(planId);
|
||||
return detail;
|
||||
}).toList();
|
||||
for (int i = 0; i < detailList.size(); i++) {
|
||||
detailList.get(i).setSortNo(i + 1);
|
||||
detail.setSortNo(i + 1);
|
||||
procurementPlanDetailService.save(detail);
|
||||
Long detailId = detail.getId();
|
||||
|
||||
// 保存物料明细
|
||||
List<ProcurementPlanMaterialVO> materialVOList = detailVO.getMaterialList();
|
||||
if (Func.isNotEmpty(materialVOList)) {
|
||||
List<ProcurementPlanMaterial> materialList = new ArrayList<>();
|
||||
for (int j = 0; j < materialVOList.size(); j++) {
|
||||
ProcurementPlanMaterialVO materialVO = materialVOList.get(j);
|
||||
ProcurementPlanMaterial material = new ProcurementPlanMaterial();
|
||||
Func.copy(materialVO, material);
|
||||
material.setPlanId(planId);
|
||||
material.setProjectId(detailId);
|
||||
material.setSortNo(j + 1);
|
||||
materialList.add(material);
|
||||
}
|
||||
procurementPlanMaterialService.saveBatch(materialList);
|
||||
// 冗余汇总
|
||||
detail.setMaterialDetail(buildMaterialSummary(materialList));
|
||||
procurementPlanDetailService.updateById(detail);
|
||||
}
|
||||
}
|
||||
procurementPlanDetailService.saveBatch(detailList);
|
||||
}
|
||||
|
||||
// TODO: 接入 blade-flow 流程引擎
|
||||
// R<BladeFlow> result = flowClient.startProcessInstanceById(
|
||||
// processDefinitionId,
|
||||
// FlowUtil.getBusinessKey("zc_procurement_plan", String.valueOf(planId)),
|
||||
// variables
|
||||
// );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算项目明细的项目属性、招标方式,并汇总主表金额
|
||||
*/
|
||||
private void calculateDetail(ProcurementPlanVO procurementPlanVO) {
|
||||
List<ProcurementPlanDetailVO> detailVOList = procurementPlanVO.getDetailList();
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
if (Func.isNotEmpty(detailVOList)) {
|
||||
for (ProcurementPlanDetailVO detailVO : detailVOList) {
|
||||
String projectType = detailVO.getProjectType();
|
||||
BigDecimal budgetAmount = detailVO.getBudgetAmount() == null ? BigDecimal.ZERO : detailVO.getBudgetAmount();
|
||||
String projectAttr = calculateProjectAttr(projectType, budgetAmount);
|
||||
String biddingMethod = calculateBiddingMethod(projectType, budgetAmount);
|
||||
detailVO.setProjectAttr(projectAttr);
|
||||
detailVO.setBiddingMethod(biddingMethod);
|
||||
totalAmount = totalAmount.add(budgetAmount);
|
||||
}
|
||||
}
|
||||
procurementPlanVO.setEstimatedAmount(totalAmount);
|
||||
procurementPlanVO.setAmountUpper(digitUppercase(totalAmount));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算项目属性
|
||||
*/
|
||||
private String calculateProjectAttr(String projectType, BigDecimal budgetAmount) {
|
||||
boolean isEngineering = "工程类".equals(projectType);
|
||||
if ((isEngineering && budgetAmount.compareTo(new BigDecimal("100")) >= 0)
|
||||
|| (!isEngineering && budgetAmount.compareTo(new BigDecimal("50")) >= 0)) {
|
||||
return "一类项目";
|
||||
}
|
||||
if ((isEngineering && budgetAmount.compareTo(new BigDecimal("50")) >= 0)
|
||||
|| (!isEngineering && budgetAmount.compareTo(new BigDecimal("10")) >= 0)) {
|
||||
return "二类项目";
|
||||
}
|
||||
return "三类项目";
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算招标方式
|
||||
*/
|
||||
private String calculateBiddingMethod(String projectType, BigDecimal budgetAmount) {
|
||||
String projectAttr = calculateProjectAttr(projectType, budgetAmount);
|
||||
if ("一类项目".equals(projectAttr) || "二类项目".equals(projectAttr)) {
|
||||
return "招标";
|
||||
}
|
||||
return "比价";
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建物料明细冗余汇总
|
||||
*/
|
||||
private String buildMaterialSummary(List<ProcurementPlanMaterial> materialList) {
|
||||
return materialList.stream()
|
||||
.map(material -> material.getMaterialName() + " x " + material.getQuantity())
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额大写转换
|
||||
*/
|
||||
private String digitUppercase(BigDecimal amount) {
|
||||
if (amount == null || amount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return "零元整";
|
||||
}
|
||||
String[] fraction = {"角", "分"};
|
||||
String[] digit = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
|
||||
String[][] unit = {{"元", "万", "亿"}, {"", "拾", "佰", "仟"}};
|
||||
double n = amount.doubleValue();
|
||||
String head = n < 0 ? "欠" : "";
|
||||
n = Math.abs(n);
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < fraction.length; i++) {
|
||||
s.append((digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("零.", ""));
|
||||
}
|
||||
if (s.length() == 0) {
|
||||
s.append("整");
|
||||
}
|
||||
n = Math.floor(n);
|
||||
for (int i = 0; i < unit[0].length && n > 0; i++) {
|
||||
StringBuilder p = new StringBuilder();
|
||||
for (int j = 0; j < unit[1].length && n > 0; j++) {
|
||||
p.insert(0, digit[(int) (n % 10)] + unit[1][j]);
|
||||
n = Math.floor(n / 10);
|
||||
}
|
||||
s.insert(0, p.toString().replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i]);
|
||||
}
|
||||
return head + s.toString()
|
||||
.replaceAll("(零.)*零元", "元")
|
||||
.replaceAll("(零.)+", "零")
|
||||
.replaceAll("^整$", "零元整");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ spring:
|
||||
datasource:
|
||||
#主数据源信息
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://172.16.92.89:3306/bladex_zhaocai?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
|
||||
url: jdbc:mysql://localhost:3306/bladex_zhaocai?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: Aa123456
|
||||
#动态数据源信息
|
||||
@@ -23,6 +23,6 @@ spring:
|
||||
#独立校验配置
|
||||
validation-query: select 1
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://172.16.92.89:3306/bladex_zhaocai?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
|
||||
url: jdbc:mysql://localhost:3306/bladex_zhaocai?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: Aa123456
|
||||
|
||||
Reference in New Issue
Block a user