添加生产报表按月统计

This commit is contained in:
2024-01-08 21:36:12 +08:00
parent 50f5cc26e7
commit b9c1f3d6dd
12 changed files with 1743 additions and 18 deletions

View File

@@ -0,0 +1,54 @@
package cn.lihongjie.coal.coalWashingMonthReport.controller;
import cn.lihongjie.coal.annotation.OrgScope;
import cn.lihongjie.coal.annotation.SysLog;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.coalWashingMonthReport.dto.CoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.dto.CreateCoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.dto.UpdateCoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.service.CoalWashingMonthReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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.RestController;
@RestController
@RequestMapping("/coalWashingMonthReport")
@SysLog(module = "生产月报表")
@Slf4j
@OrgScope
public class CoalWashingMonthReportController {
@Autowired private CoalWashingMonthReportService service;
@PostMapping("/create")
public CoalWashingMonthReportDto create(@RequestBody CreateCoalWashingMonthReportDto request) {
return this.service.create(request);
}
@PostMapping("/update")
public CoalWashingMonthReportDto update(@RequestBody UpdateCoalWashingMonthReportDto request) {
return this.service.update(request);
}
@PostMapping("/delete")
public Object delete(@RequestBody IdRequest request) {
this.service.delete(request);
return true;
}
@PostMapping("/getById")
public CoalWashingMonthReportDto getById(@RequestBody IdRequest request) {
return this.service.getById(request.getId());
}
@PostMapping("/list")
public Page<CoalWashingMonthReportDto> list(@RequestBody CommonQuery request) {
return this.service.list(request);
}
}

View File

@@ -0,0 +1,21 @@
package cn.lihongjie.coal.coalWashingMonthReport.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.time.LocalDate;
@Data
public class CoalWashingMonthReportDto extends OrgCommonDto {
@Comment("日期")
private LocalDate date;
private String remark1;
private String remark2;
private String remark3;
private String remark4;
}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.coalWashingMonthReport.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
@Data
public class CreateCoalWashingMonthReportDto extends OrgCommonDto {}

View File

@@ -0,0 +1,8 @@
package cn.lihongjie.coal.coalWashingMonthReport.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import lombok.Data;
@Data
public class UpdateCoalWashingMonthReportDto extends OrgCommonDto {}

View File

@@ -0,0 +1,56 @@
package cn.lihongjie.coal.coalWashingMonthReport.entity;
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import jakarta.persistence.Entity;
import lombok.Data;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Subselect;
import java.time.LocalDate;
@Data
@Entity
@Subselect("""
select d.organization_id,
d.name,
'' as code,
'' as remarks,
0 as sort_key,
0 as status,
date_trunc('month', d.date) as date,
sum(case
when d.remark1 is null or d.remark1 = '' then null
else d.remark1::numeric end) as remark1,
sum(case
when d.remark2 is null or d.remark2 = '' then null
else d.remark2::numeric end) as remark2,
round(sum(case when d.remark2 is null or d.remark2 = '' then null else d.remark2::numeric end) /
sum(case when d.remark1 is null or d.remark1 = '' then null else d.remark1::numeric end) * 100,
2) as remark3,
date_trunc('month', d.date) as create_time,
date_trunc('month', d.date) as update_time,
'' as create_user_id,
'' as update_user_id,
null as file_ids
from t_coal_washing_daily_analysis d
group by d.organization_id, d.name, date_trunc('month', d.date)
""")
public class CoalWashingMonthReportEntity extends OrgCommonEntity {
@Comment("日期")
private LocalDate date;
private String remark1;
private String remark2;
private String remark3;
private String remark4;
}

View File

@@ -0,0 +1,23 @@
package cn.lihongjie.coal.coalWashingMonthReport.mapper;
import cn.lihongjie.coal.base.mapper.BaseMapper;
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.coalWashingMonthReport.dto.CoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.dto.CreateCoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.dto.UpdateCoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.entity.CoalWashingMonthReportEntity;
import org.mapstruct.Mapper;
import org.mapstruct.control.DeepClone;
@Mapper(
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class, CommonEntityMapper.class},
mappingControl = DeepClone.class)
public interface CoalWashingMonthReportMapper
extends BaseMapper<
CoalWashingMonthReportEntity,
CoalWashingMonthReportDto,
CreateCoalWashingMonthReportDto,
UpdateCoalWashingMonthReportDto> {}

View File

@@ -0,0 +1,10 @@
package cn.lihongjie.coal.coalWashingMonthReport.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.coalWashingMonthReport.entity.CoalWashingMonthReportEntity;
import org.springframework.stereotype.Repository;
@Repository
public interface CoalWashingMonthReportRepository
extends BaseRepository<CoalWashingMonthReportEntity> {}

View File

