1、新增农场合约天数字段,激活方式字段改名,由_Mode改为_Way。

2、调通农场合约的新增、修改和天数计算。
3、引入junit-jupiter-5.7.2,编写天数计算的测试用例。
This commit is contained in:
jlt 2022-04-04 00:59:51 +08:00
parent c42bd7f22b
commit d0b70c1c40
8 changed files with 180 additions and 70 deletions

View File

@ -36,6 +36,7 @@
<qiniu.version>7.9.0</qiniu.version>
<gson.version>2.8.5</gson.version>
<tlog.version>1.3.6</tlog.version>
<junit-jupiter.version>5.7.2</junit-jupiter.version>
</properties>
<!-- 依赖声明 -->
@ -227,6 +228,13 @@
<version>${tlog.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -32,6 +32,11 @@
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -77,6 +77,7 @@ public class FarmerContractController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody FarmerContract farmerContract)
{
farmerContract.setCreateBy(getUsername());
return toAjax(farmerContractService.insertFarmerContract(farmerContract));
}
@ -88,6 +89,7 @@ public class FarmerContractController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody FarmerContract farmerContract)
{
farmerContract.setUpdateBy(getUsername());
return toAjax(farmerContractService.updateFarmerContract(farmerContract));
}

View File

@ -1,7 +1,16 @@
package com.jlt.csa.domain;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.TimeZone;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -37,8 +46,8 @@ public class FarmerContract extends BaseEntity
@Excel(name = "合约账户金额")
private BigDecimal balance;
/** 合约重量 */
@Excel(name = "合约重量")
/** 合约斤数 */
@Excel(name = "合约斤数")
private BigDecimal weight;
/** 合约拱棚年限 */
@ -47,15 +56,15 @@ public class FarmerContract extends BaseEntity
/** 激活方式 */
@Excel(name = "激活方式")
private String activateMode;
private String activateWay;
/** 加入凭据号码 */
@Excel(name = "加入凭据号码")
private String joinCredentialNo;
/** 加入日期 */
/** 生效日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "加入日期", width = 30, dateFormat = "yyyy-MM-dd")
@Excel(name = "生效日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date joinDate;
/** 到期日期 */
@ -63,6 +72,10 @@ public class FarmerContract extends BaseEntity
@Excel(name = "到期日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date dueDate;
/** 合约天数 */
@Excel(name = "合约天数")
private Long days;
/** 状态0正常 1停用 */
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private String status;
@ -70,6 +83,29 @@ public class FarmerContract extends BaseEntity
/** 删除标志0代表存在 2代表删除 */
private String delFlag;
/**
* 根据生效日期到期天数计算天数包含起止日即两者相加+1
* @return
*/
public Long countDays() {
if (joinDate == null) {
throw new RuntimeException("缺少生效日期!");
}
if (dueDate == null) {
throw new RuntimeException("缺少终止日期!");
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate = LocalDate.parse(simpleDateFormat.format(joinDate), dateTimeFormatter);
LocalDate endDate = LocalDate.parse(simpleDateFormat.format(dueDate), dateTimeFormatter);
this.days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
return this.days;
}
public void setContractId(Long contractId)
{
this.contractId = contractId;
@ -133,14 +169,14 @@ public class FarmerContract extends BaseEntity
{
return archedYears;
}
public void setActivateMode(String activateMode)
public void setActivateWay(String activateWay)
{
this.activateMode = activateMode;
this.activateWay = activateWay;
}
public String getActivateMode()
public String getActivateWay()
{
return activateMode;
return activateWay;
}
public void setJoinCredentialNo(String joinCredentialNo)
{
@ -174,7 +210,15 @@ public class FarmerContract extends BaseEntity
this.status = status;
}
public String getStatus()
public Long getDays() {
return days;
}
public void setDays(Long days) {
this.days = days;
}
public String getStatus()
{
return status;
}
@ -198,7 +242,7 @@ public class FarmerContract extends BaseEntity
.append("balance", getBalance())
.append("weight", getWeight())
.append("archedYears", getArchedYears())
.append("activateMode", getActivateMode())
.append("activateMode", getActivateWay())
.append("joinCredentialNo", getJoinCredentialNo())
.append("joinDate", getJoinDate())
.append("dueDate", getDueDate())

View File

@ -53,6 +53,7 @@ public class FarmerContractServiceImpl implements IFarmerContractService
@Override
public int insertFarmerContract(FarmerContract farmerContract)
{
farmerContract.countDays();
farmerContract.setCreateTime(DateUtils.getNowDate());
return farmerContractMapper.insertFarmerContract(farmerContract);
}
@ -66,6 +67,7 @@ public class FarmerContractServiceImpl implements IFarmerContractService
@Override
public int updateFarmerContract(FarmerContract farmerContract)
{
farmerContract.countDays();
farmerContract.setUpdateTime(DateUtils.getNowDate());
return farmerContractMapper.updateFarmerContract(farmerContract);
}

View File

@ -12,10 +12,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="balance" column="balance" />
<result property="weight" column="weight" />
<result property="archedYears" column="arched_years" />
<result property="activateMode" column="activate_mode" />
<result property="activateWay" column="activate_way" />
<result property="joinCredentialNo" column="join_credential_no" />
<result property="joinDate" column="join_date" />
<result property="dueDate" column="due_date" />
<result property="days" column="days" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
@ -26,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectFarmerContractVo">
select contract_id, farmer_id, member_name, coins, balance, weight, arched_years, activate_mode, join_credential_no, join_date, due_date, status, del_flag, create_by, create_time, update_by, update_time, remark from csa_farmer_contract
select contract_id, farmer_id, member_name, coins, balance, weight, arched_years, activate_way, join_credential_no, join_date, due_date, days, status, del_flag, create_by, create_time, update_by, update_time, remark from csa_farmer_contract
</sql>
<select id="selectFarmerContractList" parameterType="FarmerContract" resultMap="FarmerContractResult">
@ -53,10 +54,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="balance != null">balance,</if>
<if test="weight != null">weight,</if>
<if test="archedYears != null">arched_years,</if>
<if test="activateMode != null and activateMode != ''">activate_mode,</if>
<if test="activateWay != null and activateWay != ''">activate_way,</if>
<if test="joinCredentialNo != null and joinCredentialNo != ''">join_credential_no,</if>
<if test="joinDate != null">join_date,</if>
<if test="dueDate != null">due_date,</if>
<if test="days != null">days,</if>
<if test="status != null">status,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
@ -72,10 +74,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="balance != null">#{balance},</if>
<if test="weight != null">#{weight},</if>
<if test="archedYears != null">#{archedYears},</if>
<if test="activateMode != null and activateMode != ''">#{activateMode},</if>
<if test="activateWay != null and activateWay != ''">#{activateWay},</if>
<if test="joinCredentialNo != null and joinCredentialNo != ''">#{joinCredentialNo},</if>
<if test="joinDate != null">#{joinDate},</if>
<if test="dueDate != null">#{dueDate},</if>
<if test="days != null">#{days},</if>
<if test="status != null">#{status},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
@ -95,10 +98,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="balance != null">balance = #{balance},</if>
<if test="weight != null">weight = #{weight},</if>
<if test="archedYears != null">arched_years = #{archedYears},</if>
<if test="activateMode != null and activateMode != ''">activate_mode = #{activateMode},</if>
<if test="activateWay != null and activateWay != ''">activate_way = #{activateWay},</if>
<if test="joinCredentialNo != null and joinCredentialNo != ''">join_credential_no = #{joinCredentialNo},</if>
<if test="joinDate != null">join_date = #{joinDate},</if>
<if test="dueDate != null">due_date = #{dueDate},</if>
<if test="days != null">days = #{days},</if>
<if test="status != null">status = #{status},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>

View File

@ -0,0 +1,27 @@
package com.jlt.csa.domain;
import org.junit.jupiter.api.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
* 农场合约测试类
*/
public class FarmContractTests {
/**
* 计算农场合约根据生效日期终止日期计算天数的方法
* @throws ParseException
*/
@Test
public void testCountDays() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
FarmerContract c = new FarmerContract();
c.setJoinDate(simpleDateFormat.parse("2021-03-01"));
c.setDueDate(simpleDateFormat.parse("2022-03-01"));
Long days = c.countDays();
System.out.println("Days: " + days);
assert 366 == c.countDays();
}
}

View File

@ -84,22 +84,23 @@
<el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="姓名" align="center" prop="memberName"/>
<el-table-column label="金币" align="center" prop="coins"/>
<el-table-column label="账户金额" align="center" prop="balance"/>
<el-table-column label="菜品重量" align="center" prop="weight"/>
<el-table-column label="拱棚年限" align="center" prop="archedYears"/>
<el-table-column label="激活方式" align="center" prop="activateMode"/>
<el-table-column label="凭据号码" align="center" prop="joinCredentialNo"/>
<el-table-column label="签约日期" align="center" prop="joinDate" width="180">
<el-table-column label="金币数量" align="right" prop="coins" width="150"/>
<!-- <el-table-column label="账户金额" align="center" prop="balance"/>-->
<el-table-column label="菜品斤数" align="right" prop="weight" width="120"/>
<el-table-column label="拱棚年限" align="center" prop="archedYears"/>
<el-table-column label="激活方式" align="center" prop="activateWay"/>
<el-table-column label="生效日期" align="center" prop="joinDate" width="120">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.joinDate, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="到期日期" align="center" prop="dueDate" width="180">
<el-table-column label="到期日期" align="center" prop="dueDate" width="120">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.dueDate, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="天数" align="right" prop="days" width="80" />
<el-table-column label="状态" align="center" prop="status"/>
<el-table-column label="备注" align="center" prop="remark"/>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@ -133,56 +134,34 @@
/>
<!-- 添加或修改会员签约对话框 -->
<el-dialog :title="title" :visible.sync="open" width="660px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-row :gutter="20">
<el-dialog :title="title" :visible.sync="open" width="650px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="90px">
<el-row>
<el-col :span="12">
<el-form-item label="姓名" prop="memberName">
<el-input v-model="form.memberName" placeholder="请输入姓名"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="激活方式" prop="activateMode">
<el-input v-model="form.activateMode" placeholder="请选择激活方式"/>
<el-form-item label="激活方式" prop="activateWay">
<el-select disabled v-model="form.activateWay" placeholder="请选择激活方式">
<el-option
v-for="dict in dict.type.csa_activation_way"
:key="dict.value"
:label="dict.label"
:value="dict.value" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="凭据号码" prop="joinCredentialNo">
<el-input v-model="form.joinCredentialNo" placeholder="请输入签约凭据号码"/>
</el-form-item>
<el-row :gutter="20">
<el-row>
<el-col :span="12">
<el-form-item label="金币数量" prop="coins">
<el-input v-model="form.coins" placeholder="请输入金币"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="账户金额" prop="balance">
<el-input v-model="form.balance" placeholder="请输入账户金额"/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="菜品重量" prop="weight">
<el-input v-model="form.weight" placeholder="请输入菜品重量"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="拱棚年限" prop="archedYears">
<el-input v-model="form.archedYears" placeholder="请输入拱棚年限"/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="开始日期" prop="joinDate">
<el-form-item label="生效日期" prop="joinDate">
<el-date-picker clearable
v-model="form.joinDate"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择开始日期">
placeholder="请选择生效日期">
</el-date-picker>
</el-form-item>
</el-col>
@ -197,6 +176,41 @@
</el-form-item>
</el-col>
</el-row>
<el-form-item label="凭据号码" prop="joinCredentialNo">
<el-input v-model="form.joinCredentialNo" placeholder="请输入签约凭据编号,如合同编号、收据编号等"/>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="金币数量" prop="coins">
<el-input v-model="form.coins" placeholder="请输入金币">
<template slot="append"></template>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="账户金额" prop="balance">
<el-input disabled v-model="form.balance" placeholder="请输入账户金额">
<template slot="append"></template>
</el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="菜品重量" prop="weight">
<el-input v-model="form.weight" placeholder="请输入菜品重量">
<template slot="append"></template>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="拱棚年限" prop="archedYears">
<el-input v-model="form.archedYears" placeholder="请输入拱棚年限">
<template slot="append"></template>
</el-input>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注"/>
</el-form-item>
@ -214,6 +228,7 @@
export default {
name: 'Contract',
dicts: ['csa_activation_way'],
data() {
return {
//
@ -250,21 +265,24 @@
memberName: [
{ required: true, message: '姓名不能为空', trigger: 'blur' }
],
joinDate: [
{ required: true, message: '生效日期必选', trigger: 'blur' }
],
dueDate: [
{ required: true, message: '到期日期必选', trigger: 'blur' }
],
coins: [
{ required: true, message: '金币数量不能为空', trigger: 'blur' }
],
balance: [
{ required: true, message: '账户金额不能为空', trigger: 'blur' }
],
// balance: [
// { required: true, message: '', trigger: 'blur' }
// ],
weight: [
{ required: true, message: '菜品重量不能为空', trigger: 'blur' }
],
archedYears: [
{ required: true, message: '拱棚年限不能为空', trigger: 'blur' }
],
activateMode: [
{ required: true, message: '激活方式不能为空', trigger: 'blur' }
],
joinCredentialNo: [
{ required: true, message: '凭据号码不能为空', trigger: 'blur' }
]
@ -295,11 +313,11 @@
contractId: null,
farmerId: null,
memberName: null,
coins: null,
balance: null,
weight: null,
archedYears: null,
activateMode: null,
coins: 0,
balance: 0,
weight: 0,
archedYears: 0,
activateWay: "QY",
joinCredentialNo: null,
joinDate: null,
dueDate: null,