# SalesController.java

    package cloud.wconnect.workperformance.controller.mor.salessources;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.workperformance.pojo.dto.mor.sales.SalesPropertyDTO;
    import cloud.wconnect.workperformance.pojo.dto.mor.sales.SalesYearTotalDTO;
    import cloud.wconnect.workperformance.pojo.dto.mor.sales.SaveSalesDTO;
    import cloud.wconnect.workperformance.pojo.query.mor.sales.SalesQuery;
    import cloud.wconnect.workperformance.service.mor.ISalesService;
    import com.google.common.collect.Sets;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.List;
    import java.util.Map;

    /**
     * <p>
     * 控制器类：销售信息
     * </p>
     *
     * @author zc
     * @since 2023-04-04
     */
    @RestController
    @RequestMapping("/mor/sales-sources")
    public class SalesController {

        @Resource
        private ISalesService salesService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 获取 sales sources 列表数据
         *
         * @param salesQuery 查询条件
         * @return sales sources
         * @author zc
         * @date 2023/4/4
         */
        @ApiId(271)
        @GetMapping
        public List<SalesPropertyDTO> list(@Valid SalesQuery salesQuery) {
            if (!Sets.newHashSet(sessionContext.getPropertyIds()).containsAll(salesQuery.getPropertyIds())) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(),
                        "Cannot be operated others property data; propertyIds: " + salesQuery.getPropertyIds());
            }
            return salesService.list(salesQuery);
        }

        /**
         * 保存 sales sources 金额
         *
         * @param property     资产标识
         * @param saveSalesDTO 保存内容
         * @return empty map
         * @author zc
         * @date 2023/4/4
         */
        @ApiId(272)
        @PostMapping
        public Map<Object, Object> save(@RequestParam String property, @RequestBody @Valid SaveSalesDTO saveSalesDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            salesService.save(propertyId, saveSalesDTO, sessionContext.getLoginUserId());
            return Collections.emptyMap();
        }

        /**
         * 获取年对应金额
         *
         * @param property 资产标识
         * @return 年对应金额
         * @author zc
         * @date 2023/4/4
         */
        @ApiId(273)
        @GetMapping("/year")
        public List<SalesYearTotalDTO> listYearTotal(@RequestParam String property) {
            int propertyId = sessionContext.getPropertyId(property);
            return salesService.listYearTotal(propertyId);
        }
    }