2022
1. 查询页数据是从别的其他两个或两个以上模块推送过来
(方法一)以需要推送的模块作为主数据联查
(方法二)通过推送的模块新增数据到本页面
1.分别再其需要推送的模块相关impl层新增
表结构:关联id(物资盘点id/机械盘点id),类型(机械盘点/.物资盘点)
机械盘点impl层,物资盘点推送数据同机械
//竣工内业管理
if("竣工盘点".equals(pmMechanicalCheck.getCheckType())){ //判断盘点类型为竣工盘点可推
PmBeCompletedManage manage = new PmBeCompletedManage();
manage.setManageId(randomStr(32));
manage.setCheckId(pmMechanicalCheck.getCheckId());
manage.setProjectId(pmMechanicalCheck.getItemCode());
manage.setType("机械盘点");
manage.setCreateTime(DateUtils.getNowDate());
pmBeCompletedManageMapper.insertPmBeCompletedManage(manage);
}
2.编辑页数据来源两个及以上模块
(1)分别再需要推送的模块,机械盘点,物资盘点模块写mapper,然后调查询sql(物资盘点同机械)
机械盘点
/**
* 查询机械设备盘点明细
*
* @param checkId 机械盘点id
* @return
*/
List<PmMechanicalCheckItem> selectByCheckId(String 明细id);
<select id="selectByCheckId" parameterType="String" resultMap="PmMechanicalCheckItemResult">
select
pmc.check_id_item,
pmc.check_id,
pmc.check_num,
pmc.reason,
pmc.create_by,
pmc.update_by,
pmc.create_time,
pmc.update_time,
pmc.del_flag,
pmc.check_type,
pmc.input_item_id,
pmc.mechanical_name,
pmc.mechanical_spec,
pmc.mechanical_model,
pmc.amount,
pmc.item_code,
pmc.item_name,
pmt.tran_apply_id,
pmt.into_project_name,
pmt.into_company_name,
pmm.tran_time,
pmm.tran_people
from
pm_mechanical_check_item pmc
left join pm_mechanical_tran_apply_item pmt on pmt.input_item_id = pmc.input_item_id
left join pm_mechanical_tran_apply pmm on pmm.tran_apply_id = pmt.tran_apply_id
where check_id = #{checkId}
(2)编辑详情查询调mapper
//查询机械盘点,物资盘点明细
if("机械盘点".equals(manage.getType())){
List<PmMechanicalCheckItem> pmMechanicalCheckItems = pmMechanicalCheckItemMapper.selectByCheckId(manage.getCheckId());
manage.setBuildAllotList(pmMechanicalCheckItems);
}else{
List<PmStockInventoryItem> pmStockInventoryItems = pmStockInventoryItemMapper.selectByCheckId(manage.getCheckId());
manage.setMaterialAllotList(pmStockInventoryItems);
}
3.sql,查询条件同一个字段并列,用in 或者or
(1)where item_code = #{itemCode} and bui_type in ('3', '4')
(2)where item_code = #{itemCode} and bui_type ='3' or bui_type = '4'
2. 魔法值,及短信发送
eg: xxx.setFromStatus("0");
提取魔法值:代码中不允许出现魔法值
```java
常量信息中提取定义魔法值
/** 表单状态formStatus(0草稿 1已完成) */
public final static String FROM_STATUS_TWO = "1";
if(UserConstants.FROM_STATUS_TWO.equals(pmBeCompletedBack.getFormStatus())){}
//短信内容可提取出来,以方便维护
private final static String MSG_CONTENT = "您有履约保证金待回收,请在“要求返还日期”之前回收完毕";
//提交操作-发送短信
if(UserConstants.FROM_STATUS_TWO.equals(pmBeCompletedBack.getFormStatus())){
//TODO 项目id暂时无法带出项目经理手机号 chengminqi
List<String> userNumbers = new ArrayList<>();
userNumbers.add("13468569865");
try{
//发送短信
iMmSmsHttpSendService.sendSmsByPost(MSG_CONTENT,userNumbers, MessageType.MESSAGE, new Date(), PassageMode.LOOSE);
}catch (RequiredArgsNotFoundException ex){
ex.printStackTrace();
}
}
3. 多列表,并且每个列表字段都一样,即可把多列表进行融合到一张子表里,用类型进行区分
(1)实体中分别封装列表
//施工方案及预制加工方案-电气列表
private List<PmBuildProcessPlan> buildProcessPlanList;
//施工方案及预制加工方案-管道
private List<PmBuildProcessPlan> pipeList;
//施工方案及预制加工方案-通风
private List<PmBuildProcessPlan> ventilateList;
(2)impl
新增
//施工方案及预制加工方案
List<PmBuildProcessPlan> buildProcessPlanList = pmTechnologyPlan.getBuildProcessPlanList(); //电气
buildProcessPlanList.addAll(pmTechnologyPlan.getPipeList()); //管道
buildProcessPlanList.addAll(pmTechnologyPlan.getVentilateList()); //通风
if(buildProcessPlanList !=null){
for(PmBuildProcessPlan detail : buildProcessPlanList){
detail.setTechnologyPlanId(pmTechnologyPlan.getTechnologyPlanId());
pmBuildProcessPlanMapper.insertPmBuildProcessPlan(detail);
}
}
修改
//施工方案及预制加工方案
List<PmBuildProcessPlan> buildProcessPlanList = pmTechnologyPlan.getBuildProcessPlanList(); //电气
buildProcessPlanList.addAll(pmTechnologyPlan.getPipeList()); //管道
buildProcessPlanList.addAll(pmTechnologyPlan.getVentilateList()); //通风
//先删除
pmBuildProcessPlanMapper.deleteTechnologyPlanById(pmTechnologyPlan.getTechnologyPlanId());
for(PmBuildProcessPlan detail : buildProcessPlanList){
detail.setTechnologyPlanId(pmTechnologyPlan.getTechnologyPlanId());
pmBuildProcessPlanMapper.insertPmBuildProcessPlan(detail);
}
修改查询
//查询技术方案
PmTechnologyPlan pmTechnologyPlan = pmTechnologyPlanMapper.selectPmTechnologyPlanById(technologyPlanId);
//施工方案及预制加工方案
PmBuildProcessPlan pmBuildProcessPlan = new PmBuildProcessPlan();
pmBuildProcessPlan.setTechnologyPlanId(technologyPlanId);
List<PmBuildProcessPlan> list = pmBuildProcessPlanMapper.selectPmBuildProcessPlanList(pmBuildProcessPlan);
List<PmBuildProcessPlan> buildProcessPlanList = new ArrayList<>(); //电气
List<PmBuildProcessPlan> pipeList = new ArrayList<>(); //管道
List<PmBuildProcessPlan> ventilateList = new ArrayList<>(); //通风
for(PmBuildProcessPlan detail: list){
String tableType = detail.getTableType();
switch (tableType){
case "电气": buildProcessPlanList.add(detail); break;
case "管道": pipeList.add(detail); break;
case "通风": ventilateList.add(detail); break;
}
}
pmTechnologyPlan.setBuildProcessPlanList(buildProcessPlanList);
pmTechnologyPlan.setPipeList(pipeList);
pmTechnologyPlan.setVentilateList(ventilateList);
return pmTechnologyPlan;
4. 查询列表,从一个字段类型中分别取不同的类型数据,列表展示
如下图:
(1)实体封装一个数组
//项目分类
private String[] itemTypeArr;
(2) mapper
① 分别写两个sql,总包收款金额,内部独立收款,外部独立收款类型单独提出,剩下公司,合计,返还分公司金额,总公司金额为另一个sql,
②/**
* 查询不同项目分类对应的收款明细
* @param headProjectPayment
* @return
*/
HeadProjectPayment selectPayList(HeadProjectPayment headProjectPayment);
(3) impl
List<HeadProjectPayment> list = headProjectPaymentMapper.selectheadProjectPaymentList(headProjectPayment);
for (HeadProjectPayment projectPayment : list) {
if(StringUtils.isEmpty(projectPayment.getCompanyId())){
continue;
}
//总包
projectPayment.setItemTypeArr(new String[]{"zbnbnbzd", "zbnbnbgk", "zbnbnbjt", "zbnbnbzh", "zbnbnbaz", "zbwbwbzb", "zbwbzbqf"});
HeadProjectPayment result1 = headProjectPaymentMapper.selectPayList(projectPayment);
if(result1 != null){
projectPayment.setBank(result1.getBank());
projectPayment.setAccept(result1.getAccept());
projectPayment.setTicket(result1.getTicket());
projectPayment.setOther(result1.getOther());
projectPayment.setTotal(result1.getTotal());
}
//独立内部
projectPayment.setItemTypeArr(new String[]{"dlnbdlzy", "dlnbdljt", "dlnbdlhk", "dlnbdlzh", "dlnbdlgk"});
HeadProjectPayment result2 = headProjectPaymentMapper.selectPayList(projectPayment);
if(result2 != null){
projectPayment.setBankNB(result2.getBank());
projectPayment.setAcceptNB(result2.getAccept());
projectPayment.setTicketNB(result2.getTicket());
projectPayment.setOtherNB(result2.getOther());
projectPayment.setTotalNB(result2.getTotal());
}
//独立外部
projectPayment.setItemTypeArr(new String[]{"dlwb"});
HeadProjectPayment result3 = headProjectPaymentMapper.selectPayList(projectPayment);
if(result3 !=null){
projectPayment.setBankWB(result3.getBank());
projectPayment.setAcceptWB(result3.getAccept());
projectPayment.setTicketWB(result3.getTicket());
projectPayment.setOtherWB(result3.getOther());
projectPayment.setTotalWB(result3.getTotal());
}
}
return list;
(4)xml
```xml
注意:公司,合计,返还分公司金额,总公司金额为另一个sql略。。。
<select id="selectPayList" parameterType="com.znerp.analysisreport.domain.HeadProjectPayment" resultMap="headProjectPaymentResult">
select
nvl(sum(pca.bank), 0) as bank,
nvl(sum(pca.accept), 0) as accept,
nvl(sum(pca.ticket), 0) as ticket,
nvl(sum(pca.other), 0) as other,
nvl(sum(pca.total), 0) as total
from
pm_project_collection_actual pca
left join pm_project_collection pc on pc.id = pca.collection_id
left join pm_project_output po on po.project_output_id = pc.project_output_id
left join mm_item mi on mi.item_id = po.project_id
where mi.company_id = #{companyId} and mi.item_type in
<foreach item="itemType" collection="itemTypeArr" open="(" separator="," close=")">
#{itemType}
</foreach>
</select>
5. sql取交集,并集
union all 取两张表的交集
union 取两张表的并集
select distinct
to_char(draw_due_time, 'yyyy-MM') as receive_time
from
cm_trade_accept_receivable
union
select distinct
to_char(due_date, 'yyyy-MM') as receive_time
from
cm_pay_business_ticket
6. sql中replace替换函数
replace(original-string,search-string,replace-string)
参数说明:original-string被搜索的字符串。可为任意长度。 search-string要搜索并被 replace-string
替换的字符串 replace-string该字符串用于替换 search-string
replace(p.net_silver_ratio, '%', '')
p.net_silver_ratio为带有百分号的字符串 eg: p.net_silver_ratio= 50% 将百分号替换为'' 最终结果为 50
案例:
select
nvl(sum(((po.output_value - po.account_receivable) * replace(p.net_silver_ratio, '%', '') /100)), 0) as netSilverMoney,
nvl(sum(((po.output_value - po.account_receivable) * replace(p.accept_ratio, '%', '') / 100)), 0)as acceptUnexpired,
nvl(sum(((po.output_value - po.account_receivable) * replace(p.business_ticket_ratio, '%', '') / 100)), 0)as ticketUnexpired,
nvl(sum(((po.output_value - po.account_receivable) * replace(p.room_ratio, '%', '') / 100)), 0)as mortgagedUnexpired,
nvl(sum(((po.output_value - po.account_receivable) * replace(p.other_ratio, '%', '') / 100)), 0)as otherUnexpired
from pm_project_output p
left join pm_project_output_detail po on po.project_output_id = p.project_output_id
where p.project_id = '8ECEE39D2F9040F8BDB7370426D74A75' and po.table_type = '本月数' and po.report_type = '甲方确认产值' and p.form_status = '1'
7. sql 条件语句 case when 用法(满足多条件)
相当于if…else if… else
case when 条件 then ‘值’
when 条件 then '值'
else '值' end
注: THEN后边的值与ELSE后边的值类型应一致
例如:
(CASE WHEN bo.win_bid_flag = '1' THEN '分包履约保证金'
WHEN bo.win_bid_flag = '0' and bo.eliminate_flag = '1' THEN '分包投标保证金'
else p.margin_type END)as margin_type
8. sql 条件语句 choose when otherwise 用法(满足多条件)
类似于 switch…case…
<choose>
<when test="条件1 != null and 条件1">
and 表达式1
</when>
<when test="条件2 != null and 条件2">
and 表达式2
</when>
<otherwise>
<if test="条件3 != null and 条件3 != ''">
and 表达式 is null
</if>
</otherwise>
</choose>
例如:
<choose>
<!-- 履约保证金 -->
<when test="marginType != null and marginType == '2'.toString()">
and bo.win_bid_flag = '1'
</when>
<when test="marginType != null and marginType == '0'.toString()">
and bo.win_bid_flag = '0' and bo.eliminate_flag = '1'
</when>
<otherwise>
<if test="marginType != null and marginType != ''">
and pb.brkw_id is null
</if>
</otherwise>
</choose>