@@ -0,0 +1,71 @@
package cn.lihongjie.coal.coalWashingMonthReport.service;
import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.coalWashingMonthReport.dto.CoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.dto.CreateCoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.dto.UpdateCoalWashingMonthReportDto;
import cn.lihongjie.coal.coalWashingMonthReport.entity.CoalWashingMonthReportEntity;
import cn.lihongjie.coal.coalWashingMonthReport.mapper.CoalWashingMonthReportMapper;
import cn.lihongjie.coal.coalWashingMonthReport.repository.CoalWashingMonthReportRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Slf4j
@Transactional
public class CoalWashingMonthReportService
extends BaseService<CoalWashingMonthReportEntity, CoalWashingMonthReportRepository> {
@Autowired private CoalWashingMonthReportRepository repository;
@Autowired private CoalWashingMonthReportMapper mapper;
@Autowired private ConversionService conversionService;
public CoalWashingMonthReportDto create(CreateCoalWashingMonthReportDto request) {
CoalWashingMonthReportEntity entity = mapper.toEntity(request);
this.repository.save(entity);
return getById(entity.getId());
}
public CoalWashingMonthReportDto update(UpdateCoalWashingMonthReportDto request) {
CoalWashingMonthReportEntity entity = this.repository.get(request.getId());
this.mapper.updateEntity(entity, request);
this.repository.save(entity);
return getById(entity.getId());
}
public void delete(IdRequest request) {
this.repository.deleteAllById(request.getIds());
}
public CoalWashingMonthReportDto getById(String id) {
CoalWashingMonthReportEntity entity = repository.get(id);
return mapper.toDto(entity);
}
public Page<CoalWashingMonthReportDto> list(CommonQuery query) {
Page<CoalWashingMonthReportEntity> page =
repository.findAll(
query.specification(conversionService),
PageRequest.of(
query.getPageNo(),
query.getPageSize(),
Sort.by(query.getOrders())));
return page.map(this.mapper::toDto);
}
}

View File

@@ -32,66 +32,66 @@ public class InventoryCheckEntity extends OrgCommonEntity {
/** 精煤 合计 */
@Formula(
"""
select sum(amount) from t_inventory_check_detail d
(
select sum(d.amount) from t_inventory_check_detail d
left join t_coal_info c on d.coal_info_id = c.id
left join t_product p on d.product_id = p.id
where (c.coal_type = '0' or p.coal_type = '0') and d.inventory_check_id = id
""")
)""")
private Long sum0;
/** 中煤 合计 */
@Formula(
"""
select sum(amount) from t_inventory_check_detail d
(
select sum(d.amount) from t_inventory_check_detail d
left join t_coal_info c on d.coal_info_id = c.id
left join t_product p on d.product_id = p.id
where (c.coal_type = '1' or p.coal_type = '1') and d.inventory_check_id = id
""")
)""")
private Long sum1;
/** 原煤 合计 */
@Formula(
"""
select sum(amount) from t_inventory_check_detail d
(
select sum(d.amount) from t_inventory_check_detail d
left join t_coal_info c on d.coal_info_id = c.id
left join t_product p on d.product_id = p.id
where (c.coal_type = '2' or p.coal_type = '2') and d.inventory_check_id = id
""")
)""")
private Long sum2;
/** 煤泥 合计 */
@Formula(
"""
select sum(amount) from t_inventory_check_detail d
(
select sum(d.amount) from t_inventory_check_detail d
left join t_coal_info c on d.coal_info_id = c.id
left join t_product p on d.product_id = p.id
where (c.coal_type = '3' or p.coal_type = '3') and d.inventory_check_id = id
""")
)""")
private Long sum3;
/** 矸石 合计 */
@Formula(
"""
select sum(amount) from t_inventory_check_detail d
(
select sum(d.amount) from t_inventory_check_detail d
left join t_coal_info c on d.coal_info_id = c.id
left join t_product p on d.product_id = p.id
where (c.coal_type = '4' or p.coal_type = '4') and d.inventory_check_id = id
""")
)""")
private Long sum4;
/** 其他 合计 */
@Formula(
"""
select sum(amount) from t_inventory_check_detail d
(
select sum(d.amount) from t_inventory_check_detail d
left join t_coal_info c on d.coal_info_id = c.id
left join t_product p on d.product_id = p.id
where (c.coal_type = '5' or p.coal_type = '5') and d.inventory_check_id = id
""")
)""")
private Long sum5;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,30 @@
package scripts.dict
import cn.lihongjie.coal.base.dto.CommonQuery
import cn.lihongjie.coal.base.dto.TreeDto
import cn.lihongjie.coal.coalInfo.controller.CoalInfoController
import org.springframework.context.ApplicationContext
ApplicationContext ioc = ioc
def controller = ioc.getBean(CoalInfoController.class)
def groupBy = controller.list(new CommonQuery()).content.groupBy { it -> it.getCoalTypeName() }
return groupBy.collect { key, value ->
def treeDto = new TreeDto()
treeDto.setName(key)
treeDto.setId(key)
treeDto.setChildren(value.collect { it ->
def child = new TreeDto()
child.setName(it.getName())
child.setId(it.getId())
})
}

View File

@@ -0,0 +1,30 @@
package scripts.dict
import cn.lihongjie.coal.base.dto.CommonQuery
import cn.lihongjie.coal.base.dto.TreeDto
import cn.lihongjie.coal.product.controller.ProductController
import org.springframework.context.ApplicationContext
ApplicationContext ioc = ioc
def controller = ioc.getBean(ProductController.class)
def groupBy = controller.list(new CommonQuery()).content.groupBy { it -> it.getCoalTypeName() }
return groupBy.collect { key, value ->
def treeDto = new TreeDto()
treeDto.setName(key)
treeDto.setId(key)
treeDto.setChildren(value.collect { it ->
def child = new TreeDto()
child.setName(it.getName())
child.setId(it.getId())
})
}